Skip to content

Commit e41373d

Browse files
burnout87bsipocz
authored andcommitted
using Quantity class instead of Angle, fixed docstr
1 parent b38d853 commit e41373d

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

astroquery/desi/core.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
import numpy as np
88
import astropy.coordinates as coord
99

10+
from astropy import units as u
11+
from astropy.units import Quantity
1012
from astroquery.exceptions import NoResultsWarning
1113
from astroquery.query import BaseQuery
12-
from astroquery.utils import commons, async_to_sync
14+
from astroquery.utils import commons
1315
from astroquery.desi import conf
1416

1517
__all__ = ['DESILegacySurvey', 'DESILegacySurveyClass']
@@ -25,28 +27,28 @@ def query_region(self, coordinates, radius=None, *, data_release=9):
2527
----------
2628
coordinates : `~astropy.coordinates.SkyCoord`
2729
coordinates around which to query.
28-
radius : `~astropy.coordinates.Angle`, optional
30+
radius : `~astropy.units.Quantity`, optional
2931
the radius of the region. If missing, set to default
3032
value of 0.5 arcmin.
3133
data_release: int
3234
the data release of the LegacySurvey to use.
3335
3436
Returns
3537
-------
36-
response : `astropy.table.Table`
38+
response : `~astropy.table.Table`
3739
"""
3840

3941
if radius is None:
40-
radius = coord.Angle(0.5, unit='arcmin')
42+
radius = Quantity(0.5, unit='arcmin')
4143

4244
tap_service = vo.dal.TAPService(conf.tap_service_url)
4345
coordinates_transformed = coordinates.transform_to(coord.ICRS)
4446

4547
qstr = (f"SELECT all * FROM ls_dr{data_release}.tractor WHERE "
46-
f"dec>{coordinates_transformed.dec.deg - radius.deg} and "
47-
f"dec<{coordinates_transformed.dec.deg + radius.deg} and "
48-
f"ra>{coordinates_transformed.ra.deg - radius.deg / np.cos(coordinates_transformed.dec.deg * np.pi / 180.)} and "
49-
f"ra<{coordinates_transformed.ra.deg + radius.deg / np.cos(coordinates_transformed.dec.deg * np.pi / 180)}")
48+
f"dec>{(coordinates_transformed.dec - radius).to(u.deg).value} and "
49+
f"dec<{(coordinates_transformed.dec + radius).to(u.deg).value} and "
50+
f"ra>{coordinates_transformed.ra.to(u.deg).value - radius.to(u.deg).value / np.cos(coordinates_transformed.dec.to(u.deg).value * np.pi / 180.)} and "
51+
f"ra<{coordinates_transformed.ra.to(u.deg).value + radius.to(u.deg).value / np.cos(coordinates_transformed.dec.to(u.deg).value * np.pi / 180)}")
5052

5153
tap_result = tap_service.run_sync(qstr)
5254
tap_result = tap_result.to_table()
@@ -56,24 +58,31 @@ def query_region(self, coordinates, radius=None, *, data_release=9):
5658

5759
return filtered_table
5860

59-
def get_images(self, position, pixels, radius, *, data_release=9, show_progress=True, image_band='g'):
61+
def get_images(self, position, pixels, radius=None, *, data_release=9, show_progress=True, image_band='g'):
6062
"""
6163
Downloads the images for a certain region of interest.
6264
6365
Parameters
6466
-------
65-
position: `astropy.coordinates`.
67+
position: `~astropy.coordinates`.
6668
coordinates around which we define our region of interest.
67-
radius: `astropy.units.Quantity`.
68-
the radius of the cone search.
69-
data_release: int
69+
radius: `~astropy.units.Quantity`, optional
70+
the radius of our region of interest.
71+
data_release: int, optional
7072
the data release of the LegacySurvey to use.
73+
show_progress: bool, optional
74+
Whether to display a progress bar if the file is downloaded
75+
from a remote server. Default is True.
76+
image_band: str, optional
7177
7278
Returns
7379
-------
74-
list: A list of `astropy.io.fits.HDUList` objects.
80+
list: A list of `~astropy.io.fits.HDUList` objects.
7581
"""
7682

83+
if radius is None:
84+
radius = Quantity(0.5, u.arcmin)
85+
7786
position_transformed = position.transform_to(coord.ICRS)
7887

7988
image_size_arcsec = radius.arcsec
@@ -91,9 +100,9 @@ def get_images(self, position, pixels, radius, *, data_release=9, show_progress=
91100

92101
try:
93102
fits_file = file_container.get_fits()
94-
except (requests.exceptions.HTTPError, urllib.error.HTTPError) as e:
103+
except (requests.exceptions.HTTPError, urllib.error.HTTPError) as exp:
95104
fits_file = None
96-
warnings.warn(f"{str(e)} - Problem retrieving the file at the url: {image_url}", NoResultsWarning)
105+
warnings.warn(f"{str(exp)} - Problem retrieving the file at the url: {image_url}", NoResultsWarning)
97106

98107
return [fits_file]
99108

0 commit comments

Comments
 (0)