Skip to content

Commit bed438b

Browse files
authored
Merge pull request #2667 from eerovaher/rm-radius_to_unit
Remove `astroquery.utils.commons.radius_to_unit()`
2 parents 766a4fc + 87096d2 commit bed438b

File tree

7 files changed

+19
-59
lines changed

7 files changed

+19
-59
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: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
from zipfile import ZipFile
1111
from pathlib import Path
1212

13+
from astropy import units as u
14+
from astropy.coordinates import Angle
1315
from astropy.io import fits
1416
from astropy.utils.console import ProgressBar
1517
from astroquery import log
16-
import astropy.units
1718
from requests import HTTPError
1819
from requests import ConnectionError
1920

@@ -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 * u.arcsec).to_value(u.deg)
5455

5556
__HERSCHEL_STRING = 'herschel'
5657
__HST_STRING = 'hst'
@@ -113,7 +114,7 @@ def query(self, query, *, output_file=None, output_format="votable", verbose=Fal
113114
if not verbose:
114115
with warnings.catch_warnings():
115116
commons.suppress_vo_warnings()
116-
warnings.filterwarnings("ignore", category=astropy.units.core.UnitsWarning)
117+
warnings.filterwarnings("ignore", category=u.UnitsWarning)
117118
job = self._tap.launch_job(query=query, output_file=output_file, output_format=output_format,
118119
verbose=False, dump_to_file=output_file is not None)
119120
else:
@@ -1346,8 +1347,7 @@ def get_spectra_from_table(self, query_table_list, missions=__ALL_STRING,
13461347
return spectra
13471348

13481349
def _sanitize_input_radius(self, radius):
1349-
if (isinstance(radius, str) or isinstance(radius,
1350-
astropy.units.Quantity)):
1350+
if isinstance(radius, (str, u.Quantity)):
13511351
return radius
13521352
else:
13531353
raise ValueError("Radius must be either a string or "
@@ -1553,7 +1553,7 @@ def _open_fits(self, path, verbose=False):
15531553
if verbose:
15541554
return fits.open(path)
15551555
with warnings.catch_warnings():
1556-
warnings.filterwarnings("ignore", category=astropy.io.fits.verify.VerifyWarning)
1556+
warnings.filterwarnings("ignore", category=fits.verify.VerifyWarning)
15571557
return fits.open(path)
15581558

15591559
def _ends_with_fits_like_extentsion(self, name):
@@ -1708,7 +1708,7 @@ def _query(self, name, json, verbose=False, **kwargs):
17081708
def _build_region_query(self, coordinates, radius, row_limit, json):
17091709
ra = coordinates.transform_to('icrs').ra.deg
17101710
dec = coordinates.transform_to('icrs').dec.deg
1711-
radius_deg = commons.radius_to_unit(radius, unit='deg')
1711+
radius_deg = Angle(radius).to_value(u.deg)
17121712

17131713
select_query = "SELECT "
17141714
if row_limit > 0:
@@ -1725,17 +1725,13 @@ def _build_region_query(self, coordinates, radius, row_limit, json):
17251725
if radius_deg == 0:
17261726
if json[self.__USE_INTERSECT_STRING]:
17271727
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')))
1728+
format(ra, dec, self.__MIN_RADIUS_CATALOG_DEG))
17311729
else:
17321730
where_query = (" WHERE 1=CONTAINS(POINT('ICRS', {}, {}), CIRCLE('ICRS', {}, {}, {}))".
17331731
format(tap_ra_column, tap_dec_column,
17341732
ra,
17351733
dec,
1736-
commons.radius_to_unit(
1737-
self.__MIN_RADIUS_CATALOG_STRING,
1738-
unit='deg')))
1734+
self.__MIN_RADIUS_CATALOG_DEG))
17391735
else:
17401736
if json[self.__USE_INTERSECT_STRING]:
17411737
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)