Skip to content

Commit

Permalink
Merge pull request #201 from simontorres/add_gracefull_exit__fix_keyw…
Browse files Browse the repository at this point in the history
…ords

Add gracefull exit  fix keywords
  • Loading branch information
Simon Torres committed Aug 10, 2018
2 parents 5e7fca8 + e4be89a commit 24257c1
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 5 deletions.
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ dependencies:
- pandas
- matplotlib
- scipy
- cython
- cython=0.26.1
- astropy>3
- pip
- pip:
Expand Down
1 change: 1 addition & 0 deletions pipeline/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
extraction,
extract_fractional_pixel,
extract_optimal,
fix_keywords,
fractional_sum,
get_best_flat,
get_central_wavelength,
Expand Down
20 changes: 20 additions & 0 deletions pipeline/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,26 @@ def extract_optimal():
raise NotImplementedError


def fix_keywords(path, pattern='*.fits'):
"""Fix FITS uncompliance of some keywords
Uses automatic header fixing by :class:`~astropy.nddata.CCDData`. Note that
this only fixes FITS compliance.
Args:
path (str): Path to raw data
pattern (str): Search pattern for listing file in path.
"""
file_list = glob.glob(os.path.join(path, pattern))
for _file in file_list:
log.info("Fixing file {:s}".format(_file))
ccd = CCDData.read(_file, unit='adu')

ccd.write(_file, overwrite=True)
log.info("Fix succeeded!")


def fractional_sum(data, index, low_limit, high_limit):
"""Performs a fractional pixels sum
Expand Down
20 changes: 18 additions & 2 deletions pipeline/images/data_classifier.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import os
import sys
import logging

from astropy.io.fits.verify import VerifyError
from ccdproc import ImageFileCollection
from ..core import fix_keywords


class DataClassifier(object):
Expand Down Expand Up @@ -50,8 +54,20 @@ def __call__(self, raw_path):
self.raw_path = raw_path

# define the ImageFileCollection instance right away.
# todo add try/except astropy.io.fits.verify.VerifyError: clean exit
ifc = ImageFileCollection(self.raw_path)

try:
ifc = ImageFileCollection(self.raw_path)

except VerifyError as error:
self.log.error("Raised VerifyError: {:}".format(error))
self.log.critical("Some keywords are not FITS compliant. Trying "
"to fix the headers.")

fix_keywords(path=self.raw_path)

self.log.info("Headers have been fixed, please rerun the pipeline!")
sys.exit()

self.image_collection = ifc.summary.to_pandas()

self.objects_collection = self.image_collection[
Expand Down
2 changes: 1 addition & 1 deletion pipeline/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This is an automatic generated file please do not edit
__version__ = '1.1.0'
__version__ = '1.1.1.dev1'
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ edit_on_github = False
github_project = soar-telescope/goodman
# install_requires = astropy six gwcs scipy
# version should be PEP440 compatible (http://www.python.org/dev/peps/pep-0440)
version = 1.1.0
version = 1.1.1.dev1

0 comments on commit 24257c1

Please sign in to comment.