Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image utils updates #274

Merged
merged 1 commit into from
Dec 30, 2017
Merged
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
75 changes: 2 additions & 73 deletions pocs/utils/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,77 +204,6 @@ def get_solve_field(fname, replace=True, remove_extras=True, **kwargs):
return out_dict


def improve_wcs(fname, remove_extras=True, replace=True, **kwargs):
verbose = kwargs.get('verbose', False)
out_dict = {}
output = None
errs = None

if verbose:
print("Entering improve_wcs:", fname)

options = [
'--continue',
'-t', '3',
'-q', '0.01',
'-V', fname,
]

proc = solve_field(fname, solve_opts=options, **kwargs)
try:
output, errs = proc.communicate(timeout=kwargs.get('timeout', 30))
except subprocess.TimeoutExpired:
proc.kill()
raise error.Timeout("Timeout while solving")
else:
if verbose:
print("Output: {}", output)
print("Errors: {}", errs)

if not os.path.exists(fname.replace('.fits', '.solved')):
raise error.SolveError('File not solved')

try:
# Handle extra files created by astrometry.net
new = fname.replace('.fits', '.new')
rdls = fname.replace('.fits', '.rdls')
axy = fname.replace('.fits', '.axy')
xyls = fname.replace('.fits', '-indx.xyls')

if replace and os.path.exists(new):
# Remove converted fits
os.remove(fname)
# Rename solved fits to proper extension
os.rename(new, fname)

out_dict['solved_fits_file'] = fname
else:
out_dict['solved_fits_file'] = new

if remove_extras:
for f in [rdls, xyls, axy]:
if os.path.exists(f):
os.remove(f)

except Exception as e:
warn('Cannot remove extra files: {}'.format(e))

if errs is not None:
warn("Error in solving: {}".format(errs))
else:
# Read the EXIF information from the CR2
if fname.endswith('cr2'):
out_dict.update(read_exif(fname))

try:
out_dict.update(fits.getheader(fname))
except OSError:
if verbose:
print("Can't read fits header for", fname)

return out_dict


def crop_data(data, box_width=200, center=None, verbose=False):
""" Return a cropped portion of the image

Expand Down Expand Up @@ -347,7 +276,7 @@ def get_wcsinfo(fits_fname, verbose=False):
stderr=subprocess.STDOUT, universal_newlines=True)
try:
output, errs = proc.communicate(timeout=5)
except subprocess.TimeoutExpired: # pragma : no cover
except subprocess.TimeoutExpired: # pragma: no cover
proc.kill()
output, errs = proc.communicate()

Expand Down Expand Up @@ -514,7 +443,7 @@ def _make_pretty_from_fits(fname, timeout=15, **kwargs):
return new_filename


def _make_pretty_from_cr2(fname, timeout=15, **kwargs):
def _make_pretty_from_cr2(fname, timeout=15, **kwargs): # pragma: no cover
verbose = kwargs.get('verbose', False)

title = '{} {}'.format(kwargs.get('title', ''), current_time().isot)
Expand Down