Skip to content

Commit

Permalink
test the ExternalForcingConverter.update with only boundary conditi…
Browse files Browse the repository at this point in the history
…on data
  • Loading branch information
MAfarrag committed Dec 4, 2024
1 parent 0a17562 commit 9ff2e91
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 1 deletion.
31 changes: 31 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,37 @@ def old_forcing_file_meteo() -> Dict[str, Path]:
}


@pytest.fixture(scope="function")
def old_forcing_file_boundary() -> Dict[str, Path]:
return {
"path": Path(
"tests/data/input/boundary-conditions/old-external-boundary_condition_only.ext"
),
"quantities": [
"waterlevelbnd",
"dischargebnd",
"velocitybnd",
"tangentialvelocitybnd",
"neumannbnd",
"riemannbnd",
"outflowbnd",
"qhbnd",
"salinitybnd",
],
"locationfile": [
"tfl_01.pli",
"left01.pli",
"vel01.pli",
"tanvelN.pli",
"right01.pli",
"left01.pli",
"right01.pli",
"right01.pli",
"tfl_02_sal.pli",
],
}


@pytest.fixture
def old_forcing_file_quantities() -> List[str]:
return [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
* QUANTITY : waterlevelbnd, velocitybnd, dischargebnd, tangentialvelocitybnd, normalvelocitybnd filetype=9 method=2,3
* : outflowbnd, neumannbnd, qhbnd filetype=9 method=2,3
* : salinitybnd filetype=9 method=2,3
* : gateloweredgelevel, damlevel, pump filetype=9 method=2,3
* : frictioncoefficient, horizontaleddyviscositycoefficient, advectiontype, ibotlevtype filetype=4,7,10 method=4
* : initialwaterlevel filetype=4,7,10,12 method=4,5
* : initialtemperature filetype=4,7,10,12 method=4,5
* : initialsalinity, initialsalinitytop: use initialsalinity for depth-uniform, or
* : as bed level value in combination with initialsalinitytop filetype=4,7,10 method=4
* : initialverticaltemperatureprofile filetype=9,10 method=
* : initialverticalsalinityprofile filetype=9,10 method=
* : windx, windy, windxy, rainfall_mmperday, atmosphericpressure filetype=1,2,4,7,8 method=1,2,3
* : shiptxy, movingstationtxy filetype=1 method=1
* : discharge_salinity_temperature_sorsin filetype=9 method=1
*
* kx = Vectormax = Nr of variables specified on the same time/space frame. Eg. Wind magnitude,direction: kx = 2
* FILETYPE=1 : uniform kx = 1 value 1 dim array uni
* FILETYPE=2 : unimagdir kx = 2 values 1 dim array, uni mag/dir transf to u,v, in index 1,2
* FILETYPE=3 : svwp kx = 3 fields u,v,p 3 dim array nointerpolation
* FILETYPE=4 : arcinfo kx = 1 field 2 dim array bilin/direct
* FILETYPE=5 : spiderweb kx = 3 fields 3 dim array bilin/spw
* FILETYPE=6 : curvi kx = ? bilin/findnm
* FILETYPE=7 : triangulation kx = 1 field 1 dim array triangulation
* FILETYPE=8 : triangulation_magdir kx = 2 fields consisting of Filetype=2 triangulation in (wind) stations
*
* FILETYPE=9 : polyline kx = 1 For polyline points i= 1 through N specify boundary signals, either as
* timeseries or Fourier components or tidal constituents
* Timeseries are in files *_000i.tim, two columns: time (min) values
* Fourier components and or tidal constituents are in files *_000i.cmp, three columns
* period (min) or constituent name (e.g. M2), amplitude and phase (deg)
* If no file is specified for a node, its value will be interpolated from surrounding nodes
* If only one signal file is specified, the boundary gets a uniform signal
* For a dischargebnd, only one signal file must be specified
*
* FILETYPE=10 : inside_polygon kx = 1 field uniform value inside polygon for INITIAL fields
* FILETYPE=11 : ncgrid currently not in use
* FILETYPE=12 : ncflow kx = 1 field 1 dim array triangulation
*
* METHOD =0 : provider just updates, another provider that pointers to this one does the actual interpolation
* =1 : intp space and time (getval) keep 2 meteofields in memory
* =2 : first intp space (update), next intp. time (getval) keep 2 flowfields in memory
* =3 : save weightfactors, intp space and time (getval), keep 2 pointer- and weight sets in memory.
* =4 : only spatial, inside polygon
* =5 : only spatial, triangulation
* =6 : only spatial, averaging
* =7 : only spatial, index triangulation
* =8 : only spatial, smoothing
* =9 : only spatial, internal diffusion
* =10 : only initial vertical profiles
*
* OPERAND =O : Override at all points
* =+ : Add to previously specified value
* =* : Multiply with previously specified value
* =A : Apply only if no value specified previously (For Initial fields, similar to Quickin preserving best data specified first)
* =X : MAX with prev. spec.
* =N : MIN with prev. spec.
*
* VALUE = : Offset value for this provider
*
* FACTOR = : Conversion factor for this provider
*
**************************************************************************************************************

QUANTITY =waterlevelbnd
FILENAME =tfl_01.pli
FILETYPE =9
METHOD =3
OPERAND =O


QUANTITY =dischargebnd
FILENAME =left01.pli
FILETYPE =9
METHOD =3
OPERAND =O

QUANTITY =velocitybnd
FILENAME =vel01.pli
FILETYPE =9
METHOD =3
OPERAND =O

QUANTITY =tangentialvelocitybnd
FILENAME =tanvelN.pli
FILETYPE =9
METHOD =3
OPERAND =O

QUANTITY =neumannbnd
FILENAME =right01.pli
FILETYPE =9
METHOD =3
OPERAND =O

QUANTITY =riemannbnd
FILENAME =left01.pli
FILETYPE =9
METHOD =3
OPERAND =O


QUANTITY =outflowbnd
FILENAME =right01.pli
FILETYPE =9
METHOD =3
OPERAND =O

QUANTITY =qhbnd
FILENAME =right01.pli
FILETYPE =9
METHOD =3
OPERAND =O

QUANTITY =salinitybnd
FILENAME =tfl_02_sal.pli
FILETYPE =9
METHOD =3
OPERAND =O
25 changes: 24 additions & 1 deletion tests/tools/test_main_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from hydrolib.tools.ext_old_to_new import main_converter
from hydrolib.tools.ext_old_to_new.main_converter import (
ExternalForcingConverter,
_get_parser,
ext_old_to_new_dir_recursive,
ext_old_to_new_from_mdu,
)
Expand Down Expand Up @@ -209,3 +208,27 @@ def test_initial_contitions_only(
str(inifield_model.initial[i].datafile.filepath)
for i in range(num_quantities)
] == old_forcing_file_initial_condition["file_path"]

def test_boundary_only(self, old_forcing_file_boundary: Dict[str, str]):
"""
The old external forcing file contains only 9 boundary condition quantities all with polyline location files
and no forcing files. The update method should convert all the quantities to boundary conditions.
"""
path = old_forcing_file_boundary["path"]
converter = ExternalForcingConverter.read_old_file(path)

ext_model, inifield_model, structure_model = converter.update()

# all the quantities in the old external file are initial conditions
# check that all the quantities (3) were converted to initial conditions
num_quantities = len(old_forcing_file_boundary["quantities"])
assert len(ext_model.boundary) == num_quantities
# no parameters or any other structures, lateral or meteo data
assert len(inifield_model.parameter) == 0
assert len(ext_model.lateral) == 0
assert len(ext_model.meteo) == 0
assert len(structure_model.structure) == 0
quantities = ext_model.boundary
assert [
str(quantities[i].locationfile.filepath) for i in range(num_quantities)
] == old_forcing_file_boundary["locationfile"]

0 comments on commit 9ff2e91

Please sign in to comment.