hydromt_delwaq.components.DemissionConfigComponent#

Summary of Methods and Attributes#

class hydromt_delwaq.components.DemissionConfigComponent(model: Model, *, filename: str = 'delwaq.inp')[source]#

Bases: DelwaqConfigComponent

Manage the D-EMmission configuration input file for model simulations/settings.

DemissionConfigComponent data is stored in a dictionary. The component is used to prepare and update model simulations/settings of the D-Emission model.

Manage configuration files for delwaq simulations/settings.

Parameters:
  • model (Model) – HydroMT model instance

  • filename (str) – A path relative to the root where the configuration files will be read and written if user does not provide a path themselves. By default ‘delwaq.inp’

read(filename: str = None, skip: List[str] = ['B7_geometry', 'B2_stations', 'B2_stations-balance', 'B2_monareas'])[source]#

Read config files in ASCII format at <root/config>.

close() None#

Clean up all open datasets. Method to be called before finish_write.

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: Dict[str, Any]#

Model config values.

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.

get_value(key: str, fallback=None, abs_path: bool = False) Any#

Get a config value at key(s).

Parameters:
  • args (tuple or string) – key can given as a string with ‘.’ indicating a new level: (‘key1.key2’)

  • fallback (any, optional) – Fallback value if key not found in config, by default None.

  • abs_path (bool, optional) – If True return the absolute path relative to the model root, by default False. NOTE: this assumes the config is located in model root!

Returns:

value – dictionary value

Return type:

any type

Examples

>> self.data = {‘a’: 1, ‘b’: {‘c’: {‘d’: 2}}}

>> get_value(‘a’) >> 1

>> get_value(‘b.c.d’) >> 2

>> get_value(‘b.c’) >> {‘d’: 2}

property model: Model#

Return the model object this component is associated with.

property name_in_model: str#

Find the name of the component in the parent model components.

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}}}
test_equal(other: ModelComponent) tuple[bool, dict[str, str]]#

Test if two pointer components are equal.

Parameters:

other (ModelComponent) – The component to compare against.

Returns:

True if the components are equal, and a dict with the associated errors per property checked.

Return type:

tuple[bool, dict[str, str]]

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}}}
write()#

Write config files in ASCII format at <root/config>.