hydromt_wflow.components.WflowConfigComponent#
Summary of Methods and Attributes#
Component class |
Methods |
Attributes |
|---|---|---|
|
- class WflowConfigComponent(model: Model, *, filename: str = 'wflow_sbm.toml', default_template_filename: str | None = None)[source]#
Bases:
ConfigComponentManage the wflow TOML configuration file for model simulations/settings.
WflowConfigComponentdata is stored in a dictionary. The component is used to prepare and update model simulations/settings of the wflow model.- read(filename: str | None = None)[source]#
Read the wflow configuration file from <root/filename>.
If filename is not provided, will default to <root>/{self._filename} or default template configuration file if the model is in write only mode (ie build).
If filename is provided, it will check if the path is absolute and else will assume the given path is relative to the model root.
- write(filename: str | None = None, config_root: Path | str | None = None)[source]#
Write the configuration to a file.
The file is written to
<root>/<filename>by default, or to<config_root>/<filename>if aconfig_rootis provided.
- get_value(key: str, fallback: Any | None = None, abs_path: bool = False) Any | None[source]#
Get config options.
- remove(*args: str, errors: str = 'raise') Any[source]#
Remove a config key and return its value.
- Parameters:
- Return type:
The popped value, or raises a KeyError if the key is not found.
- remove_reservoirs(input: list[str | None] = [], state: list[str | None] = [])[source]#
Remove all reservoir related config options.
- create(template: str | Path | None = None)#
Create a new config file based on a template file.
It the template is not provided, the default template will be used if available. Only yaml and toml files are supported.
- Parameters:
template (str or Path, optional) – Path to a template config file, by default None
Examples
>> self.create() >> self.data {} >> self.create(template='path/to/template.yml') >> self.data {'a': 1, 'b': {'c': {'d': 2}}}
- property data_catalog: DataCatalog#
Return the data catalog of the model this component is associated with.
- finish_write()#
Finish the write functionality after cleanup was called for all components in the model.
All DeferredFileClose objects can overwrite any lazy loaded files now.
- property model: Model#
Return the model object this component is associated with.
- property root: ModelRoot#
Return the root of the model this component is associated with.
- set(key: str, value: Any)#
Update the config dictionary at key(s) with values.
- Parameters:
key (str) – a string with ‘.’ indicating a new level: ‘key1.key2’ will translate to {“key1”:{“key2”: value}}
value (Any) – the value to set the config to
Examples
>> self.set({'a': 1, 'b': {'c': {'d': 2}}}) >> self.data {'a': 1, 'b': {'c': {'d': 2}}} >> self.set_value('a', 99) >> {'a': 99, 'b': {'c': {'d': 2}}} >> self.set_value('b.d.e', 24) >> {'a': 99, 'b': {'c': {'d': 24}}}
- update(data: Dict[str, Any])#
Set the config dictionary at key(s) with values.
- Parameters:
data (Dict[str,Any]) – A dictionary with the values to be set. keys can be dotted like in
set_value()
Examples
Setting data as a nested dictionary:
>> self.update({'a': 1, 'b': {'c': {'d': 2}}}) >> self.data {'a': 1, 'b': {'c': {'d': 2}}}
Setting data using dotted notation:
>> self.update({'a.d.f.g': 1, 'b': {'c': {'d': 2}}}) >> self.data {'a': {'d':{'f':{'g': 1}}}, 'b': {'c': {'d': 2}}}