Commit 6288a9b5 authored by Taras Yakobchuk's avatar Taras Yakobchuk
Browse files

Merge branch 'patch_gris_headers' into 'master'

Allow NoneType key values in header validation

See merge request !5
parents a7931bc9 fe34b335
Pipeline #3851 passed with stage
in 50 seconds
......@@ -22,7 +22,9 @@ def validate_header(header, instrument):
for key in templates_core[instrument]:
if key in header:
if type(header[key]).__name__ != templates_core[instrument][key]['Type']:
key_type = type(header[key]).__name__
if key_type != templates_core[instrument][key]['Type'] and \
key_type != 'NoneType':
try:
header[key] = eval(templates_core[instrument][key]['Type'])(header[key])
except (TypeError, ValueError):
......
......@@ -5,9 +5,15 @@ Contains tools for header checking and manipulations
"""
import re
import astropy.io.fits as fitsio
from astropy.wcs import FITSFixedWarning
import warnings
from kis_headers.templates import templates, templates_core, templates_ext
warnings.simplefilter('ignore', category=FITSFixedWarning)
class StatusRecorder():
'''
Singleton class to store the status of the package.
......@@ -20,13 +26,20 @@ def get_current_file():
"""return the current file, is updated in get_fits_header"""
return util_status.current_file
def get_fits_header(filename):
"""
Returns header from associated fits file
"""
with fitsio.open(filename, ignore_missing_end=True, output_verify='silentfix') as f:
header = f[0].header
util_status.current_file = filename
util_status.current_file = filename
fits_file = fitsio.open(filename, memmap=False, ignore_missing_end=True)
try:
hdu = fits_file[0]
hdu.verify("silentfix")
header = fits_file[hdu].header
except IndexError:
header = None
fits_file.close()
return header
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment