diff --git a/CHANGES.rst b/CHANGES.rst index 6b7a418315..aefc135b35 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -28,6 +28,7 @@ mast - Filtering by file extension or by a string column is now case-insensitive in ``MastMissions.filter_products`` and ``Observations.filter_products``. [#3427] +- Raise informative error if ``MastMissions`` query radius is too large. [#3447] Infrastructure, Utility and Other Changes and Additions ------------------------------------------------------- diff --git a/astroquery/mast/missions.py b/astroquery/mast/missions.py index ba87307d30..38af7370a7 100644 --- a/astroquery/mast/missions.py +++ b/astroquery/mast/missions.py @@ -47,6 +47,9 @@ class MastMissionsClass(MastQueryWithLogin): 'spectral_type', 'bmv0_mag', 'u_mag', 'b_mag', 'v_mag', 'gaia_g_mean_mag', 'star_mass', 'instrument', 'grating', 'filter', 'observation_id'] + # maximum supported query radius + _max_query_radius = 30 * u.arcmin + def __init__(self, *, mission='hst', mast_token=None): super().__init__(mast_token=mast_token) @@ -217,6 +220,7 @@ def query_region_async(self, coordinates, *, radius=3*u.arcmin, limit=5000, offs Default is 3 arcminutes. The radius around the coordinates to search within. The string must be parsable by `~astropy.coordinates.Angle`. The appropriate `~astropy.units.Quantity` object from `~astropy.units` may also be used. + The maximum supported query radius is 30 arcminutes. limit : int Default is 5000. The maximum number of dataset IDs in the results. offset : int @@ -235,6 +239,11 @@ def query_region_async(self, coordinates, *, radius=3*u.arcmin, limit=5000, offs Returns ------- response : list of `~requests.Response` + + Raises + ------ + InvalidQueryError + If the query radius is larger than the limit (30 arcminutes). """ self.limit = limit @@ -249,6 +258,11 @@ def query_region_async(self, coordinates, *, radius=3*u.arcmin, limit=5000, offs # If radius is just a number, assume arcminutes radius = coord.Angle(radius, u.arcmin) + if radius > self._max_query_radius: + raise InvalidQueryError( + f"Query radius too large. Must be ≤{self._max_query_radius}, got {radius}." + ) + # Dataset ID column should always be returned if select_cols: select_cols.append(self.dataset_kwds.get(self.mission, None)) @@ -284,6 +298,7 @@ def query_criteria_async(self, *, coordinates=None, objectname=None, radius=3*u. Default is 3 arcminutes. The radius around the coordinates to search within. The string must be parsable by `~astropy.coordinates.Angle`. The appropriate `~astropy.units.Quantity` object from `~astropy.units` may also be used. + The maximum supported query radius is 30 arcminutes. limit : int Default is 5000. The maximum number of dataset IDs in the results. offset : int @@ -310,6 +325,11 @@ def query_criteria_async(self, *, coordinates=None, objectname=None, radius=3*u. Returns ------- response : list of `~requests.Response` + + Raises + ------ + InvalidQueryError + If the query radius is larger than the limit (30 arcminutes). """ self.limit = limit @@ -327,6 +347,11 @@ def query_criteria_async(self, *, coordinates=None, objectname=None, radius=3*u. # if radius is just a number we assume degrees radius = coord.Angle(radius, u.arcmin) + if radius > self._max_query_radius: + raise InvalidQueryError( + f"Query radius too large. Must be ≤{self._max_query_radius}, got {radius}." + ) + # Dataset ID column should always be returned if select_cols: select_cols.append(self.dataset_kwds.get(self.mission, None)) diff --git a/astroquery/mast/tests/test_mast.py b/astroquery/mast/tests/test_mast.py index 9d90da325e..63867224d3 100644 --- a/astroquery/mast/tests/test_mast.py +++ b/astroquery/mast/tests/test_mast.py @@ -510,6 +510,22 @@ def test_missions_get_dataset_kwd(patch_post, caplog): with caplog.at_level('WARNING', logger='astroquery'): assert 'The mission "unknown" does not have a known dataset ID keyword' in caplog.text + +@pytest.mark.parametrize( + 'method, kwargs,', + [['query_region', dict()], + ['query_criteria', dict(ang_sep=0.6)]] +) +def test_missions_radius_too_large(method, kwargs, patch_post): + m = mast.MastMissions(mission='jwst') + coordinates = SkyCoord(0, 0, unit=u.deg) + radius = m._max_query_radius + 0.1 * u.deg + with pytest.raises( + InvalidQueryError, match='Query radius too large. Must be*' + ): + getattr(m, method)(coordinates=coordinates, radius=radius, **kwargs) + + ################### # MastClass tests # ###################