specio.core.format
.Reader¶
-
class
specio.core.format.
Reader
(format, request)[source]¶ Context manager to read the spectra.
The purpose of a reader object is to read data from an spectra resource, and should be obtained by calling
get_reader()
.A reader can be used as an iterator to read multiple images, and (if the format permits) only reads data from the file when new data is requested (i.e. streaming). A reader can also be used as a context manager so that it is automatically closed.
Plugins implement Reader’s for different formats. Though rare, plugins may provide additional functionality (beyond what is provided by the base reader class).
Parameters: request : Request
The request to read a specific resource.
-
close
()[source]¶ Flush and close the reader.
This method has no effect if it is already closed.
Parameters: None Returns: None
-
get_data
(index=None, **kwargs)[source]¶ Read the data from the file and return a
Spectrum
instance.Read data from the file, using the spectrum index. The returned spectrum has a
meta
attribute with the meta data.Some formats may support additional keyword arguments. These are listed in the documentation of those formats.
Parameters: index : int
The index of the spectra file to read.
kwargs: dict
Additional arguments which might used by the given format.
Returns: spectrum : Spectrum
A
Spectrum
instance containing the data and metadata.
-
get_length
()[source]¶ The number of spectrum.
Get the number of spectrum in the file.
Returns: length : int
The number of spectrum. The result can be:
- 0 for files that only have meta data
- 1 for singleton spectrum
- N for spectra series
Notes
You can also use
len(reader_object)
-
get_meta_data
(index=None)[source]¶ Read the meta data for a given spectrum.
Read meta data from the file. using the spectrum index. If the index is omitted or None, return the file’s (global) meta data.
Parameters: index : int
The index of the spectra file to read.
Returns: meta : dict
A dictionary containing the meta data.
Notes
get_data()
also provides the meta data for the returned spectra as an attribute of that spectra.
-
get_next_data
(**kwargs)[source]¶ Read the next spectra from the series.
Some formats may support additional keyword arguments. These are listed in the documentation of those formats.
Parameters: kwargs: dict
Additional arguments which might used by the given format.
Returns: spectrum : Spectrum
A
Spectrum
instance containing the data and metadata.
-