sunpy.database.tables.entries_from_file(file, default_waveunit=None, time_string_parse_format='')[source] [edit on github]

Use the headers of a FITS file to generate an iterator of sunpy.database.tables.DatabaseEntry instances. Gathered information will be saved in the attribute fits_header_entries. If the key INSTRUME, WAVELNTH or DATE-OBS / DATE_OBS is available, the attribute instrument, wavemin and wavemax or observation_time_start is set, respectively. If the wavelength unit can be read, the values of wavemin and wavemax are converted to nm (nanometres). The value of the file parameter is used to set the attribute path of each generated database entry.

  • file (str or file-like object) – Either a path pointing to a FITS file or a an opened file-like object. If an opened file object, its mode must be one of the following rb, rb+, or ab+.

  • 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.

  • sunpy.database.WaveunitNotFoundError – If default_waveunit is not given and the wavelength unit cannot be found in one of the FITS headers

  • sunpy.WaveunitNotConvertibleError – If a wavelength unit could be found but cannot be used to create an instance of the type astropy.units.Unit. This can be the case for example if a FITS header has the key WAVEUNIT with the value nonsense.


>>> from sunpy.database.tables import entries_from_file
>>> import sunpy.data.sample  # doctest: +REMOTE_DATA
>>> entries = list(entries_from_file(sunpy.data.sample.SWAP_LEVEL1_IMAGE))  # doctest: +REMOTE_DATA
>>> len(entries)  # doctest: +REMOTE_DATA
>>> entry = entries.pop()  # doctest: +REMOTE_DATA
>>> entry.instrument  # doctest: +REMOTE_DATA
>>> entry.observation_time_start, entry.observation_time_end  # doctest: +REMOTE_DATA
(datetime.datetime(2011, 6, 7, 6, 33, 29, 759000), None)
>>> entry.wavemin, entry.wavemax  # doctest: +REMOTE_DATA
(17.400000000000002, 17.400000000000002)
>>> len(entry.fits_header_entries)  # doctest: +REMOTE_DATA