Skip to content

Commit a30a7d4

Browse files
committed
Added get_query_payload kwargs to gemini
1 parent 2238787 commit a30a7d4

2 files changed

Lines changed: 112 additions & 13 deletions

File tree

astroquery/gemini/core.py

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def _login(self, username, password):
132132
return True
133133

134134
@class_or_instance
135-
def query_region(self, coordinates, *, radius=0.3*units.deg):
135+
def query_region(self, coordinates, *, radius=0.3*units.deg, get_query_payload=False):
136136
"""
137137
search for Gemini observations by target on the sky.
138138
@@ -148,15 +148,20 @@ def query_region(self, coordinates, *, radius=0.3*units.deg):
148148
The string must be parsable by `~astropy.coordinates.Angle`. The
149149
appropriate `~astropy.units.Quantity` object from
150150
`~astropy.units` may also be used. Defaults to 0.3 deg.
151+
get_query_payload : bool, optional
152+
If set to `True` then returns the URL and method that would be used for the
153+
request. Defaults to `False`.
151154
152155
Returns
153156
-------
154-
response : `~astropy.table.Table`
157+
response : `~astropy.table.Table` or dict
158+
The response from the query as an `~astropy.table.Table`, or if get_query_payload
159+
is True, a dictionary containing the URL and HTTP method that would be used.
155160
"""
156-
return self.query_criteria(coordinates=coordinates, radius=radius)
161+
return self.query_criteria(coordinates=coordinates, radius=radius, get_query_payload=get_query_payload)
157162

158163
@class_or_instance
159-
def query_object(self, objectname, *, radius=0.3*units.deg):
164+
def query_object(self, objectname, *, radius=0.3*units.deg, get_query_payload=False):
160165
"""
161166
search for Gemini observations by target on the sky.
162167
@@ -173,18 +178,23 @@ def query_object(self, objectname, *, radius=0.3*units.deg):
173178
The string must be parsable by `~astropy.coordinates.Angle`. The
174179
appropriate `~astropy.units.Quantity` object from
175180
`~astropy.units` may also be used. Defaults to 0.3 deg.
181+
get_query_payload : bool, optional
182+
If set to `True` then returns the URL and method that would be used for the
183+
request. Defaults to `False`.
176184
177185
Returns
178186
-------
179-
response : `~astropy.table.Table`
187+
response : `~astropy.table.Table` or dict
188+
The response from the query as an `~astropy.table.Table`, or if get_query_payload
189+
is True, a dictionary containing the URL and HTTP method that would be used.
180190
"""
181-
return self.query_criteria(objectname=objectname, radius=radius)
191+
return self.query_criteria(objectname=objectname, radius=radius, get_query_payload=get_query_payload)
182192

183193
@class_or_instance
184194
def query_criteria(self, *rawqueryargs, coordinates=None, radius=None, pi_name=None, program_id=None, utc_date=None,
185-
instrument=None, observation_class=None, observation_type=None, mode=None,
186-
adaptive_optics=None, program_text=None, objectname=None, raw_reduced=None,
187-
orderby=None, **rawquerykwargs):
195+
instrument=None, observation_class=None, observation_type=None, mode=None,
196+
adaptive_optics=None, program_text=None, objectname=None, raw_reduced=None,
197+
orderby=None, get_query_payload=False, **rawquerykwargs):
188198
"""
189199
search a variety of known parameters against the Gemini observations.
190200
@@ -294,7 +304,9 @@ def query_criteria(self, *rawqueryargs, coordinates=None, radius=None, pi_name=N
294304
295305
Returns
296306
-------
297-
response : `~astropy.table.Table`
307+
response : `~astropy.table.Table` or dict
308+
The response from the query as an `~astropy.table.Table`, or if get_query_payload
309+
is True, a dictionary containing the URL and HTTP method that would be used.
298310
299311
Raises
300312
------
@@ -316,7 +328,8 @@ def query_criteria(self, *rawqueryargs, coordinates=None, radius=None, pi_name=N
316328
args.append(arg)
317329
if rawquerykwargs:
318330
for (k, v) in rawquerykwargs.items():
319-
kwargs[k] = v
331+
if k != 'get_query_payload':
332+
kwargs[k] = v
320333

321334
# If coordinates is set but we have no radius, set a default
322335
if (coordinates or objectname) and radius is None:
@@ -370,6 +383,8 @@ def query_criteria(self, *rawqueryargs, coordinates=None, radius=None, pi_name=N
370383
if orderby is not None:
371384
kwargs["orderby"] = orderby
372385

386+
if get_query_payload:
387+
kwargs['get_query_payload'] = get_query_payload
373388
return self.query_raw(*args, **kwargs)
374389

375390
@class_or_instance
@@ -380,7 +395,7 @@ def query_raw(self, *args, **kwargs):
380395
This is a more flexible query method. This method will do special handling for
381396
coordinates and radius if present in kwargs. However, for the remaining arguments
382397
it assumes all of args are useable as query path elements. For kwargs, it assumes
383-
all of the elements can be passed as name=value within the query path to Gemini.
398+
all of the elements can be passed as name=value within the query path to the webserver.
384399
385400
This method does not do any validation checking or attempt to interperet the
386401
values being passed, aside from coordinates and radius.
@@ -406,11 +421,24 @@ def query_raw(self, *args, **kwargs):
406421
path to the webserver. The ``orderby`` key value pair has a special
407422
intepretation and is appended as a query parameter like the one used
408423
in the archive website for sorting results.
424+
get_query_payload : bool, optional
425+
If set to `True` then returns the URL and method that would be used for the
426+
request. Defaults to `False`.
409427
410428
Returns
411429
-------
412-
response : `~astropy.table.Table`
430+
response : `~astropy.table.Table` or dict
431+
The response from the query as an `~astropy.table.Table`, or if get_query_payload
432+
is True, a dictionary containing the URL and HTTP method that would be used.
413433
"""
434+
if kwargs.pop('get_query_payload', False):
435+
url = self.url_helper.build_url(*args, **kwargs)
436+
return {
437+
'url': url,
438+
'method': 'GET',
439+
'data': {}
440+
}
441+
414442
url = self.url_helper.build_url(*args, **kwargs)
415443

416444
response = self._request(method="GET", url=url, data={}, timeout=180, cache=False)

astroquery/gemini/tests/test_gemini.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,74 @@ def test_url_helper_eng_fail(test_arg):
171171
urlsplit = url.split('/')
172172
assert (('notengineering' in urlsplit) == should_have_noteng)
173173
assert (('NotFail' in urlsplit) == should_have_notfail)
174+
175+
176+
def test_observations_query_region_get_query_payload():
177+
coords = SkyCoord(210.80242917, 54.34875, unit="deg")
178+
result = gemini.Observations.query_region(
179+
coords,
180+
radius=0.3 * units.deg,
181+
get_query_payload=True
182+
)
183+
assert isinstance(result, dict)
184+
assert 'url' in result
185+
assert 'method' in result
186+
assert result['method'] == 'GET'
187+
assert 'data' in result
188+
assert result['data'] == {}
189+
assert 'ra=210.802429' in result['url']
190+
assert 'dec=54.348750' in result['url']
191+
assert 'sr=0.300000d' in result['url']
192+
193+
194+
def test_observations_query_object_get_query_payload():
195+
result = gemini.Observations.query_object(
196+
'M101',
197+
radius=0.3 * units.deg,
198+
get_query_payload=True
199+
)
200+
assert isinstance(result, dict)
201+
assert 'url' in result
202+
assert 'method' in result
203+
assert result['method'] == 'GET'
204+
assert 'data' in result
205+
assert result['data'] == {}
206+
assert 'object=M101' in result['url']
207+
assert 'sr=0.300000d' in result['url']
208+
209+
210+
def test_observations_query_criteria_get_query_payload():
211+
result = gemini.Observations.query_criteria(
212+
instrument='GMOS-N',
213+
program_id='GN-CAL20191122',
214+
observation_type='BIAS',
215+
utc_date=(date(2019, 10, 1), date(2019, 11, 25)),
216+
get_query_payload=True
217+
)
218+
assert isinstance(result, dict)
219+
assert 'url' in result
220+
assert 'method' in result
221+
assert result['method'] == 'GET'
222+
assert 'data' in result
223+
assert result['data'] == {}
224+
assert 'GMOS-N' in result['url']
225+
assert 'BIAS' in result['url']
226+
assert '20191001-20191125' in result['url']
227+
assert 'GN-CAL20191122' in result['url']
228+
229+
230+
def test_observations_query_raw_get_query_payload():
231+
result = gemini.Observations.query_raw(
232+
'GMOS-N', 'BIAS',
233+
progid='GN-CAL20191122',
234+
get_query_payload=True
235+
)
236+
assert isinstance(result, dict)
237+
assert 'url' in result
238+
assert 'method' in result
239+
assert result['method'] == 'GET'
240+
assert 'data' in result
241+
assert result['data'] == {}
242+
assert 'GMOS-N' in result['url']
243+
assert 'BIAS' in result['url']
244+
assert 'progid=GN-CAL20191122' in result['url']

0 commit comments

Comments
 (0)