From 5d775752da2ff4295877856f7f725f2d0651cc53 Mon Sep 17 00:00:00 2001 From: Jennifer Medina Date: Tue, 4 Apr 2023 02:58:51 -0400 Subject: [PATCH] Updated unit tests to reflect new timeout arg and cutout size warning. --- astroquery/mast/cutouts.py | 12 ++++++++---- astroquery/mast/tests/test_mast_remote.py | 16 +++++++++++++++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/astroquery/mast/cutouts.py b/astroquery/mast/cutouts.py index d0a8f3fdc2..5bdd84bf65 100644 --- a/astroquery/mast/cutouts.py +++ b/astroquery/mast/cutouts.py @@ -68,11 +68,14 @@ def _parse_cutout_size(size, timeout=None, mission=None): either pixels or degrees. """ + # This local variable will change to True if input cutout size exceeds recommended limits for TESS + limit_reached = False + # Making size into an array [ny, nx] if np.isscalar(size): size = np.repeat(size, 2) - limit_reached = (size > 30).any() + if mission == 'TESS': limit_reached = (size > 30).any() if isinstance(size, u.Quantity): size = np.atleast_1d(size) @@ -83,8 +86,9 @@ def _parse_cutout_size(size, timeout=None, mission=None): # Based on the literature, TESS resolution is approx. 21 arcseconds per pixel. # We will convert the recommended upper limit for a dimension from pixels # to the unit being passed. - with u.set_enabled_equivalencies(u.pixel_scale(21 * u.arcsec / u.pixel)): - limit_reached = (size > 30 * u.pixel).any() + if mission == 'TESS': + with u.set_enabled_equivalencies(u.pixel_scale(21 * u.arcsec / u.pixel)): + limit_reached = (size > 30 * u.pixel).any() if len(size) > 2: warnings.warn("Too many dimensions in cutout size, only the first two will be used.", @@ -110,7 +114,7 @@ def _parse_cutout_size(size, timeout=None, mission=None): else: raise InvalidQueryError("Cutout size must be in pixels or angular quantity.") - if (mission == 'TESS') & (limit_reached) & (not timeout): + if (limit_reached) & (not timeout): warnings.warn("You have selected a large cutout size that may result in a timeout error. We suggest limiting" " the size of your requested cutout, or changing the request timeout limit from its" " default 600 seconds to something higher, using the timeout argument.", InputWarning) diff --git a/astroquery/mast/tests/test_mast_remote.py b/astroquery/mast/tests/test_mast_remote.py index 09e41a02a1..8bf7c2af8f 100644 --- a/astroquery/mast/tests/test_mast_remote.py +++ b/astroquery/mast/tests/test_mast_remote.py @@ -938,7 +938,7 @@ def test_tesscut_download_cutouts_mt(self, tmpdir): assert error_tica_mt in str(error_msg.value) @pytest.mark.parametrize("product", ["tica", "spoc"]) - def test_tesscut_get_cutouts(self, product): + def test_tesscut_get_cutouts(self, product, caplog): coord = SkyCoord(107.18696, -70.50919, unit="deg") @@ -964,6 +964,11 @@ def test_tesscut_get_cutouts(self, product): assert len(cutout_hdus_list) >= 1 assert isinstance(cutout_hdus_list[0], fits.HDUList) + # Check that an INFO message is returned when timeout is adjusted + mast.Tesscut.get_cutouts(product=product, coordinates=coord, size=5, timeout=1000) + with caplog.at_level("INFO", logger="astroquery"): + assert "timeout upper limit is being changed" in caplog.text + def test_tesscut_get_cutouts_mt(self): # Moving target functionality testing @@ -1016,6 +1021,15 @@ def test_tesscut_get_cutouts_mt(self): moving_target=True) assert error_tica_mt in str(error_msg.value) + @pytest.mark.xfail(raises=InputWarning) + @pytest.mark.parametrize("product", ["tica", "spoc"]) + @pytest.mark.parametrize("size", [31, 0.2 * u.deg, 5000 * u.arcsec, 20 * u.arcmin]) + def test_tesscut_timeout_param(self, product, size): + + # Check that a warning comes up when cutout size too big + coordinates = '60 60' + mast.Tesscut.get_cutouts(product=product, coordinates=coordinates, size=size) + ################### # ZcutClass tests # ###################