Skip to content

Commit 339b524

Browse files
authored
Merge pull request #3318 from nkphysics/skyview-add-get_query_payload
Added `get_query_payload` kwarg to skyview
2 parents 8e450ca + 8d3320d commit 339b524

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

CHANGES.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ SIMBAD
5151
mode. It provides slower to start, but more robust queries for which the timeout can
5252
be increased (with the ``timeout`` property or with the configuration file) [#3305]
5353

54+
skyview
55+
^^^^^^^
56+
57+
58+
- Added ``get_query_payload`` kwarg to ``Skyview.get_images()`` and ``Skyview.get_images_list()``
59+
to return the query payload [#3318]
60+
5461
utils.tap
5562
^^^^^^^^^
5663

astroquery/skyview/core.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,18 @@ def _generate_payload(self, input=None):
7979
url = urlparse.urljoin(self.URL, form.get('action'))
8080
return url, payload
8181

82-
def _submit_form(self, input=None, cache=True):
82+
def _submit_form(self, input=None, cache=True, get_query_payload=False):
8383
url, payload = self._generate_payload(input=input)
84+
if get_query_payload:
85+
return payload
8486
response = self._request('GET', url, params=payload, cache=cache)
8587
response.raise_for_status()
8688
return response
8789

8890
def get_images(self, position, survey, *, coordinates=None, projection=None,
8991
pixels=None, scaling=None, sampler=None, resolver=None,
9092
deedger=None, radius=None, height=None, width=None, cache=True,
91-
show_progress=True):
93+
show_progress=True, get_query_payload=False):
9294
"""
9395
Query the SkyView service, download the FITS file that will be
9496
found and return a generator over the local paths to the
@@ -197,15 +199,18 @@ def get_images(self, position, survey, *, coordinates=None, projection=None,
197199
projection=projection, pixels=pixels, scaling=scaling,
198200
sampler=sampler, resolver=resolver, deedger=deedger,
199201
radius=radius, height=height, width=width,
200-
cache=cache, show_progress=show_progress)
202+
cache=cache, show_progress=show_progress,
203+
get_query_payload=get_query_payload)
204+
if get_query_payload:
205+
return readable_objects
201206
return [obj.get_fits() for obj in readable_objects]
202207

203208
@prepend_docstr_nosections(get_images.__doc__)
204209
def get_images_async(self, position, survey, *, coordinates=None,
205210
projection=None, pixels=None, scaling=None,
206211
sampler=None, resolver=None, deedger=None,
207212
radius=None, height=None, width=None,
208-
cache=True, show_progress=True):
213+
cache=True, show_progress=True, get_query_payload=False):
209214
"""
210215
Returns
211216
-------
@@ -214,16 +219,19 @@ def get_images_async(self, position, survey, *, coordinates=None,
214219
image_urls = self.get_image_list(position, survey, coordinates=coordinates,
215220
projection=projection, pixels=pixels, scaling=scaling, sampler=sampler,
216221
resolver=resolver, deedger=deedger, radius=radius,
217-
height=height, width=width, cache=cache)
218-
return [commons.FileContainer(url, encoding='binary',
219-
show_progress=show_progress)
222+
height=height, width=width, cache=cache,
223+
get_query_payload=get_query_payload)
224+
if get_query_payload:
225+
return image_urls
226+
return [commons.FileContainer(url, encoding='binary', show_progress=show_progress)
220227
for url in image_urls]
221228

222229
@prepend_docstr_nosections(get_images.__doc__, sections=['Returns', 'Examples'])
223230
def get_image_list(self, position, survey, *, coordinates=None,
224231
projection=None, pixels=None, scaling=None,
225232
sampler=None, resolver=None, deedger=None,
226-
radius=None, width=None, height=None, cache=True):
233+
radius=None, width=None, height=None, cache=True,
234+
get_query_payload=False):
227235
"""
228236
Returns
229237
-------
@@ -263,7 +271,9 @@ def get_image_list(self, position, survey, *, coordinates=None,
263271
'imscale': size_deg,
264272
'size': size_deg,
265273
'pixels': pixels}
266-
response = self._submit_form(input, cache=cache)
274+
response = self._submit_form(input, cache=cache, get_query_payload=get_query_payload)
275+
if get_query_payload:
276+
return response
267277
urls = self._parse_response(response)
268278
return urls
269279

astroquery/skyview/tests/test_skyview.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ def test_get_image_list_local(patch_get, patch_fromname):
7676
assert url.startswith('../../tempspace/fits/')
7777

7878

79+
def test_get_image_list_payload(patch_get, patch_fromname):
80+
surveys = ['Fermi 5', 'HRI', 'NVSS']
81+
payload = SkyView.get_image_list(position='Eta Carinae',
82+
survey=surveys,
83+
get_query_payload=True)
84+
assert len(payload) == 14
85+
assert payload["Position"] == '161.265 -59.6844'
86+
assert len(payload["survey"]) == 3
87+
for survey in surveys:
88+
assert survey in payload["survey"]
89+
90+
7991
def test_survey_validation(patch_get):
8092
with pytest.raises(ValueError) as ex:
8193
SkyView.get_image_list(position='doesnt matter',

0 commit comments

Comments
 (0)