entries_from_file#
- sunpy.database.tables.entries_from_file(file, default_waveunit=None, time_string_parse_format='')[source]#
Use the headers of a FITS file to generate an iterator of
sunpy.database.tables.DatabaseEntry
instances. Gathered information will be saved in the attributefits_header_entries
. If the key INSTRUME, WAVELNTH or DATE-OBS / DATE_OBS is available, the attributeinstrument
,wavemin
andwavemax
orobservation_time_start
is set, respectively. If the wavelength unit can be read, the values ofwavemin
andwavemax
are converted to nm (nanometres). The value of thefile
parameter is used to set the attributepath
of each generated database entry.- Parameters:
file (str, file 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
ifsunpy.time.parse_time
is unable to automatically read thedate-obs
metadata.
- Raises:
sunpy.database.tables.WaveunitNotFoundError – If
default_waveunit
is not given and the wavelength unit cannot be found in one of the FITS headerssunpy.database.tables.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 keyWAVEUNIT
with the valuenonsense
.
Examples
>>> from sunpy.database.tables import entries_from_file >>> import sunpy.data.sample >>> entries = list(entries_from_file(sunpy.data.sample.SWAP_LEVEL1_IMAGE)) >>> len(entries) 1 >>> entry = entries.pop() >>> entry.instrument 'SWAP' >>> entry.observation_time_start, entry.observation_time_end (datetime.datetime(2011, 6, 7, 6, 33, 29, 759000), None) >>> entry.wavemin, entry.wavemax (17.400000000000002, 17.400000000000002) >>> len(entry.fits_header_entries) 110