diff --git a/environment.yml b/environment.yml index fa804caa..f69c401a 100644 --- a/environment.yml +++ b/environment.yml @@ -6,7 +6,7 @@ dependencies: - pandas - matplotlib - scipy - - cython + - cython=0.26.1 - astropy>3 - pip - pip: diff --git a/pipeline/core/__init__.py b/pipeline/core/__init__.py index 04fa0f34..cd2ee727 100644 --- a/pipeline/core/__init__.py +++ b/pipeline/core/__init__.py @@ -21,6 +21,7 @@ extraction, extract_fractional_pixel, extract_optimal, + fix_keywords, fractional_sum, get_best_flat, get_central_wavelength, diff --git a/pipeline/core/core.py b/pipeline/core/core.py index 70ee9961..529447ed 100644 --- a/pipeline/core/core.py +++ b/pipeline/core/core.py @@ -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 diff --git a/pipeline/images/data_classifier.py b/pipeline/images/data_classifier.py index 48bfc79c..da34f91a 100644 --- a/pipeline/images/data_classifier.py +++ b/pipeline/images/data_classifier.py @@ -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): @@ -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[ diff --git a/pipeline/version.py b/pipeline/version.py index 7b0d6b73..9c5e2461 100644 --- a/pipeline/version.py +++ b/pipeline/version.py @@ -1,2 +1,2 @@ # This is an automatic generated file please do not edit -__version__ = '1.1.0' \ No newline at end of file +__version__ = '1.1.1.dev1' \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index 21bce1e9..f2dab8c8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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