Skip to content

Commit 811e732

Browse files
committed
enforce upper limit on MastMissions query radius
1 parent d927bdf commit 811e732

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

astroquery/mast/missions.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ class MastMissionsClass(MastQueryWithLogin):
4747
'spectral_type', 'bmv0_mag', 'u_mag', 'b_mag', 'v_mag', 'gaia_g_mean_mag', 'star_mass',
4848
'instrument', 'grating', 'filter', 'observation_id']
4949

50+
# maximum supported query radius
51+
_max_query_radius = 30 * u.arcmin
52+
5053
def __init__(self, *, mission='hst', mast_token=None):
5154
super().__init__(mast_token=mast_token)
5255

@@ -217,6 +220,7 @@ def query_region_async(self, coordinates, *, radius=3*u.arcmin, limit=5000, offs
217220
Default is 3 arcminutes. The radius around the coordinates to search within.
218221
The string must be parsable by `~astropy.coordinates.Angle`. The
219222
appropriate `~astropy.units.Quantity` object from `~astropy.units` may also be used.
223+
The maximum supported query radius is 30 arcminutes.
220224
limit : int
221225
Default is 5000. The maximum number of dataset IDs in the results.
222226
offset : int
@@ -235,6 +239,11 @@ def query_region_async(self, coordinates, *, radius=3*u.arcmin, limit=5000, offs
235239
Returns
236240
-------
237241
response : list of `~requests.Response`
242+
243+
Raises
244+
------
245+
InvalidQueryError
246+
If the query radius is larger than the limit (30 arcminute).
238247
"""
239248

240249
self.limit = limit
@@ -249,6 +258,11 @@ def query_region_async(self, coordinates, *, radius=3*u.arcmin, limit=5000, offs
249258
# If radius is just a number, assume arcminutes
250259
radius = coord.Angle(radius, u.arcmin)
251260

261+
if radius > self._max_query_radius:
262+
raise InvalidQueryError(
263+
f"Query radius too large. Must be ≤{self._max_query_radius}, got {radius}."
264+
)
265+
252266
# Dataset ID column should always be returned
253267
if select_cols:
254268
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.
284298
Default is 3 arcminutes. The radius around the coordinates to search within.
285299
The string must be parsable by `~astropy.coordinates.Angle`. The
286300
appropriate `~astropy.units.Quantity` object from `~astropy.units` may also be used.
301+
The maximum supported query radius is 30 arcminutes.
287302
limit : int
288303
Default is 5000. The maximum number of dataset IDs in the results.
289304
offset : int
@@ -310,6 +325,11 @@ def query_criteria_async(self, *, coordinates=None, objectname=None, radius=3*u.
310325
Returns
311326
-------
312327
response : list of `~requests.Response`
328+
329+
Raises
330+
------
331+
InvalidQueryError
332+
If the query radius is larger than the limit (30 arcminute).
313333
"""
314334

315335
self.limit = limit
@@ -327,6 +347,11 @@ def query_criteria_async(self, *, coordinates=None, objectname=None, radius=3*u.
327347
# if radius is just a number we assume degrees
328348
radius = coord.Angle(radius, u.arcmin)
329349

350+
if radius > self._max_query_radius:
351+
raise InvalidQueryError(
352+
f"Query radius too large. Must be ≤{self._max_query_radius}, got {radius}."
353+
)
354+
330355
# Dataset ID column should always be returned
331356
if select_cols:
332357
select_cols.append(self.dataset_kwds.get(self.mission, None))

astroquery/mast/tests/test_mast.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,22 @@ def test_missions_get_dataset_kwd(patch_post, caplog):
510510
with caplog.at_level('WARNING', logger='astroquery'):
511511
assert 'The mission "unknown" does not have a known dataset ID keyword' in caplog.text
512512

513+
514+
@pytest.mark.parametrize(
515+
'method, kwargs,',
516+
[['query_region', dict()],
517+
['query_criteria', dict(ang_sep=0.6)]]
518+
)
519+
def test_missions_radius_too_large(method, kwargs):
520+
m = mast.MastMissions(mission='jwst')
521+
coordinates = SkyCoord(0, 0, unit=u.deg)
522+
radius = m._max_query_radius + 0.1 * u.deg
523+
with pytest.raises(
524+
InvalidQueryError, match='Query radius too large. Must be*'
525+
):
526+
getattr(m, method)(coordinates=coordinates, radius=radius, **kwargs)
527+
528+
513529
###################
514530
# MastClass tests #
515531
###################

0 commit comments

Comments
 (0)