Skip to content

Commit aa9ce56

Browse files
authored
Merge pull request #2685 from prajwel/main
` return_submission_id` option added to astrometry_net monitor_submission.
2 parents 0c06dd5 + 199e45f commit aa9ce56

File tree

3 files changed

+62
-13
lines changed

3 files changed

+62
-13
lines changed

CHANGES.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ alma
5959
- Fixed bug #2489 in which blank URLs were being sent to the downloader [#2490]
6060
- Removed deprecated broken functions from ``alma.utils``. [#2331]
6161

62-
astrometry.net
62+
astrometry_net
6363
^^^^^^^^^^^^^^
6464

6565
- Added a ``verbose=`` keyword argument to ``AstrometryNet`` to control whether or not
@@ -69,12 +69,11 @@ astrometry.net
6969
solved by constructing a source list internally before sending data to
7070
astrometry.net. [#2484]
7171

72-
astrometry.net
73-
^^^^^^^^^^^^^^
74-
7572
- Avoid duplicated warnings about API key and raise an error only when API key is
7673
needed but not set. [#2483]
7774

75+
- Added ``return_submission_id`` keyword argument to ``monitor_submission()``. [#2685]
76+
7877
cadc
7978
^^^^
8079

astroquery/astrometry_net/core.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def _validate_settings(self, settings):
199199
'values for {}'.format(scale_type, required_keys))
200200

201201
def monitor_submission(self, submission_id, *,
202-
solve_timeout=TIMEOUT, verbose=True):
202+
solve_timeout=TIMEOUT, verbose=True, return_submission_id=False):
203203
"""
204204
Monitor the submission for completion.
205205
@@ -212,15 +212,19 @@ def monitor_submission(self, submission_id, *,
212212
Time, in seconds, to wait for the astrometry.net solver to find
213213
a solution.
214214
verbose : bool, optional
215-
Whether to print out information about the solving
215+
Whether to print out information about the solving.
216+
return_submission_id : bool, optional
217+
Whether to return the Submission ID number.
216218
217219
Returns
218220
-------
219221
220-
None or `astropy.io.fits.Header`
222+
None or `~astropy.io.fits.Header` or (`~astropy.io.fits.Header`, str)
221223
The contents of the returned object depend on whether the solve
222224
succeeds or fails. If the solve succeeds the header with
223-
the WCS solution generated by astrometry.net is returned. If the solve
225+
the WCS solution generated by astrometry.net is returned. A tuple
226+
containing WCS solution and Submission ID is return if the
227+
return_submission_id parameter is set True. If the solve
224228
fails then an empty dictionary is returned. See below for the outcome
225229
if the solve times out.
226230
@@ -268,11 +272,15 @@ def monitor_submission(self, submission_id, *,
268272
else:
269273
# Try to future-proof a little bit
270274
raise RuntimeError('Unrecognized status {}'.format(status))
271-
return wcs
275+
if return_submission_id is False:
276+
return wcs
277+
else:
278+
return (wcs, submission_id)
272279

273280
def solve_from_source_list(self, x, y, image_width, image_height, *,
274281
solve_timeout=TIMEOUT,
275282
verbose=True,
283+
return_submission_id=False,
276284
**settings
277285
):
278286
"""
@@ -293,7 +301,9 @@ def solve_from_source_list(self, x, y, image_width, image_height, *,
293301
Time, in seconds, to wait for the astrometry.net solver to find
294302
a solution.
295303
verbose : bool, optional
296-
Whether to print out information about the solving
304+
Whether to print out information about the solving.
305+
return_submission_id : bool, optional
306+
Whether to return the Submission ID number.
297307
298308
For a list of the remaining settings, use the method
299309
`~AstrometryNetClass.show_allowed_settings`.
@@ -318,14 +328,16 @@ def solve_from_source_list(self, x, y, image_width, image_height, *,
318328
submission_id = response_d['subid']
319329
return self.monitor_submission(submission_id,
320330
solve_timeout=solve_timeout,
321-
verbose=verbose)
331+
verbose=verbose,
332+
return_submission_id=return_submission_id)
322333

323334
def solve_from_image(self, image_file_path, *, force_image_upload=False,
324335
ra_key=None, dec_key=None,
325336
ra_dec_units=None,
326337
fwhm=3, detect_threshold=5,
327338
solve_timeout=TIMEOUT,
328339
verbose=True,
340+
return_submission_id=False,
329341
**settings):
330342
"""
331343
Plate solve from an image, either by uploading the image to
@@ -367,7 +379,10 @@ def solve_from_image(self, image_file_path, *, force_image_upload=False,
367379
a solution.
368380
369381
verbose : bool, optional
370-
Whether to print out information about the solving
382+
Whether to print out information about the solving.
383+
384+
return_submission_id : bool, optional
385+
Whether to return the Submission ID number.
371386
372387
For a list of the remaining settings, use the method
373388
`~AstrometryNetClass.show_allowed_settings`.
@@ -432,14 +447,16 @@ def solve_from_image(self, image_file_path, *, force_image_upload=False,
432447
ccd.header['naxis2'],
433448
solve_timeout=solve_timeout,
434449
verbose=verbose,
450+
return_submission_id=return_submission_id,
435451
**settings)
436452
if response.status_code != 200:
437453
raise RuntimeError('Post of job failed')
438454
response_d = response.json()
439455
submission_id = response_d['subid']
440456
return self.monitor_submission(submission_id,
441457
solve_timeout=solve_timeout,
442-
verbose=verbose)
458+
verbose=verbose,
459+
return_submission_id=return_submission_id)
443460

444461

445462
# the default tool for users to interact with is an instance of the Class

astroquery/astrometry_net/tests/test_astrometry_net_remote.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,36 @@ def test_solve_timeout_behavior():
152152
except TypeError:
153153
pass
154154
assert difference == 0
155+
156+
157+
@pytest.mark.skipif(not api_key, reason='API key not set.')
158+
@pytest.mark.remote_data
159+
def test_solve_from_image_default_behaviour():
160+
# Test that solving by uploading an image works
161+
a = AstrometryNet()
162+
a.api_key = api_key
163+
sources = Table.read(os.path.join(DATA_DIR, 'test-source-list.fit'))
164+
# The image_width, image_height and crpix_center below are set to match the
165+
# original solve on astrometry.net.
166+
result = a.solve_from_source_list(sources['X'], sources['Y'],
167+
4109, 4096,
168+
crpix_center=True)
169+
170+
assert isinstance(result, fits.Header)
171+
172+
173+
@pytest.mark.skipif(not api_key, reason='API key not set.')
174+
@pytest.mark.remote_data
175+
def test_solve_from_image_with_return_submission_id():
176+
# Test that solving by uploading an image works
177+
a = AstrometryNet()
178+
a.api_key = api_key
179+
sources = Table.read(os.path.join(DATA_DIR, 'test-source-list.fit'))
180+
# The image_width, image_height and crpix_center below are set to match the
181+
# original solve on astrometry.net.
182+
result = a.solve_from_source_list(sources['X'], sources['Y'],
183+
4109, 4096,
184+
crpix_center=True,
185+
return_submission_id=True)
186+
187+
assert isinstance(result, tuple)

0 commit comments

Comments
 (0)