specio’s user API

Spectra reader functions

These functions represent specio’s main interface for the user. They provide a common API to read spectra data for a large variety of formats. All read functions accept keyword arguments, which are passed on to the format that does the actual work. To see what keyword arguments are supported by a specific format, use the help() function.

Functions for reading:

  • specread() - read a file with spectra from the specified uri

For a larger degree of control, specio provides a function get_reader(). It returns an Reader object, which can be used to read data and meta data in a more controlled manner. This also allows specific scientific formats to be exposed in a way that best suits that file-format.

Functions

specio.help([name]) Print the help regarding a given format.
specio.show_formats Show a nicely formatted list of available formats.
specio.specread(uri[, format, tol_wavelength]) Read spectra in a given format.
specio.get_reader(uri[, format]) Return a Reader instance.

Classes

specio.core.format.Reader(format, request) Context manager to read the spectra.

Core data structure

specio.specread() will return either a list of instances or an instance from the class specio.core.Spectrum. This class is composed of three attributes:

  • a 1D ndarray of shape (n_wavelength,) or 2D ndarray of shape (n_spectra, n_wavelength) amplitudes containing the counts/amplitude for the different wavelengths;
  • a 1D ndarray of shape (n_wavelength,) wavelength containing the wavelength for which the spectra have been acquired;
  • a dictionary meta containing the metadata.

For more information, you can check the full API documentation above.

specio.core.Spectrum(amplitudes, wavelength) Class containing the spectrum information.

Command line interface

specio provides a command line interface to make basic data manipulation.

Conversion to CSV

Any format can be exported using the specio command line:

specio convert input_file.spc output_file.csv

convert receive the input and output arguments. It is also possible to omit the output argument and an automatic output file will be generated depending of the input file name:

specio convert input_file.spc

As with specio.specread(), an input can get a name with a wildcard:

specio convert "*.spc"

In addition, this is also possible to increase the tolerance to aggregate several spectra in the same CSV as in specio.specread():

specio convert "*.spc" --tolerance 1e-2

Example datasets

The module specio.datasets includes some toy file which are supported by the plugins reader.

datasets.load_csv_path() Return the path to the CSV toy file.
datasets.load_fsm_path() Return the path to the FSM toy file.
datasets.load_mzml_path() Return the path to the mzML toy file.
datasets.load_sp_path() Return the path to the SP toy file.
datasets.load_spc_path() Return the path to the SPC toy file.