Skip to content

Commit 902c758

Browse files
authored
Merge pull request #2484 from astrofrog/astrometry-net-verbose
Added verbose= to AstrometryNet
2 parents b1fcfff + 9799890 commit 902c758

File tree

2 files changed

+40
-10
lines changed

2 files changed

+40
-10
lines changed

CHANGES.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ alma
2525

2626
- Fixed a regression to handle arrays of string input for the ``query`` methods. [#2094]
2727

28+
29+
astrometry.net
30+
^^^^^^^^^^^^^^
31+
32+
- Added a ``verbose=`` keyword argument to ``AstrometryNet`` to control whether or not
33+
to show any information during solving. [#2484]
34+
35+
- Fixed a bug which caused ``solve_timeout`` to not be respected when an image was
36+
solved by constructing a source list internally before sending data to
37+
astrometry.net. [#2484]
38+
2839
cadc
2940
^^^^
3041

astroquery/astrometry_net/core.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def _validate_settings(self, settings):
190190
'values for {}'.format(scale_type, required_keys))
191191

192192
def monitor_submission(self, submission_id,
193-
solve_timeout=TIMEOUT):
193+
solve_timeout=TIMEOUT, verbose=True):
194194
"""
195195
Monitor the submission for completion.
196196
@@ -202,6 +202,8 @@ def monitor_submission(self, submission_id,
202202
solve_timeout : ``int``
203203
Time, in seconds, to wait for the astrometry.net solver to find
204204
a solution.
205+
verbose : bool, optional
206+
Whether to print out information about the solving
205207
206208
Returns
207209
-------
@@ -223,7 +225,8 @@ def monitor_submission(self, submission_id,
223225
"""
224226
has_completed = False
225227
job_id = None
226-
print('Solving', end='', flush=True)
228+
if verbose:
229+
print('Solving', end='', flush=True)
227230
start_time = time.time()
228231
status = ''
229232
while not has_completed:
@@ -242,7 +245,8 @@ def monitor_submission(self, submission_id,
242245
elapsed = now - start_time
243246
timed_out = elapsed > solve_timeout
244247
has_completed = (status in ['success', 'failure'] or timed_out)
245-
print('.', end='', flush=True)
248+
if verbose:
249+
print('.', end='', flush=True)
246250
if status == 'success':
247251
wcs_url = url_helpers.join(self.URL, 'wcs_file', str(job_id))
248252
wcs_response = self._request('GET', wcs_url)
@@ -259,6 +263,7 @@ def monitor_submission(self, submission_id,
259263

260264
def solve_from_source_list(self, x, y, image_width, image_height,
261265
solve_timeout=TIMEOUT,
266+
verbose=True,
262267
**settings
263268
):
264269
"""
@@ -278,6 +283,8 @@ def solve_from_source_list(self, x, y, image_width, image_height,
278283
solve_timeout : int
279284
Time, in seconds, to wait for the astrometry.net solver to find
280285
a solution.
286+
verbose : bool, optional
287+
Whether to print out information about the solving
281288
282289
For a list of the remaining settings, use the method
283290
`~AstrometryNetClass.show_allowed_settings`.
@@ -301,13 +308,15 @@ def solve_from_source_list(self, x, y, image_width, image_height,
301308
response_d = response.json()
302309
submission_id = response_d['subid']
303310
return self.monitor_submission(submission_id,
304-
solve_timeout=solve_timeout)
311+
solve_timeout=solve_timeout,
312+
verbose=verbose)
305313

306314
def solve_from_image(self, image_file_path, force_image_upload=False,
307315
ra_key=None, dec_key=None,
308316
ra_dec_units=None,
309317
fwhm=3, detect_threshold=5,
310318
solve_timeout=TIMEOUT,
319+
verbose=True,
311320
**settings):
312321
"""
313322
Plate solve from an image, either by uploading the image to
@@ -343,10 +352,14 @@ def solve_from_image(self, image_file_path, force_image_upload=False,
343352
ra_dec_units : tuple, optional
344353
Tuple specifying the units of the right ascension and declination in
345354
the header. The default value is ``('hour', 'degree')``.
355+
346356
solve_timeout : int
347357
Time, in seconds, to wait for the astrometry.net solver to find
348358
a solution.
349359
360+
verbose : bool, optional
361+
Whether to print out information about the solving
362+
350363
For a list of the remaining settings, use the method
351364
`~AstrometryNetClass.show_allowed_settings`.
352365
"""
@@ -386,32 +399,38 @@ def solve_from_image(self, image_file_path, force_image_upload=False,
386399
else:
387400
with fits.open(image_file_path) as f:
388401
data = f[0].data
389-
390-
print("Determining background stats", flush=True)
402+
if verbose:
403+
print("Determining background stats", flush=True)
391404
mean, median, std = sigma_clipped_stats(data, sigma=3.0,
392405
maxiters=5)
393406
daofind = DAOStarFinder(fwhm=fwhm,
394407
threshold=detect_threshold * std)
395-
print("Finding sources", flush=True)
408+
if verbose:
409+
print("Finding sources", flush=True)
396410
sources = daofind(data - median)
397-
print('Found {} sources'.format(len(sources)), flush=True)
411+
if verbose:
412+
print('Found {} sources'.format(len(sources)), flush=True)
398413
# astrometry.net wants a sorted list of sources
399414
# Sort first (which puts things in ascending order)
400415
sources.sort('flux')
401416
# Reverse to get descending order
402417
sources.reverse()
403-
print(sources)
418+
if verbose:
419+
print(sources)
404420
return self.solve_from_source_list(sources['xcentroid'],
405421
sources['ycentroid'],
406422
ccd.header['naxis1'],
407423
ccd.header['naxis2'],
424+
solve_timeout=solve_timeout,
425+
verbose=verbose,
408426
**settings)
409427
if response.status_code != 200:
410428
raise RuntimeError('Post of job failed')
411429
response_d = response.json()
412430
submission_id = response_d['subid']
413431
return self.monitor_submission(submission_id,
414-
solve_timeout=solve_timeout)
432+
solve_timeout=solve_timeout,
433+
verbose=verbose)
415434

416435

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

0 commit comments

Comments
 (0)