py-ewr 2.0.0__py3-none-any.whl → 2.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- py_ewr/data_inputs.py +6 -217
- py_ewr/evaluate_EWRs.py +106 -964
- py_ewr/model_metadata/SiteID_MDBA.csv +80 -15
- py_ewr/observed_handling.py +3 -9
- py_ewr/parameter_metadata/parameter_sheet.csv +256 -393
- py_ewr/scenario_handling.py +19 -14
- py_ewr/summarise_results.py +1 -3
- py_ewr-2.1.0.dist-info/METADATA +221 -0
- py_ewr-2.1.0.dist-info/RECORD +15 -0
- {py_ewr-2.0.0.dist-info → py_ewr-2.1.0.dist-info}/WHEEL +1 -1
- py_ewr/climate_data/climate_cats.csv +0 -212
- py_ewr/climate_data/climate_cats_10000year.csv +0 -10003
- py_ewr-2.0.0.dist-info/METADATA +0 -190
- py_ewr-2.0.0.dist-info/RECORD +0 -17
- {py_ewr-2.0.0.dist-info → py_ewr-2.1.0.dist-info}/LICENSE +0 -0
- {py_ewr-2.0.0.dist-info → py_ewr-2.1.0.dist-info}/top_level.txt +0 -0
py_ewr/evaluate_EWRs.py
CHANGED
|
@@ -16,6 +16,8 @@ from . import data_inputs
|
|
|
16
16
|
|
|
17
17
|
log = logging.getLogger(__name__)
|
|
18
18
|
log.addHandler(logging.NullHandler())
|
|
19
|
+
import warnings
|
|
20
|
+
warnings.simplefilter(action='ignore', category=pd.errors.PerformanceWarning)
|
|
19
21
|
|
|
20
22
|
#----------------------------------- Getting EWRs from the database ------------------------------#
|
|
21
23
|
|
|
@@ -41,19 +43,6 @@ def component_pull(EWR_table: pd.DataFrame, gauge: str, PU: str, EWR: str, compo
|
|
|
41
43
|
)][component])[0]
|
|
42
44
|
return component if component else 0
|
|
43
45
|
|
|
44
|
-
def apply_correction(val: float, correction: float) -> float:
|
|
45
|
-
'''Applies a correction to the EWR component (based on user request)
|
|
46
|
-
|
|
47
|
-
Args:
|
|
48
|
-
val (float): value to be corrected
|
|
49
|
-
correction (float): the correction to be applied to the value (0-1)
|
|
50
|
-
|
|
51
|
-
Results:
|
|
52
|
-
float: new value with correction applied
|
|
53
|
-
|
|
54
|
-
'''
|
|
55
|
-
return val*correction
|
|
56
|
-
|
|
57
46
|
def get_second_multigauge(parameter_sheet: pd.DataFrame, gauge:float, ewr:str, pu:str) -> str:
|
|
58
47
|
"""get the second gauge number for a multiguage
|
|
59
48
|
|
|
@@ -71,15 +60,14 @@ def get_second_multigauge(parameter_sheet: pd.DataFrame, gauge:float, ewr:str, p
|
|
|
71
60
|
gauge_number = gauge_array[0] if gauge_array else ''
|
|
72
61
|
return gauge_number
|
|
73
62
|
|
|
74
|
-
def get_EWRs(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame,
|
|
75
|
-
'''Pulls the relevant EWR componenets for each EWR
|
|
63
|
+
def get_EWRs(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, components: list) -> dict:
|
|
64
|
+
'''Pulls the relevant EWR componenets for each EWR
|
|
76
65
|
|
|
77
66
|
Args:
|
|
78
67
|
PU (str): Planning unit ID
|
|
79
68
|
gauge (str): Gauge ID
|
|
80
69
|
EWR (str): EWR code
|
|
81
70
|
EWR_table (pd.DataFrame): EWR dataset
|
|
82
|
-
allowance (dict): How much to scale components by (0-1)
|
|
83
71
|
components (list): List of parameters needing to be pulled from the EWR dataset
|
|
84
72
|
|
|
85
73
|
Results:
|
|
@@ -110,28 +98,22 @@ def get_EWRs(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, allowance:
|
|
|
110
98
|
ewrs['end_month'] =int(end_date)
|
|
111
99
|
if 'MINF' in components:
|
|
112
100
|
min_flow = int(component_pull(EWR_table, gauge, PU, EWR, 'FlowThresholdMin'))
|
|
113
|
-
|
|
114
|
-
ewrs['min_flow'] = int(corrected)
|
|
101
|
+
ewrs['min_flow'] = int(min_flow)
|
|
115
102
|
if 'MAXF' in components:
|
|
116
103
|
max_flow = int(component_pull(EWR_table, gauge, PU, EWR, 'FlowThresholdMax'))
|
|
117
|
-
|
|
118
|
-
ewrs['max_flow'] = int(corrected)
|
|
104
|
+
ewrs['max_flow'] = int(max_flow)
|
|
119
105
|
if 'MINL' in components:
|
|
120
106
|
min_level = float(component_pull(EWR_table, gauge, PU, EWR, 'LevelThresholdMin'))
|
|
121
|
-
|
|
122
|
-
ewrs['min_level'] = corrected
|
|
107
|
+
ewrs['min_level'] = min_level
|
|
123
108
|
if 'MAXL' in components:
|
|
124
109
|
max_level = float(component_pull(EWR_table, gauge, PU, EWR, 'LevelThresholdMax'))
|
|
125
|
-
|
|
126
|
-
ewrs['max_level'] = corrected
|
|
110
|
+
ewrs['max_level'] = max_level
|
|
127
111
|
if 'MINV' in components:
|
|
128
112
|
min_volume = int(component_pull(EWR_table, gauge, PU, EWR, 'VolumeThreshold'))
|
|
129
|
-
|
|
130
|
-
ewrs['min_volume'] = int(corrected)
|
|
113
|
+
ewrs['min_volume'] = int(min_volume)
|
|
131
114
|
if 'DUR' in components:
|
|
132
115
|
duration = int(component_pull(EWR_table, gauge, PU, EWR, 'Duration'))
|
|
133
|
-
|
|
134
|
-
ewrs['duration'] = int(corrected)
|
|
116
|
+
ewrs['duration'] = int(duration)
|
|
135
117
|
if 'GP' in components:
|
|
136
118
|
gap_tolerance = int(component_pull(EWR_table, gauge, PU, EWR, 'WithinEventGapTolerance'))
|
|
137
119
|
ewrs['gap_tolerance'] = gap_tolerance
|
|
@@ -140,44 +122,25 @@ def get_EWRs(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, allowance:
|
|
|
140
122
|
ewrs['events_per_year'] = events_per_year
|
|
141
123
|
if 'ME' in components:
|
|
142
124
|
min_event = int(component_pull(EWR_table, gauge, PU, EWR, 'MinSpell'))
|
|
143
|
-
|
|
144
|
-
corrected = apply_correction(min_event, allowance['duration'])
|
|
145
|
-
else:
|
|
146
|
-
corrected = min_event
|
|
147
|
-
ewrs['min_event'] = int(corrected)
|
|
125
|
+
ewrs['min_event'] = int(min_event)
|
|
148
126
|
if 'MD' in components:
|
|
149
127
|
max_drawdown = component_pull(EWR_table, gauge, PU, EWR, 'DrawdownRate')
|
|
150
128
|
if '%' in str(max_drawdown):
|
|
151
129
|
value_only = int(max_drawdown.replace('%', ''))
|
|
152
|
-
|
|
153
|
-
ewrs['drawdown_rate'] = str(int(corrected))+'%'
|
|
130
|
+
ewrs['drawdown_rate'] = str(int(value_only))+'%'
|
|
154
131
|
else:
|
|
155
|
-
|
|
156
|
-
ewrs['drawdown_rate'] = str(corrected)
|
|
157
|
-
# If drawdown is 0, this means it was not set in the parameter sheet and therefore should not be used
|
|
132
|
+
ewrs['drawdown_rate'] = str(float(max_drawdown)) #TODO check this works
|
|
158
133
|
if max_drawdown == 0:
|
|
159
134
|
# Large value set to ensure that drawdown check is always passed in this case
|
|
160
135
|
ewrs['drawdown_rate'] = int(1000000)
|
|
161
|
-
if 'DURVD' in components:
|
|
162
|
-
try: # There may not be a very dry duration available for this EWR
|
|
163
|
-
EWR_VD = str(EWR + '_VD')
|
|
164
|
-
duration_vd = int(component_pull(EWR_table, gauge, PU, EWR_VD, 'Duration'))
|
|
165
|
-
corrected = apply_correction(duration_vd, allowance['duration'])
|
|
166
|
-
ewrs['duration_VD'] =int(corrected)
|
|
167
|
-
except IndexError: # In this case return None type for this component
|
|
168
|
-
ewrs['duration_VD'] = None
|
|
169
136
|
if 'WPG' in components:
|
|
170
137
|
weirpool_gauge = component_pull(EWR_table, gauge, PU, EWR, 'WeirpoolGauge')
|
|
171
138
|
ewrs['weirpool_gauge'] =str(weirpool_gauge)
|
|
172
139
|
if 'MG' in components:
|
|
173
140
|
ewrs['second_gauge'] = get_second_multigauge(EWR_table, gauge, EWR, PU)
|
|
174
|
-
if 'SG' in components:
|
|
175
|
-
simultaneousGaugeDict = data_inputs.get_simultaneous_gauges('all')
|
|
176
|
-
ewrs['second_gauge'] = simultaneousGaugeDict[PU][gauge]
|
|
177
141
|
if 'TF' in components:
|
|
178
142
|
try:
|
|
179
143
|
ewrs['frequency'] = component_pull(EWR_table, gauge, PU, EWR, 'TargetFrequency')
|
|
180
|
-
|
|
181
144
|
except IndexError:
|
|
182
145
|
ewrs['frequency'] = None
|
|
183
146
|
if 'MIE' in components:
|
|
@@ -203,8 +166,7 @@ def get_EWRs(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, allowance:
|
|
|
203
166
|
if 'WDD' in components:
|
|
204
167
|
try: # The rate is represented in cm
|
|
205
168
|
drawdown_rate_week = component_pull(EWR_table, gauge, PU, EWR, 'DrawDownRateWeek')
|
|
206
|
-
|
|
207
|
-
ewrs['drawdown_rate_week'] = str(corrected/100)
|
|
169
|
+
ewrs['drawdown_rate_week'] = str(float(drawdown_rate_week)/100)#TODO check this works
|
|
208
170
|
except ValueError: # In this case set a large number
|
|
209
171
|
ewrs['drawdown_rate_week'] = int(1000000)
|
|
210
172
|
if 'ML' in components:
|
|
@@ -317,7 +279,6 @@ def is_weirpool_gauge(parameter_sheet: pd.DataFrame, gauge:float, ewr:str, pu:st
|
|
|
317
279
|
return False
|
|
318
280
|
if wp[0] == '':
|
|
319
281
|
return False
|
|
320
|
-
# return int(wp[0]) > 0 Removed above line as new multigauge sites were causing program to break.
|
|
321
282
|
else:
|
|
322
283
|
return True
|
|
323
284
|
|
|
@@ -492,7 +453,7 @@ def get_index_date(date_index:Any)-> datetime.date:
|
|
|
492
453
|
|
|
493
454
|
#----------------------------------- EWR handling functions --------------------------------------#
|
|
494
455
|
|
|
495
|
-
def ctf_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame
|
|
456
|
+
def ctf_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame) -> tuple:
|
|
496
457
|
'''For handling Cease to flow type EWRs
|
|
497
458
|
|
|
498
459
|
Args:
|
|
@@ -502,8 +463,6 @@ def ctf_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.
|
|
|
502
463
|
EWR_table (pd.DataFrame): EWR dataset
|
|
503
464
|
df_F (pd.DataFrame): Daily flow data
|
|
504
465
|
PU_df (pd.DataFrame): EWR results for the current planning unit iteration
|
|
505
|
-
allowance (dict): How much to scale EWR components by (0-1)
|
|
506
|
-
climate (str): name of the climate categorisation file to be used
|
|
507
466
|
|
|
508
467
|
Results:
|
|
509
468
|
tuple[pd.DataFrame, tuple[dict]]: EWR results for the current planning unit iteration (updated); dictionary of EWR event information
|
|
@@ -511,22 +470,20 @@ def ctf_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.
|
|
|
511
470
|
'''
|
|
512
471
|
# Get information about EWR:
|
|
513
472
|
pull = data_inputs.get_EWR_components('cease to flow')
|
|
514
|
-
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table,
|
|
473
|
+
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table, pull)
|
|
515
474
|
# Mask dates
|
|
516
475
|
masked_dates = mask_dates(EWR_info, df_F)
|
|
517
|
-
# Extract a daily timeseries for water years
|
|
476
|
+
# Extract a daily timeseries for water years
|
|
518
477
|
water_years = wateryear_daily(df_F, EWR_info)
|
|
519
|
-
catchment = data_inputs.gauge_to_catchment(gauge)
|
|
520
|
-
climates = data_inputs.wy_to_climate(water_years, catchment, climate)
|
|
521
478
|
# Check flow data against EWR requirements and then perform analysis on the results:
|
|
522
479
|
if ((EWR_info['start_month'] == 7) and (EWR_info['end_month'] == 6)):
|
|
523
|
-
E, D = ctf_calc_anytime(EWR_info, df_F[gauge].values, water_years,
|
|
480
|
+
E, D = ctf_calc_anytime(EWR_info, df_F[gauge].values, water_years, df_F.index)
|
|
524
481
|
else:
|
|
525
|
-
E, D = ctf_calc(EWR_info, df_F[gauge].values, water_years,
|
|
482
|
+
E, D = ctf_calc(EWR_info, df_F[gauge].values, water_years, df_F.index, masked_dates)
|
|
526
483
|
PU_df = event_stats(df_F, PU_df, gauge, EWR, EWR_info, E, D, water_years)
|
|
527
484
|
return PU_df, tuple([E])
|
|
528
485
|
|
|
529
|
-
def lowflow_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame
|
|
486
|
+
def lowflow_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame) -> tuple:
|
|
530
487
|
'''For handling low flow type EWRs (Very low flows and baseflows)
|
|
531
488
|
|
|
532
489
|
Args:
|
|
@@ -536,8 +493,6 @@ def lowflow_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F:
|
|
|
536
493
|
EWR_table (pd.DataFrame): EWR dataset
|
|
537
494
|
df_F (pd.DataFrame): Daily flow data
|
|
538
495
|
PU_df (pd.DataFrame): EWR results for the current planning unit iteration
|
|
539
|
-
allowance (dict): How much to scale EWR components by (0-1)
|
|
540
|
-
climate (str): name of the climate categorisation file to be used
|
|
541
496
|
|
|
542
497
|
Results:
|
|
543
498
|
tuple[pd.DataFrame, tuple[dict]]: EWR results for the current planning unit iteration (updated); dictionary of EWR event information
|
|
@@ -545,19 +500,17 @@ def lowflow_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F:
|
|
|
545
500
|
'''
|
|
546
501
|
# Get information about EWR:
|
|
547
502
|
pull = data_inputs.get_EWR_components('low flow')
|
|
548
|
-
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table,
|
|
503
|
+
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table, pull)
|
|
549
504
|
# Mask dates
|
|
550
505
|
masked_dates = mask_dates(EWR_info, df_F)
|
|
551
|
-
# Extract a daily timeseries for water years
|
|
506
|
+
# Extract a daily timeseries for water years
|
|
552
507
|
water_years = wateryear_daily(df_F, EWR_info)
|
|
553
|
-
catchment = data_inputs.gauge_to_catchment(gauge)
|
|
554
|
-
climates = data_inputs.wy_to_climate(water_years, catchment, climate)
|
|
555
508
|
# Check flow data against EWR requirements and then perform analysis on the results:
|
|
556
|
-
E, D = lowflow_calc(EWR_info, df_F[gauge].values, water_years,
|
|
509
|
+
E, D = lowflow_calc(EWR_info, df_F[gauge].values, water_years, df_F.index, masked_dates)
|
|
557
510
|
PU_df = event_stats(df_F, PU_df, gauge, EWR, EWR_info, E, D, water_years)
|
|
558
511
|
return PU_df, tuple([E])
|
|
559
512
|
|
|
560
|
-
def flow_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame
|
|
513
|
+
def flow_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame) -> tuple:
|
|
561
514
|
'''For handling non low flow based flow EWRs (freshes, bankfulls, overbanks)
|
|
562
515
|
|
|
563
516
|
Args:
|
|
@@ -567,7 +520,6 @@ def flow_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd
|
|
|
567
520
|
EWR_table (pd.DataFrame): EWR dataset
|
|
568
521
|
df_F (pd.DataFrame): Daily flow data
|
|
569
522
|
PU_df (pd.DataFrame): EWR results for the current planning unit iteration
|
|
570
|
-
allowance (dict): How much to scale EWR components by (0-1)
|
|
571
523
|
|
|
572
524
|
Results:
|
|
573
525
|
tuple[pd.DataFrame, tuple[dict]]: EWR results for the current planning unit iteration (updated); dictionary of EWR event information
|
|
@@ -575,7 +527,7 @@ def flow_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd
|
|
|
575
527
|
'''
|
|
576
528
|
# Get information about EWR:
|
|
577
529
|
pull = data_inputs.get_EWR_components('flow')
|
|
578
|
-
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table,
|
|
530
|
+
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table, pull)
|
|
579
531
|
# Mask dates
|
|
580
532
|
masked_dates = mask_dates(EWR_info, df_F)
|
|
581
533
|
# Extract a daily timeseries for water years
|
|
@@ -585,7 +537,7 @@ def flow_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd
|
|
|
585
537
|
PU_df = event_stats(df_F, PU_df, gauge, EWR, EWR_info, E, D, water_years)
|
|
586
538
|
return PU_df, tuple([E])
|
|
587
539
|
|
|
588
|
-
def flow_handle_anytime(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame
|
|
540
|
+
def flow_handle_anytime(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame) -> tuple:
|
|
589
541
|
'''For handling flow based flow EWRs (freshes, bankfulls, overbanks) to allow flows to continue to record
|
|
590
542
|
if it crosses water year boundaries.
|
|
591
543
|
|
|
@@ -596,7 +548,7 @@ def flow_handle_anytime(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame,
|
|
|
596
548
|
EWR_table (pd.DataFrame): EWR dataset
|
|
597
549
|
df_F (pd.DataFrame): Daily flow data
|
|
598
550
|
PU_df (pd.DataFrame): EWR results for the current planning unit iteration
|
|
599
|
-
|
|
551
|
+
|
|
600
552
|
|
|
601
553
|
Results:
|
|
602
554
|
tuple[pd.DataFrame, tuple[dict]]: EWR results for the current planning unit iteration (updated); dictionary of EWR event information
|
|
@@ -604,7 +556,7 @@ def flow_handle_anytime(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame,
|
|
|
604
556
|
'''
|
|
605
557
|
# Get information about EWR:
|
|
606
558
|
pull = data_inputs.get_EWR_components('flow')
|
|
607
|
-
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table,
|
|
559
|
+
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table, pull)
|
|
608
560
|
# # Mask dates
|
|
609
561
|
masked_dates = mask_dates(EWR_info, df_F)
|
|
610
562
|
# Extract a daily timeseries for water years
|
|
@@ -617,7 +569,7 @@ def flow_handle_anytime(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame,
|
|
|
617
569
|
PU_df = event_stats(df_F, PU_df, gauge, EWR, EWR_info, E, D, water_years)
|
|
618
570
|
return PU_df, tuple([E])
|
|
619
571
|
|
|
620
|
-
def flow_handle_check_ctf(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame
|
|
572
|
+
def flow_handle_check_ctf(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame) -> tuple:
|
|
621
573
|
'''For handling non low flow based flow EWRs
|
|
622
574
|
|
|
623
575
|
Args:
|
|
@@ -627,7 +579,6 @@ def flow_handle_check_ctf(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame
|
|
|
627
579
|
EWR_table (pd.DataFrame): EWR dataset
|
|
628
580
|
df_F (pd.DataFrame): Daily flow data
|
|
629
581
|
PU_df (pd.DataFrame): EWR results for the current planning unit iteration
|
|
630
|
-
allowance (dict): How much to scale EWR components by (0-1)
|
|
631
582
|
|
|
632
583
|
Results:
|
|
633
584
|
tuple[pd.DataFrame, tuple[dict]]: EWR results for the current planning unit iteration (updated); dictionary of EWR event information
|
|
@@ -635,7 +586,7 @@ def flow_handle_check_ctf(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame
|
|
|
635
586
|
'''
|
|
636
587
|
# Get information about EWR:
|
|
637
588
|
pull = data_inputs.get_EWR_components('flow-ctf')
|
|
638
|
-
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table,
|
|
589
|
+
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table, pull)
|
|
639
590
|
# Mask dates
|
|
640
591
|
masked_dates = mask_dates(EWR_info, df_F)
|
|
641
592
|
# Extract a daily timeseries for water years
|
|
@@ -645,7 +596,7 @@ def flow_handle_check_ctf(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame
|
|
|
645
596
|
PU_df = event_stats(df_F, PU_df, gauge, EWR, EWR_info, E, D, water_years)
|
|
646
597
|
return PU_df, tuple([E])
|
|
647
598
|
|
|
648
|
-
def cumulative_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame
|
|
599
|
+
def cumulative_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame):
|
|
649
600
|
'''For handling cumulative flow EWRs (some large freshes and overbanks, wetland flows).
|
|
650
601
|
|
|
651
602
|
Args:
|
|
@@ -655,7 +606,6 @@ def cumulative_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df
|
|
|
655
606
|
EWR_table (pd.DataFrame): EWR dataset
|
|
656
607
|
df_F (pd.DataFrame): Daily flow data
|
|
657
608
|
PU_df (pd.DataFrame): EWR results for the current planning unit iteration
|
|
658
|
-
allowance (dict): How much to scale EWR components by (0-1)
|
|
659
609
|
|
|
660
610
|
Results:
|
|
661
611
|
tuple[pd.DataFrame, tuple[dict]]: EWR results for the current planning unit iteration (updated); dictionary of EWR event information
|
|
@@ -663,7 +613,7 @@ def cumulative_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df
|
|
|
663
613
|
'''
|
|
664
614
|
# Get information about EWR:
|
|
665
615
|
pull = data_inputs.get_EWR_components('cumulative')
|
|
666
|
-
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table,
|
|
616
|
+
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table, pull)
|
|
667
617
|
# Mask dates:
|
|
668
618
|
masked_dates = mask_dates(EWR_info, df_F)
|
|
669
619
|
# Extract a daily timeseries for water years
|
|
@@ -673,7 +623,7 @@ def cumulative_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df
|
|
|
673
623
|
|
|
674
624
|
return PU_df, tuple([E])
|
|
675
625
|
|
|
676
|
-
def cumulative_handle_qld(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame
|
|
626
|
+
def cumulative_handle_qld(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame):
|
|
677
627
|
'''For handling cumulative flow EWRs this to meet QLD requirements for bird breeding type 2.
|
|
678
628
|
|
|
679
629
|
Args:
|
|
@@ -683,7 +633,6 @@ def cumulative_handle_qld(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame
|
|
|
683
633
|
EWR_table (pd.DataFrame): EWR dataset
|
|
684
634
|
df_F (pd.DataFrame): Daily flow data
|
|
685
635
|
PU_df (pd.DataFrame): EWR results for the current planning unit iteration
|
|
686
|
-
allowance (dict): How much to scale EWR components by (0-1)
|
|
687
636
|
|
|
688
637
|
Results:
|
|
689
638
|
tuple[pd.DataFrame, tuple[dict]]: EWR results for the current planning unit iteration (updated); dictionary of EWR event information
|
|
@@ -691,7 +640,7 @@ def cumulative_handle_qld(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame
|
|
|
691
640
|
'''
|
|
692
641
|
# Get information about EWR:
|
|
693
642
|
pull = data_inputs.get_EWR_components('cumulative')
|
|
694
|
-
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table,
|
|
643
|
+
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table, pull)
|
|
695
644
|
# Mask dates:
|
|
696
645
|
masked_dates = mask_dates(EWR_info, df_F)
|
|
697
646
|
# Extract a daily timeseries for water years
|
|
@@ -701,7 +650,7 @@ def cumulative_handle_qld(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame
|
|
|
701
650
|
|
|
702
651
|
return PU_df, tuple([E])
|
|
703
652
|
|
|
704
|
-
def cumulative_handle_bbr(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, df_L: pd.DataFrame, PU_df: pd.DataFrame
|
|
653
|
+
def cumulative_handle_bbr(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, df_L: pd.DataFrame, PU_df: pd.DataFrame):
|
|
705
654
|
'''For handling cumulative flow EWRs (for bird breeding ewr QLD).
|
|
706
655
|
|
|
707
656
|
Args:
|
|
@@ -712,7 +661,6 @@ def cumulative_handle_bbr(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame
|
|
|
712
661
|
df_F (pd.DataFrame): Daily flow data
|
|
713
662
|
df_L (pd.DataFrame): Daily water level data
|
|
714
663
|
PU_df (pd.DataFrame): EWR results for the current planning unit iteration
|
|
715
|
-
allowance (dict): How much to scale EWR components by (0-1)
|
|
716
664
|
|
|
717
665
|
Results:
|
|
718
666
|
tuple[pd.DataFrame, tuple[dict]]: EWR results for the current planning unit iteration (updated); dictionary of EWR event information
|
|
@@ -720,7 +668,7 @@ def cumulative_handle_bbr(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame
|
|
|
720
668
|
'''
|
|
721
669
|
# Get information about EWR:
|
|
722
670
|
pull = data_inputs.get_EWR_components('cumulative_bbr')
|
|
723
|
-
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table,
|
|
671
|
+
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table, pull)
|
|
724
672
|
# Mask dates:
|
|
725
673
|
masked_dates = mask_dates(EWR_info, df_F)
|
|
726
674
|
# If there is no level data loaded in, let user know and skip the analysis
|
|
@@ -738,7 +686,7 @@ def cumulative_handle_bbr(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame
|
|
|
738
686
|
return PU_df, tuple([E])
|
|
739
687
|
|
|
740
688
|
def water_stability_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, df_L: pd.DataFrame,
|
|
741
|
-
PU_df: pd.DataFrame
|
|
689
|
+
PU_df: pd.DataFrame):
|
|
742
690
|
'''For handling Fish Recruitment with water stability requirement (QLD).
|
|
743
691
|
|
|
744
692
|
Args:
|
|
@@ -749,7 +697,6 @@ def water_stability_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFram
|
|
|
749
697
|
df_F (pd.DataFrame): Daily flow data
|
|
750
698
|
df_L (pd.DataFrame): Daily water level data
|
|
751
699
|
PU_df (pd.DataFrame): EWR results for the current planning unit iteration
|
|
752
|
-
allowance (dict): How much to scale EWR components by (0-1)
|
|
753
700
|
|
|
754
701
|
Results:
|
|
755
702
|
tuple[pd.DataFrame, tuple[dict]]: EWR results for the current planning unit iteration (updated); dictionary of EWR event information
|
|
@@ -757,7 +704,7 @@ def water_stability_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFram
|
|
|
757
704
|
'''
|
|
758
705
|
# Get information about EWR:
|
|
759
706
|
pull = data_inputs.get_EWR_components('water_stability')
|
|
760
|
-
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table,
|
|
707
|
+
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table, pull)
|
|
761
708
|
# Mask dates:
|
|
762
709
|
masked_dates = mask_dates(EWR_info, df_F)
|
|
763
710
|
# If there is no level data loaded in, let user know and skip the analysis
|
|
@@ -774,7 +721,7 @@ def water_stability_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFram
|
|
|
774
721
|
|
|
775
722
|
return PU_df, tuple([E])
|
|
776
723
|
|
|
777
|
-
def water_stability_level_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_L: pd.DataFrame, PU_df: pd.DataFrame
|
|
724
|
+
def water_stability_level_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_L: pd.DataFrame, PU_df: pd.DataFrame):
|
|
778
725
|
'''For handling Fish Recruitment with water stability requirement (QLD).
|
|
779
726
|
|
|
780
727
|
Args:
|
|
@@ -785,7 +732,6 @@ def water_stability_level_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.Da
|
|
|
785
732
|
df_F (pd.DataFrame): Daily flow data
|
|
786
733
|
df_L (pd.DataFrame): Daily water level data
|
|
787
734
|
PU_df (pd.DataFrame): EWR results for the current planning unit iteration
|
|
788
|
-
allowance (dict): How much to scale EWR components by (0-1)
|
|
789
735
|
|
|
790
736
|
Results:
|
|
791
737
|
tuple[pd.DataFrame, tuple[dict]]: EWR results for the current planning unit iteration (updated); dictionary of EWR event information
|
|
@@ -793,7 +739,7 @@ def water_stability_level_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.Da
|
|
|
793
739
|
'''
|
|
794
740
|
# Get information about EWR:
|
|
795
741
|
pull = data_inputs.get_EWR_components('water_stability_level')
|
|
796
|
-
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table,
|
|
742
|
+
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table, pull)
|
|
797
743
|
# Mask dates:
|
|
798
744
|
masked_dates = mask_dates(EWR_info, df_L)
|
|
799
745
|
# If there is no level data loaded in, let user know and skip the analysis
|
|
@@ -810,7 +756,7 @@ def water_stability_level_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.Da
|
|
|
810
756
|
|
|
811
757
|
return PU_df, tuple([E])
|
|
812
758
|
|
|
813
|
-
def level_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_L: pd.DataFrame, PU_df: pd.DataFrame
|
|
759
|
+
def level_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_L: pd.DataFrame, PU_df: pd.DataFrame) -> tuple:
|
|
814
760
|
'''For handling level type EWRs (low, mid, high and very high level lake fills).
|
|
815
761
|
|
|
816
762
|
Args:
|
|
@@ -820,7 +766,6 @@ def level_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_L: p
|
|
|
820
766
|
EWR_table (pd.DataFrame): EWR dataset
|
|
821
767
|
df_L (pd.DataFrame): Daily water level data
|
|
822
768
|
PU_df (pd.DataFrame): EWR results for the current planning unit iteration
|
|
823
|
-
allowance (dict): How much to scale EWR components by (0-1)
|
|
824
769
|
|
|
825
770
|
Results:
|
|
826
771
|
tuple[pd.DataFrame, tuple[dict]]: EWR results for the current planning unit iteration (updated); dictionary of EWR event information
|
|
@@ -828,7 +773,7 @@ def level_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_L: p
|
|
|
828
773
|
'''
|
|
829
774
|
# Get information about EWR:
|
|
830
775
|
pull = data_inputs.get_EWR_components('level')
|
|
831
|
-
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table,
|
|
776
|
+
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table, pull)
|
|
832
777
|
# Mask dates:
|
|
833
778
|
masked_dates = mask_dates(EWR_info, df_L)
|
|
834
779
|
# Extract a daily timeseries for water years
|
|
@@ -839,7 +784,7 @@ def level_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_L: p
|
|
|
839
784
|
PU_df = event_stats(df_L, PU_df, gauge, EWR, EWR_info, E, D, water_years)
|
|
840
785
|
return PU_df, tuple([E])
|
|
841
786
|
|
|
842
|
-
def level_change_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_L: pd.DataFrame, PU_df: pd.DataFrame
|
|
787
|
+
def level_change_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_L: pd.DataFrame, PU_df: pd.DataFrame) -> tuple:
|
|
843
788
|
'''For handling level type EWRs (low, mid, high and very high level lake fills).
|
|
844
789
|
|
|
845
790
|
Args:
|
|
@@ -849,7 +794,6 @@ def level_change_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame,
|
|
|
849
794
|
EWR_table (pd.DataFrame): EWR dataset
|
|
850
795
|
df_L (pd.DataFrame): Daily water level data
|
|
851
796
|
PU_df (pd.DataFrame): EWR results for the current planning unit iteration
|
|
852
|
-
allowance (dict): How much to scale EWR components by (0-1)
|
|
853
797
|
|
|
854
798
|
Results:
|
|
855
799
|
tuple[pd.DataFrame, tuple[dict]]: EWR results for the current planning unit iteration (updated); dictionary of EWR event information
|
|
@@ -857,7 +801,7 @@ def level_change_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame,
|
|
|
857
801
|
'''
|
|
858
802
|
# Get information about EWR:
|
|
859
803
|
pull = data_inputs.get_EWR_components('level')
|
|
860
|
-
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table,
|
|
804
|
+
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table, pull)
|
|
861
805
|
# Mask dates:
|
|
862
806
|
masked_dates = mask_dates(EWR_info, df_L)
|
|
863
807
|
# Extract a daily timeseries for water years
|
|
@@ -868,7 +812,7 @@ def level_change_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame,
|
|
|
868
812
|
PU_df = event_stats(df_L, PU_df, gauge, EWR, EWR_info, E, D, water_years)
|
|
869
813
|
return PU_df, tuple([E])
|
|
870
814
|
|
|
871
|
-
def weirpool_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, df_L: pd.DataFrame, PU_df: pd.DataFrame
|
|
815
|
+
def weirpool_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, df_L: pd.DataFrame, PU_df: pd.DataFrame) -> tuple:
|
|
872
816
|
'''For handling weirpool type EWRs.
|
|
873
817
|
|
|
874
818
|
Args:
|
|
@@ -879,7 +823,6 @@ def weirpool_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F
|
|
|
879
823
|
df_F (pd.DataFrame): Daily flow data
|
|
880
824
|
df_L (pd.DataFrame): Daily water level data
|
|
881
825
|
PU_df (pd.DataFrame): EWR results for the current planning unit iteration
|
|
882
|
-
allowance (dict): How much to scale EWR components by (0-1)
|
|
883
826
|
|
|
884
827
|
Results:
|
|
885
828
|
tuple[pd.DataFrame, tuple[dict]]: EWR results for the current planning unit iteration (updated); dictionary of EWR event information
|
|
@@ -891,7 +834,7 @@ def weirpool_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F
|
|
|
891
834
|
pull = data_inputs.get_EWR_components('weirpool-raising')
|
|
892
835
|
elif weirpool_type == 'falling':
|
|
893
836
|
pull = data_inputs.get_EWR_components('weirpool-falling')
|
|
894
|
-
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table,
|
|
837
|
+
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table, pull)
|
|
895
838
|
# Mask dates for both the flow and level dataframes:
|
|
896
839
|
masked_dates = mask_dates(EWR_info, df_F)
|
|
897
840
|
# Extract a daily timeseries for water years:
|
|
@@ -908,7 +851,7 @@ def weirpool_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F
|
|
|
908
851
|
PU_df = event_stats(df_F, PU_df, gauge, EWR, EWR_info, E, D, water_years)
|
|
909
852
|
return PU_df, tuple([E])
|
|
910
853
|
|
|
911
|
-
def nest_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, df_L: pd.DataFrame, PU_df: pd.DataFrame
|
|
854
|
+
def nest_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, df_L: pd.DataFrame, PU_df: pd.DataFrame) -> tuple:
|
|
912
855
|
'''For handling nest style EWRs.
|
|
913
856
|
|
|
914
857
|
Args:
|
|
@@ -919,7 +862,6 @@ def nest_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd
|
|
|
919
862
|
df_F (pd.DataFrame): Daily flow data
|
|
920
863
|
df_L (pd.DataFrame): Daily water level data
|
|
921
864
|
PU_df (pd.DataFrame): EWR results for the current planning unit iteration
|
|
922
|
-
allowance (dict): How much to scale EWR components by (0-1)
|
|
923
865
|
|
|
924
866
|
Results:
|
|
925
867
|
tuple[pd.DataFrame, tuple[dict]]: EWR results for the current planning unit iteration (updated); dictionary of EWR event information
|
|
@@ -931,7 +873,7 @@ def nest_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd
|
|
|
931
873
|
pull = data_inputs.get_EWR_components('nest-level')
|
|
932
874
|
else:
|
|
933
875
|
pull = data_inputs.get_EWR_components('nest-percent')
|
|
934
|
-
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table,
|
|
876
|
+
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table, pull)
|
|
935
877
|
masked_dates = mask_dates(EWR_info, df_F)
|
|
936
878
|
# Extract a daily timeseries for water years:
|
|
937
879
|
water_years = wateryear_daily(df_F, EWR_info)
|
|
@@ -964,7 +906,7 @@ def nest_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd
|
|
|
964
906
|
PU_df = event_stats(df_F, PU_df, gauge, EWR, EWR_info, E, D, water_years)
|
|
965
907
|
return PU_df, tuple([E])
|
|
966
908
|
|
|
967
|
-
def flow_handle_multi(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame
|
|
909
|
+
def flow_handle_multi(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame) -> tuple:
|
|
968
910
|
'''For handling flow EWRs where flow needs to be combined at two gauges
|
|
969
911
|
|
|
970
912
|
Args:
|
|
@@ -974,7 +916,6 @@ def flow_handle_multi(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df
|
|
|
974
916
|
EWR_table (pd.DataFrame): EWR dataset
|
|
975
917
|
df_F (pd.DataFrame): Daily flow data
|
|
976
918
|
PU_df (pd.DataFrame): EWR results for the current planning unit iteration
|
|
977
|
-
allowance (dict): How much to scale EWR components by (0-1)
|
|
978
919
|
|
|
979
920
|
Results:
|
|
980
921
|
tuple[pd.DataFrame, tuple[dict]]: EWR results for the current planning unit iteration (updated); dictionary of EWR event information
|
|
@@ -982,7 +923,7 @@ def flow_handle_multi(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df
|
|
|
982
923
|
'''
|
|
983
924
|
# Get information about the EWR:
|
|
984
925
|
pull = data_inputs.get_EWR_components('multi-gauge-flow')
|
|
985
|
-
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table,
|
|
926
|
+
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table, pull)
|
|
986
927
|
# Mask the dates:
|
|
987
928
|
masked_dates = mask_dates(EWR_info, df_F)
|
|
988
929
|
# Extract a daily timeseries for water years:
|
|
@@ -993,15 +934,17 @@ def flow_handle_multi(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df
|
|
|
993
934
|
flows2 = df_F[EWR_info['second_gauge']].values
|
|
994
935
|
flows = flows1 + flows2
|
|
995
936
|
except KeyError:
|
|
996
|
-
print('''
|
|
997
|
-
|
|
998
|
-
|
|
937
|
+
print(f'''This {EWR} at the gauge {gauge} sums the flows at two gauges ({gauge} and {EWR_info['second_gauge']}.
|
|
938
|
+
The EWR tool has not been able to find the flow data for {EWR_info["second_gauge"]} so it will only evaluate EWRs against the
|
|
939
|
+
flow at the gauge {gauge}. If you are running a model scenario through please disregard this message - most hydrology models have already
|
|
940
|
+
summed flows at these two gauges.''')
|
|
941
|
+
flows = flows1
|
|
999
942
|
|
|
1000
943
|
E, D = flow_calc(EWR_info, flows, water_years, df_F.index, masked_dates)
|
|
1001
944
|
PU_df = event_stats(df_F, PU_df, gauge, EWR, EWR_info, E, D, water_years)
|
|
1002
945
|
return PU_df, tuple([E])
|
|
1003
946
|
|
|
1004
|
-
def lowflow_handle_multi(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame
|
|
947
|
+
def lowflow_handle_multi(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame) -> tuple:
|
|
1005
948
|
'''For handling low flow EWRs where flow needs to be combined at two gauges.
|
|
1006
949
|
|
|
1007
950
|
Args:
|
|
@@ -1011,8 +954,6 @@ def lowflow_handle_multi(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame,
|
|
|
1011
954
|
EWR_table (pd.DataFrame): EWR dataset
|
|
1012
955
|
df_F (pd.DataFrame): Daily flow data
|
|
1013
956
|
PU_df (pd.DataFrame): EWR results for the current planning unit iteration
|
|
1014
|
-
allowance (dict): How much to scale EWR components by (0-1)
|
|
1015
|
-
climate (str): name of the climate categorisation file to be used
|
|
1016
957
|
|
|
1017
958
|
Results:
|
|
1018
959
|
tuple[pd.DataFrame, tuple[dict]]: EWR results for the current planning unit iteration (updated); dictionary of EWR event information
|
|
@@ -1020,28 +961,28 @@ def lowflow_handle_multi(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame,
|
|
|
1020
961
|
'''
|
|
1021
962
|
# Get information about the EWR:
|
|
1022
963
|
pull = data_inputs.get_EWR_components('multi-gauge-low flow')
|
|
1023
|
-
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table,
|
|
964
|
+
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table, pull)
|
|
1024
965
|
# Mask dates:
|
|
1025
966
|
masked_dates = mask_dates(EWR_info, df_F)
|
|
1026
|
-
# Extract a daily timeseries for water years
|
|
967
|
+
# Extract a daily timeseries for water years
|
|
1027
968
|
water_years = wateryear_daily(df_F, EWR_info)
|
|
1028
|
-
catchment = data_inputs.gauge_to_catchment(gauge)
|
|
1029
|
-
climates = data_inputs.wy_to_climate(water_years, catchment, climate)
|
|
1030
969
|
# Save flows for the two gauges to vars. If there is no flow data for the second, dont analyse:
|
|
1031
970
|
flows1 = df_F[gauge].values
|
|
1032
971
|
try:
|
|
1033
972
|
flows2 = df_F[EWR_info['second_gauge']].values
|
|
1034
973
|
flows = flows1 + flows2
|
|
1035
974
|
except KeyError:
|
|
1036
|
-
print('''
|
|
1037
|
-
|
|
1038
|
-
|
|
975
|
+
print(f'''This {EWR} at the gauge {gauge} sums the flows at two gauges ({gauge} and {EWR_info['second_gauge']}.
|
|
976
|
+
The EWR tool has not been able to find the flow data for {EWR_info["second_gauge"]} so it will only evaluate EWRs against the
|
|
977
|
+
flow at the gauge {gauge}. If you are running a model scenario through please disregard this message - most hydrology models have already
|
|
978
|
+
summed flows at these two gauges.''')
|
|
979
|
+
flows = flows1
|
|
1039
980
|
# Check flow data against EWR requirements and then perform analysis on the results:
|
|
1040
|
-
E, D = lowflow_calc(EWR_info, flows, water_years,
|
|
981
|
+
E, D = lowflow_calc(EWR_info, flows, water_years, df_F.index, masked_dates)
|
|
1041
982
|
PU_df = event_stats(df_F, PU_df, gauge, EWR, EWR_info, E, D, water_years)
|
|
1042
983
|
return PU_df, tuple([E])
|
|
1043
984
|
|
|
1044
|
-
def ctf_handle_multi(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame
|
|
985
|
+
def ctf_handle_multi(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame) -> tuple:
|
|
1045
986
|
'''For handling cease to flow EWRs where flow needs to be combined at two gauges
|
|
1046
987
|
|
|
1047
988
|
Args:
|
|
@@ -1051,8 +992,6 @@ def ctf_handle_multi(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_
|
|
|
1051
992
|
EWR_table (pd.DataFrame): EWR dataset
|
|
1052
993
|
df_F (pd.DataFrame): Daily flow data
|
|
1053
994
|
PU_df (pd.DataFrame): EWR results for the current planning unit iteration
|
|
1054
|
-
allowance (dict): How much to scale EWR components by (0-1)
|
|
1055
|
-
climate (str): name of the climate categorisation file to be used
|
|
1056
995
|
|
|
1057
996
|
Results:
|
|
1058
997
|
tuple[pd.DataFrame, tuple[dict]]: EWR results for the current planning unit iteration (updated); dictionary of EWR event information
|
|
@@ -1060,31 +999,31 @@ def ctf_handle_multi(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_
|
|
|
1060
999
|
'''
|
|
1061
1000
|
# Get information about the EWR:
|
|
1062
1001
|
pull = data_inputs.get_EWR_components('multi-gauge-cease to flow')
|
|
1063
|
-
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table,
|
|
1002
|
+
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table, pull)
|
|
1064
1003
|
# Mask dates:
|
|
1065
1004
|
masked_dates = mask_dates(EWR_info, df_F)
|
|
1066
|
-
# Extract a daily timeseries for water years
|
|
1005
|
+
# Extract a daily timeseries for water years
|
|
1067
1006
|
water_years = wateryear_daily(df_F, EWR_info)
|
|
1068
|
-
catchment = data_inputs.gauge_to_catchment(gauge)
|
|
1069
|
-
climates = data_inputs.wy_to_climate(water_years, catchment, climate)
|
|
1070
1007
|
# Save flows for the two gauges to vars. If there is no flow data for the second, dont analyse:
|
|
1071
1008
|
flows1 = df_F[gauge].values
|
|
1072
1009
|
try:
|
|
1073
1010
|
flows2 = df_F[EWR_info['second_gauge']].values
|
|
1074
1011
|
flows = flows1 + flows2
|
|
1075
1012
|
except KeyError:
|
|
1076
|
-
print('''
|
|
1077
|
-
|
|
1078
|
-
|
|
1013
|
+
print(f'''This {EWR} at the gauge {gauge} sums the flows at two gauges ({gauge} and {EWR_info['second_gauge']}.
|
|
1014
|
+
The EWR tool has not been able to find the flow data for {EWR_info["second_gauge"]} so it will only evaluate EWRs against the
|
|
1015
|
+
flow at the gauge {gauge}. If you are running a model scenario through please disregard this message - most hydrology models have already
|
|
1016
|
+
summed flows at these two gauges.''')
|
|
1017
|
+
flows = flows1
|
|
1079
1018
|
# Check flow data against EWR requirements and then perform analysis on the results:
|
|
1080
1019
|
if ((EWR_info['start_month'] == 7) and (EWR_info['end_month'] == 6)):
|
|
1081
|
-
E, D = ctf_calc_anytime(EWR_info, df_F[gauge].values, water_years,
|
|
1020
|
+
E, D = ctf_calc_anytime(EWR_info, df_F[gauge].values, water_years, df_F.index)
|
|
1082
1021
|
else:
|
|
1083
|
-
E, D = ctf_calc(EWR_info, df_F[gauge].values, water_years,
|
|
1022
|
+
E, D = ctf_calc(EWR_info, df_F[gauge].values, water_years, df_F.index, masked_dates)
|
|
1084
1023
|
PU_df = event_stats(df_F, PU_df, gauge, EWR, EWR_info, E, D, water_years)
|
|
1085
1024
|
return PU_df, tuple([E])
|
|
1086
1025
|
|
|
1087
|
-
def cumulative_handle_multi(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame
|
|
1026
|
+
def cumulative_handle_multi(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame) -> tuple:
|
|
1088
1027
|
'''For handling cumulative volume EWRs where flow needs to be combined at two gauges.
|
|
1089
1028
|
|
|
1090
1029
|
Args:
|
|
@@ -1094,7 +1033,6 @@ def cumulative_handle_multi(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFra
|
|
|
1094
1033
|
EWR_table (pd.DataFrame): EWR dataset
|
|
1095
1034
|
df_F (pd.DataFrame): Daily flow data
|
|
1096
1035
|
PU_df (pd.DataFrame): EWR results for the current planning unit iteration
|
|
1097
|
-
allowance (dict): How much to scale EWR components by (0-1)
|
|
1098
1036
|
|
|
1099
1037
|
Results:
|
|
1100
1038
|
tuple[pd.DataFrame, tuple[dict]]: EWR results for the current planning unit iteration (updated); dictionary of EWR event information
|
|
@@ -1102,7 +1040,7 @@ def cumulative_handle_multi(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFra
|
|
|
1102
1040
|
'''
|
|
1103
1041
|
# Get information about the EWR:
|
|
1104
1042
|
pull = data_inputs.get_EWR_components('multi-gauge-cumulative')
|
|
1105
|
-
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table,
|
|
1043
|
+
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table, pull)
|
|
1106
1044
|
# Mask dates:
|
|
1107
1045
|
masked_dates = mask_dates(EWR_info, df_F)
|
|
1108
1046
|
# Extract a daily timeseries for water years
|
|
@@ -1113,179 +1051,17 @@ def cumulative_handle_multi(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFra
|
|
|
1113
1051
|
flows2 = df_F[EWR_info['second_gauge']].values
|
|
1114
1052
|
flows = flows1 + flows2
|
|
1115
1053
|
except KeyError:
|
|
1116
|
-
print('''
|
|
1117
|
-
|
|
1118
|
-
|
|
1054
|
+
print(f'''This {EWR} at the gauge {gauge} sums the flows at two gauges ({gauge} and {EWR_info['second_gauge']}.
|
|
1055
|
+
The EWR tool has not been able to find the flow data for {EWR_info["second_gauge"]} so it will only evaluate EWRs against the
|
|
1056
|
+
flow at the gauge {gauge}. If you are running a model scenario through please disregard this message - most hydrology models have already
|
|
1057
|
+
summed flows at these two gauges.''')
|
|
1058
|
+
flows = flows1
|
|
1119
1059
|
E, D = cumulative_calc(EWR_info, flows, water_years, df_F.index, masked_dates)
|
|
1120
1060
|
PU_df = event_stats(df_F, PU_df, gauge, EWR, EWR_info, E, D, water_years)
|
|
1121
1061
|
return PU_df, tuple([E])
|
|
1122
1062
|
|
|
1123
|
-
def flow_handle_sim(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame, allowance: dict):
|
|
1124
|
-
'''For handling flow EWRs that need to be met simultaneously with other sites
|
|
1125
|
-
|
|
1126
|
-
Args:
|
|
1127
|
-
PU (str): Planning unit ID
|
|
1128
|
-
gauge (str): Gauge number
|
|
1129
|
-
EWR (str): EWR code
|
|
1130
|
-
EWR_table (pd.DataFrame): EWR dataset
|
|
1131
|
-
df_F (pd.DataFrame): Daily flow data
|
|
1132
|
-
PU_df (pd.DataFrame): EWR results for the current planning unit iteration
|
|
1133
|
-
allowance (dict): How much to scale EWR components by (0-1)
|
|
1134
|
-
|
|
1135
|
-
Results:
|
|
1136
|
-
tuple[pd.DataFrame, tuple[dict]]: EWR results for the current planning unit iteration (updated); dictionary of EWR event information
|
|
1137
|
-
|
|
1138
|
-
'''
|
|
1139
|
-
# Get information about the EWR for the main EWR:
|
|
1140
|
-
pull = data_inputs.get_EWR_components('simul-gauge-flow')
|
|
1141
|
-
EWR_info1 = get_EWRs(PU, gauge, EWR, EWR_table, allowance, pull)
|
|
1142
|
-
# Mask dates:
|
|
1143
|
-
masked_dates = mask_dates(EWR_info1, df_F)
|
|
1144
|
-
# Extract a daily timeseries for water years
|
|
1145
|
-
water_years = wateryear_daily(df_F, EWR_info1)
|
|
1146
|
-
# Get information about the EWR for the secondary EWR:
|
|
1147
|
-
EWR_info2 = get_EWRs(PU, EWR_info1['second_gauge'], EWR, EWR_table, allowance, pull)
|
|
1148
|
-
# Save flows for the two gauges to vars. If there is no flow data for the second, dont analyse:
|
|
1149
|
-
flows1 = df_F[gauge].values
|
|
1150
|
-
try:
|
|
1151
|
-
flows2 = df_F[EWR_info1['second_gauge']].values
|
|
1152
|
-
except KeyError:
|
|
1153
|
-
print('''Cannot evaluate this ewr for {} {}, due to missing data.
|
|
1154
|
-
Specifically, this EWR also needs data for gauge'''.format(gauge, EWR))
|
|
1155
|
-
return PU_df, None
|
|
1156
|
-
|
|
1157
|
-
E, D = flow_calc_sim(EWR_info1, EWR_info2, flows1, flows2, water_years, df_F.index, masked_dates)
|
|
1158
|
-
PU_df = event_stats(df_F, PU_df, gauge, EWR, EWR_info1, E, D, water_years)
|
|
1159
|
-
return PU_df, tuple([E])
|
|
1160
|
-
|
|
1161
|
-
def lowflow_handle_sim(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame, allowance: dict, climate: str) -> tuple:
|
|
1162
|
-
'''For handling lowflow EWRs that need to be met simultaneously with other sites
|
|
1163
|
-
|
|
1164
|
-
Args:
|
|
1165
|
-
PU (str): Planning unit ID
|
|
1166
|
-
gauge (str): Gauge number
|
|
1167
|
-
EWR (str): EWR code
|
|
1168
|
-
EWR_table (pd.DataFrame): EWR dataset
|
|
1169
|
-
df_F (pd.DataFrame): Daily flow data
|
|
1170
|
-
PU_df (pd.DataFrame): EWR results for the current planning unit iteration
|
|
1171
|
-
allowance (dict): How much to scale EWR components by (0-1)
|
|
1172
|
-
climate (str): name of the climate categorisation file to be used
|
|
1173
|
-
|
|
1174
|
-
Results:
|
|
1175
|
-
tuple[pd.DataFrame, tuple[dict]]: EWR results for the current planning unit iteration (updated); dictionary of EWR event information
|
|
1176
|
-
|
|
1177
|
-
'''
|
|
1178
|
-
# Get information about the EWR for the main EWR:
|
|
1179
|
-
pull = data_inputs.get_EWR_components('simul-gauge-low flow')
|
|
1180
|
-
EWR_info1 = get_EWRs(PU, gauge, EWR, EWR_table, allowance, pull)
|
|
1181
|
-
# Mask dates
|
|
1182
|
-
masked_dates = mask_dates(EWR_info1, df_F)
|
|
1183
|
-
# Extract a daily timeseries for water years and climates for the catchment
|
|
1184
|
-
water_years = wateryear_daily(df_F, EWR_info1)
|
|
1185
|
-
catchment = data_inputs.gauge_to_catchment(gauge)
|
|
1186
|
-
climates = data_inputs.wy_to_climate(water_years, catchment, climate)
|
|
1187
|
-
# Get information about the EWR for the secondary EWR:
|
|
1188
|
-
EWR_info2 = get_EWRs(PU, EWR_info1['second_gauge'], EWR, EWR_table, allowance, pull)
|
|
1189
|
-
# Save flows for the two gauges to vars. If there is no flow data for the second, dont analyse:
|
|
1190
|
-
flows1 = df_F[gauge].values
|
|
1191
|
-
try:
|
|
1192
|
-
flows2 = df_F[EWR_info1['second_gauge']].values
|
|
1193
|
-
except KeyError:
|
|
1194
|
-
print('''Cannot evaluate this ewr for {} {}, due to missing data.
|
|
1195
|
-
Specifically, this EWR also needs data for {}'''.format(gauge, EWR, EWR_info1['second_gauge']))
|
|
1196
|
-
return PU_df, None
|
|
1197
|
-
# Check flow data against EWR requirements and then perform analysis on the results:
|
|
1198
|
-
E1, E2, D = lowflow_calc_sim(EWR_info1, EWR_info2, flows1, flows2, water_years, climates, df_F.index, masked_dates)
|
|
1199
|
-
PU_df = event_stats_sim(df_F, PU_df, gauge, EWR, EWR_info1, E1, E2, D, water_years)
|
|
1200
|
-
return PU_df, tuple([E1, E2])
|
|
1201
|
-
|
|
1202
|
-
def ctf_handle_sim(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame, allowance: dict, climate: str) -> tuple:
|
|
1203
|
-
'''For handling cease to flow EWRs that need to be met simultaneously with other sites
|
|
1204
|
-
|
|
1205
|
-
Args:
|
|
1206
|
-
PU (str): Planning unit ID
|
|
1207
|
-
gauge (str): Gauge number
|
|
1208
|
-
EWR (str): EWR code
|
|
1209
|
-
EWR_table (pd.DataFrame): EWR dataset
|
|
1210
|
-
df_F (pd.DataFrame): Daily flow data
|
|
1211
|
-
PU_df (pd.DataFrame): EWR results for the current planning unit iteration
|
|
1212
|
-
allowance (dict): How much to scale EWR components by (0-1)
|
|
1213
|
-
climate (str): name of the climate categorisation file to be used
|
|
1214
|
-
|
|
1215
|
-
Results:
|
|
1216
|
-
tuple[pd.DataFrame, tuple[dict, dict]]: EWR results for the current planning unit iteration (updated); [dictionary of EWR event information site 1; dictionary of EWR event information site 2]
|
|
1217
|
-
|
|
1218
|
-
'''
|
|
1219
|
-
# Get information about the EWR for the main EWR:
|
|
1220
|
-
pull = data_inputs.get_EWR_components('simul-gauge-cease to flow')
|
|
1221
|
-
EWR_info1 = get_EWRs(PU, gauge, EWR, EWR_table, allowance, pull)
|
|
1222
|
-
# Mask dates
|
|
1223
|
-
masked_dates = mask_dates(EWR_info1, df_F)
|
|
1224
|
-
# Extract a daily timeseries for water years and climates for the catchment
|
|
1225
|
-
water_years = wateryear_daily(df_F, EWR_info1)
|
|
1226
|
-
catchment = data_inputs.gauge_to_catchment(gauge)
|
|
1227
|
-
climates = data_inputs.wy_to_climate(water_years, catchment, climate)
|
|
1228
|
-
# Get information about the EWR for the secondary EWR:
|
|
1229
|
-
EWR_info2 = get_EWRs(PU, EWR_info1['second_gauge'], EWR, EWR_table, allowance, pull)
|
|
1230
|
-
# Save flows for the two gauges to vars. If there is no flow data for the second, dont analyse:
|
|
1231
|
-
flows1 = df_F[gauge].values
|
|
1232
|
-
try:
|
|
1233
|
-
flows2 = df_F[EWR_info1['second_gauge']].values
|
|
1234
|
-
except KeyError:
|
|
1235
|
-
print('''Cannot evaluate this ewr for {} {}, due to missing data.
|
|
1236
|
-
Specifically, this EWR also needs data for {}'''.format(gauge, EWR, EWR_info1['second_gauge']))
|
|
1237
|
-
return PU_df, None
|
|
1238
|
-
# Check flow data against EWR requirements and then perform analysis on the results:
|
|
1239
|
-
E1, E2, D = ctf_calc_sim(EWR_info1, EWR_info2, flows1, flows2, water_years, climates, df_F.index, masked_dates)
|
|
1240
|
-
PU_df = event_stats_sim(df_F, PU_df, gauge, EWR, EWR_info1, E1, E2, D, water_years)
|
|
1241
|
-
|
|
1242
|
-
return PU_df, tuple([E1, E2])
|
|
1243
|
-
|
|
1244
|
-
def complex_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame, allowance: dict):
|
|
1245
|
-
'''Handling complex EWRs (complex EWRs are hard coded into the tool)
|
|
1246
|
-
|
|
1247
|
-
Args:
|
|
1248
|
-
PU (str): Planning unit ID
|
|
1249
|
-
gauge (str): Gauge number
|
|
1250
|
-
EWR (str): EWR code
|
|
1251
|
-
EWR_table (pd.DataFrame): EWR dataset
|
|
1252
|
-
df_F (pd.DataFrame): Daily flow data
|
|
1253
|
-
PU_df (pd.DataFrame): EWR results for the current planning unit iteration
|
|
1254
|
-
allowance (dict): How much to scale EWR components by (0-1)
|
|
1255
|
-
|
|
1256
|
-
Results:
|
|
1257
|
-
tuple[pd.DataFrame, tuple[dict]]: EWR results for the current planning unit iteration (updated); [dictionary of EWR event information]
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
'''
|
|
1261
|
-
# Get information about the EWR:
|
|
1262
|
-
pull = data_inputs.get_EWR_components('complex')
|
|
1263
|
-
EWR_info1 = get_EWRs(PU, gauge, EWR, EWR_table, allowance, pull)
|
|
1264
|
-
# Instead of pulling the other complex information, pull the second part and save it to a new EWR_info variable:
|
|
1265
|
-
if 'a' in EWR:
|
|
1266
|
-
EWR2 = EWR.replace('a', 'b')
|
|
1267
|
-
elif 'b' in EWR:
|
|
1268
|
-
EWR2 = EWR.replace('b', 'a')
|
|
1269
|
-
EWR_info2 = get_EWRs(PU, gauge, EWR2, EWR_table, allowance, pull)
|
|
1270
|
-
# Mask dates
|
|
1271
|
-
masked_dates = mask_dates(EWR_info1, df_F)
|
|
1272
|
-
# Extract a daily timeseries for water years
|
|
1273
|
-
water_years = wateryear_daily(df_F, EWR_info1)
|
|
1274
|
-
# If preferred, skip, timing window too small to meet requirements:
|
|
1275
|
-
if 'P' in EWR:
|
|
1276
|
-
return PU_df, E
|
|
1277
|
-
else:
|
|
1278
|
-
if '2' in EWR:
|
|
1279
|
-
E, NE, D = flow_calc_post_req(EWR_info1, EWR_info2, df_F[gauge].values, water_years, df_F.index, masked_dates)
|
|
1280
|
-
elif '3' in EWR:
|
|
1281
|
-
E, NE, D = flow_calc_outside_req(EWR_info1, EWR_info2, df_F[gauge].values, water_years, df_F.index, masked_dates)
|
|
1282
|
-
PU_df = event_stats(df_F, PU_df, gauge, EWR, EWR_info1, E, D, water_years)
|
|
1283
|
-
|
|
1284
|
-
return PU_df, tuple([E])
|
|
1285
|
-
|
|
1286
1063
|
|
|
1287
|
-
def flow_handle_sa(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame,
|
|
1288
|
-
PU_df: pd.DataFrame, allowance: dict) -> tuple:
|
|
1064
|
+
def flow_handle_sa(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame) -> tuple:
|
|
1289
1065
|
'''For handling SA IC(in channel) and FP (flood plain) type EWRs.
|
|
1290
1066
|
It checks Flow thresholds, and check for Flow raise and fall.
|
|
1291
1067
|
|
|
@@ -1297,7 +1073,6 @@ def flow_handle_sa(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F:
|
|
|
1297
1073
|
df_F (pd.DataFrame): Daily flow data
|
|
1298
1074
|
df_L (pd.DataFrame): Daily water level data
|
|
1299
1075
|
PU_df (pd.DataFrame): EWR results for the current planning unit iteration
|
|
1300
|
-
allowance (dict): How much to scale EWR components by (0-1)
|
|
1301
1076
|
|
|
1302
1077
|
Results:
|
|
1303
1078
|
tuple[pd.DataFrame, tuple[dict]]: EWR results for the current planning unit iteration (updated); dictionary of EWR event information
|
|
@@ -1305,7 +1080,7 @@ def flow_handle_sa(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F:
|
|
|
1305
1080
|
'''
|
|
1306
1081
|
|
|
1307
1082
|
pull = data_inputs.get_EWR_components('flood-plains')
|
|
1308
|
-
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table,
|
|
1083
|
+
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table, pull)
|
|
1309
1084
|
# Mask dates for both the flow and level dataframes:
|
|
1310
1085
|
masked_dates = mask_dates(EWR_info, df_F)
|
|
1311
1086
|
# Extract a daily timeseries for water years:
|
|
@@ -1315,8 +1090,7 @@ def flow_handle_sa(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F:
|
|
|
1315
1090
|
PU_df = event_stats(df_F, PU_df, gauge, EWR, EWR_info, E, D, water_years)
|
|
1316
1091
|
return PU_df, tuple([E])
|
|
1317
1092
|
|
|
1318
|
-
def barrage_flow_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame,
|
|
1319
|
-
PU_df: pd.DataFrame, allowance: dict) -> tuple:
|
|
1093
|
+
def barrage_flow_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame) -> tuple:
|
|
1320
1094
|
"""handle function to calculate barrage flow type EWRs
|
|
1321
1095
|
|
|
1322
1096
|
Args:
|
|
@@ -1326,7 +1100,6 @@ def barrage_flow_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame,
|
|
|
1326
1100
|
EWR_table (pd.DataFrame): EWR dataset
|
|
1327
1101
|
df_F (pd.DataFrame): Daily flow data
|
|
1328
1102
|
PU_df (pd.DataFrame): EWR results for the current planning unit iteration
|
|
1329
|
-
allowance (dict): How much to scale EWR components by (0-1)
|
|
1330
1103
|
|
|
1331
1104
|
Returns:
|
|
1332
1105
|
tuple[pd.DataFrame, tuple[dict]]: EWR results for the current planning unit iteration (updated); dictionary of EWR event information
|
|
@@ -1338,7 +1111,7 @@ def barrage_flow_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame,
|
|
|
1338
1111
|
# check if current gauge is the main barrage gauge
|
|
1339
1112
|
if all_required_gauges_in_df_F:
|
|
1340
1113
|
pull = data_inputs.get_EWR_components('barrage-flow')
|
|
1341
|
-
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table,
|
|
1114
|
+
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table, pull)
|
|
1342
1115
|
# Mask dates for both the flow and level dataframes:
|
|
1343
1116
|
# Extract a daily timeseries for water years:
|
|
1344
1117
|
water_years = wateryear_daily(df_F, EWR_info)
|
|
@@ -1352,8 +1125,7 @@ def barrage_flow_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame,
|
|
|
1352
1125
|
print(f'Missing data for barrage gauges {" ".join(all_required_gauges)}')
|
|
1353
1126
|
return PU_df, None
|
|
1354
1127
|
|
|
1355
|
-
def barrage_level_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_L: pd.DataFrame,
|
|
1356
|
-
PU_df: pd.DataFrame, allowance: dict) -> tuple:
|
|
1128
|
+
def barrage_level_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_L: pd.DataFrame, PU_df: pd.DataFrame) -> tuple:
|
|
1357
1129
|
"""handle function to calculate barrage level type EWRs
|
|
1358
1130
|
|
|
1359
1131
|
Args:
|
|
@@ -1363,7 +1135,6 @@ def barrage_level_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame,
|
|
|
1363
1135
|
EWR_table (pd.DataFrame): EWR dataset
|
|
1364
1136
|
df_L (pd.DataFrame): Daily level data
|
|
1365
1137
|
PU_df (pd.DataFrame): EWR results for the current planning unit iteration
|
|
1366
|
-
allowance (dict): How much to scale EWR components by (0-1)
|
|
1367
1138
|
|
|
1368
1139
|
Returns:
|
|
1369
1140
|
tuple[pd.DataFrame, tuple[dict]]: EWR results for the current planning unit iteration (updated); dictionary of EWR event information
|
|
@@ -1375,7 +1146,7 @@ def barrage_level_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame,
|
|
|
1375
1146
|
# check if current gauge is the main barrage gauge
|
|
1376
1147
|
if all_required_gauges_in_df_L:
|
|
1377
1148
|
pull = data_inputs.get_EWR_components('barrage-level')
|
|
1378
|
-
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table,
|
|
1149
|
+
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table, pull)
|
|
1379
1150
|
masked_dates = mask_dates(EWR_info, df_L)
|
|
1380
1151
|
# Extract a daily timeseries for water years:
|
|
1381
1152
|
water_years = wateryear_daily(df_L, EWR_info)
|
|
@@ -1397,8 +1168,7 @@ def barrage_level_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame,
|
|
|
1397
1168
|
print(f'skipping calculation because gauge {" ".join(all_required_gauges)} is not the main barrage level gauge ')
|
|
1398
1169
|
return PU_df, None
|
|
1399
1170
|
|
|
1400
|
-
def rise_and_fall_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, df_L: pd.DataFrame,
|
|
1401
|
-
PU_df: pd.DataFrame, allowance: dict) -> tuple:
|
|
1171
|
+
def rise_and_fall_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, df_L: pd.DataFrame, PU_df: pd.DataFrame) -> tuple:
|
|
1402
1172
|
"""For handling rise and fall EWRs of type FLOW and LEVEL.
|
|
1403
1173
|
|
|
1404
1174
|
Args:
|
|
@@ -1409,7 +1179,6 @@ def rise_and_fall_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame,
|
|
|
1409
1179
|
df_F (pd.DataFrame): Daily flow data
|
|
1410
1180
|
df_L (pd.DataFrame): Daily level data
|
|
1411
1181
|
PU_df (pd.DataFrame): EWR results for the current planning unit iteration
|
|
1412
|
-
allowance (dict): How much to scale EWR components by (0-1)
|
|
1413
1182
|
|
|
1414
1183
|
Returns:
|
|
1415
1184
|
tuple[pd.DataFrame, tuple[dict]]: EWRS results for the current planning unit iteration (updated); dictionary of EWR event information
|
|
@@ -1417,7 +1186,7 @@ def rise_and_fall_handle(PU: str, gauge: str, EWR: str, EWR_table: pd.DataFrame,
|
|
|
1417
1186
|
|
|
1418
1187
|
# Get information about EWR:
|
|
1419
1188
|
pull = data_inputs.get_EWR_components('rise_fall')
|
|
1420
|
-
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table,
|
|
1189
|
+
EWR_info = get_EWRs(PU, gauge, EWR, EWR_table, pull)
|
|
1421
1190
|
# Mask dates:
|
|
1422
1191
|
masked_dates = mask_dates(EWR_info, df_F)
|
|
1423
1192
|
# If there is no level data loaded in, let user know and skip the analysis
|
|
@@ -1962,49 +1731,6 @@ def ctf_check(EWR_info: dict, iteration: int, flow: float, event: list, all_even
|
|
|
1962
1731
|
|
|
1963
1732
|
return event, all_events
|
|
1964
1733
|
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
def flow_check_sim(iteration: int, EWR_info1: dict, EWR_info2: dict, water_years: np.array, flow1: float, flow2: float, event: list, all_events: dict,
|
|
1968
|
-
gap_track: int, total_event: int, flow_date: date) -> tuple:
|
|
1969
|
-
'''Checks daily flow for both sites against EWR thresholds. Saves events to the relevant
|
|
1970
|
-
water year in the event tracking dictionary. Saves all event gaps to the relevant
|
|
1971
|
-
water year in the no event dictionary.
|
|
1972
|
-
|
|
1973
|
-
Args:
|
|
1974
|
-
iteration (int): current iteration
|
|
1975
|
-
EWR_info1 (dict): dictionary with the parameter info of the EWR being calculated (site 1)
|
|
1976
|
-
EWR_info2 (dict): dictionary with the parameter info of the EWR being calculated (site 2)
|
|
1977
|
-
flow (float): current flow
|
|
1978
|
-
event (list): current event state
|
|
1979
|
-
all_events (dict): current all events state
|
|
1980
|
-
water_years (np.array): list of water year for every flow iteration
|
|
1981
|
-
flow_date (date): current flow date
|
|
1982
|
-
|
|
1983
|
-
Returns:
|
|
1984
|
-
tuple: the current state of the event, all_events
|
|
1985
|
-
|
|
1986
|
-
'''
|
|
1987
|
-
|
|
1988
|
-
if ((flow1 >= EWR_info1['min_flow']) and (flow1 <= EWR_info1['max_flow']) and\
|
|
1989
|
-
(flow2 >= EWR_info2['min_flow']) and (flow2 <= EWR_info2['max_flow'])):
|
|
1990
|
-
threshold_flow = (get_index_date(flow_date), flow1)
|
|
1991
|
-
event.append(threshold_flow)
|
|
1992
|
-
total_event += 1
|
|
1993
|
-
gap_track = EWR_info1['gap_tolerance'] # reset the gapTolerance after threshold is reached
|
|
1994
|
-
else:
|
|
1995
|
-
if gap_track > 0:
|
|
1996
|
-
gap_track = gap_track - 1
|
|
1997
|
-
total_event += 1
|
|
1998
|
-
else:
|
|
1999
|
-
if len(event) >= EWR_info1['min_event']:
|
|
2000
|
-
water_year = which_water_year(iteration, total_event, water_years)
|
|
2001
|
-
all_events[water_year].append(event)
|
|
2002
|
-
|
|
2003
|
-
event = []
|
|
2004
|
-
total_event = 0
|
|
2005
|
-
|
|
2006
|
-
return event, all_events, gap_track, total_event
|
|
2007
|
-
|
|
2008
1734
|
def date_check(date, masked_dates):
|
|
2009
1735
|
'''Pass in a date, if the date is within the range of accepted dates, return True, else False'''
|
|
2010
1736
|
return True if date in masked_dates else False
|
|
@@ -2157,8 +1883,6 @@ def volume_level_check_bbr(EWR_info:Dict, iteration:int, flow:float, event:List,
|
|
|
2157
1883
|
|
|
2158
1884
|
# if go back to cease to flow and level is below and never crosses up
|
|
2159
1885
|
if flow <= 1:
|
|
2160
|
-
# if achieved_min_volume(event, EWR_info) :
|
|
2161
|
-
# all_events[water_years[iteration]].append(event)
|
|
2162
1886
|
total_event = 0
|
|
2163
1887
|
event_state["level_crossed_up"] = False
|
|
2164
1888
|
event_state["level_crossed_down"] = False
|
|
@@ -2382,7 +2106,6 @@ def flow_level_check(EWR_info: dict, iteration: int, flow: float, level: float,
|
|
|
2382
2106
|
Returns:
|
|
2383
2107
|
tuple: after the check return the current state of the event, all_events, gap_track, total_event
|
|
2384
2108
|
"""
|
|
2385
|
-
# if flow >= EWR_info['min_flow'] and check_daily_level_change(level_change, EWR_info) and level > 0:
|
|
2386
2109
|
if flow >= EWR_info['min_flow'] and check_weekly_level_change(levels, EWR_info, iteration, len(event)) and level > 0:
|
|
2387
2110
|
threshold_flow = (get_index_date(flow_date), flow)
|
|
2388
2111
|
event.append(threshold_flow)
|
|
@@ -2901,25 +2624,6 @@ def create_water_stability_event(flow_date: pd.Period, flows:List, iteration: in
|
|
|
2901
2624
|
return [(d, flow) for d, flow in zip(event_dates, event_flows)]
|
|
2902
2625
|
|
|
2903
2626
|
|
|
2904
|
-
def get_duration(climate: str, EWR_info: dict) -> int:
|
|
2905
|
-
'''Determines the relevant duration for the water year
|
|
2906
|
-
|
|
2907
|
-
Args:
|
|
2908
|
-
climate (str): Climate value for this year
|
|
2909
|
-
EWR_info (dict): Dictionary with the parameter info of the EWR being calculated
|
|
2910
|
-
|
|
2911
|
-
Results:
|
|
2912
|
-
int: Duration value
|
|
2913
|
-
|
|
2914
|
-
'''
|
|
2915
|
-
|
|
2916
|
-
if ((climate == 'Very Dry') and (EWR_info['duration_VD'] !=None)):
|
|
2917
|
-
duration = EWR_info['duration_VD']
|
|
2918
|
-
else:
|
|
2919
|
-
duration = EWR_info['duration']
|
|
2920
|
-
|
|
2921
|
-
return duration
|
|
2922
|
-
|
|
2923
2627
|
def construct_event_dict(water_years: np.array) -> dict:
|
|
2924
2628
|
''' Pulling together a dictionary with a key per year in the timeseries,
|
|
2925
2629
|
and an empty list as each value, where events will be saved into
|
|
@@ -3481,7 +3185,7 @@ def calc_nest_cut_date(EWR_info: dict, iteration: int, dates: list) -> date:
|
|
|
3481
3185
|
d = d.replace(day = EWR_info['end_day'])
|
|
3482
3186
|
return d
|
|
3483
3187
|
|
|
3484
|
-
def lowflow_calc(EWR_info: dict, flows: np.array, water_years: np.array,
|
|
3188
|
+
def lowflow_calc(EWR_info: dict, flows: np.array, water_years: np.array, dates: np.array, masked_dates: set) -> tuple:
|
|
3485
3189
|
'''For calculating low flow ewrs. These have no consecutive requirement on their durations
|
|
3486
3190
|
Events and event gaps are calculated on an annual basis, and are reset at the end of
|
|
3487
3191
|
each water year.
|
|
@@ -3490,7 +3194,6 @@ def lowflow_calc(EWR_info: dict, flows: np.array, water_years: np.array, climate
|
|
|
3490
3194
|
EWR_info (dict): dictionary with the parameter info of the EWR being calculated
|
|
3491
3195
|
flows (np.array): array of daily flows
|
|
3492
3196
|
water_years (np.array): array of daily water year values
|
|
3493
|
-
climates (np.array): array of daily climate values
|
|
3494
3197
|
dates (np.array): array of dates
|
|
3495
3198
|
masked_dates (set): Dates within required date range
|
|
3496
3199
|
|
|
@@ -3512,7 +3215,7 @@ def lowflow_calc(EWR_info: dict, flows: np.array, water_years: np.array, climate
|
|
|
3512
3215
|
if len(event) > 0:
|
|
3513
3216
|
all_events[water_years[i]].append(event)
|
|
3514
3217
|
event = [] # Reset at the end of the water year
|
|
3515
|
-
durations.append(
|
|
3218
|
+
durations.append(EWR_info['duration'])
|
|
3516
3219
|
|
|
3517
3220
|
# Check the final iteration, saving any ongoing events/event gaps to their spots in the dictionaries
|
|
3518
3221
|
if dates[-1] in masked_dates:
|
|
@@ -3520,10 +3223,10 @@ def lowflow_calc(EWR_info: dict, flows: np.array, water_years: np.array, climate
|
|
|
3520
3223
|
event, all_events = lowflow_check(EWR_info, -1, flows[-1], event, all_events, water_years, flow_date)
|
|
3521
3224
|
if len(event) > 0:
|
|
3522
3225
|
all_events[water_years[-1]].append(event)
|
|
3523
|
-
durations.append(
|
|
3226
|
+
durations.append(EWR_info['duration'])
|
|
3524
3227
|
return all_events, durations
|
|
3525
3228
|
|
|
3526
|
-
def ctf_calc_anytime(EWR_info: dict, flows: np.array, water_years: np.array,
|
|
3229
|
+
def ctf_calc_anytime(EWR_info: dict, flows: np.array, water_years: np.array, dates: np.array) -> tuple:
|
|
3527
3230
|
'''For calculating cease to flow ewrs. These have a consecutive requirement on their durations
|
|
3528
3231
|
Events and event gaps are calculated on an annual basis, and are reset at the end of each
|
|
3529
3232
|
water year.
|
|
@@ -3532,7 +3235,6 @@ def ctf_calc_anytime(EWR_info: dict, flows: np.array, water_years: np.array, cli
|
|
|
3532
3235
|
EWR_info (dict): dictionary with the parameter info of the EWR being calculated
|
|
3533
3236
|
flows (np.array): array of daily flows
|
|
3534
3237
|
water_years (np.array): array of daily water year values
|
|
3535
|
-
climates (np.array): array of daily climate values
|
|
3536
3238
|
dates (np.array): array of dates
|
|
3537
3239
|
|
|
3538
3240
|
Results:
|
|
@@ -3549,19 +3251,19 @@ def ctf_calc_anytime(EWR_info: dict, flows: np.array, water_years: np.array, cli
|
|
|
3549
3251
|
event, all_events = ctf_check(EWR_info, i, flow, event, all_events, water_years, flow_date)
|
|
3550
3252
|
# At the end of each water year, save any ongoing events and event gaps to the dictionaries, and reset the list and counter
|
|
3551
3253
|
if water_years[i] != water_years[i+1]:
|
|
3552
|
-
durations.append(
|
|
3254
|
+
durations.append(EWR_info['duration'])
|
|
3553
3255
|
# Check final iteration in the flow timeseries, saving any ongoing events/event gaps to their spots in the dictionaries:
|
|
3554
3256
|
flow_date = dates[-1]
|
|
3555
3257
|
event, all_events = ctf_check(EWR_info, -1, flows[-1], event, all_events, water_years, flow_date)
|
|
3556
3258
|
if len(event) > 0:
|
|
3557
3259
|
all_events[water_years[-1]].append(event)
|
|
3558
3260
|
|
|
3559
|
-
durations.append(
|
|
3261
|
+
durations.append(EWR_info['duration'])
|
|
3560
3262
|
|
|
3561
3263
|
return all_events, durations
|
|
3562
3264
|
|
|
3563
3265
|
|
|
3564
|
-
def ctf_calc(EWR_info: dict, flows: np.array, water_years: np.array,
|
|
3266
|
+
def ctf_calc(EWR_info: dict, flows: np.array, water_years: np.array, dates: np.array, masked_dates: set) -> tuple:
|
|
3565
3267
|
'''For calculating cease to flow ewrs. These have a consecutive requirement on their durations
|
|
3566
3268
|
Events and event gaps are calculated on an annual basis, and are reset at the end of each
|
|
3567
3269
|
water year.
|
|
@@ -3570,7 +3272,6 @@ def ctf_calc(EWR_info: dict, flows: np.array, water_years: np.array, climates: n
|
|
|
3570
3272
|
EWR_info (dict): dictionary with the parameter info of the EWR being calculated
|
|
3571
3273
|
flows (np.array): array of daily flows
|
|
3572
3274
|
water_years (np.array): array of daily water year values
|
|
3573
|
-
climates (np.array): array of daily climate values
|
|
3574
3275
|
dates (np.array): array of dates
|
|
3575
3276
|
masked_dates (set): Dates within required date range
|
|
3576
3277
|
|
|
@@ -3592,14 +3293,14 @@ def ctf_calc(EWR_info: dict, flows: np.array, water_years: np.array, climates: n
|
|
|
3592
3293
|
if len(event) > 0:
|
|
3593
3294
|
all_events[water_years[i]].append(event)
|
|
3594
3295
|
event = []
|
|
3595
|
-
durations.append(
|
|
3296
|
+
durations.append(EWR_info['duration'])
|
|
3596
3297
|
# Check final iteration in the flow timeseries, saving any ongoing events/event gaps to their spots in the dictionaries:
|
|
3597
3298
|
if dates[-1] in masked_dates:
|
|
3598
3299
|
flow_date = dates[-1]
|
|
3599
3300
|
event, all_events = ctf_check(EWR_info, -1, flows[-1], event, all_events, water_years, flow_date)
|
|
3600
3301
|
if len(event) > 0:
|
|
3601
3302
|
all_events[water_years[-1]].append(event)
|
|
3602
|
-
durations.append(
|
|
3303
|
+
durations.append(EWR_info['duration'])
|
|
3603
3304
|
|
|
3604
3305
|
return all_events, durations
|
|
3605
3306
|
|
|
@@ -4222,161 +3923,6 @@ def weirpool_calc(EWR_info: Dict, flows: List, levels: List, water_years: List,
|
|
|
4222
3923
|
|
|
4223
3924
|
return all_events, durations
|
|
4224
3925
|
|
|
4225
|
-
def flow_calc_anytime_sim(EWR_info1: dict, EWR_info2: dict, flows1: np.array, flows2: np.array, water_years: np.array, dates: np.array) -> tuple:
|
|
4226
|
-
'''For calculating flow EWRs with no time constraint within their requirements. Events crossing
|
|
4227
|
-
water year boundaries will be saved to the water year where the majority of event days were.
|
|
4228
|
-
These EWRs need to be met simultaneously with EWRs at partner sites.
|
|
4229
|
-
|
|
4230
|
-
Args:
|
|
4231
|
-
EWR_info1 (Dict): dictionary with the parameter info of the EWR being calculated (site 1)
|
|
4232
|
-
EWR_info2 (Dict): dictionary with the parameter info of the EWR being calculated (site 2)
|
|
4233
|
-
flows1 (List): List with all the flows measurements for the current calculated EWR (site 1)
|
|
4234
|
-
flows2 (List): List with all the flows measurements for the current calculated EWR (site 2)
|
|
4235
|
-
water_years (List): List of the water year of each day of the current calculated EWR
|
|
4236
|
-
dates (List): List of the dates of the current calculated EWR
|
|
4237
|
-
|
|
4238
|
-
Returns:
|
|
4239
|
-
tuple: final output with the calculation of volume all_events, durations
|
|
4240
|
-
|
|
4241
|
-
'''
|
|
4242
|
-
# Declare variables:
|
|
4243
|
-
event = []
|
|
4244
|
-
all_events = construct_event_dict(water_years)
|
|
4245
|
-
durations = []
|
|
4246
|
-
gap_track = 0
|
|
4247
|
-
total_event = 0
|
|
4248
|
-
# Iterate over flows
|
|
4249
|
-
for i, flow in enumerate(flows1[:-1]):
|
|
4250
|
-
flow_date = dates[i]
|
|
4251
|
-
# Each iteration send to a simultaneous flow check function, to see if both sites requirements are met:
|
|
4252
|
-
event, all_events, gap_track, total_event = flow_check_sim(i,EWR_info1,
|
|
4253
|
-
EWR_info2, water_years,
|
|
4254
|
-
flow, flows2[i], event,
|
|
4255
|
-
all_events,
|
|
4256
|
-
gap_track, total_event, flow_date)
|
|
4257
|
-
if water_years[i] != water_years[i+1]:
|
|
4258
|
-
durations.append(EWR_info1['duration'])
|
|
4259
|
-
# Check final iteration:
|
|
4260
|
-
flow_date = dates[-1]
|
|
4261
|
-
event, all_events, gap_track, total_event = flow_check_sim(i,EWR_info1,
|
|
4262
|
-
EWR_info2, water_years,
|
|
4263
|
-
flows1[-1], flows2[-1], event,
|
|
4264
|
-
all_events, gap_track,
|
|
4265
|
-
total_event, flow_date)
|
|
4266
|
-
if len(event) >= EWR_info1['min_event']:
|
|
4267
|
-
water_year = which_water_year(-1, total_event, water_years)
|
|
4268
|
-
all_events[water_year].append(event)
|
|
4269
|
-
durations.append(EWR_info1['duration'])
|
|
4270
|
-
return all_events, durations
|
|
4271
|
-
|
|
4272
|
-
def flow_calc_sim(EWR_info1: dict, EWR_info2: dict, flows1: np.array, flows2: np.array, water_years: np.array, dates: np.array, masked_dates: set):
|
|
4273
|
-
'''For calculating flow EWRs with a time constraint within their requirements. Events are
|
|
4274
|
-
therefore reset at the end of each water year. These EWRs need to be met simultaneously
|
|
4275
|
-
with EWRs at partner sites.
|
|
4276
|
-
|
|
4277
|
-
Args:
|
|
4278
|
-
EWR_info1 (Dict): dictionary with the parameter info of the EWR being calculated (site 1)
|
|
4279
|
-
EWR_info2 (Dict): dictionary with the parameter info of the EWR being calculated (site 2)
|
|
4280
|
-
flows1 (List): List with all the flows measurements for the current calculated EWR (site 1)
|
|
4281
|
-
flows2 (List): List with all the flows measurements for the current calculated EWR (site 2)
|
|
4282
|
-
water_years (List): List of the water year of each day of the current calculated EWR
|
|
4283
|
-
dates (List): List of the dates of the current calculated EWR
|
|
4284
|
-
masked_dates (List): List of the dates that the EWR needs to be calculated i.e. the time window.
|
|
4285
|
-
|
|
4286
|
-
Returns:
|
|
4287
|
-
tuple: final output with the calculation of volume all_events, durations
|
|
4288
|
-
|
|
4289
|
-
'''
|
|
4290
|
-
# Declare variables:
|
|
4291
|
-
event = []
|
|
4292
|
-
all_events = construct_event_dict(water_years)
|
|
4293
|
-
durations = []
|
|
4294
|
-
gap_track = 0
|
|
4295
|
-
lines_to_skip = 0
|
|
4296
|
-
total_event = 0
|
|
4297
|
-
# Iterate over flows
|
|
4298
|
-
for i, flow in enumerate(flows1[:-1]):
|
|
4299
|
-
if dates[i] in masked_dates:
|
|
4300
|
-
flow_date = dates[i]
|
|
4301
|
-
# Each iteration send to a simultaneous flow check function, to see if both sites requirements are met:
|
|
4302
|
-
event, all_events, gap_track, total_event = flow_check_sim(i,EWR_info1,EWR_info2,
|
|
4303
|
-
water_years, flow,
|
|
4304
|
-
flows2[i],event,
|
|
4305
|
-
all_events, gap_track,
|
|
4306
|
-
total_event, flow_date)
|
|
4307
|
-
if water_years[i] != water_years[i+1]:
|
|
4308
|
-
if len(event) >= EWR_info1['min_event']:
|
|
4309
|
-
all_events[water_years[i]].append(event)
|
|
4310
|
-
total_event = 0
|
|
4311
|
-
event = []
|
|
4312
|
-
durations.append(EWR_info1['duration'])
|
|
4313
|
-
|
|
4314
|
-
# Check final iteration:
|
|
4315
|
-
if dates[-1] in masked_dates:
|
|
4316
|
-
flow_date = dates[-1]
|
|
4317
|
-
event, all_events, gap_track, total_event = flow_check_sim(i,EWR_info1,
|
|
4318
|
-
EWR_info2, water_years,
|
|
4319
|
-
flows1[-1], flows2[-1], event,
|
|
4320
|
-
all_events, gap_track,
|
|
4321
|
-
total_event,flow_date)
|
|
4322
|
-
if len(event) >= EWR_info1['min_event']:
|
|
4323
|
-
all_events[water_years[-1]].append(event)
|
|
4324
|
-
total_event = 0
|
|
4325
|
-
durations.append(EWR_info1['duration'])
|
|
4326
|
-
return all_events, durations
|
|
4327
|
-
|
|
4328
|
-
def lowflow_calc_sim(EWR_info1: dict, EWR_info2: dict, flows1: np.array, flows2: np.array, water_years: np.array, climates: np.array, dates: np.array, masked_dates: set) -> set:
|
|
4329
|
-
'''For calculating low flow ewrs. These have no consecutive requirement on their durations
|
|
4330
|
-
Events and event gaps are calculated on an annual basis, and are reset at the end of
|
|
4331
|
-
each water year. These EWRs need to be met simultaneously with EWRs at partner sites.
|
|
4332
|
-
|
|
4333
|
-
Args:
|
|
4334
|
-
EWR_info1 (Dict): dictionary with the parameter info of the EWR being calculated (site 1)
|
|
4335
|
-
EWR_info2 (Dict): dictionary with the parameter info of the EWR being calculated (site 2)
|
|
4336
|
-
flows1 (List): List with all the flows measurements for the current calculated EWR (site 1)
|
|
4337
|
-
flows2 (List): List with all the flows measurements for the current calculated EWR (site 2)
|
|
4338
|
-
water_years (List): List of the water year of each day of the current calculated EWR
|
|
4339
|
-
climates (np.array): array of daily climate values
|
|
4340
|
-
dates (List): List of the dates of the current calculated EWR
|
|
4341
|
-
masked_dates (List): List of the dates that the EWR needs to be calculated i.e. the time window.
|
|
4342
|
-
|
|
4343
|
-
Returns:
|
|
4344
|
-
tuple: final output with the calculation of volume all_events, durations
|
|
4345
|
-
|
|
4346
|
-
'''
|
|
4347
|
-
# Decalre variables:
|
|
4348
|
-
event1, event2 = [], []
|
|
4349
|
-
all_events1 = construct_event_dict(water_years)
|
|
4350
|
-
all_events2 = construct_event_dict(water_years)
|
|
4351
|
-
durations = []
|
|
4352
|
-
for i, flow in enumerate(flows1[:-1]):
|
|
4353
|
-
if dates[i] in masked_dates:
|
|
4354
|
-
flow_date = dates[i]
|
|
4355
|
-
# Check flows at each site against their respective EWR requirements:
|
|
4356
|
-
event1, all_events1 = lowflow_check(EWR_info1, i, flow, event1, all_events1, water_years, flow_date)
|
|
4357
|
-
event2, all_events2 = lowflow_check(EWR_info2, i, flows2[i], event2, all_events2, water_years, flow_date)
|
|
4358
|
-
if water_years[i] != water_years[i+1]:
|
|
4359
|
-
if len(event1) > 0:
|
|
4360
|
-
all_events1[water_years[i]].append(event1)
|
|
4361
|
-
if len(event2) > 0:
|
|
4362
|
-
all_events2[water_years[i]].append(event2)
|
|
4363
|
-
|
|
4364
|
-
event1, event2 = [], []
|
|
4365
|
-
durations.append(get_duration(climates[i], EWR_info1))
|
|
4366
|
-
|
|
4367
|
-
# Check final iteration:
|
|
4368
|
-
if dates[-1] in masked_dates:
|
|
4369
|
-
flow_date = dates[-1]
|
|
4370
|
-
event1, all_events1 = lowflow_check(EWR_info1, -1, flows1[-1], event1, all_events1, water_years, flow_date)
|
|
4371
|
-
event2, all_events2 = lowflow_check(EWR_info2, -1, flows2[-1], event2, all_events2, water_years, flow_date)
|
|
4372
|
-
if len(event1) > 0:
|
|
4373
|
-
all_events1[water_years[-1]].append(event1)
|
|
4374
|
-
if len(event2) > 0:
|
|
4375
|
-
all_events2[water_years[-1]].append(event2)
|
|
4376
|
-
durations.append(get_duration(climates[-1], EWR_info1))
|
|
4377
|
-
# If there are event gaps left over, save these to the last year in the dictionary
|
|
4378
|
-
return all_events1, all_events2, durations
|
|
4379
|
-
|
|
4380
3926
|
def flow_level_calc(EWR_info: Dict, flows: List, levels: List, water_years: List,
|
|
4381
3927
|
dates:List, masked_dates:List)-> tuple:
|
|
4382
3928
|
""" Iterates each yearly flows to manage calculation of flow and level raise and fall. It delegates to flow_level_check function
|
|
@@ -4750,259 +4296,6 @@ def lower_lakes_level_calc(EWR_info: Dict, levels: pd.Series, water_years: List,
|
|
|
4750
4296
|
event = []
|
|
4751
4297
|
durations.append(EWR_info['duration'])
|
|
4752
4298
|
return all_events, durations
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
def ctf_calc_sim(EWR_info1: dict, EWR_info2: dict, flows1: np.array, flows2: np.array, water_years: np.array, climates: np.array, dates: np.array, masked_dates: set) -> tuple:
|
|
4757
|
-
'''For calculating cease to flow ewrs. These have a consecutive requirement on their durations
|
|
4758
|
-
Events and event gaps are calculated on an annual basis, and are reset at the end of each
|
|
4759
|
-
water year. These EWRs need to be met simultaneously with EWRs at partner sites.
|
|
4760
|
-
|
|
4761
|
-
Args:
|
|
4762
|
-
EWR_info1 (Dict): dictionary with the parameter info of the EWR being calculated (site 1)
|
|
4763
|
-
EWR_info2 (Dict): dictionary with the parameter info of the EWR being calculated (site 2)
|
|
4764
|
-
flows1 (List): List with all the flows measurements for the current calculated EWR (site 1)
|
|
4765
|
-
flows2 (List): List with all the flows measurements for the current calculated EWR (site 2)
|
|
4766
|
-
water_years (List): List of the water year of each day of the current calculated EWR
|
|
4767
|
-
climates (np.array): array of daily climate values
|
|
4768
|
-
dates (List): List of the dates of the current calculated EWR
|
|
4769
|
-
masked_dates (List): List of the dates that the EWR needs to be calculated i.e. the time window.
|
|
4770
|
-
|
|
4771
|
-
Returns:
|
|
4772
|
-
tuple: final output with the calculation of volume all_events, durations
|
|
4773
|
-
|
|
4774
|
-
'''
|
|
4775
|
-
# Declare variables:
|
|
4776
|
-
event1, event2 = [], []
|
|
4777
|
-
no_event1, no_event2 = 0, 0
|
|
4778
|
-
all_events1 = construct_event_dict(water_years)
|
|
4779
|
-
all_events2 = construct_event_dict(water_years)
|
|
4780
|
-
all_no_events1 = construct_event_dict(water_years)
|
|
4781
|
-
all_no_events2 = construct_event_dict(water_years)
|
|
4782
|
-
durations = []
|
|
4783
|
-
for i, flow in enumerate(flows1[:-1]):
|
|
4784
|
-
# Check flows at each site against their respective EWR requirements:
|
|
4785
|
-
if dates[i] in masked_dates:
|
|
4786
|
-
flow_date = dates[i]
|
|
4787
|
-
event1, all_events1 = ctf_check(EWR_info1, i, flow, event1, all_events1, water_years, flow_date)
|
|
4788
|
-
event2, all_events2 = ctf_check(EWR_info2, i, flows2[i], event2, all_events2, water_years, flow_date)
|
|
4789
|
-
if water_years[i] != water_years[i+1]:
|
|
4790
|
-
if len(event1) > 0:
|
|
4791
|
-
all_events1[water_years[i]].append(event1)
|
|
4792
|
-
if len(event2) > 0:
|
|
4793
|
-
all_events2[water_years[i]].append(event2)
|
|
4794
|
-
event1, event2 = [], []
|
|
4795
|
-
durations.append(get_duration(climates[i], EWR_info1))
|
|
4796
|
-
# Check final iteration:
|
|
4797
|
-
if dates[-1] in masked_dates:
|
|
4798
|
-
flow_date = dates[-1]
|
|
4799
|
-
event1, all_events1 = ctf_check(EWR_info1, -1, flows1[-1], event1, all_events1, water_years, flow_date)
|
|
4800
|
-
event2, all_events2 = ctf_check(EWR_info2, -1, flows2[-1], event2, all_events2, water_years, flow_date)
|
|
4801
|
-
if len(event1) > 0:
|
|
4802
|
-
all_events1[water_years[-1]].append(event1)
|
|
4803
|
-
if len(event2) > 0:
|
|
4804
|
-
all_events2[water_years[-1]].append(event2)
|
|
4805
|
-
durations.append(get_duration(climates[-1], EWR_info1))
|
|
4806
|
-
return all_events1, all_events2, durations
|
|
4807
|
-
|
|
4808
|
-
def check_trigger(EWR_info: dict, flow: float, event: list, gap_track: int, trigger: bool, total_event: int) -> tuple:
|
|
4809
|
-
'''Checks daily flow against ewr threshold requirement.
|
|
4810
|
-
Saves events to the relevant water year in the event tracking dictionary.
|
|
4811
|
-
returns the event list, event dictionary, and time between events
|
|
4812
|
-
|
|
4813
|
-
Args:
|
|
4814
|
-
EWR_info (dict): dictionary with the parameter info of the EWR being calculated
|
|
4815
|
-
flow (float): Flow of current day
|
|
4816
|
-
event (list): Current state of the event list
|
|
4817
|
-
gap_track (int): Current state of tracker for gap between event days
|
|
4818
|
-
trigger (bool): Current state of the trigger
|
|
4819
|
-
total_event (int): Current state of the total event
|
|
4820
|
-
|
|
4821
|
-
Results:
|
|
4822
|
-
tuple: Updated instances of any ongoing events, event gaps, and event triggers
|
|
4823
|
-
|
|
4824
|
-
'''
|
|
4825
|
-
|
|
4826
|
-
if ((flow >= EWR_info['min_flow']) and (flow <= EWR_info['max_flow'])):
|
|
4827
|
-
event.append(flow)
|
|
4828
|
-
total_event += 1
|
|
4829
|
-
gap_track = EWR_info['gap_tolerance'] # reset the gapTolerance after threshold is reached
|
|
4830
|
-
if len(event) >= EWR_info['min_event']:
|
|
4831
|
-
trigger = True
|
|
4832
|
-
else:
|
|
4833
|
-
if gap_track > 0:
|
|
4834
|
-
gap_track = gap_track - 1
|
|
4835
|
-
total_event += 1
|
|
4836
|
-
else:
|
|
4837
|
-
gap_track = -1
|
|
4838
|
-
event = []
|
|
4839
|
-
total_event = 0
|
|
4840
|
-
trigger = False
|
|
4841
|
-
|
|
4842
|
-
return event, gap_track, trigger, total_event
|
|
4843
|
-
|
|
4844
|
-
def flow_calc_post_req(EWR_info1: dict, EWR_info2: dict, flows: np.array, water_years: np.array, dates: np.array, masked_dates: set) -> tuple:
|
|
4845
|
-
''' For flow EWRs with a main requirement, and a secondary requirement which needs to be
|
|
4846
|
-
satisfied immediately after the main requirement. Currently only two EWRs have this requirement,
|
|
4847
|
-
gauge 409025 OB2_S and OB2_P
|
|
4848
|
-
|
|
4849
|
-
Args:
|
|
4850
|
-
EWR_info1 (dict): dictionary with the parameter info of the EWR being calculated (Part 1 of EWR)
|
|
4851
|
-
EWR_info2 (dict): dictionary with the parameter info of the EWR being calculated (Part 2 of EWR)
|
|
4852
|
-
flows (np.array): List with all the flows measurements for the current calculated EWR
|
|
4853
|
-
water_years (np.array): Daily sequence of water year values
|
|
4854
|
-
dates (np.array): Daily sequence of date values
|
|
4855
|
-
masked_dates (set): Set of dates within the required timing window
|
|
4856
|
-
|
|
4857
|
-
Results:
|
|
4858
|
-
tuple: final output with the calculation of all_events, all_no_events, durations
|
|
4859
|
-
'''
|
|
4860
|
-
trigger, post_trigger = False, False
|
|
4861
|
-
event = []
|
|
4862
|
-
post_event = []
|
|
4863
|
-
total_event = 0
|
|
4864
|
-
no_event = 0
|
|
4865
|
-
all_events = construct_event_dict(water_years)
|
|
4866
|
-
all_no_events = construct_event_dict(water_years)
|
|
4867
|
-
durations = []
|
|
4868
|
-
durations = len(set(water_years))*[EWR_info1['duration']]
|
|
4869
|
-
gap_track = 0
|
|
4870
|
-
skip_lines = 0
|
|
4871
|
-
for i, flow in enumerate(flows):
|
|
4872
|
-
if skip_lines > 0:
|
|
4873
|
-
skip_lines -= 1
|
|
4874
|
-
else:
|
|
4875
|
-
no_event += 1
|
|
4876
|
-
if gap_track == -1:
|
|
4877
|
-
trigger, post_trigger = False, False
|
|
4878
|
-
if ((trigger == False) and (post_trigger == False)):
|
|
4879
|
-
event, gap_track, trigger, total_event = check_trigger(EWR_info1, flow, event, gap_track, trigger, total_event)
|
|
4880
|
-
elif ((trigger == True) and (post_trigger == False)):
|
|
4881
|
-
# Send to check the post requirement
|
|
4882
|
-
post_event, gap_track, post_trigger, total_event = check_trigger(EWR_info2, flow, post_event, gap_track, post_trigger, total_event)
|
|
4883
|
-
elif ((trigger == True) and (post_trigger == True)):
|
|
4884
|
-
water_year = which_water_year(i, total_event, water_years)
|
|
4885
|
-
full_event = event + post_event
|
|
4886
|
-
all_events[water_year].append(full_event)
|
|
4887
|
-
ne_water_year = which_water_year_no_event(i, total_event, water_years)
|
|
4888
|
-
all_no_events[ne_water_year].append([no_event-total_event])
|
|
4889
|
-
no_event = 0
|
|
4890
|
-
trigger, post_trigger = False, False
|
|
4891
|
-
event, post_event = [], []
|
|
4892
|
-
total_event = 0
|
|
4893
|
-
if ((trigger == True) and (post_trigger == True)):
|
|
4894
|
-
water_year = which_water_year(i, total_event, water_years)
|
|
4895
|
-
full_event = event + post_event
|
|
4896
|
-
all_events[water_year].append(full_event)
|
|
4897
|
-
ne_water_year = which_water_year_no_event(i, total_event, water_years)
|
|
4898
|
-
all_no_events[ne_water_year].append([no_event-total_event])
|
|
4899
|
-
no_event = 0
|
|
4900
|
-
if no_event > 0:
|
|
4901
|
-
all_no_events[water_years[-1]].append([no_event])
|
|
4902
|
-
return all_events, all_no_events, durations
|
|
4903
|
-
|
|
4904
|
-
def flow_calc_outside_req(EWR_info1: dict, EWR_info2: dict, flows: np.array, water_years: np.array, dates: np.array, masked_dates: set) -> tuple:
|
|
4905
|
-
''' For flow EWRs with a main requirement, and a secondary requirement which can either be
|
|
4906
|
-
satisfied immediately after the main requirement, or immediately before.
|
|
4907
|
-
Currently only two EWRs have this requirement, gauge 409025 OB3_S and OB3_P
|
|
4908
|
-
|
|
4909
|
-
Args:
|
|
4910
|
-
EWR_info1 (dict): dictionary with the parameter info of the EWR being calculated (Part 1 of EWR)
|
|
4911
|
-
EWR_info2 (dict): dictionary with the parameter info of the EWR being calculated (Part 2 of EWR)
|
|
4912
|
-
flows (np.array): List with all the flows measurements for the current calculated EWR
|
|
4913
|
-
water_years (np.array): Daily sequence of water year values
|
|
4914
|
-
dates (np.array): Daily sequence of date values
|
|
4915
|
-
masked_dates (set): Set of dates within the required timing window
|
|
4916
|
-
|
|
4917
|
-
Results:
|
|
4918
|
-
tuple: final output with the calculation of all_events, all_no_events, durations
|
|
4919
|
-
|
|
4920
|
-
'''
|
|
4921
|
-
trigger, pre_trigger, post_trigger = False, False, False
|
|
4922
|
-
event, pre_event, post_event = [], [], []
|
|
4923
|
-
no_event = 0
|
|
4924
|
-
total_event = 0
|
|
4925
|
-
all_events = construct_event_dict(water_years)
|
|
4926
|
-
all_no_events = construct_event_dict(water_years)
|
|
4927
|
-
durations = []
|
|
4928
|
-
durations = len(set(water_years))*[EWR_info1['duration']]
|
|
4929
|
-
skip_lines = 0
|
|
4930
|
-
gap_track = 0
|
|
4931
|
-
for i, flow in enumerate(flows):
|
|
4932
|
-
if skip_lines > 0:
|
|
4933
|
-
skip_lines -= 1
|
|
4934
|
-
else:
|
|
4935
|
-
no_event += 1
|
|
4936
|
-
if gap_track == -1:
|
|
4937
|
-
trigger = False
|
|
4938
|
-
if trigger == False:
|
|
4939
|
-
event, gap_track, trigger, total_event = check_trigger(EWR_info1, flow, event, gap_track, trigger, total_event)
|
|
4940
|
-
elif trigger == True: # Event registered, now check for event pre/post this
|
|
4941
|
-
gap_track = EWR_info1['gap_tolerance']
|
|
4942
|
-
# First check if there was an event before the main event:
|
|
4943
|
-
total_event_pre = total_event
|
|
4944
|
-
for pre_i, pre_flow in enumerate(reversed(flows[:(i-len(event))])):
|
|
4945
|
-
pre_event, gap_track, pre_trigger, total_event_pre = check_trigger(EWR_info2, pre_flow, pre_event, gap_track, pre_trigger, total_event_pre)
|
|
4946
|
-
if gap_track == -1: # If the pre event gap tolerance is exceeded, break
|
|
4947
|
-
pre_trigger = False
|
|
4948
|
-
pre_event = []
|
|
4949
|
-
total_event_pre = 0
|
|
4950
|
-
break
|
|
4951
|
-
if pre_trigger == True:
|
|
4952
|
-
event = list(reversed(pre_event)) + event
|
|
4953
|
-
water_year = which_water_year(i, total_event_pre, water_years)
|
|
4954
|
-
all_events[water_year].append(event)
|
|
4955
|
-
ne_water_year = which_water_year_no_event(i, total_event_pre, water_years)
|
|
4956
|
-
all_no_events[ne_water_year].append([no_event-len(event)])
|
|
4957
|
-
pre_event = []
|
|
4958
|
-
total_event_pre = 0
|
|
4959
|
-
trigger, pre_trigger, post_trigger = False, False, False
|
|
4960
|
-
break
|
|
4961
|
-
# If the above fails, enter sub routine to check for an event after:
|
|
4962
|
-
if pre_trigger == False:
|
|
4963
|
-
gap_track = EWR_info1['gap_tolerance']
|
|
4964
|
-
total_event_post = total_event
|
|
4965
|
-
for post_i, post_flow in enumerate(flows[i:]):
|
|
4966
|
-
post_event, gap_track, post_trigger, total_event_post = check_trigger(EWR_info2, post_flow, post_event, gap_track, post_trigger, total_event_post)
|
|
4967
|
-
if gap_track == -1:
|
|
4968
|
-
post_event = []
|
|
4969
|
-
total_event_post = 0
|
|
4970
|
-
trigger, pre_trigger, post_trigger = False, False, False
|
|
4971
|
-
break
|
|
4972
|
-
if post_trigger == True:
|
|
4973
|
-
water_year = which_water_year((i+post_i+2), total_event_post, water_years) #Check loc
|
|
4974
|
-
ne_water_year = which_water_year_no_event((i+post_i+1), total_event_post, water_years)
|
|
4975
|
-
all_no_events[ne_water_year].append([no_event-len(event)])
|
|
4976
|
-
no_event = 0
|
|
4977
|
-
event = event + post_event
|
|
4978
|
-
all_events[water_year].append(event)
|
|
4979
|
-
skip_lines = len(post_event) -1
|
|
4980
|
-
total_event_post = 0
|
|
4981
|
-
post_event = []
|
|
4982
|
-
trigger, pre_trigger, post_trigger = False, False, False
|
|
4983
|
-
break
|
|
4984
|
-
if pre_trigger == False and post_trigger == False:
|
|
4985
|
-
trigger, pre_trigger, post_trigger = False, False, False
|
|
4986
|
-
event, pre_event, post_event = [], [], []
|
|
4987
|
-
total_event = 0
|
|
4988
|
-
|
|
4989
|
-
if trigger == True and post_trigger == True:
|
|
4990
|
-
water_year = which_water_year(i, total_event, water_years)
|
|
4991
|
-
all_events[water_year].append(event)
|
|
4992
|
-
ne_water_year = which_water_year_no_event(i, total_event, water_years)
|
|
4993
|
-
all_no_events[ne_water_year].append([no_event-len(event)])
|
|
4994
|
-
no_event = 0
|
|
4995
|
-
if trigger == True and pre_trigger==True:
|
|
4996
|
-
water_year = which_water_year(i, total_event, water_years)
|
|
4997
|
-
all_events[water_year].append(event)
|
|
4998
|
-
ne_water_year = which_water_year_no_event(i, total_event, water_years)
|
|
4999
|
-
all_no_events[ne_water_year].append([no_event-len(event)])
|
|
5000
|
-
no_event = 0
|
|
5001
|
-
|
|
5002
|
-
if no_event > 0:
|
|
5003
|
-
all_no_events[water_years[-1]].append([no_event])
|
|
5004
|
-
|
|
5005
|
-
return all_events, all_no_events, durations
|
|
5006
4299
|
|
|
5007
4300
|
#------------------------------------ Stats on EWR events ----------------------------------------#
|
|
5008
4301
|
|
|
@@ -5508,75 +4801,6 @@ def get_total_series_days(water_years:List) -> pd.Series:
|
|
|
5508
4801
|
|
|
5509
4802
|
return intoSeries
|
|
5510
4803
|
|
|
5511
|
-
def event_years_sim(events1:List, events2:List) -> np.array:
|
|
5512
|
-
'''add the event lists, event only occurs when both are met.
|
|
5513
|
-
|
|
5514
|
-
Args:
|
|
5515
|
-
events1 (List): Annual years with events - (site 1)
|
|
5516
|
-
events2 (List): Annual years with events - (site 2)
|
|
5517
|
-
|
|
5518
|
-
Results:
|
|
5519
|
-
np.array: returns combined years with events array
|
|
5520
|
-
|
|
5521
|
-
'''
|
|
5522
|
-
added = np.array(list(events1)) + np.array(list(events2))
|
|
5523
|
-
mask = added == 2
|
|
5524
|
-
results = mask*1
|
|
5525
|
-
return results
|
|
5526
|
-
|
|
5527
|
-
def get_achievements_sim(events1:List, events2:List) -> List:
|
|
5528
|
-
'''get the minimum number of events for simultaneous EWRs.
|
|
5529
|
-
|
|
5530
|
-
Args:
|
|
5531
|
-
events1 (List): Annual EWR achievements - (site 1)
|
|
5532
|
-
events2 (List): Annual EWR achievements - (site 2)
|
|
5533
|
-
|
|
5534
|
-
Results:
|
|
5535
|
-
List: Annual achievements (minimum from each year chosen)
|
|
5536
|
-
|
|
5537
|
-
'''
|
|
5538
|
-
e1 = np.array(list(events1))
|
|
5539
|
-
e2 = np.array(list(events2))
|
|
5540
|
-
results = []
|
|
5541
|
-
for i, event in enumerate(e1):
|
|
5542
|
-
results.append(min([event, e2[i]]))
|
|
5543
|
-
return results
|
|
5544
|
-
|
|
5545
|
-
def get_number_events_sim(events1:List, events2:List) -> List:
|
|
5546
|
-
'''get the minimum number of events for simultaneous EWRs.
|
|
5547
|
-
|
|
5548
|
-
Args:
|
|
5549
|
-
events1 (List): Annual number of events - (site 1)
|
|
5550
|
-
events2 (List): Annual number of events - (site 2)
|
|
5551
|
-
|
|
5552
|
-
Results:
|
|
5553
|
-
List: Annual events (minimum from each year chosen)
|
|
5554
|
-
|
|
5555
|
-
'''
|
|
5556
|
-
e1 = np.array(list(events1))
|
|
5557
|
-
e2 = np.array(list(events2))
|
|
5558
|
-
results = []
|
|
5559
|
-
for i, event in enumerate(e1):
|
|
5560
|
-
results.append(min([event, e2[i]]))
|
|
5561
|
-
return results
|
|
5562
|
-
|
|
5563
|
-
def average_event_length_sim(events1:List, events2:List) -> List:
|
|
5564
|
-
'''get the average event length between two series.
|
|
5565
|
-
|
|
5566
|
-
Args:
|
|
5567
|
-
events1 (List): Annual average events lengths - (site 1)
|
|
5568
|
-
events2 (List): Annual average events lengths - (site 2)
|
|
5569
|
-
|
|
5570
|
-
Results:
|
|
5571
|
-
List: Annual average event length
|
|
5572
|
-
|
|
5573
|
-
'''
|
|
5574
|
-
|
|
5575
|
-
e1 = np.array([list(events1)])
|
|
5576
|
-
e2 = np.array([list(events2)])
|
|
5577
|
-
average = (e1 + e2)/2
|
|
5578
|
-
return average[0]
|
|
5579
|
-
|
|
5580
4804
|
def event_stats(df:pd.DataFrame, PU_df:pd.DataFrame, gauge:str, EWR:str, EWR_info:Dict, events:Dict, durations:List, water_years:List) -> pd.DataFrame:
|
|
5581
4805
|
''' Produces statistics based on the event dictionaries and event gap dictionaries.
|
|
5582
4806
|
|
|
@@ -5586,7 +4810,7 @@ def event_stats(df:pd.DataFrame, PU_df:pd.DataFrame, gauge:str, EWR:str, EWR_inf
|
|
|
5586
4810
|
gauge (str): current iteration gauge string
|
|
5587
4811
|
EWR (str): current iteration EWR string
|
|
5588
4812
|
EWR_info (Dict): Parameter information for current EWR
|
|
5589
|
-
events (Dict): Detailed event information
|
|
4813
|
+
events (Dict): Detailed event information events
|
|
5590
4814
|
durations (List): List of annual required durations
|
|
5591
4815
|
water_years (List): Daily water year values
|
|
5592
4816
|
|
|
@@ -5681,66 +4905,6 @@ def event_stats(df:pd.DataFrame, PU_df:pd.DataFrame, gauge:str, EWR:str, EWR_inf
|
|
|
5681
4905
|
|
|
5682
4906
|
return PU_df
|
|
5683
4907
|
|
|
5684
|
-
def event_stats_sim(df:pd.DataFrame, PU_df:pd.DataFrame, gauge:str, EWR:str, EWR_info:Dict, events1:Dict, events2:Dict, durations:List, water_years:List) -> pd.DataFrame:
|
|
5685
|
-
''' Produces statistics based on the event dictionaries and event gap dictionaries for simultaneous EWRs
|
|
5686
|
-
|
|
5687
|
-
Args:
|
|
5688
|
-
df (pd.DataFrame): Raw flow/level dataframe
|
|
5689
|
-
PU_df (pd.DataFrame): Dataframe with the results from the EWRs in the current planning unit
|
|
5690
|
-
gauge (str): current iteration gauge string
|
|
5691
|
-
EWR (str): current iteration EWR string
|
|
5692
|
-
EWR_info (Dict): Parameter information for current EWR
|
|
5693
|
-
events1 (Dict): Detailed event information (site 1)
|
|
5694
|
-
events2 (Dict): Detailed event information (site 2)
|
|
5695
|
-
no_events1 (Dict): Detailed event gap information (site 1)
|
|
5696
|
-
durations (List): List of annual required durations
|
|
5697
|
-
water_years (List): Daily water year values
|
|
5698
|
-
|
|
5699
|
-
Results:
|
|
5700
|
-
pd.DataFrame: Updated results dataframe for this current planning unit
|
|
5701
|
-
|
|
5702
|
-
'''
|
|
5703
|
-
unique_water_years = set(water_years)
|
|
5704
|
-
# Years with events
|
|
5705
|
-
years_with_events1 = get_event_years(EWR_info, events1, unique_water_years, durations)
|
|
5706
|
-
years_with_events2 = get_event_years(EWR_info, events2, unique_water_years, durations)
|
|
5707
|
-
years_with_events = event_years_sim(years_with_events1, years_with_events2)
|
|
5708
|
-
YWE = pd.Series(name = str(EWR + '_eventYears'), data = years_with_events, index = unique_water_years)
|
|
5709
|
-
PU_df = pd.concat([PU_df, YWE], axis = 1)
|
|
5710
|
-
# Number of event achievements per year
|
|
5711
|
-
num_events_ach_1 = get_achievements(EWR_info, events1, unique_water_years, durations)
|
|
5712
|
-
num_events_ach_2 = get_achievements(EWR_info, events2, unique_water_years, durations)
|
|
5713
|
-
num_events_ach = get_achievements_sim(num_events_ach_1, num_events_ach_2)
|
|
5714
|
-
NEA = pd.Series(name = str(EWR + '_numAchieved'), data= num_events_ach, index = unique_water_years)
|
|
5715
|
-
PU_df = pd.concat([PU_df, NEA], axis = 1)
|
|
5716
|
-
# Total number of event per year
|
|
5717
|
-
num_events1 = get_number_events(EWR_info, events1, unique_water_years, durations)
|
|
5718
|
-
num_events2 = get_number_events(EWR_info, events2, unique_water_years, durations)
|
|
5719
|
-
num_events = get_number_events_sim(num_events1, num_events2)
|
|
5720
|
-
NE = pd.Series(name = str(EWR + '_numEvents'), data= num_events, index = unique_water_years)
|
|
5721
|
-
PU_df = pd.concat([PU_df, NE], axis = 1)
|
|
5722
|
-
# Average length of events
|
|
5723
|
-
av_length1 = get_average_event_length(events1, unique_water_years)
|
|
5724
|
-
av_length2 = get_average_event_length(events2, unique_water_years)
|
|
5725
|
-
av_length = average_event_length_sim(av_length1, av_length2)
|
|
5726
|
-
AL = pd.Series(name = str(EWR + '_eventLength'), data = av_length, index = unique_water_years)
|
|
5727
|
-
PU_df = pd.concat([PU_df, AL], axis = 1)
|
|
5728
|
-
# Total event days
|
|
5729
|
-
total_days1 = get_total_days(events1, unique_water_years)
|
|
5730
|
-
total_days2 = get_total_days(events2, unique_water_years)
|
|
5731
|
-
av_total_days = average_event_length_sim(total_days1, total_days2)
|
|
5732
|
-
TD = pd.Series(name = str(EWR + '_totalEventDays'), data = av_total_days, index = unique_water_years)
|
|
5733
|
-
PU_df = pd.concat([PU_df, TD], axis = 1)
|
|
5734
|
-
# Append information around available and missing data:
|
|
5735
|
-
yearly_gap = get_data_gap(df, water_years, gauge) # Only adding data gap for main gauge
|
|
5736
|
-
total_days = get_total_series_days(water_years)
|
|
5737
|
-
YG = pd.Series(name = str(EWR + '_missingDays'), data = yearly_gap, index = unique_water_years)
|
|
5738
|
-
TD = pd.Series(name = str(EWR + '_totalPossibleDays'), data = total_days, index = unique_water_years)
|
|
5739
|
-
PU_df = pd.concat([PU_df, YG], axis = 1)
|
|
5740
|
-
PU_df = pd.concat([PU_df, TD], axis = 1)
|
|
5741
|
-
|
|
5742
|
-
return PU_df
|
|
5743
|
-
|
|
5744
4908
|
#-----------------------------Post processing-----------------------------------------------------#
|
|
5745
4909
|
|
|
5746
4910
|
def merge_weirpool_with_freshes(wp_freshes:List, PU_df:pd.DataFrame)-> pd.DataFrame:
|
|
@@ -5802,16 +4966,13 @@ def merge_weirpool_with_freshes(wp_freshes:List, PU_df:pd.DataFrame)-> pd.DataFr
|
|
|
5802
4966
|
HANDLING_FUNCTIONS = {
|
|
5803
4967
|
'ctf_handle':ctf_handle,
|
|
5804
4968
|
'ctf_handle_multi': ctf_handle_multi,
|
|
5805
|
-
'ctf_handle_sim': ctf_handle_sim,
|
|
5806
4969
|
'cumulative_handle': cumulative_handle,
|
|
5807
4970
|
'cumulative_handle_multi': cumulative_handle_multi,
|
|
5808
4971
|
'flow_handle': flow_handle,
|
|
5809
4972
|
'flow_handle_multi': flow_handle_multi,
|
|
5810
|
-
'flow_handle_sim': flow_handle_sim,
|
|
5811
4973
|
'level_handle': level_handle,
|
|
5812
4974
|
'lowflow_handle': lowflow_handle,
|
|
5813
4975
|
'lowflow_handle_multi': lowflow_handle_multi,
|
|
5814
|
-
'lowflow_handle_sim': lowflow_handle_sim,
|
|
5815
4976
|
'nest_handle': nest_handle,
|
|
5816
4977
|
'weirpool_handle' : weirpool_handle,
|
|
5817
4978
|
'flow_handle_sa': flow_handle_sa,
|
|
@@ -5827,7 +4988,7 @@ HANDLING_FUNCTIONS = {
|
|
|
5827
4988
|
'rise_and_fall_handle' : rise_and_fall_handle
|
|
5828
4989
|
}
|
|
5829
4990
|
|
|
5830
|
-
def get_gauge_calc_type(
|
|
4991
|
+
def get_gauge_calc_type(multigauge:bool)-> str:
|
|
5831
4992
|
"""Get the gauge calculation type
|
|
5832
4993
|
|
|
5833
4994
|
Args:
|
|
@@ -5838,12 +4999,8 @@ def get_gauge_calc_type(complex_:bool, multigauge:bool, simultaneous:bool)-> str
|
|
|
5838
4999
|
Returns:
|
|
5839
5000
|
str: gauge calculation type
|
|
5840
5001
|
"""
|
|
5841
|
-
if
|
|
5842
|
-
return 'complex'
|
|
5843
|
-
elif multigauge:
|
|
5002
|
+
if multigauge:
|
|
5844
5003
|
return 'multigauge'
|
|
5845
|
-
elif simultaneous:
|
|
5846
|
-
return 'simultaneous'
|
|
5847
5004
|
else:
|
|
5848
5005
|
return 'single'
|
|
5849
5006
|
|
|
@@ -5903,25 +5060,21 @@ def find_function(ewr_key:str, new_config_file:dict) -> str:
|
|
|
5903
5060
|
|
|
5904
5061
|
#---------------------------- Sorting and distributing to handling functions ---------------------#
|
|
5905
5062
|
|
|
5906
|
-
def calc_sorter(df_F:pd.DataFrame, df_L:pd.DataFrame, gauge:str,
|
|
5907
|
-
climate:str, EWR_table:pd.DataFrame, calc_config: dict) -> tuple:
|
|
5063
|
+
def calc_sorter(df_F:pd.DataFrame, df_L:pd.DataFrame, gauge:str, EWR_table:pd.DataFrame, calc_config: dict) -> tuple:
|
|
5908
5064
|
'''Sends to handling functions to get calculated depending on the type of EWR
|
|
5909
5065
|
|
|
5910
5066
|
Args:
|
|
5911
5067
|
df_F (pd.DataFrame): Dataframe with the daily flows
|
|
5912
5068
|
df_L (pd.DataFrame): Dataframe with the daily levels
|
|
5913
5069
|
gauge (str): gauge string of current iteration
|
|
5914
|
-
allowance (Dict): allowance applied to EWR elements
|
|
5915
|
-
climate (str): location string for the climate file
|
|
5916
5070
|
EWR_table (pd.DataFrame): Dataframe of EWR parameters
|
|
5917
5071
|
|
|
5918
5072
|
Results:
|
|
5919
5073
|
tuple[dict, dict]: annual results summary and detailed event information
|
|
5920
5074
|
|
|
5921
5075
|
'''
|
|
5922
|
-
# Get
|
|
5076
|
+
# Get EWR tables:
|
|
5923
5077
|
PU_items = EWR_table.groupby(['PlanningUnitID', 'PlanningUnitName']).size().reset_index().drop([0], axis=1)
|
|
5924
|
-
complex_EWRs = data_inputs.get_complex_calcs()
|
|
5925
5078
|
# Extract relevant sections of the EWR table:
|
|
5926
5079
|
gauge_table = EWR_table[EWR_table['Gauge'] == gauge]
|
|
5927
5080
|
# save the planning unit dataframes to this dictionary:
|
|
@@ -5938,13 +5091,7 @@ def calc_sorter(df_F:pd.DataFrame, df_L:pd.DataFrame, gauge:str, allowance:Dict,
|
|
|
5938
5091
|
desc= str('Evaluating ewrs for '+ gauge))):
|
|
5939
5092
|
events = {}
|
|
5940
5093
|
|
|
5941
|
-
# Get the overarching EWR category (flow/cumulative flow/level)
|
|
5942
|
-
# Determine if its classified as a complex EWR:
|
|
5943
|
-
COMPLEX = gauge in complex_EWRs and EWR in complex_EWRs[gauge]
|
|
5944
5094
|
MULTIGAUGE = is_multigauge(EWR_table, gauge, EWR, PU)
|
|
5945
|
-
# SIMULTANEOUS calculations is switched off
|
|
5946
|
-
# SIMULTANEOUS = PU in simultaneous_gauges and gauge in simultaneous_gauges[PU]
|
|
5947
|
-
SIMULTANEOUS = False
|
|
5948
5095
|
|
|
5949
5096
|
# Save dict with function arguments value
|
|
5950
5097
|
all_args = {"PU": PU,
|
|
@@ -5953,12 +5100,11 @@ def calc_sorter(df_F:pd.DataFrame, df_L:pd.DataFrame, gauge:str, allowance:Dict,
|
|
|
5953
5100
|
"EWR_table": EWR_table,
|
|
5954
5101
|
"df_F": df_F,
|
|
5955
5102
|
"df_L": df_L,
|
|
5956
|
-
"PU_df": PU_df,
|
|
5957
|
-
|
|
5958
|
-
"climate": climate}
|
|
5103
|
+
"PU_df": PU_df,
|
|
5104
|
+
}
|
|
5959
5105
|
|
|
5960
5106
|
cat = EWR_categories[i]
|
|
5961
|
-
gauge_calc_type = get_gauge_calc_type(
|
|
5107
|
+
gauge_calc_type = get_gauge_calc_type(MULTIGAUGE)
|
|
5962
5108
|
ewr_key = f'{EWR}-{gauge_calc_type}-{cat}'
|
|
5963
5109
|
function_name = find_function(ewr_key, calc_config)
|
|
5964
5110
|
if function_name == 'unknown':
|
|
@@ -5970,10 +5116,6 @@ def calc_sorter(df_F:pd.DataFrame, df_L:pd.DataFrame, gauge:str, allowance:Dict,
|
|
|
5970
5116
|
log.warning(f"add {ewr_key} to the configuration file in the appropriate handle function")
|
|
5971
5117
|
continue
|
|
5972
5118
|
kwargs = build_args(all_args, handle_function)
|
|
5973
|
-
|
|
5974
|
-
if COMPLEX:
|
|
5975
|
-
log.warning(f"skipping due to not validated calculations for {PU}-{gauge}-{EWR}")
|
|
5976
|
-
continue
|
|
5977
5119
|
|
|
5978
5120
|
PU_df, events = handle_function(**kwargs)
|
|
5979
5121
|
if events != {}:
|