Skip to content

Commit 006481d

Browse files
committed
Update reservoir.py
1 parent cfee83e commit 006481d

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/pownet/data_model/reservoir.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import dataclasses
2+
import math
3+
24
import pandas as pd
35

46

@@ -19,8 +21,8 @@ class ReservoirParams:
1921
max_generation (float): The maximum power generation capacity (MW).
2022
turbine_factor (float): The efficiency factor of the turbine(s).
2123
inflow_ts (pd.Series): Timeseries of daily natural inflow into the reservoir (m³/day),
22-
indexed from 1 to sim_horizon.
23-
minflow_ts (pd.Series): Minimum environmental flow (m³/day), indexed from 1 to sim_horizon.
24+
indexed from 1.
25+
minflow_ts (pd.Series): Minimum environmental flow (m³/day), indexed from 1.
2426
upstream_units (list[str]): List of upstream reservoir names that feed into this reservoir.
2527
downstream_flow_fracs (dict[str, float]): Dictionary mapping downstream reservoir names to their
2628
respective flow fractions (0-1).
@@ -45,7 +47,9 @@ def __post_init__(self):
4547
"""Perform basic validation after initialization."""
4648
# Flow fractions of downstream units should sum to 1
4749
if self.downstream_flow_fracs:
48-
if not 0.999 <= sum(self.downstream_flow_fracs.values()) <= 1.001:
50+
if not math.isclose(
51+
sum(self.downstream_flow_fracs.values()), 1.0, abs_tol=1e-4
52+
):
4953
raise ValueError(
5054
f"Downstream units for {self.name} do not sum to 1: "
5155
f"{self.downstream_flow_fracs}"

0 commit comments

Comments
 (0)