Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove astroquery.utils.commons.radius_to_unit() #2667

Merged
merged 2 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions astroquery/cadc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)}
Expand Down Expand Up @@ -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 " \
Expand Down
4 changes: 2 additions & 2 deletions astroquery/esa/jwst/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)},"
Expand Down
22 changes: 9 additions & 13 deletions astroquery/esasky/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 "
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand All @@ -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)".
Expand Down
4 changes: 2 additions & 2 deletions astroquery/gaia/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
26 changes: 1 addition & 25 deletions astroquery/utils/commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
8 changes: 0 additions & 8 deletions astroquery/utils/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 2 additions & 7 deletions astroquery/vo_conesearch/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down