Skip to content

Commit d0ed8c9

Browse files
authored
Merge pull request #1998 from olyoberdorf/default_radius_none_if_no_coords
Make radius defaut smarter in criteria query
2 parents 82e4d08 + 6d9010d commit d0ed8c9

File tree

4 files changed

+46
-15
lines changed

4 files changed

+46
-15
lines changed

CHANGES.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ mast
4141
- Added ``Observations.download_file`` method to download a single file from MAST given an input
4242
data URI. [#1825]
4343
- Added case for passing a row to ``Observations.download_file` [#1881]
44-
- Removed deprecated ``Observations.get_hst_s3_uris()``, ``Observations.get_hst_s3_uri()``,
45-
``Core.get_token()``, ``Core.enable_s3_hst_dataset()``, ``Core.disable_s3_hst_dataset()`` and
44+
- Removed deprecated ``Observations.get_hst_s3_uris()``, ``Observations.get_hst_s3_uri()``,
45+
``Core.get_token()``, ``Core.enable_s3_hst_dataset()``, ``Core.disable_s3_hst_dataset()`` and
4646
variables obstype and silent [#1884]
4747
- Added Zcut functionality to astroquery [#1911]
4848
- Fixed error causing empty products passed to ``Observations.get_product_list()`` to yeild a
@@ -56,6 +56,7 @@ esa/hubble
5656
- Module added to query eHST TAP based on a set of specific criteria and
5757
asynchronous jobs are now supported. [#1723]
5858

59+
5960
esa/xmm_newton
6061
^^^^^^^^^^^^^^
6162

@@ -75,15 +76,15 @@ Gemini
7576
- get_file() support for downloading files [#1778]
7677
- fix syntax error in query_criteria() [#1823]
7778
- If QA and/or engineering parameters are explicitly passed, remove the add defaults of `notengineering` and/or
78-
`NotFail` [#1996]
79+
- Smarter defaulting of radius to None unless coordinates are specified, in
80+
which case defaults to 0.3 degrees. [#1995]
7981

8082
heasarc
8183
^^^^^^^
8284

8385
- A ``NoResultsWarning`` is now returned when there is no matching rows were
8486
found in query. [#1829]
8587

86-
8788
SVO FPS
8889
^^^^^^^
8990

astroquery/gemini/core.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def query_object(self, objectname, radius=0.3*units.deg):
182182
return self.query_criteria(objectname=objectname, radius=radius)
183183

184184
@class_or_instance
185-
def query_criteria(self, *rawqueryargs, coordinates=None, radius=0.3*units.deg, pi_name=None, program_id=None, utc_date=None,
185+
def query_criteria(self, *rawqueryargs, coordinates=None, radius=None, pi_name=None, program_id=None, utc_date=None,
186186
instrument=None, observation_class=None, observation_type=None, mode=None,
187187
adaptive_optics=None, program_text=None, objectname=None, raw_reduced=None,
188188
orderby=None, **rawquerykwargs):
@@ -199,7 +199,7 @@ def query_criteria(self, *rawqueryargs, coordinates=None, radius=0.3*units.deg,
199199
The target around which to search. It may be specified as a
200200
string or as the appropriate `~astropy.coordinates` object.
201201
radius : str or `~astropy.units.Quantity` object, optional
202-
Default 0.3 degrees.
202+
Default 0.3 degrees if coordinates are set, else None
203203
The string must be parsable by `~astropy.coordinates.Angle`. The
204204
appropriate `~astropy.units.Quantity` object from
205205
`~astropy.units` may also be used. Defaults to 0.3 deg.
@@ -319,6 +319,9 @@ def query_criteria(self, *rawqueryargs, coordinates=None, radius=0.3*units.deg,
319319
for (k, v) in rawquerykwargs.items():
320320
kwargs[k] = v
321321

322+
# If coordinates is set but we have no radius, set a default
323+
if (coordinates or objectname) and radius is None:
324+
radius = 0.3 * units.deg
322325
# Now consider the canned criteria
323326
if radius is not None:
324327
kwargs["radius"] = radius

astroquery/gemini/tests/test_gemini.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,14 @@ def patch_get(request):
4040
return mp
4141

4242

43+
# to inspect behavior, updated when the mock get call is made
44+
saved_request = None
45+
46+
4347
def get_mockreturn(url, *args, **kwargs):
4448
""" generate the actual mock textual data from our included datafile with json results """
49+
global saved_request
50+
saved_request = {'url': url, 'args': args, 'kwargs': kwargs}
4551
filename = data_path(DATA_FILES['m101'])
4652
f = open(filename, 'r')
4753
text = f.read()
@@ -76,6 +82,25 @@ def test_observations_query_criteria(patch_get):
7682
assert len(result) > 0
7783

7884

85+
def test_observations_query_criteria_radius_defaults(patch_get):
86+
""" test query against an instrument/program via criteria """
87+
result = gemini.Observations.query_criteria(instrument='GMOS-N', program_id='GN-CAL20191122',
88+
observation_type='BIAS')
89+
global saved_request
90+
assert(saved_request is not None and 'args' in saved_request and len(saved_request['args']) >= 2)
91+
assert('/sr=' not in saved_request['args'][1])
92+
saved_request = None
93+
result = gemini.Observations.query_criteria(instrument='GMOS-N', program_id='GN-2016A-Q-9',
94+
observation_type='BIAS', coordinates=coords)
95+
assert(saved_request is not None and 'args' in saved_request and len(saved_request['args']) >= 2)
96+
assert('/sr=0.300000d' in saved_request['args'][1])
97+
saved_request = None
98+
result = gemini.Observations.query_criteria(instrument='GMOS-N', program_id='GN-2016A-Q-9',
99+
observation_type='BIAS', objectname='m101')
100+
assert(saved_request is not None and 'args' in saved_request and len(saved_request['args']) >= 2)
101+
assert('/sr=0.300000d' in saved_request['args'][1])
102+
103+
79104
def test_observations_query_raw(patch_get):
80105
""" test querying raw """
81106
result = gemini.Observations.query_raw('GMOS-N', 'BIAS', progid='GN-CAL20191122')

docs/gemini/gemini.rst

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Positional queries can be based on a sky position. Radius is an optional parame
2525
>>> coord = coordinates.SkyCoord(210.80242917, 54.34875, unit="deg")
2626
>>> data = Observations.query_region(coordinates=coord, radius=0.3*units.deg)
2727
>>> print(data[0:5])
28-
28+
2929
exposure_time detector_roi_setting detector_welldepth_setting telescope ...
3030
------------- -------------------- -------------------------- ------------ ...
3131
119.9986 Full Frame -- Gemini-North ...
@@ -60,14 +60,16 @@ Observation Criteria Queries
6060
----------------------------
6161

6262
Additional search terms are available as optional arguments to the `~astroquery.gemini.ObservationsClass.query_criteria`
63-
call. These all have default values of None, in which case they will not be considered during the search.
63+
call. These all have default values of None, in which case they will not be considered during the search. The one
64+
exception is ``radius``, which will be set to 0.3 degrees by default if either ``coordinates`` or ``objectname`` are
65+
specified.
6466

6567
Some examples of available search fields are the instrument used, such as GMOS-N, the observation_type, such as BIAS,
6668
and the program ID. For a complete list of available search fields, see
6769
`~astroquery.gemini.ObservationsClass.query_criteria`
6870

6971
.. code-block:: python
70-
72+
7173
>>> from astroquery.gemini import Observations
7274
7375
>>> data = Observations.query_criteria(instrument='GMOS-N',
@@ -83,7 +85,7 @@ and the program ID. For a complete list of available search fields, see
8385
0.0 Full Frame -- Gemini-North True ...
8486
0.0 Full Frame -- Gemini-North True ...
8587
86-
In addition, the criteria query can accept additional parameters via the ``*rawqueryargs`` and ``**rawquerykwargs``
88+
In addition, the criteria query can accept additional parameters via the ``*rawqueryargs`` and ``**rawquerykwargs``
8789
optional parameters.
8890

8991
The ``orderby`` parameter can be used to pass the desired sort order.
@@ -111,14 +113,15 @@ Regular *args* search terms are sent down as part of the URL path. Any *kwargs*
111113
key=value also in the URL path. You can infer what to pass the function by inspecting the URL after a search in the
112114
Gemini website. This call also supports the ``orderby`` kwarg for requesting the sort order.
113115

114-
This example is equivalent to doing a web search with
116+
This example is equivalent to doing a web search with
115117
`this example search <https://archive.gemini.edu/searchform/RAW/cols=CTOWEQ/notengineering/GMOS-N/PIname=Hirst/NotFail>`_ .
116-
Note that *NotFail*, *notengineering*, *RAW*, and *cols* are all sent automatically. Only the additional
118+
119+
Note that *NotFail*, *notengineering*, *RAW*, and *cols* are all sent automatically. Only the additional
117120
terms need be passed into the method. If QA or engineering search terms are passed, those will replace
118121
the *NotFail* or *notengineering* terms respectively.
119122

120123
.. code-block:: python
121-
124+
122125
>>> from astroquery.gemini import Observations
123126
124127
>>> data = Observations.query_raw('GMOS-N', 'BIAS', progid='GN-CAL20191122')
@@ -137,7 +140,7 @@ Authenticated Sessions
137140
----------------------
138141

139142
The Gemini module allows for authenticated sessions using your GOA account. This is the same account you login
140-
with on the GOA homepage at `<https://archive.gemini.edu/>`__. The `astroquery.gemini.ObservationsClass.login`
143+
with on the GOA homepage at `<https://archive.gemini.edu/>`__. The `astroquery.gemini.ObservationsClass.login`
141144
method returns `True` if successful.
142145

143146
.. code-block:: python
@@ -167,4 +170,3 @@ Reference/API
167170

168171
.. automodapi:: astroquery.gemini
169172
:no-inheritance-diagram:
170-

0 commit comments

Comments
 (0)