Skip to content

Commit

Permalink
Merge pull request #932 from nens/leendert-result-aggregation-presets
Browse files Browse the repository at this point in the history
Result aggregation presets
  • Loading branch information
leendertvanwolfswinkel authored Mar 13, 2024
2 parents daaee85 + 7f40998 commit 9761037
Show file tree
Hide file tree
Showing 6 changed files with 1,331 additions and 21 deletions.
104 changes: 100 additions & 4 deletions tool_statistics/presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
STYLE_TIMESTEP_REDUCTION_ANALYSIS,
STYLE_BALANCE,
STYLE_WATER_ON_STREET_DURATION_NODE,
STYLE_MANHOLE_WATER_DEPTH_0D1D_NODE,
STYLE_MANHOLE_WATER_DEPTH_1D2D_NODE,
STYLE_MANHOLE_MIN_FREEBOARD_0D1D,
STYLE_MANHOLE_MIN_FREEBOARD_1D2D,
)


Expand Down Expand Up @@ -269,7 +273,7 @@ def aggregations(self):
]

WATER_ON_STREET_DURATION_0D1D_PRESET = Preset(
name="Water on street duration (0D1D)",
name="Manhole: Water on street duration (0D1D)",
description="Time [s] that the water level in manholes exceeds the drain level.\n\n"
"In 3Di models without 2D, this is the level at which water flows onto the street (i.e., where the "
"storage area changes from what is specified at the connection node to what is specified as manhole "
Expand All @@ -281,12 +285,12 @@ def aggregations(self):
aggregations=water_on_street_aggregations_0d1d,
nodes_style=STYLE_WATER_ON_STREET_DURATION_NODE,
nodes_style_param_values={"column": "s1_time_above_threshold_drain_level"},
nodes_layer_name="Water on street duration (0D1D)",
nodes_layer_name="Manhole: Water on street duration (0D1D)",
only_manholes=True,
)

WATER_ON_STREET_DURATION_1D2D_PRESET = Preset(
name="Water on street duration (1D2D)",
name="Manhole: Water on street duration (1D2D)",
description="Time [s] that the water level in manholes exceeds the 1D2D exchange level.\n\n"
"In 3Di models with 2D, this is the level at which water flows onto the street. The exchange level is "
"the maximum of two values: the drain level specified for the manhole, or the bottom level (lowest "
Expand All @@ -298,17 +302,109 @@ def aggregations(self):
aggregations=water_on_street_aggregations_1d2d,
nodes_style=STYLE_WATER_ON_STREET_DURATION_NODE,
nodes_style_param_values={"column": "s1_time_above_threshold_exchange_level"},
nodes_layer_name="Water on street duration (1D2D)",
nodes_layer_name="Manhole: Water on street duration (1D2D)",
only_manholes=True,
)

# Manhole: Max water depth on street
max_depth_on_street_aggregations = [
Aggregation(
variable=AGGREGATION_VARIABLES.get_by_short_name("s1"),
method=AGGREGATION_METHODS.get_by_short_name("max")
),
]

MAX_DEPTH_ON_STREET_0D1D_PRESETS = Preset(
name="Manhole: Max water depth on street (0D1D)",
description="Maximum water depth on manholes, calculated as maximum water level - drain level\n\n"
"In 3Di models without 2D, this is the level at which water flows onto the street (i.e., where the "
"storage area changes from what is specified at the connection node to what is specified as manhole "
"storage area in the global settings).\n\n"
"⚠ Do not use this preset for 3Di models with 2D. In such models, the drain level defined at the "
"manhole is not always the level at which water flows onto the street. If the drain level is lower "
"than the bottom level (lowest pixel) of the 2D cell the manhole is in, the water must rise to the "
"2D cell's bottom level before it can flow onto the street.",
aggregations=max_depth_on_street_aggregations,
nodes_style=STYLE_MANHOLE_WATER_DEPTH_0D1D_NODE,
nodes_style_param_values={"value": "s1_max"},
nodes_layer_name="Manhole: Max water depth on street (0D1D)",
only_manholes=True
)

MAX_DEPTH_ON_STREET_1D2D_PRESETS = Preset(
name="Manhole: Max water depth on street (1D2D)",
description="Maximum water depth on manholes, calculated as maximum water level - 1D2D exchange level. \n\n"
"In 3Di models with 2D, this is the level at which water flows onto the street. The exchange level is "
"the maximum of two values: the drain level specified for the manhole, or the bottom level (lowest "
"pixel) of the 2D cell the manhole is in.\n\n"
"⚠ Manholes that have no connection to the 2D domain do not have an exchange level. The 'water depth "
"on street' is NULL for these manholes.\n\n"
"⚠ Do not use this preset for 3Di models without 2D. In such models, none of the manholes have a "
"connection to the 2D domain, so the 'water depth on street' will be NULL for all manholes.",
aggregations=max_depth_on_street_aggregations,
nodes_style=STYLE_MANHOLE_WATER_DEPTH_1D2D_NODE,
nodes_style_param_values={"value": "s1_max"},
nodes_layer_name="Manhole: Max water depth on street (1D2D)",
only_manholes=True
)


# Manhole: Minimum freeboard
max_depth_on_street_aggregations = [
Aggregation(
variable=AGGREGATION_VARIABLES.get_by_short_name("s1"),
method=AGGREGATION_METHODS.get_by_short_name("max")
),
]

MIN_FREEBOARD_0D1D_PRESETS = Preset(
name="Manhole: Minimum freeboard (0D1D)",
description="Minimum freeboard for manholes, "
"i.e. the difference between the maximum water level and the manhole drain level.\n\n"
"In 3Di models without 2D, this is the level at which water flows onto the street (i.e., where the "
"storage area changes from what is specified at the connection node to what is specified as manhole "
"storage area in the global settings).\n\n"
"⚠ Do not use this preset for 3Di models with 2D. In such models, the drain level defined at the "
"manhole is not always the level at which water flows onto the street. If the drain level is lower "
"than the bottom level (lowest pixel) of the 2D cell the manhole is in, the water must rise to the "
"2D cell's bottom level before it can flow onto the street.",
aggregations=max_depth_on_street_aggregations,
nodes_style=STYLE_MANHOLE_MIN_FREEBOARD_0D1D,
nodes_style_param_values={"value": "s1_max"},
nodes_layer_name="Manhole: Minimum freeboard (0D1D)",
only_manholes=True
)

MIN_FREEBOARD_1D2D_PRESETS = Preset(
name="Manhole: Minimum freeboard (1D2D)",
description="Minimum freeboard for manholes, "
"i.e. the difference between the maximum water level and the 1D2D exchange level.\n\n"
"In 3Di models with 2D, this is the level at which water flows onto the street. The exchange level is "
"the maximum of two values: the drain level specified for the manhole, or the bottom level (lowest "
"pixel) of the 2D cell the manhole is in.\n\n"
"⚠ Manholes that have no connection to the 2D domain do not have an exchange level. The 'minimum "
"freeboard' is always NULL for these manholes.\n\n"
"⚠ Do not use this preset for 3Di models without 2D. In such models, none of the manholes have a "
"connection to the 2D domain, so the 'minimum freeboard' will be NULL for all manholes.",
aggregations=max_depth_on_street_aggregations,
nodes_style=STYLE_MANHOLE_MIN_FREEBOARD_1D2D,
nodes_style_param_values={"value": "s1_max"},
nodes_layer_name="Manhole: Minimum freeboard (1D2D)",
only_manholes=True
)


PRESETS = [
NO_PRESET,
MAX_WL_PRESETS,
CHANGE_WL_PRESETS,
SOURCE_SINK_MM_PRESETS,
FLOW_PATTERN_PRESETS,
TS_REDUCTION_ANALYSIS_PRESETS,
MAX_DEPTH_ON_STREET_0D1D_PRESETS,
MAX_DEPTH_ON_STREET_1D2D_PRESETS,
MIN_FREEBOARD_0D1D_PRESETS,
MIN_FREEBOARD_1D2D_PRESETS,
WATER_ON_STREET_DURATION_0D1D_PRESET,
WATER_ON_STREET_DURATION_1D2D_PRESET,
]
73 changes: 73 additions & 0 deletions tool_statistics/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ def style_on_single_column(layer, qml: str, column: str, update_classes: bool =
utils.iface.layerTreeView().refreshLayerSymbology(layer.id())


def style_difference(layer, qml: str, value: str, reference: str, update_classes: bool = True):
layer.loadNamedStyle(qml)
layer.renderer().setClassAttribute(f"{value} - {reference}")
if update_classes:
layer.renderer().updateClasses(
vlayer=layer,
mode=layer.renderer().mode(),
nclasses=len(layer.renderer().ranges()),
)
layer.triggerRepaint()
utils.iface.layerTreeView().refreshLayerSymbology(layer.id())


def style_balance(
layer,
qml: str,
Expand Down Expand Up @@ -299,6 +312,62 @@ def style_ts_reduction_analysis(
),
)

STYLE_MANHOLE_WATER_DEPTH_0D1D_NODE = Style(
name="Manhole water depth (0D1D)",
output_type="node",
params={"value": "column"},
qml="manhole_water_depth.qml",
styling_method=lambda layer, qml, value, reference="drain_level", update_classes=False: style_difference(
layer,
qml,
value,
reference,
update_classes
),
)

STYLE_MANHOLE_WATER_DEPTH_1D2D_NODE = Style(
name="Manhole water depth (1D2D)",
output_type="node",
params={"value": "column"},
qml="manhole_water_depth.qml",
styling_method=lambda layer, qml, value, reference="exchange_level_1d2d", update_classes=False: style_difference(
layer,
qml,
value,
reference,
update_classes
),
)

STYLE_MANHOLE_MIN_FREEBOARD_0D1D = Style(
name="Manhole freeboard (0D1D)",
output_type="node",
params={"value": "column"},
qml="manhole_freeboard.qml",
styling_method=lambda layer, qml, value, reference="drain_level", update_classes=False: style_difference(
layer,
qml,
value,
reference,
update_classes
),
)

STYLE_MANHOLE_MIN_FREEBOARD_1D2D = Style(
name="Manhole freeboard (1D2D)",
output_type="node",
params={"value": "column"},
qml="manhole_freeboard.qml",
styling_method=lambda layer, qml, value, reference="exchange_level_1d2d", update_classes=False: style_difference(
layer,
qml,
value,
reference,
update_classes
),
)

STYLE_CHANGE_WL = Style(
name="Change in water level",
output_type="cell",
Expand Down Expand Up @@ -349,6 +418,10 @@ def style_ts_reduction_analysis(
STYLE_CHANGE_WL,
STYLE_BALANCE,
STYLE_WATER_ON_STREET_DURATION_NODE,
STYLE_MANHOLE_WATER_DEPTH_0D1D_NODE,
STYLE_MANHOLE_WATER_DEPTH_1D2D_NODE,
STYLE_MANHOLE_MIN_FREEBOARD_0D1D,
STYLE_MANHOLE_MIN_FREEBOARD_1D2D
]

DEFAULT_STYLES = {
Expand Down
Loading

0 comments on commit 9761037

Please sign in to comment.