Skip to content

Commit

Permalink
Add support for pumps in result aggregation tool (#1014)
Browse files Browse the repository at this point in the history
* Support for pumps in result aggregation tool
* Add threshold compare methods
* Add preset "Total pumped volume" to Result Aggregation tool
* Add preset "Pumps: % of time at max capacity" to Result Aggregation tool
* Cross-sectional discharge algorithm: allow cross-section lines to have different crs than 3Di results, automatically reproject
  • Loading branch information
leendertvanwolfswinkel authored Sep 9, 2024
1 parent f519a01 commit 5c77ea5
Show file tree
Hide file tree
Showing 17 changed files with 4,691 additions and 1,010 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
3.9.4 (unreleased)
------------------

- Add pump support to Result Aggregation tool
- Add preset "Total pumped volume" to Result Aggregation tool
- Add preset "Pumps: % of time at max capacity" to Result Aggregation tool
- Cross-sectional discharge algorithm: allow cross-section lines to have different crs than 3Di results, automatically reproject
- Watershed tool: 2D flowlines intersecting obstacles are no longer shown as 1D flowlines (#1034)
- Model selection dialog: fixed order bug when sorting.
- Bump threedi-mi-utils to 0.1.4
Expand Down
12 changes: 9 additions & 3 deletions processing/cross_sectional_discharge_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

from osgeo import ogr
from qgis.core import QgsCoordinateReferenceSystem
from qgis.core import QgsCoordinateTransform
from qgis.core import QgsFeatureSink
from qgis.core import QgsField
from qgis.core import QgsFields
Expand Down Expand Up @@ -287,14 +288,17 @@ def processAlgorithm(self, parameters, context, feedback):
QgsField(name="q_net_sum", type=QVariant.Double)
)

crs = QgsCoordinateReferenceSystem(f"EPSG:{gr.epsg_code}")
threedi_results_crs = QgsCoordinateReferenceSystem(f"EPSG:{gr.epsg_code}")
cross_section_lines_crs = cross_section_lines.sourceCrs()
coordinate_transform = QgsCoordinateTransform(cross_section_lines_crs, threedi_results_crs, context.project())

(flowlines_sink, self.flowlines_sink_dest_id) = self.parameterAsSink(
parameters,
self.OUTPUT_FLOWLINES,
context,
fields=flowlines_sink_fields,
geometryType=QgsWkbTypes.LineString,
crs=crs,
crs=threedi_results_crs,
)

self.target_field_idx = (
Expand Down Expand Up @@ -326,7 +330,9 @@ def processAlgorithm(self, parameters, context, feedback):
feedback.setProgressText(
f"Processing cross-section line {gauge_line.id()}..."
)
shapely_linestring = wkt.loads(gauge_line.geometry().asWkt())
transformed_geometry = gauge_line.geometry()
transformed_geometry.transform(coordinate_transform)
shapely_linestring = wkt.loads(transformed_geometry.asWkt())
tgt_ds = MEMORY_DRIVER.CreateDataSource("")
ts_gauge_line, total_discharge = left_to_right_discharge_ogr(
gr=gr,
Expand Down
2 changes: 1 addition & 1 deletion processing/deps/discharge/cross_sectional_discharge.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def left_to_right_discharge(
content_type__in=content_types
)
ts, tintervals = prepare_timeseries(
nodes_or_lines=intersecting_lines,
threedigrid_object=intersecting_lines,
start_time=start_time,
end_time=end_time,
aggregation=Q_NET_SUM,
Expand Down
2 changes: 1 addition & 1 deletion processing/deps/discharge/discharge_reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(
feedback.setProgressText("Calculate cumulative discharges...")
all_2d_open_water_flowlines = grid_result_admin.lines.subset('2D_OPEN_WATER').filter(id__in=flowline_ids)
discharges, self.tintervals = prepare_timeseries(
nodes_or_lines=all_2d_open_water_flowlines,
threedigrid_object=all_2d_open_water_flowlines,
aggregation=self.Q_NET_SUM
)
q_net_sum = aggregate_prepared_timeseries(
Expand Down
77 changes: 72 additions & 5 deletions tool_statistics/presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
from threedi_results_analysis.utils.threedi_result_aggregation.constants import (
AGGREGATION_VARIABLES,
AGGREGATION_METHODS,
THRESHOLD_DRAIN_LEVEL,
THRESHOLD_EXCHANGE_LEVEL,
)
from .style import (
Style,
Expand All @@ -18,6 +16,8 @@
STYLE_MANHOLE_WATER_DEPTH_1D2D_NODE,
STYLE_MANHOLE_MIN_FREEBOARD_0D1D,
STYLE_MANHOLE_MIN_FREEBOARD_1D2D,
STYLE_SINGLE_COLUMN_GRADUATED_PUMP,
STYLE_SINGLE_COLUMN_GRADUATED_PUMP_LINESTRING,
)


Expand All @@ -28,16 +28,26 @@ def __init__(
description: str = "",
aggregations=None,
resample_point_layer: bool = False,

flowlines_style: Style = None,
cells_style: Style = None,
nodes_style: Style = None,
pumps_style: Style = None,
pumps_linestring_style: Style = None,

flowlines_style_param_values: dict = None,
cells_style_param_values: dict = None,
nodes_style_param_values: dict = None,
pumps_style_param_values: dict = None,
pumps_linestring_style_param_values: dict = None,

flowlines_layer_name: str = None,
cells_layer_name: str = None,
nodes_layer_name: str = None,
pumps_layer_name: str = None,
pumps_linestring_layer_name: str = None,
raster_layer_name: str = None,

only_manholes: bool = False,
):
if aggregations is None:
Expand All @@ -46,16 +56,26 @@ def __init__(
self.description = description
self.__aggregations = aggregations
self.resample_point_layer = resample_point_layer

self.flowlines_style = flowlines_style
self.cells_style = cells_style
self.nodes_style = nodes_style
self.pumps_style = pumps_style
self.pumps_linestring_style = pumps_linestring_style

self.flowlines_style_param_values = flowlines_style_param_values
self.cells_style_param_values = cells_style_param_values
self.nodes_style_param_values = nodes_style_param_values
self.pumps_style_param_values = pumps_style_param_values
self.pumps_linestring_style_param_values = pumps_linestring_style_param_values

self.flowlines_layer_name = flowlines_layer_name
self.cells_layer_name = cells_layer_name
self.nodes_layer_name = nodes_layer_name
self.pumps_layer_name = pumps_layer_name
self.pumps_linestring_layer_name = pumps_linestring_layer_name
self.raster_layer_name = raster_layer_name

self.only_manholes = only_manholes

def add_aggregation(self, aggregation: Aggregation):
Expand Down Expand Up @@ -260,15 +280,15 @@ def aggregations(self):
Aggregation(
variable=AGGREGATION_VARIABLES.get_by_short_name("s1"),
method=AGGREGATION_METHODS.get_by_short_name("time_above_threshold"),
threshold=THRESHOLD_DRAIN_LEVEL,
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,
threshold="exchange_level_1d2d",
),
]

Expand Down Expand Up @@ -301,7 +321,7 @@ def aggregations(self):
"connection to the 2D domain, so the 'water on street duration' will be 0 for all manholes.",
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_style_param_values={"column": "s1_time_above_threshold_exchange_level_1d2d"},
nodes_layer_name="Manhole: Water on street duration (1D2D)",
only_manholes=True,
)
Expand Down Expand Up @@ -393,6 +413,51 @@ def aggregations(self):
only_manholes=True
)

# Pump: Total pumped volume
total_pumped_volume_aggregations = [
Aggregation(
variable=AGGREGATION_VARIABLES.get_by_short_name("q_pump"),
method=AGGREGATION_METHODS.get_by_short_name("sum")
),
]

TOTAL_PUMPED_VOLUME_PRESETS = Preset(
name="Pump: Total pumped volume",
description="Total volume pumped by each pump in the selected time period.",
aggregations=total_pumped_volume_aggregations,

pumps_style=STYLE_SINGLE_COLUMN_GRADUATED_PUMP,
pumps_style_param_values={"column": "q_pump_sum"},
pumps_layer_name="Pump (point): Total pumped volume [m3]",

pumps_linestring_style=STYLE_SINGLE_COLUMN_GRADUATED_PUMP_LINESTRING,
pumps_linestring_style_param_values={"column": "q_pump_sum"},
pumps_linestring_layer_name="Pump (line): Total pumped volume [m3]",
)

# Pump: time at max capacity
pump_time_at_max_capacity_aggregations = [
Aggregation(
variable=AGGREGATION_VARIABLES.get_by_short_name("q_pump"),
method=AGGREGATION_METHODS.get_by_short_name("on_thres"),
threshold="capacity"
),
]

PUMP_TIME_AT_MAX_CAPACITY_PRESETS = Preset(
name="Pump: % of time at max capacity",
description="Percentage of time that each pump is pumping at its maximum capacity in the selected time period.\n\n"
"Note that both the pump implicit factor and the output time step will affect the result.",
aggregations=pump_time_at_max_capacity_aggregations,

pumps_style=STYLE_SINGLE_COLUMN_GRADUATED_PUMP,
pumps_style_param_values={"column": "q_pump_on_thres_capacity"},
pumps_layer_name="Pump (point): % of time at max capacity",

pumps_linestring_style=STYLE_SINGLE_COLUMN_GRADUATED_PUMP_LINESTRING,
pumps_linestring_style_param_values={"column": "q_pump_on_thres_capacity"},
pumps_linestring_layer_name="Pump (line): % of time at max capacity",
)

PRESETS = [
NO_PRESET,
Expand All @@ -407,4 +472,6 @@ def aggregations(self):
MIN_FREEBOARD_1D2D_PRESETS,
WATER_ON_STREET_DURATION_0D1D_PRESET,
WATER_ON_STREET_DURATION_1D2D_PRESET,
TOTAL_PUMPED_VOLUME_PRESETS,
PUMP_TIME_AT_MAX_CAPACITY_PRESETS,
]
Loading

0 comments on commit 5c77ea5

Please sign in to comment.