Commit 400672496068037ee3d5b358ffc5bfd550be86cb

Authored by Benjamin Renard
1 parent 7e8a899e

Update EPN/TAP granules generation

Showing 1 changed file with 85 additions and 8 deletions   Show diff stats
update_amda/makeEPNTAPGranules.php
... ... @@ -2,6 +2,8 @@
2 2  
3 3 //error_reporting(E_ERROR);
4 4  
  5 +date_default_timezone_set("UTC");
  6 +
5 7 $localparams_tree = getenv('LocalData')."/LocalParams.xml";
6 8 $output_file = getenv('EPNTAPData')."/amda-granules.csv";
7 9 $ddservice_wsdl = getenv('DD_WSDL');
... ... @@ -54,7 +56,7 @@ $mapping = array(
54 56 'modification_date' => '@@modification_date@@',
55 57 'release_date' => '@@release_date@@',
56 58 'service_title' => 'AMDADB',
57   - 'access_url' => '@@amda_rest_api_entry_point@@getGranule.php?obs_id=@@dataset_id@@&start=@@granule_start_time_timestamp@@&stop=@@granule_stop_time_timestamp@@&format=CDF',
  59 + 'access_url' => '@@amda_rest_api_entry_point@@getGranule.php?obs_id=@@dataset_id@@&start=@@granule_start_time_timestamp@@&stop=@@granule_stop_time_timestamp@@',
58 60 'access_format' => 'application/x-cdf-istp',
59 61 'target_region' => '@@target_region@@',
60 62 'publisher' => 'CDPP',
... ... @@ -94,14 +96,61 @@ function parseProcessingLevel($info) {
94 96 return '3';
95 97 }
96 98  
97   -function spaseToEpnTapMeasurementType($measurement_type) {
98   - return $measurement_type;
  99 +function getEpnTapMeasurementType($measurement_type, $UCDs) {
  100 + $generic_ucd = '';
  101 + switch ($measurement_type) {
  102 + case 'ThermalPlasma':
  103 + $generic_ucd = 'phys.flux';
  104 + break;
  105 + case 'IonComposition':
  106 + case 'NeutralGas':
  107 + $generic_ucd = 'phys.composition';
  108 + break;
  109 + case 'EnergeticParticles':
  110 + $generic_ucd = 'phys.particle';
  111 + break;
  112 + case 'Waves':
  113 + case 'Waves.Passive':
  114 + $generic_ucd = 'em.pw';
  115 + break;
  116 + case 'Ephemeris':
  117 + $generic_ucd = 'pos.ephem';
  118 + break;
  119 + case 'ElectricField':
  120 + $generic_ucd = 'phys.electField';
  121 + break;
  122 + case 'MagneticField':
  123 + $generic_ucd = 'phys.magField';
  124 + break;
  125 + case 'Spectrum':
  126 + $generic_ucd = 'spect';
  127 + break;
  128 + case 'InstrumentStatus':
  129 + $generic_ucd = 'instr';
  130 + break;
  131 + case 'Irradiance':
  132 + $generic_ucd = 'phot.flux';
  133 + break;
  134 + case 'Radiance':
  135 + $generic_ucd = 'phot.radiance';
  136 + break;
  137 + default:
  138 + echo "[WARNING] UCD - Unknown measurement type: ".$measurement_type.PHP_EOL;
  139 + break;
  140 + }
  141 + if (!empty($generic_ucd) && !in_array($generic_ucd, $UCDs))
  142 + array_unshift($UCDs, $generic_ucd);
  143 + return implode(';', $UCDs);
99 144 }
100 145  
101 146 function timestampToJulianDay($timestamp) {
102 147 return intval($timestamp) / 86400 + 2440587.5;
103 148 }
104 149  
  150 +function timestampToISO($timestamp) {
  151 + return date("Y-m-d\TH:i:s\Z", $timestamp);
  152 +}
  153 +
105 154 function getTargetClass($spaseRegion) {
106 155 $parts = explode(".", $spaseRegion);
107 156 if (count($parts) < 1) {
... ... @@ -143,6 +192,7 @@ function getTargetName($targetClass, $spaseRegion, $missionName, $dataset_id) {
143 192 }
144 193 switch ($targetClass) {
145 194 case "planet":
  195 + case "satellite":
146 196 if ((count($parts) > 1) && !in_array($parts[1], array("Magnetosheath", "Magnetosphere", "NearSurface", "Surface"))) {
147 197 return $parts[1];
148 198 }
... ... @@ -232,6 +282,8 @@ foreach ($dataset_nodes as $dataset_node) {
232 282 $dataset_place_holders = array();
233 283 //Dataset id
234 284 $datasetId = $dataset_node->getAttribute("xml:id");
  285 + //if ($datasetId != 'psp-het-1hr')
  286 + // continue;
235 287 if (empty($datasetId)) {
236 288 echo "[WARNING] Cannot retrieve dataset id".PHP_EOL;
237 289 continue;
... ... @@ -255,11 +307,27 @@ foreach ($dataset_nodes as $dataset_node) {
255 307 continue;
256 308 }
257 309  
  310 + $UCDs = array();
  311 + $parameter_nodes = $dataset_node->getElementsByTagName("parameter");
  312 + foreach ($parameter_nodes as $parameter_node) {
  313 + $ucd = trim($parameter_node->getAttribute('ucd'));
  314 + if (empty($ucd))
  315 + continue;
  316 + $ucd_list = explode(';', $ucd);
  317 + foreach ($ucd_list as $u) {
  318 + $u = trim($u);
  319 + if (empty($u))
  320 + continue;
  321 + if (!in_array($u, $UCDs))
  322 + $UCDs[] = $u;
  323 + }
  324 + }
  325 +
258 326 $dataset_place_holders['min_sampling'] = parseSampling($dataset_node->getAttribute("sampling"));
259 327 $dataset_place_holders['max_sampling'] = parseSampling($dataset_node->getAttribute("maxSampling"));
260 328 $dataset_place_holders['spase_resource_id'] = $dataset_node->getAttribute("spaseId");
261 329 $dataset_place_holders['spase_measurement_type'] = $dataset_node->getAttribute("measurement_type");
262   - $dataset_place_holders['measurement_type'] = spaseToEpnTapMeasurementType($dataset_place_holders['spase_measurement_type']);
  330 + $dataset_place_holders['measurement_type'] = getEpnTapMeasurementType($dataset_place_holders['spase_measurement_type'], $UCDs);
263 331 $dataset_place_holders['processing_level'] = parseProcessingLevel($dataset_node->getAttribute("xml:id"));
264 332 $target = $dataset_node->getAttribute("target");
265 333  
... ... @@ -315,8 +383,11 @@ foreach ($dataset_nodes as $dataset_node) {
315 383 if (!empty($observatory_node)) {
316 384 $mission_name = $observatory_node->getAttribute('name');
317 385 }
318   - $dataset_place_holders['mission_name'] = $mission_name;
319   - $dataset_place_holders['instrument_name'] = $instrument_name;
  386 + $dataset_place_holders['mission_name'] = utf8_encode($mission_name);
  387 + $dataset_place_holders['instrument_name'] = preg_replace('/[^:\/\(\) \w-]/', ' ', $instrument_name);
  388 + if ($dataset_place_holders['instrument_name'] != $instrument_name) {
  389 + echo "=================> ".$dataset_place_holders['instrument_name'].PHP_EOL;
  390 + }
320 391 if (!empty($dataset_group_node)) {
321 392 if ($dataset_place_holders['processing_level'] == 'L2') {
322 393 $dataset_place_holders['processing_level'] = parseProcessingLevel($dataset_group_node->getAttribute("xml:id"));
... ... @@ -324,7 +395,13 @@ foreach ($dataset_nodes as $dataset_node) {
324 395 }
325 396  
326 397 try {
327   - $vi = str_replace("-","_",$datasetId);
  398 + $prior_id = trim($dataset_node->getAttribute('PriorID'));
  399 + if (!empty($prior_id)) {
  400 + $vi = str_replace("-","_",$prior_id);
  401 + }
  402 + else {
  403 + $vi = str_replace("-","_",$datasetId);
  404 + }
328 405 $res = $client->getGranules($vi);
329 406 }
330 407 catch (SoapFault $exception) {
... ... @@ -347,7 +424,7 @@ foreach ($dataset_nodes as $dataset_node) {
347 424 $granule_place_holders['granule_index'] = str_replace(".nc", "", $granule_info[2]);
348 425 $granule_place_holders['granule_start_time'] = timestampToJulianDay($granule_info[0]);
349 426 $granule_place_holders['granule_stop_time'] = timestampToJulianDay($granule_info[1]);
350   - $granule_place_holders['modification_date'] = timestampToJulianDay($granule_info[3]);
  427 + $granule_place_holders['modification_date'] = timestampToISO($granule_info[3]);
351 428 $granule_place_holders['granule_start_time_timestamp'] = $granule_info[0];
352 429 $granule_place_holders['granule_stop_time_timestamp'] = $granule_info[1];
353 430 $granule_place_holders['creation_date'] = $granule_place_holders['modification_date'];
... ...