Skip to content

Commit

Permalink
compare the temperature and salinity between the mdu vs ext vs tim file
Browse files Browse the repository at this point in the history
  • Loading branch information
MAfarrag committed Jan 7, 2025
1 parent de31910 commit f086597
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
42 changes: 42 additions & 0 deletions hydrolib/tools/ext_old_to_new/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ def parse_tim_model(
Args:
tim_file (Path): The path to the TIM file.
ext_file_quantity_list (List[str]): A list of other quantities that are present in the external forcings file.
**kwargs: keyword argumens that will be provided if you want to provide the temperature and salinity
details from the mdu file, the dictionary will have two keys `temperature`, `salinity` and the values are
only bool. (i.e. {"temperature", False, "salinity": True})
Returns:
Dict[str, List[float]]: A dictionary containing the time series data form each column in the tim_file.
Expand Down Expand Up @@ -340,6 +343,28 @@ def parse_tim_model(
"salinitydelta": [3.0, 3.0, 3.0, 3.0, 3.0],
"initialtracer-anyname": [4.0, 4.0, 4.0, 4.0, 4.0],
}
- the function will raise a `ValueError` if the temperature and salinity are present in the MDU file (value
is 1) file but not in the external forcings file.
mdu file:
```
[physics]
...
Salinity = 1 # Include salinity, (0=no, 1=yes)
...
Temperature = 1 # Include temperature, (0=no, 1=only transport, 3=excess model of D3D,5=heat flux model (5) of D3D)
```
external forcings file:
```
QUANTITY=initialtemperature
FILENAME=right.pol
...
QUANTITY=initialsalinity
FILENAME=right.pol
...
```
"""
time_file = TimParser.parse(tim_file)
tim_model = TimModel(**time_file)
Expand All @@ -356,6 +381,23 @@ def parse_tim_model(
ext_file_quantity_list
)

# test if the temperature and salinity in the ext file conforms with the mdu file
# compare the temperature and salinity from mdu with the temperature and salinity from the external file
if kwargs:
# the kwargs will be provided only from the source and sinks converter
if (
kwargs["temperature"]
and "temperaturedelta" not in temp_salinity_from_ext
):
raise ValueError(
"Temperature is present in the MDU file but not in the external forcings file."
)

if kwargs["salinity"] and "salinitydelta" not in temp_salinity_from_ext:
raise ValueError(
"Salinity is present in the MDU file but not in the external forcings file."
)

ext_file_quantity_list = (
["discharge"]
+ list(temp_salinity_from_ext.keys())
Expand Down
4 changes: 2 additions & 2 deletions tests/tools/test_main_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ def test_sources_sinks_with_fm(self, old_forcing_file_boundary: Dict[str, str]):

# Mock the fm_model
mock_fm_model = Mock()
mock_fm_model.physics.salinity = False
mock_fm_model.physics.temperature = False
mock_fm_model.physics.salinity = True
mock_fm_model.physics.temperature = True
converter._fm_model = mock_fm_model

tim_file = Path("tim-3-columns.tim")
Expand Down

0 comments on commit f086597

Please sign in to comment.