@@ -108,11 +108,22 @@ def __init__(self, location=None, keywords=None,
108108 else :
109109 self ._location = ''
110110
111+ # Set file name extensions
112+ # Do our best to keep the file extensions immutable
113+ if extensions is not None :
114+ if isinstance (extensions , str ):
115+ # Comma at the end to force it to be a tuple
116+ self ._file_extensions = (extensions ,)
117+ else :
118+ self ._file_extensions = tuple (extensions )
119+ else :
120+ self ._file_extensions = tuple (_recognized_fits_file_extensions )
121+
111122 self ._find_fits_by_reading = find_fits_by_reading
112123
113124 self ._filenames = filenames
114125 self ._files = []
115- self ._files = self ._get_files (extensions = extensions )
126+ self ._files = self ._get_files ()
116127
117128 if self ._files == []:
118129 warnings .warn ("no FITS files in the collection." ,
@@ -292,11 +303,19 @@ def glob_exclude(self):
292303 @property
293304 def ext (self ):
294305 """
295- str or int, The extension from which the header and data will
306+ str or int, The FITS extension from which the header and data will
296307 be read in all files.
297308 """
298309 return self ._ext
299310
311+ @property
312+ def file_extensions (self ):
313+ """
314+ List of file name extensions to match when populating or refreshing
315+ the ``ImageFileCollection``.
316+ """
317+ return self ._file_extensions
318+
300319 def values (self , keyword , unique = False ):
301320 """
302321 List of values for a keyword.
@@ -437,7 +456,7 @@ def filter(self, **kwd):
437456 return ImageFileCollection (filenames = files ,
438457 keywords = self .keywords )
439458
440- def _get_files (self , extensions = None ):
459+ def _get_files (self ):
441460 """ Helper method which checks whether ``files`` should be set
442461 to a subset of file names or to all file names in a directory.
443462
@@ -752,18 +771,13 @@ def _find_keywords_by_values(self, **kwd):
752771 self .summary ['file' ].mask = ma .nomask
753772 self .summary ['file' ].mask [~ matches ] = True
754773
755- def _fits_files_in_directory (self , extensions = None ,
774+ def _fits_files_in_directory (self ,
756775 compressed = True ):
757776 """
758777 Get names of FITS files in directory, based on filename extension.
759778
760779 Parameters
761780 ----------
762- extensions : list of str or None, optional
763- List of filename extensions that are FITS files. Default is
764- ``['fit', 'fits', 'fts']``.
765- Default is ``None``.
766-
767781 compressed : bool, optional
768782 If ``True``, compressed files should be included in the list
769783 (e.g. `.fits.gz`).
@@ -774,10 +788,12 @@ def _fits_files_in_directory(self, extensions=None,
774788 list
775789 *Names* of the files (with extension), not the full pathname.
776790 """
791+ # Force a copy of the extensions to avoid endless combinations of
792+ # compression extensions.
793+ full_extensions = list (self .file_extensions )
777794
778- full_extensions = extensions or list (_recognized_fits_file_extensions )
779-
780- # The common compressed fits image .fz is supported using ext=1 when calling ImageFileCollection
795+ # The common compressed fits image .fz is supported using ext=1 when
796+ # calling ImageFileCollection
781797 if compressed :
782798 for comp in ['.gz' , '.bz2' , '.Z' , '.zip' , '.fz' ]:
783799 with_comp = [extension + comp for extension in full_extensions ]
0 commit comments