From 7cc8d8b12829a7d3696266f333da1cfca3fe3d01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brigitta=20Sip=C5=91cz?= Date: Tue, 8 Nov 2022 16:27:16 -0800 Subject: [PATCH] TST: addressing more review comments --- astroquery/desi/core.py | 34 +++++++++---------- astroquery/desi/tests/test_desi.py | 8 ++--- astroquery/desi/tests/test_desi_remote.py | 41 ++++++++++------------- docs/desi/desi.rst | 12 +++---- 4 files changed, 44 insertions(+), 51 deletions(-) diff --git a/astroquery/desi/core.py b/astroquery/desi/core.py index 65c0a8c608..5c45e90962 100644 --- a/astroquery/desi/core.py +++ b/astroquery/desi/core.py @@ -18,7 +18,7 @@ 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. @@ -26,10 +26,10 @@ def query_region(self, coordinates, radius=0.5*u.arcmin, *, data_release=9): ---------- 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 @@ -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() @@ -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}?" diff --git a/astroquery/desi/tests/test_desi.py b/astroquery/desi/tests/test_desi.py index 75f58e025e..0d9ae737ff 100644 --- a/astroquery/desi/tests/test_desi.py +++ b/astroquery/desi/tests/test_desi.py @@ -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'] @@ -101,8 +101,8 @@ 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) @@ -110,6 +110,6 @@ def test_coords_query_region(patch_tap, coords=coords, radius=radius): 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') diff --git a/astroquery/desi/tests/test_desi_remote.py b/astroquery/desi/tests/test_desi_remote.py index a33bfa7328..be607955cd 100644 --- a/astroquery/desi/tests/test_desi_remote.py +++ b/astroquery/desi/tests/test_desi_remote.py @@ -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) diff --git a/docs/desi/desi.rst b/docs/desi/desi.rst index 4dca0d0149..eb66967644 100644 --- a/docs/desi/desi.rst +++ b/docs/desi/desi.rst @@ -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:: @@ -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 ... ---------------- ----------------- ------------------ ... ---- ------------- @@ -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".