diff --git a/astroquery/cadc/core.py b/astroquery/cadc/core.py index cbde115d38..958e30ba49 100644 --- a/astroquery/cadc/core.py +++ b/astroquery/cadc/core.py @@ -20,6 +20,7 @@ from ..query import BaseQuery from bs4 import BeautifulSoup from astropy import units as u +from astropy.coordinates import Angle import pyvo from pyvo.auth import authsession @@ -432,7 +433,7 @@ def get_image_list(self, query_result, coordinates, radius): raise AttributeError('Missing query_result argument') parsed_coordinates = commons.parse_coordinates(coordinates).fk5 - radius_deg = commons.radius_to_unit(radius, unit='degree') + radius_deg = Angle(radius).to_value(u.deg) ra = parsed_coordinates.ra.degree dec = parsed_coordinates.dec.degree cutout_params = {'POS': 'CIRCLE {} {} {}'.format(ra, dec, radius_deg)} @@ -708,7 +709,7 @@ def _args_to_payload(self, *args, **kwargs): # and force the coordinates to FK5 (assuming FK5/ICRS are # interchangeable) since RA/Dec are used below coordinates = commons.parse_coordinates(kwargs['coordinates']).fk5 - radius_deg = commons.radius_to_unit(kwargs['radius'], unit='degree') + radius_deg = Angle(kwargs["radius"]).to_value(u.deg) payload = {format: 'VOTable'} payload['query'] = \ "SELECT * from caom2.Observation o join caom2.Plane p " \ diff --git a/astroquery/esa/jwst/core.py b/astroquery/esa/jwst/core.py index 17b5b1d381..7526f6382c 100644 --- a/astroquery/esa/jwst/core.py +++ b/astroquery/esa/jwst/core.py @@ -20,7 +20,7 @@ from astropy import log from astropy import units -from astropy.coordinates import SkyCoord +from astropy.coordinates import Angle, SkyCoord from astropy.table import vstack from astropy.units import Quantity from requests.exceptions import ConnectionError @@ -438,7 +438,7 @@ def cone_search(self, coordinate, radius, *, if radius is not None: radius_quantity = self.__get_quantity_input(value=radius, msg="radius") - radius_deg = commons.radius_to_unit(radius_quantity, unit='deg') + radius_deg = Angle(radius_quantity).to_value(units.deg) query = (f"SELECT DISTANCE(POINT('ICRS'," f"{str(conf.JWST_MAIN_TABLE_RA)}," diff --git a/astroquery/esasky/core.py b/astroquery/esasky/core.py index 4aee51f97b..90cf75b6d2 100644 --- a/astroquery/esasky/core.py +++ b/astroquery/esasky/core.py @@ -10,10 +10,11 @@ from zipfile import ZipFile from pathlib import Path +from astropy import units as u +from astropy.coordinates import Angle from astropy.io import fits from astropy.utils.console import ProgressBar from astroquery import log -import astropy.units from requests import HTTPError from requests import ConnectionError @@ -50,7 +51,7 @@ class ESASkyClass(BaseQuery): __ACCESS_URL_STRING = "access_url" __USE_INTERSECT_STRING = "useIntersectPolygonInsteadOfContainsPoint" __ZERO_ARCMIN_STRING = "0 arcmin" - __MIN_RADIUS_CATALOG_STRING = "5 arcsec" + __MIN_RADIUS_CATALOG_DEG = Angle(5 * u.arcsec).to_value(u.deg) __HERSCHEL_STRING = 'herschel' __HST_STRING = 'hst' @@ -113,7 +114,7 @@ def query(self, query, *, output_file=None, output_format="votable", verbose=Fal if not verbose: with warnings.catch_warnings(): commons.suppress_vo_warnings() - warnings.filterwarnings("ignore", category=astropy.units.core.UnitsWarning) + warnings.filterwarnings("ignore", category=u.UnitsWarning) job = self._tap.launch_job(query=query, output_file=output_file, output_format=output_format, verbose=False, dump_to_file=output_file is not None) else: @@ -1346,8 +1347,7 @@ def get_spectra_from_table(self, query_table_list, missions=__ALL_STRING, return spectra def _sanitize_input_radius(self, radius): - if (isinstance(radius, str) or isinstance(radius, - astropy.units.Quantity)): + if isinstance(radius, (str, u.Quantity)): return radius else: raise ValueError("Radius must be either a string or " @@ -1553,7 +1553,7 @@ def _open_fits(self, path, verbose=False): if verbose: return fits.open(path) with warnings.catch_warnings(): - warnings.filterwarnings("ignore", category=astropy.io.fits.verify.VerifyWarning) + warnings.filterwarnings("ignore", category=fits.verify.VerifyWarning) return fits.open(path) def _ends_with_fits_like_extentsion(self, name): @@ -1708,7 +1708,7 @@ def _query(self, name, json, verbose=False, **kwargs): def _build_region_query(self, coordinates, radius, row_limit, json): ra = coordinates.transform_to('icrs').ra.deg dec = coordinates.transform_to('icrs').dec.deg - radius_deg = commons.radius_to_unit(radius, unit='deg') + radius_deg = Angle(radius).to_value(u.deg) select_query = "SELECT " if row_limit > 0: @@ -1725,17 +1725,13 @@ def _build_region_query(self, coordinates, radius, row_limit, json): if radius_deg == 0: if json[self.__USE_INTERSECT_STRING]: where_query = (" WHERE 1=INTERSECTS(CIRCLE('ICRS', {}, {}, {}), fov)". - format(ra, dec, commons.radius_to_unit( - self.__MIN_RADIUS_CATALOG_STRING, - unit='deg'))) + format(ra, dec, self.__MIN_RADIUS_CATALOG_DEG)) else: where_query = (" WHERE 1=CONTAINS(POINT('ICRS', {}, {}), CIRCLE('ICRS', {}, {}, {}))". format(tap_ra_column, tap_dec_column, ra, dec, - commons.radius_to_unit( - self.__MIN_RADIUS_CATALOG_STRING, - unit='deg'))) + self.__MIN_RADIUS_CATALOG_DEG)) else: if json[self.__USE_INTERSECT_STRING]: where_query = (" WHERE 1=INTERSECTS(CIRCLE('ICRS', {}, {}, {}), fov)". diff --git a/astroquery/gaia/core.py b/astroquery/gaia/core.py index bb008435a9..3d555f485a 100644 --- a/astroquery/gaia/core.py +++ b/astroquery/gaia/core.py @@ -20,6 +20,7 @@ from collections.abc import Iterable from astropy import units +from astropy.coordinates import Angle from astropy.units import Quantity from astropy.io import votable from astropy.io import fits @@ -544,8 +545,7 @@ def __cone_search(self, coordinate, radius, table_name=None, raHours, dec = commons.coord_to_radec(coord) ra = raHours * 15.0 # Converts to degrees if radius is not None: - radiusQuantity = self.__getQuantityInput(radius, "radius") - radiusDeg = commons.radius_to_unit(radiusQuantity, unit='deg') + radiusDeg = Angle(self.__getQuantityInput(radius, "radius")).to_value(u.deg) if columns: columns = ','.join(map(str, columns)) diff --git a/astroquery/utils/commons.py b/astroquery/utils/commons.py index aa8cb9a7ee..7187c64d7e 100644 --- a/astroquery/utils/commons.py +++ b/astroquery/utils/commons.py @@ -17,7 +17,7 @@ import astropy.utils.data as aud from astropy.io import fits, votable -from astropy.coordinates import Angle, BaseCoordinateFrame, SkyCoord +from astropy.coordinates import BaseCoordinateFrame, SkyCoord from ..exceptions import TimeoutError, InputWarning @@ -39,30 +39,6 @@ ASTROPY_LT_5_1 = not minversion('astropy', '5.1') -def radius_to_unit(radius, unit='degree'): - """ - Helper function: Parse a radius, then return its value in degrees - - Parameters - ---------- - radius : str or `~astropy.units.Quantity` - The radius of a region - - Returns - ------- - Floating point scalar value of radius in degrees - """ - rad = Angle(radius) - - if isinstance(unit, str): - if hasattr(rad, unit): - return getattr(rad, unit) - elif hasattr(rad, f"{unit}s"): - return getattr(rad, f"{unit}s") - - return rad.to(unit).value - - def parse_coordinates(coordinates): """ Takes a string or astropy.coordinates object. Checks if the diff --git a/astroquery/utils/tests/test_utils.py b/astroquery/utils/tests/test_utils.py index 7328ba3435..b86d8daee0 100644 --- a/astroquery/utils/tests/test_utils.py +++ b/astroquery/utils/tests/test_utils.py @@ -438,11 +438,3 @@ def test_filecontainer_get(patch_getreadablefileobj): def test_is_coordinate(coordinates, expected): out = commons._is_coordinate(coordinates) assert out == expected - - -@pytest.mark.parametrize(('radius'), - [0.01*u.deg, '0.01 deg', 0.01*u.arcmin] - ) -def test_radius_to_unit(radius): - c = commons.radius_to_unit(radius) - assert c is not None diff --git a/astroquery/vo_conesearch/core.py b/astroquery/vo_conesearch/core.py index e13b109eb5..a31c21eb93 100644 --- a/astroquery/vo_conesearch/core.py +++ b/astroquery/vo_conesearch/core.py @@ -6,7 +6,7 @@ from numbers import Number from astropy import units as u -from astropy.coordinates import (BaseCoordinateFrame, ICRS, SkyCoord, +from astropy.coordinates import (Angle, BaseCoordinateFrame, ICRS, SkyCoord, Longitude, Latitude) from astropy.io.votable import table @@ -227,12 +227,7 @@ def _validate_coord(coordinates): def _validate_sr(radius): """Validate search radius and return value in deg.""" - if isinstance(radius, Number): - sr = radius - else: - sr = commons.radius_to_unit(radius) - - return sr + return radius if isinstance(radius, Number) else Angle(radius).to_value(u.deg) def _validate_verb(verb):