landlab.core.model_parameter_loader

exception ConfigurationError[source]

Bases: ValueError

__init__(*args, **kwargs)
classmethod __new__(*args, **kwargs)
add_note()

Exception.add_note(note) – add a note to the exception

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception InvalidConfigurationError[source]

Bases: ConfigurationError

__init__(*args, **kwargs)
classmethod __new__(*args, **kwargs)
add_note()

Exception.add_note(note) – add a note to the exception

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception NonDictConfigurationError[source]

Bases: InvalidConfigurationError

__init__(*args, **kwargs)
classmethod __new__(*args, **kwargs)
add_note()

Exception.add_note(note) – add a note to the exception

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

type ParameterLoader = Callable[[str], dict[str, Any]]
load_file_contents(file_like)[source]

Load the contents of a file or file-like object.

Parameters:

file_like (file_like or str) – File to load either as a file-like object, path to an existing file, or the contents of a file.

Returns:

The contents of the file.

Return type:

str

load_params(file_like, *, fmt=None)[source]

Load parameters from a YAML or TOML file.

Parameters:
  • file_like (file_like or str) – Contents of a parameter file, a file-like object, or the path to a parameter file.

  • fmt ({'yaml', 'toml'}, optional) – Format of the parameter file. If not provided, the format is chosen based on the filename. Filenames, with a .toml extension are parsed as TOML, otherwise they are parsed as YAML.

Returns:

Parameters as key-value pairs.

Return type:

dict

Examples

>>> from landlab.core import load_params
>>> contents = '''
... start: 0.
... stop: 10.
... step: 2.
... '''
>>> params = load_params(contents)
>>> isinstance(params, dict)
True
>>> params["start"], params["stop"], params["step"]
(0.0, 10.0, 2.0)