Skip to content

Commit

Permalink
Statistics: Split water on street presets.
Browse files Browse the repository at this point in the history
  • Loading branch information
arjanverkerk committed Oct 25, 2023
1 parent 04d5ae5 commit 964dc7b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 10 deletions.
38 changes: 32 additions & 6 deletions tool_statistics/presets.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from threedi_results_analysis.utils.threedi_result_aggregation.base import Aggregation
from threedi_results_analysis.utils.threedi_result_aggregation.constants import AGGREGATION_VARIABLES, AGGREGATION_METHODS
from threedi_results_analysis.utils.threedi_result_aggregation.constants import (
AGGREGATION_VARIABLES,
AGGREGATION_METHODS,
THRESHOLD_DRAIN_LEVEL,
THRESHOLD_EXCHANGE_LEVEL,
)
from .style import (
Style,
STYLE_SINGLE_COLUMN_GRADUATED_NODE,
Expand Down Expand Up @@ -247,17 +252,37 @@ def aggregations(self):
)

# Change in water level
water_on_street_aggregations = [
water_on_street_aggregations_0d1d = [
Aggregation(
variable=AGGREGATION_VARIABLES.get_by_short_name("s1"),
method=AGGREGATION_METHODS.get_by_short_name("time_above_threshold"),
threshold=THRESHOLD_DRAIN_LEVEL,
),
]

water_on_street_aggregations_1d2d = [
Aggregation(
variable=AGGREGATION_VARIABLES.get_by_short_name("s1"),
method=AGGREGATION_METHODS.get_by_short_name("time_above_threshold"),
threshold=THRESHOLD_EXCHANGE_LEVEL,
),
]

WATER_ON_STREET_DURATION_PRESET = Preset(
name="Water on street duration",
WATER_ON_STREET_DURATION_0D1D_PRESET = Preset(
name="Water on street duration (0D1D)",
description="Duration of water level above manhole drain level.",
aggregations=water_on_street_aggregations,
aggregations=water_on_street_aggregations_0d1d,
nodes_style=STYLE_WATER_ON_STREET_DURATION_NODE,
nodes_style_param_values={"column": "s1_time_above_threshold"},
nodes_layer_name="Water on street duration (nodes)",
raster_layer_name="Water on street duration (raster)",
only_manholes=True,
)

WATER_ON_STREET_DURATION_1D2D_PRESET = Preset(
name="Water on street duration (1D2D)",
description="Duration of water level above manhole exchange level.",
aggregations=water_on_street_aggregations_1d2d,
nodes_style=STYLE_WATER_ON_STREET_DURATION_NODE,
nodes_style_param_values={"column": "s1_time_above_threshold"},
nodes_layer_name="Water on street duration (nodes)",
Expand All @@ -272,5 +297,6 @@ def aggregations(self):
SOURCE_SINK_MM_PRESETS,
FLOW_PATTERN_PRESETS,
TS_REDUCTION_ANALYSIS_PRESETS,
WATER_ON_STREET_DURATION_PRESET,
WATER_ON_STREET_DURATION_0D1D_PRESET,
WATER_ON_STREET_DURATION_1D2D_PRESET,
]
8 changes: 7 additions & 1 deletion tool_statistics/threedi_custom_stats_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,12 @@ def add_aggregation(
# set the threshold _after_ the units widget is in place
if aggregation.threshold is not None:
threshold_widget = self.tableWidgetAggregations.cellWidget(current_row, 3)
threshold_widget.setValue(aggregation.threshold)
if method.threshold_sources:
threshold_widget.setCurrentIndex(
threshold_widget.findText(aggregation.threshold),
)
else:
threshold_widget.setValue(aggregation.threshold)

# TODO: dit is nu lastig te setten obv aggregation, omdat die wel een attribuut multiplier heeft,
# maar niet een attribuut units. laat ik nu even voor wat het is
Expand Down Expand Up @@ -882,6 +887,7 @@ def demanded_aggregations_are_valid(self) -> bool:

def validate(self) -> bool:
valid = True

logger.info([agg.variable.long_name for agg in self.demanded_aggregations])
if not isinstance(self.gr, GridH5ResultAdmin):
logger.warning("Invalid or no result file selected")
Expand Down
8 changes: 6 additions & 2 deletions utils/threedi_result_aggregation/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
from .constants import (
AGGREGATION_VARIABLES,
NON_TS_REDUCING_KCU,
NP_OGR_DTYPES
NP_OGR_DTYPES,
THRESHOLD_DRAIN_LEVEL,
THRESHOLD_EXCHANGE_LEVEL,
)
from .aggregation_classes import (
Aggregation,
Expand Down Expand Up @@ -1073,7 +1075,9 @@ def aggregate_threedi_results(
raise Exception("No manholes found within bounding box.")

for aggregation in demanded_aggregations:
if aggregation.threshold == "exchange_level":
if aggregation.threshold == THRESHOLD_DRAIN_LEVEL:
aggregation.threshold = nodes.drain_level
elif aggregation.threshold == THRESHOLD_EXCHANGE_LEVEL:
# set exchange level from dpumax of adjacent lines
lines = filter_lines_by_node_ids(lines, nodes.id).subset("1D2D")
dpumax = lines.dpumax
Expand Down
6 changes: 5 additions & 1 deletion utils/threedi_result_aggregation/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
np.dtype("int64"): ogr.OFTInteger64,
}

# Thresholds for time above threshold aggregation method
THRESHOLD_EXCHANGE_LEVEL = "Exchange level"
THRESHOLD_DRAIN_LEVEL = "Drain level"

# Aggregation methods
AGGREGATION_METHODS = AggregationVariableList()

Expand Down Expand Up @@ -73,7 +77,7 @@
"long_name": "Time above threshold",
"has_threshold": True,
"is_duration": True,
"threshold_sources": ["exchange_level"],
"threshold_sources": [THRESHOLD_EXCHANGE_LEVEL, THRESHOLD_DRAIN_LEVEL],
},
]

Expand Down

0 comments on commit 964dc7b

Please sign in to comment.