Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
criteria["intentType"] = "calibration"
# Build the mashup filter object and store it in the correct service_name entry
if coordinates or objectname:
mashup_filters = self._build_filter_set("Mast.Caom.Cone", "Mast.Caom.Filtered.Position", **criteria)
else:
mashup_filters = self._build_filter_set("Mast.Caom.Cone", "Mast.Caom.Filtered", **criteria)
if not mashup_filters:
raise InvalidQueryError("At least one non-positional criterion must be supplied.")
# handle position info (if any)
position = None
if objectname and coordinates:
raise InvalidQueryError("Only one of objectname and coordinates may be specified.")
if objectname:
coordinates = self.resolve_object(objectname)
if coordinates:
# Put coordinates and radius into consitant format
coordinates = commons.parse_coordinates(coordinates)
# if radius is just a number we assume degrees
if isinstance(radius, (int, float)):
radius = radius * u.deg
radius = coord.Angle(radius)
# build the coordinates string needed by Mast.Caom.Filtered.Position
position = ', '.join([str(x) for x in (coordinates.ra.deg, coordinates.dec.deg, radius.deg)])
@prepend_docstr_nosections("\n" + _args_to_payload.__doc__)
def get_images_async(self, coordinates, image_size=1 * u.arcmin,
survey='bolocam', get_query_payload=False):
"""
get_query_payload : bool, optional
if set to `True` then returns the dictionary sent as the HTTP
request. Defaults to `False`
Returns
-------
response : `requests.Response`
The HTTP response returned from the service
"""
if survey not in self.surveys:
raise InvalidQueryError("Survey must be one of " +
(",".join(self.list_surveys())))
request_payload = self._args_to_payload(
coordinates, image_size=image_size, survey=survey)
if get_query_payload:
return request_payload
response = self._request("POST", url=self.URL, data=request_payload,
timeout=self.TIMEOUT, verify=False)
return response
# Getting x and y out of the size
if np.isscalar(size[0]):
x = size[1]
y = size[0]
units = "px"
elif size[0].unit == u.pixel:
x = size[1].value
y = size[0].value
units = "px"
elif size[0].unit.physical_type == 'angle':
x = size[1].to(u.deg).value
y = size[0].to(u.deg).value
units = "d"
else:
raise InvalidQueryError("Cutout size must be in pixels or angular quantity.")
path = os.path.join(path, '')
astrocut_request = "ra={}&dec={}&y={}&x={}&units={}".format(coordinates.ra.deg,
coordinates.dec.deg,
y, x, units)
if sector:
astrocut_request += "§or={}".format(sector)
astrocut_url = self._TESSCUT_URL + "astrocut?" + astrocut_request
zipfile_path = "{}tesscut_{}.zip".format(path, time.strftime("%Y%m%d%H%M%S"))
self._download_file(astrocut_url, zipfile_path)
localpath_table = Table(names=["Local Path"], dtype=[str])
# Checking if we got a zip file or a json no results message
def _check_page(self, url, keyword, wait_time=1, max_attempts=30):
page_loaded = False
while not page_loaded and max_attempts > 0:
if self.logged_in():
response = self.session.get(url)
else:
response = requests.get(url=url)
self.response = response
content = response.text
if re.search("error", content, re.IGNORECASE):
raise InvalidQueryError(
"Service returned with an error! "
"Check self.response for more information.")
elif re.search(keyword, content, re.IGNORECASE):
page_loaded = True
max_attempts -= 1
# wait for wait_time seconds before checking again
time.sleep(wait_time)
if page_loaded is False:
raise TimeoutError("Page did not load.")
return response
service = "Mast.Catalogs.Filtered.Ctl"
if coordinates or objectname:
service += ".Position"
service += ".Rows" # Using the rowstore version of the query for speed
mashup_filters = self._build_filter_set("Mast.Catalogs.Tess.Cone", service, **criteria)
elif catalog.lower() == "diskdetective":
service = "Mast.Catalogs.Filtered.DiskDetective"
if coordinates or objectname:
service += ".Position"
mashup_filters = self._build_filter_set("Mast.Catalogs.Dd.Cone", service, **criteria)
else:
raise InvalidQueryError("Criteria query not available for {}".format(catalog))
if not mashup_filters:
raise InvalidQueryError("At least one non-positional criterion must be supplied.")
if objectname and coordinates:
raise InvalidQueryError("Only one of objectname and coordinates may be specified.")
if objectname:
coordinates = self.resolve_object(objectname)
if coordinates:
# Put coordinates and radius into consitant format
coordinates = commons.parse_coordinates(coordinates)
# if radius is just a number we assume degrees
if isinstance(radius, (int, float)):
radius = radius * u.deg
radius = coord.Angle(radius)
advanced path construction that is not yet supported. ``'sia'``
provides access to the 'simple image access' IVOA protocol
Returns
-------
response : `~requests.Response`
The HTTP response returned from the service
"""
if coordinate is None and where is None:
raise InvalidQueryError(
'At least one of `coordinate` or `where` is required')
intersect = intersect.upper()
if intersect not in ('COVERS', 'ENCLOSED', 'CENTER', 'OVERLAPS'):
raise InvalidQueryError(
"Invalid value for `intersects` " +
"(must be 'COVERS', 'ENCLOSED', 'CENTER', or 'OVERLAPS')")
if action not in ('sia', 'data', 'search'):
raise InvalidQueryError("Valid actions are: sia, data, search.")
if action == 'data':
raise NotImplementedError(
"The action='data' option is a placeholder for future " +
"functionality.")
args = {
'INTERSECT': intersect
}
# Note: in IBE, if 'mcen' argument is present, it is true.
# If absent, it is false.
# Getting x and y out of the size
if np.isscalar(size[0]):
x = size[1]
y = size[0]
units = "px"
elif size[0].unit == u.pixel:
x = size[1].value
y = size[0].value
units = "px"
elif size[0].unit.physical_type == 'angle':
x = size[1].to(u.deg).value
y = size[0].to(u.deg).value
units = "d"
else:
raise InvalidQueryError("Cutout size must be in pixels or angular quantity.")
astrocut_request = "ra={}&dec={}&y={}&x={}&units={}".format(coordinates.ra.deg,
coordinates.dec.deg,
y, x, units)
if sector:
astrocut_request += "§or={}".format(sector)
response = self._request("GET", self._TESSCUT_URL+"astrocut", params=astrocut_request)
response.raise_for_status() # Raise any errors
try:
ZIPFILE = zipfile.ZipFile(BytesIO(response.content), 'r')
except zipfile.BadZipFile:
message = response.json()
warnings.warn(message['msg'], NoResultsWarning)
return []
most_centered : bool
If True, then only the most centered image is returned.
action : ``'search'``, ``'data'``, or ``'sia'``
The action to perform at the server. The default is ``'search'``,
which returns a table of the available data. ``'data'`` requires
advanced path construction that is not yet supported. ``'sia'``
provides access to the 'simple image access' IVOA protocol
Returns
-------
response : `~requests.Response`
The HTTP response returned from the service
"""
if coordinate is None and where is None:
raise InvalidQueryError(
'At least one of `coordinate` or `where` is required')
intersect = intersect.upper()
if intersect not in ('COVERS', 'ENCLOSED', 'CENTER', 'OVERLAPS'):
raise InvalidQueryError(
"Invalid value for `intersects` " +
"(must be 'COVERS', 'ENCLOSED', 'CENTER', or 'OVERLAPS')")
if action not in ('sia', 'data', 'search'):
raise InvalidQueryError("Valid actions are: sia, data, search.")
if action == 'data':
raise NotImplementedError(
"The action='data' option is a placeholder for future " +
"functionality.")
args = {
if start is None:
eph = []
for i in range(len(_epochs)):
e = MPC.get_ephemeris(targetid, location=location,
start=Time(_epochs[i],
scale='utc'),
number=1, **kwargs)
e['Date'] = e['Date'].iso # for vstack to work
eph.append(e)
eph = vstack(eph)
eph['Date'] = Time(eph['Date'], scale='utc')
else:
eph = MPC.get_ephemeris(targetid, location=location,
start=start, step=step,
number=number, **kwargs)
except InvalidQueryError as e:
raise QueryError(
'Error raised by astroquery.mpc: {:s}'.format(str(e)))
# add targetname column
eph.add_column(Column([targetid]*len(eph),
name='Targetname'), index=0)
if all_eph is None:
all_eph = eph
else:
all_eph = vstack([all_eph, eph])
# if ra_format or dec_format is defined, then units must be
# dropped or else QTable will raise an exception because
# strings cannot have units
if 'ra_format' in kwargs: