-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create
TimToForcingConverter
class and tests
- Loading branch information
Showing
2 changed files
with
116 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from pathlib import Path | ||
|
||
from hydrolib.core.dflowfm.tim.models import TimModel | ||
from hydrolib.tools.ext_old_to_new.converters import TimToForcingConverter | ||
|
||
|
||
def test_tim_to_bc_converter(input_files_dir: Path): | ||
filepath = input_files_dir / "source-sink/tim-5-columns.tim" | ||
user_defined_names = [ | ||
"any-name-1", | ||
"any-name-2", | ||
"any-name-3", | ||
"any-name-4", | ||
"any-name-5", | ||
] | ||
tim_model = TimModel(filepath, user_defined_names) | ||
|
||
units = ["m³/s", "m", "C", "ppt", "check-later"] | ||
start_time = "minutes since 2015-01-01 00:00:00" | ||
df = tim_model.as_dataframe() | ||
converter = TimToForcingConverter() | ||
forcing_model = converter.convert( | ||
tim_model=tim_model, | ||
start_time=start_time, | ||
units=units, | ||
user_defined_names=user_defined_names, | ||
) | ||
|
||
assert len(forcing_model.forcing) == 5 | ||
assert [forcing_model.forcing[i].name for i in range(5)] == user_defined_names | ||
assert [ | ||
forcing_model.forcing[i].quantityunitpair[1].unit for i in range(5) | ||
] == units | ||
forcing = forcing_model.forcing[0] | ||
assert forcing.datablock[0] == df.index.tolist() | ||
assert forcing.datablock[1] == df.iloc[:, 0].tolist() |