Skip to content

Commit 681ca99

Browse files
committed
add examples for the TimToForcingConverter
1 parent aaf3315 commit 681ca99

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

hydrolib/tools/ext_old_to_new/converters.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,28 @@ def convert(
575575
576576
Returns:
577577
ForcingModel: The converted ForcingModel.
578+
579+
Raises:
580+
ValueError: If `units` and `user_defined_names` are not provided.
581+
ValueError: If the lengths of `units`, `user_defined_names`, and the columns in the first row of the TimModel
582+
do not match.
583+
584+
Examples:
585+
```python
586+
>>> file_path = "tests/data/input/tim/single_data_for_timeseries.tim"
587+
>>> user_defined_names = ["discharge"]
588+
>>> tim_model = TimModel(file_path, user_defined_names)
589+
>>> print(tim_model.as_dict())
590+
{'discharge': [0.0, 0.01, 0.0, -0.01, 0.0, 0.01, 0.0, -0.01, 0.0, 0.01, 0.0, -0.01, 0.0]}
591+
>>> converter = TimToForcingConverter()
592+
>>> forcing_model = converter.convert(
593+
... tim_model, "minutes since 2015-01-01 00:00:00", "linear", ["m³/s"], ["discharge"]
594+
... )
595+
>>> print(forcing_model.forcing[0].name)
596+
discharge
597+
>>> print(forcing_model.forcing[0].datablock)
598+
[[0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0, 110.0, 120.0], [0.0, 0.01, 0.0, -0.01, 0.0, 0.01, 0.0, -0.01, 0.0, 0.01, 0.0, -0.01, 0.0]]
599+
```
578600
"""
579601
if units is None or user_defined_names is None:
580602
raise ValueError("Both 'units' and 'user_defined_names' must be provided.")

0 commit comments

Comments
 (0)