Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------------------------------------------------
Expand Down
25 changes: 25 additions & 0 deletions astroquery/mast/missions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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))
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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))
Expand Down
16 changes: 16 additions & 0 deletions astroquery/mast/tests/test_mast.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
###################
Expand Down
Loading