Commits
C. Enrique Garcia Dabo authored 1f7b64d95df Merge
197 197 | |
198 198 | .. _hosts: |
199 199 | |
200 200 | | ``hosts (stringVec=['https://asa.alma.cl/uncertainties-service/uncertainties/versions/last/measurements/casa/'])`` - Priority-ranked list of hosts to query to obtain positions. Only one server that returns a list of antenna positions is required. That response will be written and no additional hosts will be queried. |
201 201 | | Example: hosts=["server1.alma.cl", "server2.alma.cl"] |
202 202 | |
203 203 | |
204 204 | """ |
205 205 | if not outfile: |
206 206 | raise ValueError("Parameter outfile must be specified") |
207 - | md = {"outfile": outfile} |
207 + | md = { |
208 + | "caltype": "ALMA antenna positions", |
209 + | "description": "ALMA ITRF antenna positions in meters", |
210 + | "product_code": "antposalma", |
211 + | "outfile": outfile |
212 + | } |
208 213 | if not overwrite and os.path.exists(outfile): |
209 214 | raise RuntimeError( |
210 215 | f"A file or directory named {outfile} already exists and overwrite " |
211 216 | "is False, so exiting. Either rename the existing file or directory, " |
212 217 | "change the value of overwrite to True, or both." |
213 218 | ) |
214 219 | if not hosts: |
215 220 | raise ValueError("Parameter hosts must be specified") |
216 221 | if isinstance(hosts, list) and not hosts[0]: |
217 222 | raise ValueError("The first element of the hosts list must be specified") |
255 260 | for h in hosts: |
256 261 | if not _is_valid_url_host(h): |
257 262 | raise ValueError( |
258 263 | f'Parameter hosts: {h} is not a valid host expressed as a URL.' |
259 264 | ) |
260 265 | url = f"{h}/{qs}" |
261 266 | casalog.post(f"Trying {url} ...", "NORMAL") |
262 267 | antpos = _query(url) |
263 268 | if antpos: |
264 269 | md["successful_url"] = url |
270 + | antpos = json.loads(antpos) |
265 271 | break |
266 272 | if not antpos: |
267 273 | raise RuntimeError("All URLs failed to return an antenna position list.") |
268 274 | if os.path.exists(outfile): |
269 275 | if overwrite: |
270 276 | if os.path.isdir(outfile): |
271 277 | casalog.post( |
272 278 | f"Removing existing directory {outfile} before writing new " |
273 279 | "file of same name", |
274 280 | "WARN" |
280 286 | "same name", |
281 287 | "WARN" |
282 288 | ) |
283 289 | os.remove(outfile) |
284 290 | else: |
285 291 | raise RuntimeError( |
286 292 | "Logic Error: shouldn't have gotten to this point with overwrite=False" |
287 293 | ) |
288 294 | md["timestamp"] = str(datetime.now()) |
289 295 | with open(outfile, "w") as f: |
290 - | json.dump([antpos, md], f) |
296 + | json.dump({"data": antpos, "metadata": md}, f) |