@@ -20,15 +20,15 @@ def find_upstream_units(flow_paths: pd.DataFrame, unit_name: str) -> list[str]:
2020
2121def find_downstream_flow_fractions (
2222 flow_paths : pd .DataFrame , unit_name : str
23- ) -> list [str , float ]:
23+ ) -> dict [str , float ]:
2424 """Find downstream units for a given unit.
2525
2626 Args:
2727 flow_paths (pd.DataFrame): DataFrame containing flow paths between units.
2828 unit_name (str): The name of the unit to find downstream units for.
2929
3030 Returns:
31- list [str, float]: List of downstream unit names and their flow fractions.
31+ dict [str, float]: Dict of downstream unit names and their flow fractions.
3232 """
3333 return (
3434 flow_paths .loc [flow_paths ["source" ] == unit_name , ["sink" , "flow_fraction" ]]
@@ -54,8 +54,7 @@ def find_simulation_order(
5454 G = nx .DiGraph (edgelist )
5555 try :
5656 simulation_order = list (nx .topological_sort (G ))
57- # The current list excludes reservoirs that are not in the flow paths,
58- # so we need to add them to the end of the list
57+ # Some reservoirs are not in the flow paths, so we need to add them to the end of the list
5958 reservoirs_not_in_paths = []
6059 for reservoir in reservoir_names :
6160 if reservoir not in simulation_order :
@@ -78,8 +77,8 @@ def adjust_hydropeaking(
7877 Also, the release cannot be lower than the minimum release or higher than the maximum release.
7978
8079 Args:
81- release (float): The release for the current day. Can be both negative and positive
82- release_t0 (float): The release for the previous day. Can be both negative and positive
80+ release (float): The release for the current day.
81+ release_t0 (float): The release for the previous day.
8382 max_release (float): The maximum release as a positive value
8483 min_release (float): The minimum release as a positive value
8584 hydropeak_factor (float): The factor to limit the change in release. Default is 0.15.
@@ -112,78 +111,78 @@ def adjust_hydropeaking(
112111 return adj_release
113112
114113
115- def calc_min_environ_flow (
116- inflow : float ,
117- mean_annual_flow : float ,
118- max_release : float ,
119- ) -> float :
120- """Tdetermine the minimum amount of water that should be released
121- from a reservoir to maintain the health of the downstream ecosystem.
122-
123- Example of three cases:
124-
125- 1) If the inflow is less than 40% of the mean annual flow,
126- the minimum flow is set to 60% of the inflow.
127- This ensures that a reasonable portion of the limited water
128- is still released to support the ecosystem.
129-
130- 2) If the inflow is greater than 80% of the mean annual flow,
131- the minimum flow is 30% of the inflow. a smaller percentage is
132- released since the ecosystem is likely receiving ample water already.
133-
134- 3) Otherwise, the minimum flow is 45% of the inflow.
135-
136- Args:
137- inflow (float): The inflow to the reservoir
138- mean_annual_flow (float): The mean annual flow
139- max_release (float): The maximum release
140-
141- Returns:
142- float: The minimum environmental flow
143- """
144- lower_maf_fraction = 0.4
145- upper_maf_fraction = 0.8
146-
147- low_flow_scenario = lower_maf_fraction * mean_annual_flow
148- upper_maf_fraction = upper_maf_fraction * mean_annual_flow
149-
150- small_fraction = 0.3
151- medium_fraction = 0.45
152- large_fraction = 0.6
153-
154- # Also need to ensure that the minimum environmental flow is less than the maximum release
155- if inflow <= low_flow_scenario :
156- return min (large_fraction * inflow , max_release )
157- elif inflow > upper_maf_fraction :
158- return min (small_fraction * inflow , max_release )
159- else :
160- return min (medium_fraction * inflow , max_release )
161-
162-
163- def calc_minflow (
164- inflow : pd .Series , mean_annual_flow : pd .Series , max_release : float
165- ) -> pd .Series :
166- """Find the minimum environmental flow.
167-
168- Args:
169- inflow (pd.Series): The inflow to the reservoir
170- mean_annual_flow (pd.Series): The mean annual flow
171- max_release (float): The maximum release
172-
173- Returns:
174- pd.Series: The minimum environmental flow
175-
176- """
177- df = pd .DataFrame ({"inflow" : inflow , "mean_annual_flow" : mean_annual_flow })
178- minflow = df .apply (
179- lambda x : calc_min_environ_flow (
180- inflow = x .inflow ,
181- mean_annual_flow = x .mean_annual_flow ,
182- max_release = max_release ,
183- ),
184- axis = 1 ,
185- )
186- return minflow
114+ # def calc_min_environ_flow(
115+ # inflow: float,
116+ # mean_annual_flow: float,
117+ # max_release: float,
118+ # ) -> float:
119+ # """Tdetermine the minimum amount of water that should be released
120+ # from a reservoir to maintain the health of the downstream ecosystem.
121+
122+ # Example of three cases:
123+
124+ # 1) If the inflow is less than 40% of the mean annual flow,
125+ # the minimum flow is set to 60% of the inflow.
126+ # This ensures that a reasonable portion of the limited water
127+ # is still released to support the ecosystem.
128+
129+ # 2) If the inflow is greater than 80% of the mean annual flow,
130+ # the minimum flow is 30% of the inflow. a smaller percentage is
131+ # released since the ecosystem is likely receiving ample water already.
132+
133+ # 3) Otherwise, the minimum flow is 45% of the inflow.
134+
135+ # Args:
136+ # inflow (float): The inflow to the reservoir
137+ # mean_annual_flow (float): The mean annual flow
138+ # max_release (float): The maximum release
139+
140+ # Returns:
141+ # float: The minimum environmental flow
142+ # """
143+ # lower_maf_fraction = 0.4
144+ # upper_maf_fraction = 0.8
145+
146+ # low_flow_scenario = lower_maf_fraction * mean_annual_flow
147+ # upper_maf_threshold = upper_maf_fraction * mean_annual_flow
148+
149+ # small_fraction = 0.3
150+ # medium_fraction = 0.45
151+ # large_fraction = 0.6
152+
153+ # # Also need to ensure that the minimum environmental flow is less than the maximum release
154+ # if inflow <= low_flow_scenario:
155+ # return min(large_fraction * inflow, max_release)
156+ # elif inflow > upper_maf_threshold :
157+ # return min(small_fraction * inflow, max_release)
158+ # else:
159+ # return min(medium_fraction * inflow, max_release)
160+
161+
162+ # def calc_minflow(
163+ # inflow: pd.Series, mean_annual_flow: pd.Series, max_release: float
164+ # ) -> pd.Series:
165+ # """Find the minimum environmental flow.
166+
167+ # Args:
168+ # inflow (pd.Series): The inflow to the reservoir
169+ # mean_annual_flow (pd.Series): The mean annual flow
170+ # max_release (float): The maximum release
171+
172+ # Returns:
173+ # pd.Series: The minimum environmental flow
174+
175+ # """
176+ # df = pd.DataFrame({"inflow": inflow, "mean_annual_flow": mean_annual_flow})
177+ # minflow = df.apply(
178+ # lambda x: calc_min_environ_flow(
179+ # inflow=x.inflow,
180+ # mean_annual_flow=x.mean_annual_flow,
181+ # max_release=max_release,
182+ # ),
183+ # axis=1,
184+ # )
185+ # return minflow
187186
188187
189188def calc_target_level (
0 commit comments