tesliper.extraction.parameters_parser

Parser for reading spectra calculation parameters from file.

Functions

fitting(s)

Get fitting function mentioned in a given string s, ignoring anything else.

quantity(s)

Convert to float first occurrence of float-looking part of string s, ignoring anything else.

Classes

ParametersParser()

Parser for configuration files containing spectra calculation parameters.

tesliper.extraction.parameters_parser.quantity(s: str) float[source]

Convert to float first occurrence of float-looking part of string s, ignoring anything else. Raise configparser.ParsingError if float cannot be found.

Parameters

s (str) – string containing a float

Returns

extracted float value

Return type

float

tesliper.extraction.parameters_parser.fitting(s: str) Callable[source]

Get fitting function mentioned in a given string s, ignoring anything else. Raise configparser.ParsingError if known function name cannot be found.

Parameters

s (str) – string containing name of fitting function

Returns

an identified fitting function

Return type

callable

class tesliper.extraction.parameters_parser.ParametersParser[source]

Parser for configuration files containing spectra calculation parameters.

Configuration file should be in format similar to .ini files: a list of key-value pairs, separated with “=” or “:”, one pair for line. Standard parameters (width, start, stop, step, and fitting) will be converted to appropriate data type, i.e. float or function reference. If parameter value cannot be converted to its target type, it will be ignored and warning will be emitted. Any other (unexpected) parameters are included in the output and left as they are.

The parser is case-insensitive and knows some alias names of expected parameters: for instance, “hwhm”, “half width of band in half height”, “half width at half maximum” will be all recognized as “width” parameter. If you wish to add custom aliases, update ParametersParser.ALIASES dictionary with appropriate “alias”: “target” pair.

Notes

ParametersParser is using Python’s configparser, so it will parse files that contain a section header, enclosed in braces. However, the section name will be ignored and there may be only one such section, otherwise an exception is raised.

optionxform(optionstr: str) str[source]

Translates option names to desired form - lowercase and standard wording, as defined in ALIASES.

property parameters: dict

Dictionary of parameters for calculating spectra extracted from parsed file and converted to appropriate type.

parse(source: Union[str, pathlib.Path])[source]

Parse given source file to get stored parameters.

Parameters

source (str or Path) – Path to file with calculations’ parameters.

Returns

Parsed parameters.

Return type

dict