Skip to content

Commit

Permalink
Updated unit tests to reflect new timeout arg and cutout size warning.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaymedina committed Apr 4, 2023
1 parent 64157c9 commit 5d77575
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
12 changes: 8 additions & 4 deletions astroquery/mast/cutouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.",
Expand All @@ -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)
Expand Down
16 changes: 15 additions & 1 deletion astroquery/mast/tests/test_mast_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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
Expand Down Expand Up @@ -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 #
###################
Expand Down

0 comments on commit 5d77575

Please sign in to comment.