sequence.input_reader module#
Read input files.
This module contains utilities for reading Sequence input data.
- class sequence.input_reader.TimeVaryingConfig(times: Iterable[float], dicts: Iterable[dict])[source]#
Bases:
object
A configuration dictionary that is able to change with time.
- __init__(times: Iterable[float], dicts: Iterable[dict])[source]#
Create a time-varying configuration.
- Parameters:
Examples
>>> from sequence.input_reader import TimeVaryingConfig >>> params = TimeVaryingConfig([0, 1], [dict(foo=0, bar=1), dict(foo=1)]) >>> sorted(params.items()) [(('bar',), 1), (('foo',), 0)] >>> params.update(1) {'foo': 1} >>> sorted(params.items()) [(('bar',), 1), (('foo',), 1)]
- diff(start: float, stop: float) dict [source]#
Return the difference between two different configurations.
- classmethod from_file(name: PathLike, fmt: str | None = None) TimeVaryingConfig [source]#
Load a configuration from a file.
- Parameters:
name (path-like) – The name of the configuration file to read.
fmt (str, optional) – The format of the configuration file.
- classmethod from_files(names: Iterable[str | PathLike[str]], times: Iterable[float] | None = None) TimeVaryingConfig [source]#
Load a configuration from a set of files.
- Parameters:
names (iterable of path-like) – Names of files to read.
times (iterable of float) – Times associated with each file.
- static get_loader(fmt: str) Callable[[TextIO], list[tuple[float, dict]]] [source]#
Get a configuration loader for a given format.
- Parameters:
fmt (str) – The configuration format (e.g. ‘toml’, ‘yaml’).
- Returns:
A loader function for the format.
- Return type:
func
- Raises:
ValueError – If a loader for the format can’t be found.
- static get_supported_formats() list[str] [source]#
Return a list of supported configuration formats.
- static load_toml(stream: TextIO) list[tuple[float, dict]] [source]#
Load a configuration in toml-format.
- sequence.input_reader.load_config(stream: TextIO | str | PathLike[str], fmt: str | None = None) Iterable[tuple[float, dict]] | dict [source]#
Load model configuration from a file-like object.
- Parameters:
stream (file-like) – A test stream that contains the configuration.
fmt (str, optional) – The format of the configuration (e.g. ‘toml’, ‘yaml’).
- Returns:
The, possibly time-varying, configuration.
- Return type: