Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T3D header not correct #356

Merged
merged 48 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
d47cf4e
Added ZSurf option for verticalPositionType.
tim-vd-aardweg Sep 29, 2022
1b48656
Added a child class that inherrits from QuantityUnitPair that also ha…
tim-vd-aardweg Sep 29, 2022
7282233
Fixed the aliases to adhere to the 2D3D manual.
tim-vd-aardweg Sep 29, 2022
0e70a0a
Reverted Time Interpolation back to the original timeInterpolation. U…
tim-vd-aardweg Sep 29, 2022
1a1163e
Added support for the timeInterpolation keyword when creating a T3D f…
tim-vd-aardweg Sep 29, 2022
096b2b8
Removed the QuantityUnitPositionPair class again, in favour of a bett…
tim-vd-aardweg Sep 30, 2022
4164906
Fixed failing tests as a result of making the QuantityUnitPair a Base…
tim-vd-aardweg Oct 3, 2022
105c9e8
Added new test for the QuantityUnitPair.
tim-vd-aardweg Oct 3, 2022
1c05236
Added documentation to the VerticalInterpolation enum.
tim-vd-aardweg Oct 3, 2022
15499a9
Added documentation to the TimeInterpolation enum.
tim-vd-aardweg Oct 3, 2022
91ddeef
Added documentation to the QuantityUnitPair class.
tim-vd-aardweg Oct 3, 2022
ea938a7
Updated documentation of ForcingBase to the new documentation style.
tim-vd-aardweg Oct 3, 2022
5d691e0
Added documenation to the T3D class.
tim-vd-aardweg Oct 3, 2022
c37deeb
Added validation: Ensure the first QuantityUnitPair is for `time`.
tim-vd-aardweg Oct 3, 2022
7d7a6cb
Intermediate commit of the new validation.
tim-vd-aardweg Oct 3, 2022
b417154
Intermediate commit of the new validation.
tim-vd-aardweg Oct 3, 2022
c50c71f
Fixed an error in the validator and fixed formatting.
tim-vd-aardweg Oct 3, 2022
735a3c8
Fixed some testcases and added a couple of testcases.
tim-vd-aardweg Oct 3, 2022
1a10026
Added additional testcases
tim-vd-aardweg Oct 4, 2022
bbde372
Added additional testcases
tim-vd-aardweg Oct 4, 2022
8d4d6f3
Added additional test cases.
tim-vd-aardweg Oct 4, 2022
fdebf78
Updated reference data for T3D
tim-vd-aardweg Oct 4, 2022
3a44fe3
Updated the remaining documentation for this file.
tim-vd-aardweg Oct 4, 2022
82b386a
autoformat: isort & black
tim-vd-aardweg Oct 4, 2022
3e24262
Fixed a bug with the `number_of_verticalpositions`. Implemented revie…
tim-vd-aardweg Oct 6, 2022
2cb275a
Use `Vertical Position` instead of `verticalpositionindex`
tim-vd-aardweg Oct 7, 2022
83c11f0
Updated keywords for the T3D header and added a test to ensure loadin…
tim-vd-aardweg Oct 7, 2022
87e78bd
Fixed code smells.
tim-vd-aardweg Oct 10, 2022
0694680
Fixed code smells.
tim-vd-aardweg Oct 10, 2022
f140d80
Add failing testcase that should pass
tim-vd-aardweg Oct 11, 2022
93e4f4b
Added a way to support the 'Vertical Position Specification' keyword …
tim-vd-aardweg Oct 11, 2022
aee2917
autoformat: isort & black
tim-vd-aardweg Oct 11, 2022
72c8d49
Merge branch 'main' into fix/317_t3d_header_not_correct
priscavdsluis Oct 12, 2022
0e1048a
Updated the keywords to the new keywords.
tim-vd-aardweg Oct 13, 2022
864ce5b
Merge branch 'fix/317_t3d_header_not_correct' of https://github.com/D…
tim-vd-aardweg Oct 13, 2022
5489c15
Updated error message to be more clear
tim-vd-aardweg Oct 13, 2022
88fb9fc
Added backwards compatibility for the keywords in the .bc file that u…
tim-vd-aardweg Oct 13, 2022
64b972c
autoformat: isort & black
tim-vd-aardweg Oct 13, 2022
f64a069
Added backwards compatibility for the `Time Interpolation` keyword in…
tim-vd-aardweg Oct 13, 2022
ae1d1a4
Added error when the user forgot to specify the vertpositions field t…
tim-vd-aardweg Oct 13, 2022
2e6bc19
Fixed the default enum values for timeinterpolation and verticalinter…
tim-vd-aardweg Oct 13, 2022
68a6cc5
Removed the check for this unit as it causes problems on the build se…
tim-vd-aardweg Oct 13, 2022
49c1575
Removed the ForcingBackwardsCompatibilityHelper and instead added a g…
tim-vd-aardweg Oct 13, 2022
dd24bf0
autoformat: isort & black
tim-vd-aardweg Oct 13, 2022
9f55295
Update hydrolib/core/io/bc/models.py
arthurvd Oct 13, 2022
5a9339a
Implemented review comments.
tim-vd-aardweg Oct 14, 2022
6c436bd
Merge branch 'main' into fix/317_t3d_header_not_correct
priscavdsluis Oct 14, 2022
0061257
autoformat: isort & black
priscavdsluis Oct 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
254 changes: 230 additions & 24 deletions hydrolib/core/io/bc/models.py

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions hydrolib/core/io/ini/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,3 +462,28 @@ def is_valid_coordinates_with_num_coordinates_specification() -> bool:
raise ValueError(error)

return root_validator(allow_reuse=True)(validate_location_specification)


def get_key_renaming_root_validator(keys_to_rename: Dict[str, List[str]]):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Like this a lot :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! :)

priscavdsluis marked this conversation as resolved.
Show resolved Hide resolved
"""
Gets a root validator that renames the provided keys to support backwards compatibility.

Args:
keys_to_rename Dict[str, List[str]]: Dictionary of keys and a list of old keys that
should be converted to the current key.
"""

def rename_keys(cls, values: Dict) -> Dict:
for current_keyword, old_keywords in keys_to_rename.items():
if current_keyword in values:
continue

for old_keyword in old_keywords:
if (value := values.get(old_keyword)) is not None:
values[current_keyword] = value
del values[old_keyword]
break

return values

return root_validator(allow_reuse=True, pre=True)(rename_keys)
1 change: 1 addition & 0 deletions hydrolib/core/io/mdu/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class AutoStartOption(IntEnum):
Enum class containing the valid values for the AutoStart
attribute in the [General][hydrolib.core.io.mdu.models.General] class.
"""

no = 0
autostart = 1
autostartstop = 2
Expand Down
43 changes: 43 additions & 0 deletions tests/data/reference/bc/t3d_backwards_compatibility.bc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# written by HYDROLIB-core 0.3.0

[General]
fileVersion = 1.01
fileType = boundConds

[Forcing]
name = boundary_timeseries
function = timeseries
Time Interpolation = blockTo
offset = 1.23
factor = 2.34
quantity = time
unit = minutes since 2015-01-01 00:00:00
quantity = dischargebnd
unit = m³/s
0.0 1.23
60.0 2.34
120.0 3.45

[Forcing]
name = boundary_t3d
function = t3d
offset = 1.23
factor = 2.34
Vertical Position Specification = 3.45 4.56 5.67
Vertical Interpolation = log
Vertical Position Type = percBed
Time Interpolation = linear
quantity = time
unit = m
quantity = salinitybnd
unit = ppt
Vertical Position = 1
quantity = salinitybnd
unit = ppt
Vertical Position = 2
quantity = salinitybnd
unit = ppt
Vertical Position = 3
0.0 1.0 2.0 3.0
60.0 4.0 5.0 6.0
120.0 7.0 8.0 9.0
34 changes: 19 additions & 15 deletions tests/data/reference/bc/test.bc
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,25 @@ unit = deg
60.0 3.45 4.56

[Forcing]
name = boundary_t3d
function = t3d
offset = 1.23
factor = 2.34
verticalPositions = 3.45 4.56 5.67
verticalInterpolation = log
verticalPositionType = percBed
quantity = time
unit = m
quantity = salinitybnd
unit = ppt
quantity = salinitybnd
unit = ppt
quantity = salinitybnd
unit = ppt
name = boundary_t3d
function = t3d
offset = 1.23
factor = 2.34
vertPositions = 3.45 4.56 5.67
vertInterpolation = log
vertPositionType = percBed
timeInterpolation = linear
quantity = time
unit = m
quantity = salinitybnd
unit = ppt
vertPositionIndex = 1
quantity = salinitybnd
unit = ppt
vertPositionIndex = 2
quantity = salinitybnd
unit = ppt
vertPositionIndex = 3
0.0 1.0 2.0 3.0
60.0 4.0 5.0 6.0
120.0 7.0 8.0 9.0
Expand Down
41 changes: 41 additions & 0 deletions tests/io/ini/test_util.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from typing import Dict, List, Optional

import pytest
from pydantic import Extra
from pydantic.error_wrappers import ValidationError

from hydrolib.core.basemodel import BaseModel
from hydrolib.core.io.ini.util import (
LocationValidationConfiguration,
LocationValidationFieldNames,
get_key_renaming_root_validator,
get_location_specification_rootvalidator,
)

Expand Down Expand Up @@ -198,3 +200,42 @@ def test_correct_1d_fields_locationtype_is_added(
values
)
assert validated_values == expected_values


class TestGetKeyRenamingRootValidator:
class DummyModel(BaseModel):
"""Dummy model to test the validation of the location specification."""

randomproperty: str

validator = get_key_renaming_root_validator(
{
"randomproperty": [
"randomProperty",
"random_property",
"oldRandomProperty",
],
}
)

class Config:
extra = Extra.allow

@pytest.mark.parametrize(
"old_key", ["randomProperty", "random_property", "oldRandomProperty"]
)
def test_old_keys_are_correctly_renamed_to_current_keyword(self, old_key: str):
values = {old_key: "randomString"}

model = TestGetKeyRenamingRootValidator.DummyModel(**values)

assert model.randomproperty == "randomString"

def test_unknown_key_still_raises_error(self):
values = {"randomKeyThatNeverExisted": "randomString"}

with pytest.raises(ValidationError) as error:
TestGetKeyRenamingRootValidator.DummyModel(**values)

expected_message = "field required"
assert expected_message in str(error.value)
Loading