sambuca_core.spectra_readers¶
Contains functions for loading collections of spectra from Sambuca spectral database directories.
-
sambuca_core.spectra_readers.load_all_spectral_libraries(path, validate=True)[source]¶ Loads all valid spectra from the given location.
Parameters: - path (str) – The directory path to scan for supported spectra files.
- validate (bool) – If true, data validation will be performed.
Returns: - A dictionary of 2-tuples of numpy.ndarrays.
The first element contains the band centre wavelengths of the input bands, while the second element contains the spectra values. Dictionary is keyed by spectra name built from the file and band/sheet names, separated by a colon.
Note that names are not disambiguated, so that if more than one filter has the same name, only the first will be returned and no error will be raised (although it will be logged).
Note that the filename component is always converted to lower case. This is required for consistent results on Linux and Windows.
Return type: dict
-
sambuca_core.spectra_readers.load_csv_spectral_library(filename, validate=True)[source]¶ Loads a spectral library from a CSV file. The CSV file must have a header row, and the wavelengths must be the first column.
Parameters: - filename (str) – full path to the Excel file.
- validate (bool) – If true, data validation will be performed.
Returns: - A dictionary of 2-tuples of numpy.ndarrays.
The first element contains the band centre wavelengths, while the second element contains the spectra. The dictionary is keyed by spectra name, formed by concatenation of the file and band names. This allows multiple spectra from multiple files to be unambigiously collected into a dictionary. Note that the filename component is always converted to lower case. This is required for consistent results on Linux and Windows.
Return type: dict
-
sambuca_core.spectra_readers.load_envi_spectral_library(directory, base_filename, validate=True)[source]¶ Loads spectra from an ENVI spectral library.
Parameters: - directory (str) – Directory containing the spectral library file.
- base_filename (str) – The filename without the extension or ‘.’ preceeding the extension.
- validate (bool) – If true, data validation will be performed.
Returns: - A dictionary of 2-tuples of numpy.ndarrays.
The first element contains the band centre wavelengths, while the second element contains the spectra. The dictionary is keyed by spectra name, formed by concatenation of the file and band names. This allows multiple spectra from multiple files to be unambigiously collected into a dictionary. Note that the filename component is always converted to lower case. This is required for consistent results on Linux and Windows.
Return type: dict
-
sambuca_core.spectra_readers.load_excel_spectral_library(filename, sheet_names=None, validate=True)[source]¶ Loads a spectral library from an Excel file. Both new style XLSX and old-style XLS formats are supported.
Parameters: - filename (str) – full path to the Excel file.
- sheet_names (list) – Optional list of worksheet names to load. The default is to attempt to load all worksheets.
- validate (bool) – If true, data validation will be performed.
Returns: - A dictionary of 2-tuples of numpy.ndarrays.
The first element contains the band centre wavelengths, while the second element contains the spectra. The dictionary is keyed by spectra name, formed by concatenation of the file and band names. This allows multiple spectra from multiple files to be unambigiously collected into a dictionary. Note that the filename component is always converted to lower case. This is required for consistent results on Linux and Windows.
Return type: dict
-
sambuca_core.spectra_readers.load_spectral_library(filename, validate=True)[source]¶ Loads a single spectral library from the given file name from any supported format (selected by file extension).
Parameters: - filename (str) – full path to the file.
- validate (bool) – If true, data validation will be performed.
Returns: - A dictionary of 2-tuples of numpy.ndarrays.
The first element contains the band centre wavelengths of the input bands, while the second element contains the spectra values. Dictionary is keyed by spectra name built from the file and band/sheet names, separated by a colon. For example:
Moreton_Bay_speclib:white_sandNote that names are not disambiguated, so that if more than one filter has the same name, only the first will be returned and no error will be raised (although it will be logged).
Note that the filename component is always converted to lower case. This is required for consistent results on Linux and Windows.
Return type: dict