Skip to content

Commit 3367e61

Browse files
committed
merge base branch
2 parents f086597 + d9387e0 commit 3367e61

File tree

8 files changed

+62
-42
lines changed

8 files changed

+62
-42
lines changed

.github/pull_request_template.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ Check relevant points.
2525
- [ ] Test B
2626

2727
# Checklist:
28+
Prepare items below using:
29+
\[ :x: \] (markdown: `[ :x: ]`) for TODO items
30+
\[ :white_check_mark: \] (markdown: `[ :white_check_mark: ]`) for DONE items
31+
\[ N/A \] for items that are not applicable for this PR.
32+
2833

2934
- [ ] updated version number in setup.py/pyproject.toml/environment.yml.
3035
- [ ] updated the lock file.

hydrolib/core/dflowfm/extold/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class ExtOldParametersQuantity(StrEnum):
175175
FrictionCoefficient = "frictioncoefficient"
176176
HorizontalEddyViscosityCoefficient = "horizontaleddyviscositycoefficient"
177177
HorizontalEddyDiffusivityCoefficient = "horizontaleddydiffusivitycoefficient"
178-
Advectiontype = "advectiontype"
178+
AdvectionType = "advectiontype"
179179
InfiltrationCapacity = "infiltrationcapacity"
180180

181181

@@ -307,7 +307,7 @@ class ExtOldSourcesSinks(StrEnum):
307307

308308

309309
class ExtOldQuantity(StrEnum):
310-
"""Enum class containing th e valid values for the boundary conditions category
310+
"""Enum class containing the valid values for the boundary conditions category
311311
of the external forcings.
312312
"""
313313

hydrolib/core/dflowfm/inifield/models.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,8 @@ class InitialField(AbstractSpatialField):
189189
an inifield file.
190190
Typically inside the definition list of a [FMModel][hydrolib.core.dflowfm.mdu.models.FMModel]`.geometry.inifieldfile.initial[..]`
191191
192-
A `[Initial Condition]` block for use inside an external forcings file,
193-
i.e., a [ExtModel][hydrolib.core.dflowfm.ext.models.ExtModel].
194-
195-
All lowercased attributes match with the meteo input as described in
196-
[UM Sec.C.5.2.3](https://content.oss.deltares.nl/delft3dfm1d2d/D-Flow_FM_User_Manual_1D2D.pdf#subsection.C.5.2.3).
192+
All lowercased attributes match with the initial field input as described in
193+
[UM Sec.D.2](https://content.oss.deltares.nl/delft3dfm1d2d/D-Flow_FM_User_Manual_1D2D.pdf#subsection.D.2).
197194
"""
198195

199196
_header: Literal["Initial"] = "Initial"

hydrolib/tools/ext_old_to_new/converters.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
from hydrolib.core.dflowfm.tim.models import TimModel
2323
from hydrolib.core.dflowfm.tim.parser import TimParser
2424
from hydrolib.tools.ext_old_to_new.utils import (
25-
convert_initial_cond_param_dict,
2625
convert_interpolation_data,
26+
create_initial_cond_and_parameter_input_dict,
2727
find_temperature_salinity_in_quantities,
2828
oldfiletype_to_forcing_file_type,
2929
)
@@ -120,12 +120,12 @@ def __init__(self):
120120
super().__init__()
121121

122122
def convert(self, forcing: ExtOldForcing) -> Boundary:
123-
"""Convert an old external forcing block with meteo data to a boundary
124-
forcing block suitable for inclusion in a new external forcings file.
123+
"""Convert an old external forcing block to a boundary forcing block
124+
suitable for inclusion in a new external forcings file.
125125
126126
This function takes a forcing block from an old external forcings
127127
file, represented by an instance of ExtOldForcing, and converts it
128-
into a Meteo object. The Boundary object is suitable for use in new
128+
into a boundary object. The Boundary object is suitable for use in new
129129
external forcings files, adhering to the updated format and
130130
specifications.
131131
@@ -136,7 +136,7 @@ def convert(self, forcing: ExtOldForcing) -> Boundary:
136136
required for the conversion process.
137137
138138
Returns:
139-
Boundary: A Boindary object that represents the converted forcing
139+
Boundary: A Boundary object that represents the converted forcing
140140
block, ready to be included in a new external forcings file. The
141141
Boundary object conforms to the new format specifications, ensuring
142142
compatibility with updated systems and models.
@@ -191,7 +191,7 @@ def convert(self, forcing: ExtOldForcing) -> InitialField:
191191
References:
192192
[Sec.D](https://content.oss.deltares.nl/delft3dfm1d2d/D-Flow_FM_User_Manual_1D2D.pdf#subsection.D)
193193
"""
194-
data = convert_initial_cond_param_dict(forcing)
194+
data = create_initial_cond_and_parameter_input_dict(forcing)
195195
new_block = InitialField(**data)
196196

197197
return new_block
@@ -203,14 +203,14 @@ def __init__(self):
203203
super().__init__()
204204

205205
def convert(self, forcing: ExtOldForcing) -> ParameterField:
206-
"""Convert an old external forcing block with meteo data to a boundary
207-
forcing block suitable for inclusion in a new external forcings file.
206+
"""Convert an old external forcing block to a parameter forcing block
207+
suitable for inclusion in an initial field and parameter file.
208208
209209
This function takes a forcing block from an old external forcings
210210
file, represented by an instance of ExtOldForcing, and converts it
211-
into a Meteo object. The Boundary object is suitable for use in new
212-
external forcings files, adhering to the updated format and
213-
specifications.
211+
into a ParameterField object. The ParameterField object is suitable for use in
212+
an IniFieldModel, representing an initial field and parameter file, adhering
213+
to the updated format and specifications.
214214
215215
Args:
216216
forcing (ExtOldForcing): The contents of a single forcing block
@@ -219,18 +219,19 @@ def convert(self, forcing: ExtOldForcing) -> ParameterField:
219219
required for the conversion process.
220220
221221
Returns:
222-
Boundary: A Boindary object that represents the converted forcing
223-
block, ready to be included in a new external forcings file. The
224-
Boundary object conforms to the new format specifications, ensuring
225-
compatibility with updated systems and models.
222+
ParameterField:
223+
A ParameterField object that represents the converted forcing
224+
block, ready to be included in an initial field and parameter file. The
225+
ParameterField object conforms to the new format specifications, ensuring
226+
compatibility with updated systems and models.
226227
227228
Raises:
228229
ValueError: If the forcing block contains a quantity that is not
229230
supported by the converter, a ValueError is raised. This ensures
230231
that only compatible forcing blocks are processed, maintaining
231232
data integrity and preventing errors in the conversion process.
232233
"""
233-
data = convert_initial_cond_param_dict(forcing)
234+
data = create_initial_cond_and_parameter_input_dict(forcing)
234235
new_block = ParameterField(**data)
235236

236237
return new_block

hydrolib/tools/ext_old_to_new/main_converter.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,16 @@ def structure_model(self, path: PathOrStr):
164164
@staticmethod
165165
def _read_old_file(extoldfile: PathOrStr) -> ExtOldModel:
166166
"""Read a legacy D-Flow FM external forcings file (.ext) into an
167-
ExtOldModel object.
167+
ExtOldModel object.
168168
169169
Args:
170170
extoldfile (PathOrStr): path to the external forcings file (.ext)
171171
172-
Returns:
173-
ExtOldModel: object with all forcing blocks.
172+
Returns:
173+
ExtOldModel: object with all forcing blocks.
174174
175-
Raises:
176-
FileNotFoundError: If the old external forcing file does not exist.
175+
Raises:
176+
FileNotFoundError: If the old external forcing file does not exist.
177177
"""
178178
if not isinstance(extoldfile, Path):
179179
extoldfile = Path(extoldfile)

hydrolib/tools/ext_old_to_new/utils.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,18 @@ def convert_interpolation_data(
194194
return data
195195

196196

197-
def convert_initial_cond_param_dict(forcing: ExtOldForcing) -> Dict[str, str]:
198-
"""Initial condition and Parameters data dictionary.
197+
def create_initial_cond_and_parameter_input_dict(
198+
forcing: ExtOldForcing,
199+
) -> Dict[str, str]:
200+
"""Create the input dictionary for the `InitialField` or `ParameterField`
201+
202+
Args:
203+
forcing: [ExtOldForcing]
204+
External forcing block from the old external forcings file.
199205
200-
Initial condition and Parameters have the same structure for the conversion.
206+
Returns:
207+
Dict[str, str]:
208+
the input dictionary to the `InitialField` or `ParameterField` constructor
201209
"""
202210
block_data = {
203211
"quantity": forcing.quantity,

poetry.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/tools/test_converters.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33
from hydrolib.core.basemodel import DiskOnlyFileModel
44
from hydrolib.core.dflowfm.bc.models import ForcingModel
5-
from hydrolib.core.dflowfm.ext.models import Boundary, Meteo
5+
from hydrolib.core.dflowfm.common.models import Operand
6+
from hydrolib.core.dflowfm.ext.models import (
7+
Boundary,
8+
Meteo,
9+
MeteoForcingFileType,
10+
MeteoInterpolationMethod,
11+
)
612
from hydrolib.core.dflowfm.extold.models import ExtOldForcing, ExtOldQuantity
713
from hydrolib.core.dflowfm.inifield.models import InitialField, ParameterField
814
from hydrolib.tools.ext_old_to_new.converters import (
@@ -72,10 +78,13 @@ def test_default(self):
7278
new_quantity_block = MeteoConverter().convert(forcing)
7379
assert isinstance(new_quantity_block, Meteo)
7480
assert new_quantity_block.quantity == "windx"
75-
assert new_quantity_block.operand == "O"
81+
assert new_quantity_block.operand == Operand.override
7682
assert new_quantity_block.forcingfile == DiskOnlyFileModel("windtest.amu")
77-
assert new_quantity_block.forcingfiletype == "meteoGridEqui"
78-
assert new_quantity_block.interpolationmethod == "linearSpaceTime"
83+
assert new_quantity_block.forcingfiletype == MeteoForcingFileType.meteogridequi
84+
assert (
85+
new_quantity_block.interpolationmethod
86+
== MeteoInterpolationMethod.linearSpaceTime
87+
)
7988

8089

8190
class TestBoundaryConverter:

0 commit comments

Comments
 (0)