specio.core.Format

class specio.core.Format(name, description, extensions=None)[source][source]

Represents an implementation to read a particular spectrum format.

A format instance is responsible for: (i) providing information about a format, (ii) determining whether a certain file can be read with this format, and (iii) providing a reader class.

Generally, specio will select the right format and use that to read the spectrum. A format can also be explicitly chosen in all read function. Use print(format) or help(format) to see its documentation.

To implement a specific format, one should create a subclass of Format and the Format.Reader class.

Parameters:

name : str

A short name of this format. Users can select a format using its name.

description : str

A one-line description of the format.

extensions : str | list | None

List of filename extensions that this format supports. If a string is passed it should be space or comma separated. The extensions are used in the documentation and to allow users to select a format by file extension. It is not used to determine what format to use for reading a file.

__init__(name, description, extensions=None)[source][source]

Methods

__init__(name, description[, extensions])
can_read(request) Indicate a spectra resource can be read.
get_reader(request) Return a Reader instance.
can_read(request)[source][source]

Indicate a spectra resource can be read.

Get whether this format can read data from the specified uri.

Parameters:

request : Request

The request to read a specific resource.

Returns:

is_readable : bool

Returns True if the file can be read and False otherwise.

description

Format description.

doc

Format documention.

extensions

Format extension.

get_reader(request)[source][source]

Return a Reader instance.

Return a reader object that can be used to read data and info from the given file. Users are encouraged to use specio.get_reader() instead.

Parameters:

request : Request

The request to read a specific resource.

Returns:

reader : Format.Reader

specio.Reader instance allowing to read the data.

name

Format name.