Skip to content

Commit

Permalink
TST: addressing more review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bsipocz committed Nov 9, 2022
1 parent 4a13dd6 commit 7cc8d8b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 51 deletions.
34 changes: 17 additions & 17 deletions astroquery/desi/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@

class DESILegacySurveyClass(BaseQuery):

def query_region(self, coordinates, radius=0.5*u.arcmin, *, data_release=9):
def query_region(self, coordinates, *, width=0.5*u.arcmin, data_release=9):
"""
Queries a region around the specified coordinates.
Parameters
----------
coordinates : `~astropy.coordinates.SkyCoord`
coordinates around which to query.
radius : `~astropy.units.Quantity`, optional
the radius of the region. If missing, set to default
width : `~astropy.units.Quantity`, optional
the width of the region. If missing, set to default
value of 0.5 arcmin.
data_release: int
data_release : int
the data release of the LegacySurvey to use.
Returns
Expand All @@ -41,9 +41,9 @@ def query_region(self, coordinates, radius=0.5*u.arcmin, *, data_release=9):
coordinates_transformed = coordinates.transform_to(coord.ICRS)

qstr = (f"SELECT all * FROM ls_dr{data_release}.tractor WHERE "
f"dec<{(coordinates_transformed.dec + radius).to_value(u.deg)} and "
f"ra>{coordinates_transformed.ra.to_value(u.deg) - radius.to_value(u.deg) / np.cos(coordinates_transformed.dec)} and "
f"ra<{coordinates_transformed.ra.to_value(u.deg) + radius.to_value(u.deg) / np.cos(coordinates_transformed.dec)}")
f"dec<{(coordinates_transformed.dec + width).to_value(u.deg)} and "
f"ra>{coordinates_transformed.ra.to_value(u.deg) - width.to_value(u.deg) / np.cos(coordinates_transformed.dec)} and "
f"ra<{coordinates_transformed.ra.to_value(u.deg) + width.to_value(u.deg) / np.cos(coordinates_transformed.dec)}")

tap_result = tap_service.run_sync(qstr)
tap_result = tap_result.to_table()
Expand All @@ -53,32 +53,32 @@ def query_region(self, coordinates, radius=0.5*u.arcmin, *, data_release=9):

return filtered_table

def get_images(self, position, pixels=None, radius=0.5*u.arcmin, *, data_release=9, show_progress=True, image_band='g'):
def get_images(self, position, *, pixels=None, width=0.5*u.arcmin, data_release=9, show_progress=True, image_band='g'):
"""
Downloads the images for a certain region of interest.
Parameters
-------
position: `astropy.coordinates`.
----------
position : `astropy.coordinates`.
coordinates around which we define our region of interest.
radius: `~astropy.units.Quantity`, optional
the radius of our region of interest.
data_release: int, optional
width : `~astropy.units.Quantity`, optional
the width of our region of interest.
data_release : int, optional
the data release of the LegacySurvey to use.
show_progress: bool, optional
show_progress : bool, optional
Whether to display a progress bar if the file is downloaded
from a remote server. Default is True.
image_band: str, optional
image_band : str, optional
Default to 'g'
Returns
-------
list: A list of `~astropy.io.fits.HDUList` objects.
list : A list of `~astropy.io.fits.HDUList` objects.
"""

position_transformed = position.transform_to(coord.ICRS)

image_size_arcsec = radius.arcsec
image_size_arcsec = width.arcsec
pixsize = 2 * image_size_arcsec / pixels

image_url = (f"{conf.legacysurvey_service_url}?"
Expand Down
8 changes: 4 additions & 4 deletions astroquery/desi/tests/test_desi.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
}

coords = coord.SkyCoord('11h04m27s +38d12m32s', frame='icrs')
radius = coord.Angle(0.5, unit='arcmin')
width = coord.Angle(0.5, unit='arcmin')
pixels = 60
data_release = 9
emispheres_list = ['north', 'south']
Expand Down Expand Up @@ -101,15 +101,15 @@ def image_tester(images, filetype):
assert np.array_equal(images[0][0].data, data[0].data)


def test_coords_query_region(patch_tap, coords=coords, radius=radius):
result = desi.DESILegacySurvey.query_region(coords, radius)
def test_coords_query_region(patch_tap):
result = desi.DESILegacySurvey.query_region(coords, width=width)
data = Table.read(data_path(DATA_FILES['dummy_tap_table']),
format='ascii.csv', comment='#')
data['objid'] = data['objid'].astype(np.int64)
compare_result_data(result, data)


def test_coords_get_images(patch_get_readable_fileobj, dr=data_release):
images_list = desi.DESILegacySurvey.get_images(coords, data_release=dr, radius=radius, pixels=pixels)
images_list = desi.DESILegacySurvey.get_images(coords, data_release=dr, width=width, pixels=pixels)

image_tester(images_list, 'dummy_hdu_list_fits')
41 changes: 17 additions & 24 deletions astroquery/desi/tests/test_desi_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,26 @@ def test_query_region(self):
dec = 38.209
coordinates = SkyCoord(ra, dec, unit='degree')

radius = Angle(5, unit='arcmin')
width = Angle(15, unit='arcsec')

query1 = DESILegacySurvey.query_region(coordinates, radius=radius, data_release=9)
query1 = DESILegacySurvey.query_region(coordinates, width=width, data_release=9)

assert isinstance(query1, Table)

@pytest.mark.parametrize("valid_inputs", [True, False])
def test_get_images(self, valid_inputs):
@pytest.mark.parametrize(('ra', 'dec', 'width', 'pixels'),
((166.1125, 38.209, 0.5, 60),))
def test_get_images(self, ra, dec, width, pixels):
pos = SkyCoord(ra, dec, unit='degree')
width = Angle(width, unit='arcmin')

if valid_inputs:
ra = 166.1125
dec = 38.209
radius_input = 0.5
pixels = 60
else:
ra = 86.633212
dec = 22.01446
radius_input = 3
pixels = 1296000
query1 = DESILegacySurvey.get_images(pos, pixels=pixels, width=width, data_release=9)
assert isinstance(query1, list)
assert isinstance(query1[0], HDUList)

pos = SkyCoord(ra, dec, unit='degree')
radius = Angle(radius_input, unit='arcmin')

if valid_inputs:
query1 = DESILegacySurvey.get_images(pos, pixels, radius, data_release=9)
assert isinstance(query1, list)
assert isinstance(query1[0], HDUList)
else:
with pytest.raises(NoResultsWarning):
DESILegacySurvey.get_images(pos, pixels, radius, data_release=9)
def test_noresults_warning(self):
# Using position with no coverage
pos = SkyCoord(86.633212, 22.01446, unit='degree')
width = Angle(3, unit='arcmin')

with pytest.warns(NoResultsWarning):
DESILegacySurvey.get_images(pos, width=width, pixels=100)
12 changes: 6 additions & 6 deletions docs/desi/desi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Query a region

This example shows how to query a certain region with DesiLegacySurvey.
We'll use a set of coordinates that define the region of interest,
and search within a 5 arcmin radius.
and search within a 15 arcsec box.

.. doctest-remote-data::

Expand All @@ -25,9 +25,9 @@ and search within a 5 arcmin radius.
>>> ra = Angle('11h04m27s', unit='hourangle').degree
>>> dec = Angle('+38d12m32s', unit='hourangle').degree
>>> coordinates = SkyCoord(ra, dec, unit='degree')
>>> radius = Angle(5, unit='arcmin')
>>> table_out = DESILegacySurvey.query_region(coordinates, radius, data_release=9)
>>> print(table_out[:5])
>>> width = Angle(15, unit='arcsec')
>>> table_out = DESILegacySurvey.query_region(coordinates, width=width, data_release=9)
>>> print(table_out[:5]) # doctest: +IGNORE_OUTPUT
ls_id dec ra ... type wise_coadd_id
...
---------------- ----------------- ------------------ ... ---- -------------
Expand Down Expand Up @@ -56,8 +56,8 @@ we can define our region in the same way used in the example above.
>>> pixels = 60
>>>
>>> pos = SkyCoord(ra, dec, unit='degree')
>>> radius = Angle(radius_input, unit='arcmin')
>>> im = DESILegacySurvey.get_images(pos, pixels, radius, data_release=9)
>>> width = Angle(radius_input, unit='arcmin')
>>> im = DESILegacySurvey.get_images(pos, pixels=pixels, width=width, data_release=9)

All the information we need can be found within the object "im".

Expand Down

0 comments on commit 7cc8d8b

Please sign in to comment.