from casatasks import casalog
from casatools import quanta
import certifi
from datetime import datetime
import json, os, shutil
import ssl
from urllib import request
from urllib.error import HTTPError, URLError
from urllib.parse import urlencode, urlparse
def _is_valid_url_host(url):
parsed = urlparse(url)
return bool(parsed.netloc)
def _query(url):
myjson = None
response = None
try:
context = ssl.create_default_context(cafile=certifi.where())
with request.urlopen(url, context=context, timeout=400) as response:
if response.status == 200:
myjson = response.read().decode('utf-8')
except HTTPError as e:
casalog.post(
f"Caught HTTPError: {e.code} {e.reason}: {e.read().decode('utf-8')}",
"WARN"
)
except URLError as e:
casalog.post(f"Caught URLError: {str(e)}", "WARN")
except Exception as e:
casalog.post(f"Caught Exception when trying to connect: {str(e)}", "WARN")
return myjson
def getantposalma(
outfile='', overwrite=False, asdm='', tw='', snr=0, search='both_latest',
hosts=['tbd1.alma.cl', 'tbd2.alma.cl']
):
r"""
Retrieve antenna positions by querying ALMA web service.
[`Description`_] [`Examples`_] [`Development`_] [`Details`_]
Parameters
- outfile_ (path='') - Name of output file to which to write retrieved antenna positions.
- overwrite_ (bool=False) - Overwrite a file by the same name if it exists?
- asdm_ (string='') - The associated ASDM name. Must be specified
- tw_ (string='') - Optional time window in which to consider baseline measurements in the database, when calculating the antenna positions.
- snr_ (float=0) - Optional signal-to-noise.
- search_ (string='both_latest') - Search algorithm to use.
- hosts_ (stringVec=['https://asa.alma.cl/uncertainties-service/uncertainties/versions/last/measurements/casa/']) - Priority-ranked list of hosts to query.
.. _Description:
Description
.. warning:: **WARNING**: This task should be considered experimental
since the values returned by the JAO service are in the process of
being validated.
This task retrieves ALMA antenna positions via a web service which runs
on an ALMA-hosted server. The antenna positions are with respect to ITRF.
The user must specify the value of the outfile parameter. This parameter
is the name of the file to which the antenna positions will be written.
This file can then be read by gencal so that it can use the most up to
date antenna positions for the observation.
The web service is described by the server development team and can be
found `at this location <https://asw.alma.cl/groups/ASW/-/packages/843>`__.
The input parameters are discussed in detail below.
outfile is required to be specified. It is the name of the file to which to
write antenna positions.
overwrite If False and a file with the same name exists, and exception
will be thrown. If true, an existing file with the same name will be
overwriten.
asdm is required to be specified. It is the associated ASDM UID in the
form uid://A002/Xc02418/X29c8.
tw is an optional parameter. It is time window in which the antenna positions
are required, specified as a comma separated pair. Times are UTC and are
expressed in YY-MM-DDThh:mm:ss.sss format. The end time must be later than