Skip to content

Commit 2a13214

Browse files
author
“Javier
committed
Minor comments, cone_searches with quantity
1 parent 2f3e583 commit 2a13214

File tree

2 files changed

+43
-34
lines changed

2 files changed

+43
-34
lines changed

astroquery/esa/hubble/core.py

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,10 @@ def cone_search(self, coordinates, radius, filename=None,
231231
232232
Parameters
233233
----------
234-
radius : float
235-
radius in arcmin of the cone_search
236234
coordinates : astropy.coordinate, mandatory
237235
coordinates of the center in the cone search
236+
radius : float or quantity
237+
radius in arcmin (int, float) or quantity of the cone_search
238238
filename : str, default None
239239
Path and name of the file to store the results.
240240
If the filename is defined, the file will be
@@ -257,7 +257,10 @@ def cone_search(self, coordinates, radius, filename=None,
257257
astropy.table.Table with the result of the cone_search
258258
"""
259259
coord = self._getCoordInput(coordinates)
260-
radius_in_grades = Angle(radius, units.arcmin).deg
260+
if type(radius) == int or type(radius) == float:
261+
radius_in_grades = Angle(radius, units.arcmin).deg
262+
else:
263+
radius_in_grades = radius.to(units.deg).value
261264
ra = coord.ra.deg
262265
dec = coord.dec.deg
263266
query = "select o.observation_id, "\
@@ -312,8 +315,8 @@ def cone_search_criteria(self, radius, target=None,
312315
313316
Parameters
314317
----------
315-
radius : float
316-
radius in arcmin of the cone_search
318+
radius : float or quantity
319+
radius in arcmin (int, float) or quantity of the cone_search
317320
target : str, mandatory if no coordinates is provided
318321
name of the target, that will act as center in the cone search
319322
coordinates : astropy.coordinate, mandatory if no target is provided
@@ -377,16 +380,16 @@ def cone_search_criteria(self, radius, target=None,
377380
raise TypeError("Please use only target or coordinates as"
378381
"parameter.")
379382
if target:
380-
try:
381-
ra, dec = self._query_tap_target(target)
382-
except Exception:
383-
raise ValueError('This target cannot be resolved')
383+
ra, dec = self._query_tap_target(target)
384384
else:
385385
coord = self._getCoordInput(coordinates)
386386
ra = coord.ra.deg
387387
dec = coord.dec.deg
388388

389-
radius_in_grades = Angle(radius, units.arcmin).deg
389+
if type(radius) == int or type(radius) == float:
390+
radius_in_grades = Angle(radius, units.arcmin).deg
391+
else:
392+
radius_in_grades = radius.to(units.deg).value
390393
cone_query = "1=CONTAINS(POINT('ICRS', pos.ra, pos.dec),"\
391394
"CIRCLE('ICRS', {0}, {1}, {2}))".\
392395
format(str(ra), str(dec), str(radius_in_grades))
@@ -401,17 +404,20 @@ def cone_search_criteria(self, radius, target=None,
401404
return table
402405

403406
def _query_tap_target(self, target):
404-
params = {"TARGET_NAME": target,
405-
"RESOLVER_TYPE": "SN",
406-
"FORMAT": "json"}
407-
target_response = self._request('GET',
408-
self.target_url,
409-
cache=True,
410-
params=params)
411-
target_result = target_response.json()['data'][0]
412-
ra = target_result['RA_DEGREES']
413-
dec = target_result['DEC_DEGREES']
414-
return ra, dec
407+
try:
408+
params = {"TARGET_NAME": target,
409+
"RESOLVER_TYPE": "SN",
410+
"FORMAT": "json"}
411+
target_response = self._request('GET',
412+
self.target_url,
413+
cache=True,
414+
params=params)
415+
target_result = target_response.json()['data'][0]
416+
ra = target_result['RA_DEGREES']
417+
dec = target_result['DEC_DEGREES']
418+
return ra, dec
419+
except KeyError as e:
420+
raise ValueError("This target cannot be resolved")
415421

416422
def query_metadata(self, output_format='votable', verbose=False):
417423
return
@@ -582,14 +588,14 @@ def query_criteria(self, calibration_level=None,
582588
"JOIN ehst.position as pos on p.plane_id = pos.plane_id"
583589
if parameters:
584590
query += " where({})".format(" AND ".join(parameters))
585-
table = self.query_hst_tap(query=query, async_job=async_job,
586-
output_file=output_file,
587-
output_format=output_format,
588-
verbose=verbose)
589591
if verbose:
590592
log.info(query)
591593
if get_query:
592594
return query
595+
table = self.query_hst_tap(query=query, async_job=async_job,
596+
output_file=output_file,
597+
output_format=output_format,
598+
verbose=verbose)
593599
return table
594600

595601
def __get_calibration_level(self, calibration_level):

docs/esa/hubble.rst

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -284,22 +284,25 @@ and a set of criteria to filter the results.
284284
filename = 'output1.vot.gz',
285285
output_format="votable")
286286
>>> result
287-
<Table length=302>
288-
algorithm_name collection end_time end_time_mjd exposure_duration ... target_name calibration_level data_product_type ra dec
289-
object object object float64 float64 ... object object object float64 float64
290-
-------------- ---------- -------------------------- ------------------ ----------------- ... ----------- ----------------- ----------------- ------------------ ------------------
291-
drizzle HST 2002-06-29 14:15:20.787 52454.51065725694 1600.0 ... M31-T3 CALIBRATED image 10.791884595154517 41.28819762447081
292-
drizzle HST 2002-06-29 14:15:20.787 52454.51065725694 1600.0 ... M31-T3 PRODUCT image 10.791884595154517 41.28819762447081
293-
...
294-
exposure HST 2014-06-26 03:40:17.0 56834.06964120371 1246.0 ... M-31-CORE RAW image 10.531742116262286 41.25273489574185
287+
288+
<Table length=302>
289+
algorithm_name collection end_time end_time_mjd exposure_duration ... target_name calibration_level data_product_type ra dec
290+
object object object float64 float64 ... object object object float64 float64
291+
-------------- ---------- ----------------------- ----------------- ----------------- ... ----------- ----------------- ----------------- ------------------ -----------------
292+
drizzle HST 2002-06-29 14:15:20.787 52454.51065725694 1600.0 ... M31-T3 CALIBRATED image 10.791884595154517 41.28819762447081
293+
... ... ... ... ... ... ... ... ... ... ...
294+
exposure HST 2014-06-26 03:40:17.0 56834.06964120371 1246.0 ... M-31-CORE CALIBRATED image 10.531742116262286 41.25273489574185
295+
exposure HST 2014-06-26 03:40:17.0 56834.06964120371 1246.0 ... M-31-CORE RAW image 10.531742116262286 41.25273489574185
296+
295297
296298
.. code-block:: python
297299
298300
>>> from astropy import coordinates
301+
>>> from astropy import units as u
299302
>>> from astroquery.esa.hubble import ESAHubble
300303
>>> esahubble = ESAHubble()
301304
>>> c = coordinates.SkyCoord("00h42m44.51s +41d16m08.45s", frame='icrs')
302-
>>> result = esahubble.cone_search_criteria(coordinates=c,radius=7,
305+
>>> result = esahubble.cone_search_criteria(coordinates=c,radius=7*u.arcmin,
303306
obs_collection=['HST'],
304307
instrument_name = ['WFPC2'],
305308
filters = ['F606W'],

0 commit comments

Comments
 (0)