From 6ccadb496b38388bc2f63aeca2ece986f0abf5db Mon Sep 17 00:00:00 2001 From: Ryan Murray <74630349+rywm-dhi@users.noreply.github.com> Date: Mon, 16 Sep 2024 15:09:42 +0200 Subject: [PATCH] Add reach flooding as default derived quantity --- .../default_quantities/reach_flooding.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 mikeio1d/quantities/derived/default_quantities/reach_flooding.py diff --git a/mikeio1d/quantities/derived/default_quantities/reach_flooding.py b/mikeio1d/quantities/derived/default_quantities/reach_flooding.py new file mode 100644 index 00000000..f3f4b99b --- /dev/null +++ b/mikeio1d/quantities/derived/default_quantities/reach_flooding.py @@ -0,0 +1,27 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from typing import List + + import pandas as pd + + from mikeio1d.result_network import ResultLocation + +from ..derived_quantity import DerivedQuantity +from ...timeseries_id import TimeSeriesIdGroup + + +class ReachFlooding(DerivedQuantity): + _NAME = "ReachFlooding" + _GROUPS = {TimeSeriesIdGroup.REACH} + _SOURCE_QUANTITY = "WaterLevel" + + def derive(self, df_source: pd.DataFrame, locations: List[ResultLocation]): + ground_levels = tuple( + gridpoint.result_reach.interpolate_reach_ground_level(gridpoint.chainage) + for gridpoint in locations + ) + df_derived = df_source - ground_levels + return df_derived