Commit a63e610847e41910a5b240192ce9ea227b692e26

Authored by Myriam Bouchemit
1 parent fa5a398d

Fix scripts for HAPI & EPN-TAP (cf. #11867)

update_amda/makeEPNTAPGranules.php
@@ -41,7 +41,7 @@ $mapping = array( @@ -41,7 +41,7 @@ $mapping = array(
41 'c2_resol_max' => '', 41 'c2_resol_max' => '',
42 'c3_resol_min' => '', 42 'c3_resol_min' => '',
43 'c3_resol_max' => '', 43 'c3_resol_max' => '',
44 - 'spatial_frame_type' => '', 44 + 'spatial_frame_type' => 'none',
45 'incidence_min' => '', 45 'incidence_min' => '',
46 'incidence_max' => '', 46 'incidence_max' => '',
47 'emergence_min' => '', 47 'emergence_min' => '',
@@ -55,7 +55,7 @@ $mapping = array( @@ -55,7 +55,7 @@ $mapping = array(
55 'creation_date' => '@@creation_date@@', 55 'creation_date' => '@@creation_date@@',
56 'modification_date' => '@@modification_date@@', 56 'modification_date' => '@@modification_date@@',
57 'release_date' => '@@release_date@@', 57 'release_date' => '@@release_date@@',
58 - 'service_title' => 'AMDADB', 58 + 'service_title' => 'amdadb',
59 'access_url' => '@@amda_rest_api_entry_point@@getGranule.php?obs_id=@@dataset_id@@&start=@@granule_start_time_timestamp@@&stop=@@granule_stop_time_timestamp@@', 59 'access_url' => '@@amda_rest_api_entry_point@@getGranule.php?obs_id=@@dataset_id@@&start=@@granule_start_time_timestamp@@&stop=@@granule_stop_time_timestamp@@',
60 'access_format' => 'application/x-cdf-istp', 60 'access_format' => 'application/x-cdf-istp',
61 'target_region' => '@@target_region@@', 61 'target_region' => '@@target_region@@',
@@ -86,14 +86,15 @@ function parseSampling($sampling) { @@ -86,14 +86,15 @@ function parseSampling($sampling) {
86 } 86 }
87 } 87 }
88 88
89 -function parseProcessingLevel($info) {  
90 - if (strpos($info, 'L1') !== FALSE) {  
91 - return '2';  
92 - }  
93 - if (strpos($info, 'L3') !== FALSE) {  
94 - return '5'; 89 +function parseProcessingLevel($processing_level) {
  90 + switch ($processing_level) {
  91 + case 'Uncalibrated':
  92 + return '2';
  93 + case 'ValueAdded':
  94 + return '5';
  95 + default:
  96 + return '3';
95 } 97 }
96 - return '3';  
97 } 98 }
98 99
99 function getEpnTapMeasurementType($measurement_type, $UCDs) { 100 function getEpnTapMeasurementType($measurement_type, $UCDs) {
@@ -104,14 +105,14 @@ function getEpnTapMeasurementType($measurement_type, $UCDs) { @@ -104,14 +105,14 @@ function getEpnTapMeasurementType($measurement_type, $UCDs) {
104 break; 105 break;
105 case 'IonComposition': 106 case 'IonComposition':
106 case 'NeutralGas': 107 case 'NeutralGas':
107 - $generic_ucd = 'phys.composition'; 108 + $generic_ucd = 'phys';
108 break; 109 break;
109 case 'EnergeticParticles': 110 case 'EnergeticParticles':
110 - $generic_ucd = 'phys.particle'; 111 + $generic_ucd = 'phys';
111 break; 112 break;
112 case 'Waves': 113 case 'Waves':
113 case 'Waves.Passive': 114 case 'Waves.Passive':
114 - $generic_ucd = 'em.pw'; 115 + $generic_ucd = 'phys';
115 break; 116 break;
116 case 'Ephemeris': 117 case 'Ephemeris':
117 $generic_ucd = 'pos.ephem'; 118 $generic_ucd = 'pos.ephem';
@@ -138,9 +139,10 @@ function getEpnTapMeasurementType($measurement_type, $UCDs) { @@ -138,9 +139,10 @@ function getEpnTapMeasurementType($measurement_type, $UCDs) {
138 echo "[WARNING] UCD - Unknown measurement type: ".$measurement_type.PHP_EOL; 139 echo "[WARNING] UCD - Unknown measurement type: ".$measurement_type.PHP_EOL;
139 break; 140 break;
140 } 141 }
141 - if (!empty($generic_ucd) && !in_array($generic_ucd, $UCDs)) 142 + if (!empty($generic_ucd) && !in_array($generic_ucd, $UCDs)) {
142 array_unshift($UCDs, $generic_ucd); 143 array_unshift($UCDs, $generic_ucd);
143 - return implode(';', $UCDs); 144 + }
  145 + return implode('#', $UCDs);
144 } 146 }
145 147
146 function timestampToJulianDay($timestamp) { 148 function timestampToJulianDay($timestamp) {
@@ -161,6 +163,7 @@ function getTargetClass($spaseRegion) { @@ -161,6 +163,7 @@ function getTargetClass($spaseRegion) {
161 case "Asteroid": 163 case "Asteroid":
162 return "asteroid"; 164 return "asteroid";
163 case "Comet": 165 case "Comet":
  166 + case "Rosetta@C-G":
164 return "comet"; 167 return "comet";
165 case "Earth": 168 case "Earth":
166 case "Jupiter": 169 case "Jupiter":
@@ -180,6 +183,12 @@ function getTargetClass($spaseRegion) { @@ -180,6 +183,12 @@ function getTargetClass($spaseRegion) {
180 return "interplanetary_medium"; 183 return "interplanetary_medium";
181 case "Sun": 184 case "Sun":
182 return "star"; 185 return "star";
  186 + case "Bepi":
  187 + case "Juno":
  188 + case "SolO":
  189 + case "PSP":
  190 + case "Cassini":
  191 + return "spacecraft";
183 } 192 }
184 echo "[WARNING] Error in ObservatoryRegion definition : ".$spaseRegion.PHP_EOL; 193 echo "[WARNING] Error in ObservatoryRegion definition : ".$spaseRegion.PHP_EOL;
185 return "planet"; 194 return "planet";
@@ -203,6 +212,7 @@ function getTargetName($targetClass, $spaseRegion, $missionName, $dataset_id) { @@ -203,6 +212,7 @@ function getTargetName($targetClass, $spaseRegion, $missionName, $dataset_id) {
203 case "comet": 212 case "comet":
204 switch ($missionName) { 213 switch ($missionName) {
205 case "Rosetta": 214 case "Rosetta":
  215 + case "Rosetta@C-G":
206 return "67P"; 216 return "67P";
207 case "Giotto": 217 case "Giotto":
208 return "1P"; 218 return "1P";
@@ -213,9 +223,21 @@ function getTargetName($targetClass, $spaseRegion, $missionName, $dataset_id) { @@ -213,9 +223,21 @@ function getTargetName($targetClass, $spaseRegion, $missionName, $dataset_id) {
213 case "ICE": 223 case "ICE":
214 if ($dataset_id == "ice-mag-p21") 224 if ($dataset_id == "ice-mag-p21")
215 return "21P"; 225 return "21P";
  226 + case "Solar Wind Propagation Models":
  227 + if (in_array($dataset_id, array("bls-ros-omni", "tao-ros-sw")))
  228 + return "67P";
216 } 229 }
217 - echo "[WARNING] Comet Id not defined for mission : ".$missionName.PHP_EOL; 230 + echo "[WARNING] Comet Id not defined for mission : ".$missionName." - ".$dataset_id.PHP_EOL;
218 return ""; 231 return "";
  232 + case "spacecraft":
  233 + switch ($spaseRegion) {
  234 + case "SolO":
  235 + return "SolarOrbiter";
  236 + case "Bepi":
  237 + return "BepiColombo";
  238 + default:
  239 + return $spaseRegion;
  240 + }
219 } 241 }
220 echo "[WARNING] Cannot retrieve target name from target class : ".$targetClass.PHP_EOL; 242 echo "[WARNING] Cannot retrieve target name from target class : ".$targetClass.PHP_EOL;
221 return ""; 243 return "";
@@ -276,13 +298,13 @@ $xpath = new DOMXpath($doc); @@ -276,13 +298,13 @@ $xpath = new DOMXpath($doc);
276 $output_file_handle = fopen($output_file, 'w'); 298 $output_file_handle = fopen($output_file, 'w');
277 fputcsv($output_file_handle, array_keys($mapping)); 299 fputcsv($output_file_handle, array_keys($mapping));
278 300
279 -$dataset_nodes = $xpath->query("/dataRoot/dataCenter/mission/instrument/dataset | /dataRoot/dataCenter/mission/observatory/instrument/dataset | /dataRoot/dataCenter/mission/instrument/datasetGroup/dataset"); 301 +$dataset_nodes = $xpath->query("/dataRoot/dataCenter/mission/instrument/dataset | /dataRoot/dataCenter/mission/observatory/instrument/dataset | /dataRoot/dataCenter/mission/instrument/datasetGroup/dataset | /dataRoot/dataCenter/mission/observatory/instrument/datasetGroup/dataset");
280 $datasets = array(); 302 $datasets = array();
281 foreach ($dataset_nodes as $dataset_node) { 303 foreach ($dataset_nodes as $dataset_node) {
282 $dataset_place_holders = array(); 304 $dataset_place_holders = array();
283 //Dataset id 305 //Dataset id
284 $datasetId = $dataset_node->getAttribute("xml:id"); 306 $datasetId = $dataset_node->getAttribute("xml:id");
285 - //if ($datasetId != 'psp-het-1hr') 307 + //if ($datasetId != 'so-pas-mom')
286 // continue; 308 // continue;
287 if (empty($datasetId)) { 309 if (empty($datasetId)) {
288 echo "[WARNING] Cannot retrieve dataset id".PHP_EOL; 310 echo "[WARNING] Cannot retrieve dataset id".PHP_EOL;
@@ -293,11 +315,17 @@ foreach ($dataset_nodes as $dataset_node) { @@ -293,11 +315,17 @@ foreach ($dataset_nodes as $dataset_node) {
293 //Exclude dataset with group 315 //Exclude dataset with group
294 $to_exclude = FALSE; 316 $to_exclude = FALSE;
295 $crt_node = $dataset_node; 317 $crt_node = $dataset_node;
  318 + $time_restriction = 0;
296 while (($crt_node != NULL) && !$to_exclude) { 319 while (($crt_node != NULL) && !$to_exclude) {
297 if ($crt_node->nodeType == XML_ELEMENT_NODE) { 320 if ($crt_node->nodeType == XML_ELEMENT_NODE) {
298 $group = $crt_node->getAttribute("group"); 321 $group = $crt_node->getAttribute("group");
299 if (!empty($group)) { 322 if (!empty($group)) {
300 - $to_exclude = TRUE; 323 + $restriction = $crt_node->getAttribute("restriction");
  324 + if (empty($restriction))
  325 + $to_exclude = TRUE;
  326 + $time_restriction = strtotime($restriction);
  327 + if ($time_restriction === FALSE)
  328 + $to_exclude = TRUE;
301 } 329 }
302 } 330 }
303 $crt_node = $crt_node->parentNode; 331 $crt_node = $crt_node->parentNode;
@@ -313,22 +341,28 @@ foreach ($dataset_nodes as $dataset_node) { @@ -313,22 +341,28 @@ foreach ($dataset_nodes as $dataset_node) {
313 $ucd = trim($parameter_node->getAttribute('ucd')); 341 $ucd = trim($parameter_node->getAttribute('ucd'));
314 if (empty($ucd)) 342 if (empty($ucd))
315 continue; 343 continue;
316 - $ucd_list = explode(';', $ucd); 344 + if (!in_array($ucd, $UCDs)) {
  345 + $UCDs[] = $ucd;
  346 + }
  347 + /*$ucd_list = explode(';', $ucd);
317 foreach ($ucd_list as $u) { 348 foreach ($ucd_list as $u) {
318 $u = trim($u); 349 $u = trim($u);
319 if (empty($u)) 350 if (empty($u))
320 continue; 351 continue;
321 if (!in_array($u, $UCDs)) 352 if (!in_array($u, $UCDs))
322 $UCDs[] = $u; 353 $UCDs[] = $u;
323 - } 354 + }*/
324 } 355 }
325 356
326 $dataset_place_holders['min_sampling'] = parseSampling($dataset_node->getAttribute("sampling")); 357 $dataset_place_holders['min_sampling'] = parseSampling($dataset_node->getAttribute("sampling"));
327 $dataset_place_holders['max_sampling'] = parseSampling($dataset_node->getAttribute("maxSampling")); 358 $dataset_place_holders['max_sampling'] = parseSampling($dataset_node->getAttribute("maxSampling"));
  359 + if (empty($dataset_place_holders['max_sampling'])) {
  360 + $dataset_place_holders['max_sampling'] = $dataset_place_holders['min_sampling'];
  361 + }
328 $dataset_place_holders['spase_resource_id'] = $dataset_node->getAttribute("spaseId"); 362 $dataset_place_holders['spase_resource_id'] = $dataset_node->getAttribute("spaseId");
329 $dataset_place_holders['spase_measurement_type'] = $dataset_node->getAttribute("measurement_type"); 363 $dataset_place_holders['spase_measurement_type'] = $dataset_node->getAttribute("measurement_type");
330 $dataset_place_holders['measurement_type'] = getEpnTapMeasurementType($dataset_place_holders['spase_measurement_type'], $UCDs); 364 $dataset_place_holders['measurement_type'] = getEpnTapMeasurementType($dataset_place_holders['spase_measurement_type'], $UCDs);
331 - $dataset_place_holders['processing_level'] = parseProcessingLevel($dataset_node->getAttribute("xml:id")); 365 + $dataset_place_holders['processing_level'] = parseProcessingLevel($dataset_node->getAttribute("processing_level"));
332 $target = $dataset_node->getAttribute("target"); 366 $target = $dataset_node->getAttribute("target");
333 367
334 368
@@ -384,13 +418,16 @@ foreach ($dataset_nodes as $dataset_node) { @@ -384,13 +418,16 @@ foreach ($dataset_nodes as $dataset_node) {
384 $mission_name = $observatory_node->getAttribute('name'); 418 $mission_name = $observatory_node->getAttribute('name');
385 } 419 }
386 $dataset_place_holders['mission_name'] = utf8_encode($mission_name); 420 $dataset_place_holders['mission_name'] = utf8_encode($mission_name);
  421 + if ($dataset_node->getAttribute('simulation') == '1') {
  422 + $dataset_place_holders['mission_name'] = 'Simulation';
  423 + }
387 $dataset_place_holders['instrument_name'] = preg_replace('/[^:\/\(\) \w-]/', ' ', $instrument_name); 424 $dataset_place_holders['instrument_name'] = preg_replace('/[^:\/\(\) \w-]/', ' ', $instrument_name);
388 if ($dataset_place_holders['instrument_name'] != $instrument_name) { 425 if ($dataset_place_holders['instrument_name'] != $instrument_name) {
389 - echo "=================> ".$dataset_place_holders['instrument_name'].PHP_EOL;  
390 - }  
391 - if (!empty($dataset_group_node)) {  
392 - if ($dataset_place_holders['processing_level'] == 'L2') {  
393 - $dataset_place_holders['processing_level'] = parseProcessingLevel($dataset_group_node->getAttribute("xml:id")); 426 + if ($dataset_place_holders['instrument_name'] == "IS IS EPI-Lo") {
  427 + $dataset_place_holders['instrument_name'] = "ISOIS EPI-Lo";
  428 + }
  429 + else if ($dataset_place_holders['instrument_name'] == "IS IS EPI-Hi") {
  430 + $dataset_place_holders['instrument_name'] = "ISOIS EPI-Hi";
394 } 431 }
395 } 432 }
396 433
@@ -424,6 +461,16 @@ foreach ($dataset_nodes as $dataset_node) { @@ -424,6 +461,16 @@ foreach ($dataset_nodes as $dataset_node) {
424 $granule_place_holders['granule_index'] = str_replace(".nc", "", $granule_info[2]); 461 $granule_place_holders['granule_index'] = str_replace(".nc", "", $granule_info[2]);
425 $granule_place_holders['granule_start_time'] = timestampToJulianDay($granule_info[0]); 462 $granule_place_holders['granule_start_time'] = timestampToJulianDay($granule_info[0]);
426 $granule_place_holders['granule_stop_time'] = timestampToJulianDay($granule_info[1]); 463 $granule_place_holders['granule_stop_time'] = timestampToJulianDay($granule_info[1]);
  464 + if ($granule_place_holders['granule_start_time'] > $granule_place_holders['granule_stop_time']) {
  465 + echo "[ERROR] Bad start/stop definition for granule ".$granule_place_holders['granule_index']." of ".$datasetId.PHP_EOL;
  466 + continue;
  467 + }
  468 + if (!empty($time_restriction)) {
  469 + // Exclude restricted granules
  470 + if (intval($granule_info[1]) > $time_restriction) {
  471 + continue;
  472 + }
  473 + }
427 $granule_place_holders['modification_date'] = timestampToISO($granule_info[3]); 474 $granule_place_holders['modification_date'] = timestampToISO($granule_info[3]);
428 $granule_place_holders['granule_start_time_timestamp'] = $granule_info[0]; 475 $granule_place_holders['granule_start_time_timestamp'] = $granule_info[0];
429 $granule_place_holders['granule_stop_time_timestamp'] = $granule_info[1]; 476 $granule_place_holders['granule_stop_time_timestamp'] = $granule_info[1];
update_amda/makeHAPIMetadata.php
@@ -9,10 +9,9 @@ $output_file = getenv('HAPIData')."/metadata/amda-catalog.json"; @@ -9,10 +9,9 @@ $output_file = getenv('HAPIData')."/metadata/amda-catalog.json";
9 $doc = new DOMDocument(); 9 $doc = new DOMDocument();
10 @$doc->load($localparams_tree); 10 @$doc->load($localparams_tree);
11 11
12 -  
13 $xpath = new DOMXpath($doc); 12 $xpath = new DOMXpath($doc);
14 13
15 -$dataset_nodes = $xpath->query("/dataRoot/dataCenter/mission/instrument/dataset | /dataRoot/dataCenter/mission/observatory/instrument/dataset | /dataRoot/dataCenter/mission/instrument/datasetGroup/dataset"); 14 +$dataset_nodes = $xpath->query("/dataRoot/dataCenter/mission/instrument/dataset | /dataRoot/dataCenter/mission/observatory/instrument/dataset | /dataRoot/dataCenter/mission/instrument/datasetGroup/dataset | /dataRoot/dataCenter/mission/observatory/instrument/datasetGroup/dataset");
16 $datasets = array(); 15 $datasets = array();
17 foreach ($dataset_nodes as $dataset_node) { 16 foreach ($dataset_nodes as $dataset_node) {
18 //Dataset id 17 //Dataset id