Skip to content

Commit

Permalink
Add astrometry option for color camera
Browse files Browse the repository at this point in the history
  • Loading branch information
mwcraig committed Jul 17, 2017
1 parent f4c8a0c commit cd9607b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 25 deletions.
43 changes: 40 additions & 3 deletions msumastro/header_processing/astrometry.py
Expand Up @@ -21,7 +21,8 @@ def call_astrometry(filename, sextractor=False,
ra_dec=None, overwrite=False,
wcs_reference_image_center=True,
odds_ratio=None,
astrometry_config=None):
astrometry_config=None,
additional_args=None):
"""
Wrapper around astrometry.net solve-field.
Expand Down Expand Up @@ -58,6 +59,13 @@ def call_astrometry(filename, sextractor=False,
wcs_reference_image_center :
If ``True``, force the WCS reference point in the image to be the
image center.
odds_ratio : float, optional
The odds ratio to use for a successful solve. Default is to use the
default in `solve-field`.
astrometry_config : str, optional
Name of configuration file to use for SExtractor.
additional_args : str or list of str, optional
Additional arguments to pass to `solve-field`
"""
solve_field = ["solve-field"]
option_list = []
Expand All @@ -67,6 +75,13 @@ def call_astrometry(filename, sextractor=False,
option_list.append(
"--scale-low 0.4 --scale-high 0.6 --scale-units arcsecperpix")

if additional_args is not None:
if isinstance(additional_args, basestring):
add_ons = [additional_args]
else:
add_ons = additional_args
option_list.extend(additional_args)

if isinstance(sextractor, six.string_types):
option_list.append("--sextractor-path " + sextractor)
elif sextractor:
Expand Down Expand Up @@ -157,7 +172,8 @@ def add_astrometry(filename, overwrite=False, ra_dec=None,
verify=None, try_builtin_source_finder=False,
custom_sextractor=False,
odds_ratio=None,
astrometry_config=None):
astrometry_config=None,
camera=''):
"""Add WCS headers to FITS file using astrometry.net
Parameters
Expand All @@ -183,6 +199,9 @@ def add_astrometry(filename, overwrite=False, ra_dec=None,
verify :
See :func:`call_astrometry`
camera : str, one of ['celestron', 'u9', 'cp16'], optional
Name of camera; determines the pixel scale used in the solved. Default
is to use `'u9'`.
Returns
-------
bool
Expand All @@ -202,6 +221,22 @@ def add_astrometry(filename, overwrite=False, ra_dec=None,
"""
base, ext = path.splitext(filename)

# All are in arcsec per pixel, values are approximate
camera_pixel_scales = {
'celestron': 0.3,
'u9': 0.55,
'cp16': 0.55
}

if camera:
use_feder = False
scale = camera_pixel_scales[camera]
scale_options = ("--scale-low {low} --scale-high {high} "
"--scale-units arcsecperpix".format(low=0.8*scale, high=1.2 * scale))
else:
use_feder = True
scale_options = None

logger.info('BEGIN ADDING ASTROMETRY on {0}'.format(filename))
try:
logger.debug('About to call call_astrometry')
Expand All @@ -211,7 +246,9 @@ def add_astrometry(filename, overwrite=False, ra_dec=None,
save_wcs=save_wcs, verify=verify,
custom_sextractor_config=custom_sextractor,
odds_ratio=odds_ratio,
astrometry_config=astrometry_config)
astrometry_config=astrometry_config,
feder_settings=use_feder,
additional_args=scale_options)
== 0)
except subprocess.CalledProcessError as e:
logger.debug('Failed with error')
Expand Down
22 changes: 0 additions & 22 deletions msumastro/tests/test_image_collection.py
Expand Up @@ -411,28 +411,6 @@ def test_initializing_from_table(self, triage_setup):
# Does ImageFileCollection summary contain values from table?
assert nonsense in ic.summary_info['imagetyp']

def test_initializing_from_table_file_that_does_not_exist(self,
triage_setup,
caplog):
# Do we get a warning if we try reading a file that doesn't exist,
# but where we can initialize from a directory?
ic = tff.ImageFileCollection(location=triage_setup.test_dir,
info_file='iufadsdhfasdifre')
warnings = [rec for rec in caplog.records()
if ((rec.levelno == logging.WARN) &
('Unable to open table file' in rec.message))]
assert (len(warnings) == 1)
# Do we raise an error if the table name is bad AND the location
# is None?
with pytest.raises(IOError):
ic = tff.ImageFileCollection(location=None,
info_file='iufadsdhfasdifre')
# Do we raise an error if the table name is bad AND
# the location is given but is bad?
with pytest.raises(OSError):
ic = tff.ImageFileCollection(location='dasifjoaurun',
info_file='iufadsdhfasdifre')

def test_initialization_with_no_keywords(self, triage_setup):
ic = tff.ImageFileCollection(location=triage_setup.test_dir,
keywords=[])
Expand Down

0 comments on commit cd9607b

Please sign in to comment.