Commit 78b305f11943028c5829e97c1b2190acd7be9bc5
1 parent
b3ed6bd4
Exists in
SpeasyGet
For now
Showing
3 changed files
with
83 additions
and
14 deletions
Show diff stats
php/RemoteDataCenter/SPEASY_CDAWEB.php
... | ... | @@ -20,12 +20,78 @@ class SPEASY_CDAWEB extends RemoteDataCenterClientClass |
20 | 20 | |
21 | 21 | protected function makeInternalParamXml($param) |
22 | 22 | { |
23 | - return true; | |
24 | - } | |
23 | + $xml = new DomDocument("1.0"); | |
24 | + $paramNode = $xml->createElement("param"); | |
25 | + $xml->appendChild($paramNode); | |
26 | + | |
27 | + $paramId = $param->getAttribute('xml:id'); | |
28 | + $paramNode->setAttribute("xml:id", $paramId); | |
29 | + | |
30 | + $ViId = substr($param->parentNode->getAttribute('xml:id'), strlen($this->baseID)+1); | |
31 | + | |
32 | + $infoNode = $xml->createElement("info"); | |
33 | + $infoNode->appendChild($xml->createElement("name",$paramId)); | |
34 | + $infoNode->appendChild($xml->createElement("short_name",$param->getAttribute('name'))); | |
35 | + | |
36 | + // $size = $param->getAttribute('size'); | |
37 | + | |
38 | + // //TODO spectra components | |
39 | + // if ($size > 1 && $param->hasAttribute('labels')) | |
40 | + // { | |
41 | + // $components = $param->getAttribute('labels'); | |
42 | + // } | |
43 | + // else { | |
44 | + // $components = null; | |
45 | + // } | |
46 | + | |
47 | + // $infoNode->appendChild($xml->createElement("components",$components)); | |
48 | + // $infoNode->appendChild($xml->createElement("units",$param->getAttribute('units'))); | |
49 | + // $infoNode->appendChild($xml->createElement("coordinates_system")); | |
50 | + // $infoNode->appendChild($xml->createElement("tensor_order")); | |
51 | + // $infoNode->appendChild($xml->createElement("si_conversion")); | |
52 | + // $infoNode->appendChild($xml->createElement("fill_value", $this->fillValue)); | |
53 | + // $infoNode->appendChild($xml->createElement("ucd")); | |
54 | + // $infoNode->appendChild($xml->createElement("dataset_id",strtolower($ViId))); | |
55 | + // $infoNode->appendChild($xml->createElement("instrument_id",strtolower($this->baseID." ".$ViId))); | |
56 | + | |
57 | + $getNode = $xml->createElement("get"); | |
58 | + $speasyNode = $xml->createElement("speasy_proxy"); | |
59 | + $baseParamNode = $xml->createElement("param"); | |
60 | + | |
61 | + $baseParamNode->setAttribute("speasyUID", $param->getAttribute('speasyUID')); | |
62 | + $baseParamNode->setAttribute("minSampling", $param->getAttribute('minSampling')); | |
63 | + $baseParamNode->setAttribute("dim1", $param->getAttribute('dim1')); | |
64 | + $baseParamNode->setAttribute("dim2", $param->getAttribute('dim2')); | |
65 | + $baseParamNode->setAttribute("type", $param->getAttribute('type')); | |
66 | + // $baseParamNode->setAttribute("name", $baseParamName); | |
67 | + // $viNode->setAttribute("name", strtolower(strtr($ViId,"_", ":"))); | |
68 | + $speasyNode->appendChild($baseParamNode); | |
69 | + $getNode->appendChild($speasyNode); | |
70 | + | |
71 | + $paramNode->appendChild($infoNode); | |
72 | + $paramNode->appendChild($getNode); | |
73 | + $paramNode->appendChild($xml->createElement("process")); | |
74 | + $paramNode->appendChild($xml->createElement("output")); | |
75 | + | |
76 | + $xmlNameRemote = RemoteData."/PARAMS/".$paramId.".xml"; | |
77 | + | |
78 | + if (!is_dir(RemoteData."/PARAMS")) | |
79 | + mkdir(RemoteData."/PARAMS", 0775, true); | |
80 | + chmod(RemoteData."/PARAMS", 0775); | |
81 | + | |
82 | + return $xml->save($xmlNameRemote); | |
83 | + } | |
25 | 84 | |
26 | 85 | public function makeAllParams() |
27 | 86 | { |
87 | + $xpath = new DOMXPath($this->baseDom); | |
88 | + $params = $xpath->query("//parameter");//$this->baseDom->getElementsByTagName('parameter'); | |
28 | 89 | |
90 | + foreach ($params as $param) | |
91 | + { | |
92 | + if (!$this->makeInternalParamXml($param)) | |
93 | + echo 'Error while making '.$param->getAttribute('xml:id').PHP_EOL; | |
94 | + } | |
29 | 95 | } |
30 | 96 | |
31 | 97 | // make components description from base.xml | ... | ... |
php/RemoteDataCenter/getRemoteDDBaseProxies.php
... | ... | @@ -54,6 +54,7 @@ |
54 | 54 | |
55 | 55 | // add remote base if it doesn't exist |
56 | 56 | if (!$basesDom->getElementById($baseId)) { |
57 | + echo $baseDir; | |
57 | 58 | if (!is_dir($baseDir)) mkdir($baseDir, 0775, true); |
58 | 59 | chmod($baseDir,0775); |
59 | 60 | if (!copy("$baseDirRemote/base.xml", "$baseDir/base.xml")) { |
... | ... | @@ -63,8 +64,8 @@ |
63 | 64 | $baseClone = $basesDom->importNode($baseRemote); |
64 | 65 | $basesDom->documentElement->appendChild($baseClone); |
65 | 66 | echo "Added $baseId".PHP_EOL; |
66 | - if ($baseId == "THEMIS") { | |
67 | - $center = new THEMIS(); | |
67 | + if ($baseId == "THEMIS" || $baseId == "SPEASY_CDAWEB") { | |
68 | + $center = new $baseId(); | |
68 | 69 | $center->makeAllParams(); |
69 | 70 | } |
70 | 71 | } | ... | ... |
scripts/get_speasy_invetories.py
... | ... | @@ -5,9 +5,9 @@ from xml.dom import minidom |
5 | 5 | def create_element_with_id(tag, name, uid, parent_uid=None): |
6 | 6 | """Create an XML element with a specific id and name.""" |
7 | 7 | if parent_uid: |
8 | - uid = f"{parent_uid}:{uid}" | |
8 | + uid = f"{parent_uid}_{uid}" | |
9 | 9 | elem = ET.Element(tag) |
10 | - elem.set('xml:id', f"SPEASY_CDAWEB:{uid}") | |
10 | + elem.set('xml:id', f"SPEASY_CDAWEB_{uid}") | |
11 | 11 | elem.set('name', name) |
12 | 12 | return elem |
13 | 13 | |
... | ... | @@ -24,8 +24,10 @@ def parse_dimensions(shape): |
24 | 24 | |
25 | 25 | return dim1, dim2 |
26 | 26 | |
27 | -def getParamInfo(parameter, shape): | |
27 | +def getParamInfo(parameter, paramInfo): | |
28 | 28 | """Get dims and type info from the json to the XML element.""" |
29 | + shape = paramInfo.get('spz_shape', '') | |
30 | + speasyUID = paramInfo.get('__spz_provider__','') + "/" + paramInfo.get('__spz_uid__','') | |
29 | 31 | dim1, dim2 = parse_dimensions(shape) |
30 | 32 | if not dim1 == None: |
31 | 33 | parameter.set('dim1', str(dim1)) |
... | ... | @@ -35,6 +37,7 @@ def getParamInfo(parameter, shape): |
35 | 37 | parameter.set('dim2', str(dim2)) |
36 | 38 | parameter.set('type', 'double') |
37 | 39 | parameter.set('minSampling', '4') |
40 | + parameter.set('speasyUID', speasyUID) | |
38 | 41 | |
39 | 42 | def count_levels(data): |
40 | 43 | """Recursively count the levels of nested dictionaries.""" |
... | ... | @@ -59,13 +62,13 @@ def add_instrument(observatory, observatory_data, mission_observatory_key): |
59 | 62 | |
60 | 63 | for dataset_key, dataset_data in instrument_data.items(): |
61 | 64 | if isinstance(dataset_data, dict) and '__spz_name__' in dataset_data: |
62 | - dataset = create_element_with_id('dataset', dataset_data.get('__spz_name__', ''), dataset_key, f"{mission_observatory_key}:{instrument_key}") | |
65 | + dataset = create_element_with_id('dataset', dataset_data.get('__spz_name__', ''), dataset_key, f"{mission_observatory_key}_{instrument_key}") | |
63 | 66 | instrument.append(dataset) |
64 | 67 | |
65 | 68 | for param_key, param_data in dataset_data.items(): |
66 | 69 | if isinstance(param_data, dict) and param_data.get('__spz_type__') == 'ParameterIndex': |
67 | - parameter = create_element_with_id('parameter', param_data.get('__spz_name__', ''), param_key, f"{mission_observatory_key}:{instrument_key}:{dataset_key}") | |
68 | - getParamInfo(parameter, param_data.get('spz_shape', '')) | |
70 | + parameter = create_element_with_id('parameter', param_data.get('__spz_name__', ''), param_key, f"{mission_observatory_key}_{instrument_key}_{dataset_key}") | |
71 | + getParamInfo(parameter, param_data) | |
69 | 72 | dataset.append(parameter) |
70 | 73 | |
71 | 74 | |
... | ... | @@ -95,11 +98,10 @@ def json_to_custom_xml(json_obj, levels): |
95 | 98 | if isinstance(data, dict): |
96 | 99 | observatory = create_element_with_id('observatory', data.get('__spz_name__', ''), observatory_key, mission_key) |
97 | 100 | observatory_data = data |
98 | - mission_observatory_key = f"{mission_key}:{observatory_key}" | |
101 | + mission_observatory_key = f"{mission_key}_{observatory_key}" | |
99 | 102 | mission.append(observatory) |
100 | 103 | |
101 | - add_instrument(observatory, observatory_data, mission_observatory_key) | |
102 | - break | |
104 | + add_instrument(observatory, observatory_data, mission_observatory_key) | |
103 | 105 | |
104 | 106 | return ET.tostring(dataRoot, encoding='unicode') |
105 | 107 | |
... | ... | @@ -120,4 +122,4 @@ def convert_json_file_to_xml(json_file_path, xml_file_path): |
120 | 122 | with open(xml_file_path, 'w') as xml_file: |
121 | 123 | xml_file.write(pretty_xml) |
122 | 124 | |
123 | -convert_json_file_to_xml('data.json', 'base.xml') | |
124 | 125 | \ No newline at end of file |
126 | +convert_json_file_to_xml('data.json', 'base.xml') | ... | ... |