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
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ vo_conesearch
Service fixes and enhancements
------------------------------

astrometry_net
^^^^^^^^^^^^^^

- Added ``get_query_payload`` kwarg to aid in debugging. [#3555]

svo_fps
^^^^^^^

Expand Down
13 changes: 13 additions & 0 deletions astroquery/astrometry_net/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ def solve_from_source_list(self, x, y, image_width, image_height, *,
solve_timeout=TIMEOUT,
verbose=True,
return_submission_id=False,
get_query_payload=False,
**settings
):
"""
Expand All @@ -307,6 +308,9 @@ def solve_from_source_list(self, x, y, image_width, image_height, *,
Whether to print out information about the solving.
return_submission_id : bool, optional
Whether to return the Submission ID number.
get_query_payload : bool, optional
if set to `True` then returns the dictionary sent as the HTTP
request. Defaults to `False`.

For a list of the remaining settings, use the method
`~AstrometryNetClass.show_allowed_settings`.
Expand All @@ -323,6 +327,8 @@ def solve_from_source_list(self, x, y, image_width, image_height, *,
settings['image_height'] = image_height
settings['session'] = self._session_id
payload = self._construct_payload(settings)
if get_query_payload:
return payload
url = url_helpers.join(self.API_URL, 'url_upload')
response = self._request('POST', url, data=payload, cache=False)
if response.status_code != 200:
Expand All @@ -342,6 +348,7 @@ def solve_from_image(self, image_file_path, *, force_image_upload=False,
solve_timeout=TIMEOUT,
verbose=True,
return_submission_id=False,
get_query_payload=False,
**settings):
"""
Plate solve from an image, either by uploading the image to
Expand Down Expand Up @@ -387,6 +394,9 @@ def solve_from_image(self, image_file_path, *, force_image_upload=False,

return_submission_id : bool, optional
Whether to return the Submission ID number.
get_query_payload : bool, optional
if set to `True` then returns the dictionary sent as the HTTP
request. Defaults to `False`.

For a list of the remaining settings, use the method
`~AstrometryNetClass.show_allowed_settings`.
Expand All @@ -410,6 +420,8 @@ def solve_from_image(self, image_file_path, *, force_image_upload=False,
self._login()
settings['session'] = self._session_id
payload = self._construct_payload(settings)
if get_query_payload:
return payload
url = url_helpers.join(self.API_URL, 'upload')
with open(image_file_path, 'rb') as f:
response = self._request('POST', url, data=payload,
Expand Down Expand Up @@ -464,6 +476,7 @@ def solve_from_image(self, image_file_path, *, force_image_upload=False,
solve_timeout=solve_timeout,
verbose=verbose,
return_submission_id=return_submission_id,
get_query_payload=get_query_payload,
**settings)
if response.status_code != 200:
raise RuntimeError('Post of job failed')
Expand Down
41 changes: 41 additions & 0 deletions astroquery/astrometry_net/tests/test_astrometry_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json

import pytest
from unittest.mock import patch, mock_open

from .. import AstrometryNet

Expand Down Expand Up @@ -186,3 +187,43 @@ def test_invalid_setting_in_solve_from_source_list_name_raises_error():
# The keyword argument is definitely not one of the allowed ones.
anet.solve_from_source_list([], [], [], [], im_a_bad_setting_name=5)
assert 'im_a_bad_setting_name is not allowed' in str(e.value)


def test_get_query_payload_solve_from_source_list():
anet = AstrometryNet()
anet.api_key = 'fakekey'
# Mock the _login method to prevent actual HTTP requests
with patch.object(anet, '_login'):
# Test that get_query_payload=True returns the payload dict
payload = anet.solve_from_source_list([1, 2, 3], [4, 5, 6], 100, 100,
get_query_payload=True)
assert isinstance(payload, dict)
assert 'request-json' in payload
settings = json.loads(payload['request-json'])
assert settings['x'] == [1.0, 2.0, 3.0]
assert settings['y'] == [4.0, 5.0, 6.0]
assert settings['image_width'] == 100
assert settings['image_height'] == 100


def test_get_query_payload_solve_from_image():
anet = AstrometryNet()
anet.api_key = 'fakekey'
with patch.object(anet, '_login'):
anet._session_id = 'fakesessionid'
with patch('builtins.open', mock_open()):
payload = anet.solve_from_image('fake_image.fits',
get_query_payload=True,
center_ra=10.5,
center_dec=20.3)
assert isinstance(payload, dict)
assert 'request-json' in payload
settings = json.loads(payload['request-json'])
assert settings['session'] == 'fakesessionid'
assert settings['center_ra'] == 10.5
assert settings['center_dec'] == 20.3
# Verify that source list specific parameters are not present
assert 'x' not in settings
assert 'y' not in settings
assert 'image_width' not in settings
assert 'image_height' not in settings
12 changes: 12 additions & 0 deletions docs/astrometry_net/astrometry_net.rst
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,18 @@ There are two parameters that describe setting a license:
other users. This can either be set to ``y``, ``n``, or ``d``, which
uses the default license associated with the api key.

Debugging Options
^^^^^^^^^^^^^^^^^

To inspect the data being sent to the server for debugging purposes without
making a network call, you can use the following parameter:

``get_query_payload``
If set to ``True``, returns the prepared query payload and does not send
the request to the external server. No job is created and no solution is
returned. This allows verification of parameters, source lists, or image
headers before submitting an actual solve operation.

Reference/API
=============

Expand Down
Loading