entries_from_dir#

sunpy.database.tables.entries_from_dir(fitsdir, recursive=False, pattern='*', default_waveunit=None, time_string_parse_format=None)[source]#

Search the given directory for FITS files and use the corresponding FITS headers to generate instances of DatabaseEntry. FITS files are detected by reading the content of each file, the pattern argument may be used to avoid reading entire directories if one knows that all FITS files have the same filename extension.

Parameters:
  • fitsdir (str) – The directory where to look for FITS files.

  • recursive (bool, optional) – If True, the given directory will be searched recursively. Otherwise, only the given directory and no subdirectories are searched. The default is False, i.e. the given directory is not searched recursively.

  • pattern (str, optional) – The pattern can be used to filter the list of filenames before the files are attempted to be read. The default is to collect all files. This value is passed to the function fnmatch.filter(), see its documentation for more information on the supported syntax.

  • default_waveunit (str, optional) – The wavelength unit that is used for a header if it cannot be found.

  • time_string_parse_format (str, optional) – Fallback timestamp format which will be passed to strptime if sunpy.time.parse_time is unable to automatically read the date-obs metadata.

Returns:

generator of (DatabaseEntry, str) pairs – A generator where each item is a tuple consisting of a DatabaseEntry instance and the absolute path to the filename which was used to make the database entry.

Examples

>>> import os
>>> from sunpy.data.test import rootdir as fitsdir
>>> from sunpy.database.tables import entries_from_dir
>>> eitdir = os.path.join(fitsdir, 'EIT')
>>> entries = list(entries_from_dir(eitdir, default_waveunit='angstrom'))
>>> len(entries)
2