@@ -108,11 +108,22 @@ def __init__(self, location=None, keywords=None,
108
108
else :
109
109
self ._location = ''
110
110
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
+
111
122
self ._find_fits_by_reading = find_fits_by_reading
112
123
113
124
self ._filenames = filenames
114
125
self ._files = []
115
- self ._files = self ._get_files (extensions = extensions )
126
+ self ._files = self ._get_files ()
116
127
117
128
if self ._files == []:
118
129
warnings .warn ("no FITS files in the collection." ,
@@ -292,11 +303,19 @@ def glob_exclude(self):
292
303
@property
293
304
def ext (self ):
294
305
"""
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
296
307
be read in all files.
297
308
"""
298
309
return self ._ext
299
310
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
+
300
319
def values (self , keyword , unique = False ):
301
320
"""
302
321
List of values for a keyword.
@@ -437,7 +456,7 @@ def filter(self, **kwd):
437
456
return ImageFileCollection (filenames = files ,
438
457
keywords = self .keywords )
439
458
440
- def _get_files (self , extensions = None ):
459
+ def _get_files (self ):
441
460
""" Helper method which checks whether ``files`` should be set
442
461
to a subset of file names or to all file names in a directory.
443
462
@@ -752,18 +771,13 @@ def _find_keywords_by_values(self, **kwd):
752
771
self .summary ['file' ].mask = ma .nomask
753
772
self .summary ['file' ].mask [~ matches ] = True
754
773
755
- def _fits_files_in_directory (self , extensions = None ,
774
+ def _fits_files_in_directory (self ,
756
775
compressed = True ):
757
776
"""
758
777
Get names of FITS files in directory, based on filename extension.
759
778
760
779
Parameters
761
780
----------
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
-
767
781
compressed : bool, optional
768
782
If ``True``, compressed files should be included in the list
769
783
(e.g. `.fits.gz`).
@@ -774,10 +788,12 @@ def _fits_files_in_directory(self, extensions=None,
774
788
list
775
789
*Names* of the files (with extension), not the full pathname.
776
790
"""
791
+ # Force a copy of the extensions to avoid endless combinations of
792
+ # compression extensions.
793
+ full_extensions = list (self .file_extensions )
777
794
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
781
797
if compressed :
782
798
for comp in ['.gz' , '.bz2' , '.Z' , '.zip' , '.fz' ]:
783
799
with_comp = [extension + comp for extension in full_extensions ]
0 commit comments