Skip to content

Commit

Permalink
making generic variable list
Browse files Browse the repository at this point in the history
  • Loading branch information
CindyvdVries committed Jul 2, 2024
1 parent f084d2e commit 057be2a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
11 changes: 8 additions & 3 deletions decoimpact/business/entities/rules/depth_average_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
)
from decoimpact.business.entities.rules.rule_base import RuleBase
from decoimpact.crosscutting.i_logger import ILogger
from decoimpact.crosscutting.delft3d_specific_data import (
interfaces_name,
bed_level_name,
water_level_name,
)


class DepthAverageRule(RuleBase, IMultiArrayBasedRule):
Expand All @@ -42,9 +47,9 @@ def execute(
variables = next(iter(value_arrays.values()))

# depths interfaces = borders of the layers in terms of depth
depths_interfaces = value_arrays["mesh2d_interface_z"]
water_level_values = value_arrays["mesh2d_s1"]
bed_level_values = value_arrays["mesh2d_flowelem_bl"]
depths_interfaces = value_arrays[interfaces_name]
water_level_values = value_arrays[water_level_name]
bed_level_values = value_arrays[bed_level_name]

# Get the dimension names for the interfaces and for the layers
dim_interfaces_name = list(depths_interfaces.dims)[0]
Expand Down
3 changes: 3 additions & 0 deletions decoimpact/crosscutting/delft3d_specific_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interfaces_name = "mesh2d_interface_z"
bed_level_name = "mesh2d_flowelem_bl"
water_level_name = "mesh2d_s1"
11 changes: 8 additions & 3 deletions decoimpact/data/parsers/parser_depth_average_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
from decoimpact.data.dictionary_utils import get_dict_element
from decoimpact.data.entities.depth_average_rule_data import DepthAverageRuleData
from decoimpact.data.parsers.i_parser_rule_base import IParserRuleBase
from decoimpact.crosscutting.delft3d_specific_data import (
interfaces_name,
bed_level_name,
water_level_name,
)


class ParserDepthAverageRule(IParserRuleBase):
Expand All @@ -38,9 +43,9 @@ def parse_dict(self, dictionary: Dict[str, Any], logger: ILogger) -> IRuleData:
name: str = get_dict_element("name", dictionary)
input_variable_names: List[str] = [
get_dict_element("input_variable", dictionary),
"mesh2d_interface_z",
"mesh2d_s1",
"mesh2d_flowelem_bl",
interfaces_name,
water_level_name,
bed_level_name,
]
output_variable_name: str = get_dict_element("output_variable", dictionary)
description: str = get_dict_element("description", dictionary, False) or ""
Expand Down
2 changes: 1 addition & 1 deletion tests/business/entities/rules/test_depth_average_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_depth_average_rule(
data_variable: List[float],
mesh2d_interface_z: List[float],
mesh2d_flowelem_bl: List[float],
mesh2d_s1: List[List[float]],
mesh2d_s1: List[float],
result_data: List[float],
):
"""Make sure the calculation of the depth average is correct. Including
Expand Down

0 comments on commit 057be2a

Please sign in to comment.