From 1c4e4cd404b5812632b5250d4c1f79d4cf6e4c0f Mon Sep 17 00:00:00 2001 From: Jens Jessen-Hansen Date: Tue, 14 Jan 2020 16:05:37 +0100 Subject: [PATCH] ImageFileCollection fails if the headers contain the keyword 'FILE' There's an assert statement on line 503: assert 'file' not in h to catch and raise the problem - but no handling is implemented. If not caught the 'file' value list in the summary dictionary would get a filename appended twice for each image. This will cause the generation of the summary_table to fail. The suggested way to fix this is to remove the header 'FILE' keyword if present. This should be okay since it will either be the same as the input filename or likely incorrect - I guess? --- ccdproc/image_collection.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ccdproc/image_collection.py b/ccdproc/image_collection.py index 6fd9f6bb..25c62d07 100644 --- a/ccdproc/image_collection.py +++ b/ccdproc/image_collection.py @@ -500,8 +500,6 @@ def _add_val_to_dict(key, value, tbl_dict, n_previous, missing_marker): h = fits.getheader(file_name, self.ext) - assert 'file' not in h - if self.location: # We have a location and can reconstruct the path using it name_for_file_column = path.basename(file_name) @@ -509,6 +507,17 @@ def _add_val_to_dict(key, value, tbl_dict, n_previous, missing_marker): # No location, so use whatever path the user passed in name_for_file_column = file_name + # Remove the header 'FILE' keyword if present to avoid adding the value + # twice to the summary dictionary. + if h.get('file') is not None: + if h.get('file').strip() != name_for_file_column.strip(): + warnings.warn( + 'Header from file "{f}" contains keyword "FILE" with ' + 'FILE={v}" which will be ignored.' + ''.format(v=h.get('file').strip(), f=file_name), + UserWarning) + h.remove('file') + # Try opening header before this so that file name is only added if # file is valid FITS try: