Commit 17e47c9e7a7cf0dd34b8260a9508fd4c4e1d28b0
1 parent
28d547b1
Exists in
master
and in
91 other branches
Add bins definition in HAPI (#6318)
Showing
1 changed file
with
53 additions
and
5 deletions
Show diff stats
update_amda/makeHAPIMetadata.php
... | ... | @@ -100,18 +100,25 @@ foreach ($dataset_nodes as $dataset_node) { |
100 | 100 | //type |
101 | 101 | $parameter->{"type"} = "double"; |
102 | 102 | |
103 | + //Load info_file if exists | |
104 | + $infofile_path = $infofiles_path . "/info_".$parameter_node->getAttribute("xml:id").".xml"; | |
105 | + $info_doc = NULL; | |
106 | + if (file_exists($infofile_path)) { | |
107 | + $info_doc = new DOMDocument(); | |
108 | + if (!@$info_doc->load($infofile_path)) { | |
109 | + $info_doc = NULL; | |
110 | + } | |
111 | + } | |
112 | + | |
103 | 113 | //size |
104 | 114 | $size = $parameter_node->getAttribute("size"); |
105 | 115 | if (empty($size)) { |
106 | 116 | if ($parameter_node->getAttribute("display_type") == "spectrogram") { |
107 | - //Load info_file if exists and retrieve dimensions | |
108 | - $infofile_path = $infofiles_path . "/info_".$parameter_node->getAttribute("xml:id").".xml"; | |
109 | - if (!file_exists($infofile_path)) { | |
117 | + //Retrieve dimensions in info file | |
118 | + if (!isset($info_doc)) { | |
110 | 119 | echo "[WARNING] Parameter ".$param_id." defines as a spectrogram but cannot retrieve info file => Skip this parameter".PHP_EOL; |
111 | 120 | continue; |
112 | 121 | } |
113 | - $info_doc = new DOMDocument(); | |
114 | - @$info_doc->load($infofile_path); | |
115 | 122 | $dimensions_node = $info_doc->getElementsByTagName("dimensions"); |
116 | 123 | if ($dimensions_node->length == 0) { |
117 | 124 | echo "[WARNING] Cannot retrieve size for ".$param_id.PHP_EOL; |
... | ... | @@ -144,6 +151,47 @@ foreach ($dataset_nodes as $dataset_node) { |
144 | 151 | $parameter->{"size"} = $size; |
145 | 152 | } |
146 | 153 | |
154 | + //bins | |
155 | + $bins = NULL; | |
156 | + if (!empty($size) && isset($info_doc)) { | |
157 | + $tables_node = $info_doc->getElementsByTagName("tables"); | |
158 | + if ($tables_node->length > 0) { | |
159 | + $bins = array(); | |
160 | + $tables_node = $tables_node->item(0); | |
161 | + $table_nodes = $tables_node->getElementsByTagName("table"); | |
162 | + if ($table_nodes->length > 0) { | |
163 | + foreach ($table_nodes as $table_node) { | |
164 | + $relatedDim = $table_node->getAttribute("relatedDim"); | |
165 | + $bin_index = ($relatedDim == "dim_1") ? 0 : 1; | |
166 | + $nameBin = $table_node->getAttribute("name"); | |
167 | + $unitsBin = $table_node->getAttribute("units"); | |
168 | + $channel_nodes = $table_node->getElementsByTagName("channel"); | |
169 | + $ranges = array(); | |
170 | + foreach ($channel_nodes as $channel_node) { | |
171 | + $min_range = $channel_node->getAttribute("min"); | |
172 | + $max_range = $channel_node->getAttribute("max"); | |
173 | + $ranges[] = array(floatval($min_range), floatval($max_range)); | |
174 | + } | |
175 | + if (!empty($ranges)) { | |
176 | + $bin_info = (Object)array(); | |
177 | + $bin_info->{"name"} = $nameBin; | |
178 | + $bin_info->{"units"} = $unitsBin; | |
179 | + $bin_info->{"ranges"} = $ranges; | |
180 | + if ($bin_index == 0) { | |
181 | + array_unshift($bins, $bin_info); | |
182 | + } | |
183 | + else { | |
184 | + array_push($bins, $bin_info); | |
185 | + } | |
186 | + } | |
187 | + } | |
188 | + } | |
189 | + } | |
190 | + } | |
191 | + if (!empty($bins)) { | |
192 | + $parameter->{"bins"} = $bins; | |
193 | + } | |
194 | + | |
147 | 195 | //units |
148 | 196 | $units = $parameter_node->getAttribute("units"); |
149 | 197 | if (empty($units)) | ... | ... |