Skip to content

Commit 31528de

Browse files
committed
Remove astroquery.utils.commons.radius_to_unit()
`radius_to_unit(radius, unit)` was equivalent to `astropy.coordinates.Angle(radius).to_value(unit)` except that if `unit` was not specified then it defaulted to degrees. The convenience of not having to specify degrees was not worth obscuring the simple `Angle.to_value()` call, so the function has been removed.
1 parent 766a4fc commit 31528de

File tree

7 files changed

+15
-54
lines changed

7 files changed

+15
-54
lines changed

astroquery/cadc/core.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from ..query import BaseQuery
2121
from bs4 import BeautifulSoup
2222
from astropy import units as u
23+
from astropy.coordinates import Angle
2324
import pyvo
2425
from pyvo.auth import authsession
2526

@@ -432,7 +433,7 @@ def get_image_list(self, query_result, coordinates, radius):
432433
raise AttributeError('Missing query_result argument')
433434

434435
parsed_coordinates = commons.parse_coordinates(coordinates).fk5
435-
radius_deg = commons.radius_to_unit(radius, unit='degree')
436+
radius_deg = Angle(radius).to_value(u.deg)
436437
ra = parsed_coordinates.ra.degree
437438
dec = parsed_coordinates.dec.degree
438439
cutout_params = {'POS': 'CIRCLE {} {} {}'.format(ra, dec, radius_deg)}
@@ -708,7 +709,7 @@ def _args_to_payload(self, *args, **kwargs):
708709
# and force the coordinates to FK5 (assuming FK5/ICRS are
709710
# interchangeable) since RA/Dec are used below
710711
coordinates = commons.parse_coordinates(kwargs['coordinates']).fk5
711-
radius_deg = commons.radius_to_unit(kwargs['radius'], unit='degree')
712+
radius_deg = Angle(kwargs["radius"]).to_value(u.deg)
712713
payload = {format: 'VOTable'}
713714
payload['query'] = \
714715
"SELECT * from caom2.Observation o join caom2.Plane p " \

astroquery/esa/jwst/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
from astropy import log
2222
from astropy import units
23-
from astropy.coordinates import SkyCoord
23+
from astropy.coordinates import Angle, SkyCoord
2424
from astropy.table import vstack
2525
from astropy.units import Quantity
2626
from requests.exceptions import ConnectionError
@@ -438,7 +438,7 @@ def cone_search(self, coordinate, radius, *,
438438

439439
if radius is not None:
440440
radius_quantity = self.__get_quantity_input(value=radius, msg="radius")
441-
radius_deg = commons.radius_to_unit(radius_quantity, unit='deg')
441+
radius_deg = Angle(radius_quantity).to_value(units.deg)
442442

443443
query = (f"SELECT DISTANCE(POINT('ICRS',"
444444
f"{str(conf.JWST_MAIN_TABLE_RA)},"

astroquery/esasky/core.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from zipfile import ZipFile
1111
from pathlib import Path
1212

13+
from astropy.coordinates import Angle
1314
from astropy.io import fits
1415
from astropy.utils.console import ProgressBar
1516
from astroquery import log
@@ -50,7 +51,7 @@ class ESASkyClass(BaseQuery):
5051
__ACCESS_URL_STRING = "access_url"
5152
__USE_INTERSECT_STRING = "useIntersectPolygonInsteadOfContainsPoint"
5253
__ZERO_ARCMIN_STRING = "0 arcmin"
53-
__MIN_RADIUS_CATALOG_STRING = "5 arcsec"
54+
__MIN_RADIUS_CATALOG_DEG = Angle(5*astropy.units.arcsec).to_value(astropy.units.deg)
5455

5556
__HERSCHEL_STRING = 'herschel'
5657
__HST_STRING = 'hst'
@@ -1708,7 +1709,7 @@ def _query(self, name, json, verbose=False, **kwargs):
17081709
def _build_region_query(self, coordinates, radius, row_limit, json):
17091710
ra = coordinates.transform_to('icrs').ra.deg
17101711
dec = coordinates.transform_to('icrs').dec.deg
1711-
radius_deg = commons.radius_to_unit(radius, unit='deg')
1712+
radius_deg = Angle(radius).to_value(astropy.units.deg)
17121713

17131714
select_query = "SELECT "
17141715
if row_limit > 0:
@@ -1725,17 +1726,13 @@ def _build_region_query(self, coordinates, radius, row_limit, json):
17251726
if radius_deg == 0:
17261727
if json[self.__USE_INTERSECT_STRING]:
17271728
where_query = (" WHERE 1=INTERSECTS(CIRCLE('ICRS', {}, {}, {}), fov)".
1728-
format(ra, dec, commons.radius_to_unit(
1729-
self.__MIN_RADIUS_CATALOG_STRING,
1730-
unit='deg')))
1729+
format(ra, dec, self.__MIN_RADIUS_CATALOG_DEG))
17311730
else:
17321731
where_query = (" WHERE 1=CONTAINS(POINT('ICRS', {}, {}), CIRCLE('ICRS', {}, {}, {}))".
17331732
format(tap_ra_column, tap_dec_column,
17341733
ra,
17351734
dec,
1736-
commons.radius_to_unit(
1737-
self.__MIN_RADIUS_CATALOG_STRING,
1738-
unit='deg')))
1735+
self.__MIN_RADIUS_CATALOG_DEG))
17391736
else:
17401737
if json[self.__USE_INTERSECT_STRING]:
17411738
where_query = (" WHERE 1=INTERSECTS(CIRCLE('ICRS', {}, {}, {}), fov)".

astroquery/gaia/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from collections.abc import Iterable
2121

2222
from astropy import units
23+
from astropy.coordinates import Angle
2324
from astropy.units import Quantity
2425
from astropy.io import votable
2526
from astropy.io import fits
@@ -544,8 +545,7 @@ def __cone_search(self, coordinate, radius, table_name=None,
544545
raHours, dec = commons.coord_to_radec(coord)
545546
ra = raHours * 15.0 # Converts to degrees
546547
if radius is not None:
547-
radiusQuantity = self.__getQuantityInput(radius, "radius")
548-
radiusDeg = commons.radius_to_unit(radiusQuantity, unit='deg')
548+
radiusDeg = Angle(self.__getQuantityInput(radius, "radius")).to_value(u.deg)
549549

550550
if columns:
551551
columns = ','.join(map(str, columns))

astroquery/utils/commons.py

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import astropy.utils.data as aud
1818
from astropy.io import fits, votable
1919

20-
from astropy.coordinates import Angle, BaseCoordinateFrame, SkyCoord
20+
from astropy.coordinates import BaseCoordinateFrame, SkyCoord
2121

2222
from ..exceptions import TimeoutError, InputWarning
2323

@@ -39,30 +39,6 @@
3939
ASTROPY_LT_5_1 = not minversion('astropy', '5.1')
4040

4141

42-
def radius_to_unit(radius, unit='degree'):
43-
"""
44-
Helper function: Parse a radius, then return its value in degrees
45-
46-
Parameters
47-
----------
48-
radius : str or `~astropy.units.Quantity`
49-
The radius of a region
50-
51-
Returns
52-
-------
53-
Floating point scalar value of radius in degrees
54-
"""
55-
rad = Angle(radius)
56-
57-
if isinstance(unit, str):
58-
if hasattr(rad, unit):
59-
return getattr(rad, unit)
60-
elif hasattr(rad, f"{unit}s"):
61-
return getattr(rad, f"{unit}s")
62-
63-
return rad.to(unit).value
64-
65-
6642
def parse_coordinates(coordinates):
6743
"""
6844
Takes a string or astropy.coordinates object. Checks if the

astroquery/utils/tests/test_utils.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -438,11 +438,3 @@ def test_filecontainer_get(patch_getreadablefileobj):
438438
def test_is_coordinate(coordinates, expected):
439439
out = commons._is_coordinate(coordinates)
440440
assert out == expected
441-
442-
443-
@pytest.mark.parametrize(('radius'),
444-
[0.01*u.deg, '0.01 deg', 0.01*u.arcmin]
445-
)
446-
def test_radius_to_unit(radius):
447-
c = commons.radius_to_unit(radius)
448-
assert c is not None

astroquery/vo_conesearch/core.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from numbers import Number
77

88
from astropy import units as u
9-
from astropy.coordinates import (BaseCoordinateFrame, ICRS, SkyCoord,
9+
from astropy.coordinates import (Angle, BaseCoordinateFrame, ICRS, SkyCoord,
1010
Longitude, Latitude)
1111
from astropy.io.votable import table
1212

@@ -227,12 +227,7 @@ def _validate_coord(coordinates):
227227

228228
def _validate_sr(radius):
229229
"""Validate search radius and return value in deg."""
230-
if isinstance(radius, Number):
231-
sr = radius
232-
else:
233-
sr = commons.radius_to_unit(radius)
234-
235-
return sr
230+
return radius if isinstance(radius, Number) else Angle(radius).to_value(u.deg)
236231

237232

238233
def _validate_verb(verb):

0 commit comments

Comments
 (0)