py-ewr 2.3.8__py3-none-any.whl → 2.4.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 +39 -12
- py_ewr/evaluate_EWRs.py +168 -221
- py_ewr/model_metadata/EWR_Sitelist_FIRM_20250718.csv +11 -2
- py_ewr/observed_handling.py +22 -5
- py_ewr/parameter_metadata/ewr_calc_config.json +71 -2
- py_ewr/parameter_metadata/objective_reference.csv +911 -0
- py_ewr/parameter_metadata/parameter_sheet.csv +3249 -3443
- py_ewr/scenario_handling.py +7 -7
- py_ewr/summarise_results.py +2 -2
- {py_ewr-2.3.8.dist-info → py_ewr-2.4.0.dist-info}/METADATA +22 -22
- py_ewr-2.4.0.dist-info/RECORD +19 -0
- {py_ewr-2.3.8.dist-info → py_ewr-2.4.0.dist-info}/WHEEL +1 -1
- py_ewr/parameter_metadata/objective_reference_NB_SA_WIM_NE_LACH_BIDG_MLD_ACT.csv +0 -806
- py_ewr/parameter_metadata/parameter_sheet_NB_SA_WIM_NE_LACH_BIDG_MLD_ACT.csv +0 -3127
- py_ewr/parameter_metadata/parameter_sheet_NB_SA_WIM_NE_LACH_BIDG_MLD_ACT_added_act_env.csv +0 -3188
- py_ewr-2.3.8.dist-info/RECORD +0 -21
- {py_ewr-2.3.8.dist-info → py_ewr-2.4.0.dist-info}/licenses/LICENSE +0 -0
- {py_ewr-2.3.8.dist-info → py_ewr-2.4.0.dist-info}/top_level.txt +0 -0
py_ewr/evaluate_EWRs.py
CHANGED
|
@@ -22,7 +22,7 @@ warnings.simplefilter(action='ignore', category=pd.errors.PerformanceWarning)
|
|
|
22
22
|
|
|
23
23
|
def component_pull(EWR_table: pd.DataFrame, gauge: str, pu: str, ewr: str, component: str, pu_ID: bool = True) -> str:
|
|
24
24
|
'''Pass ewr details (planning unit, gauge, ewr, and ewr component) and the ewr table,
|
|
25
|
-
this function will then pull the component from the table.
|
|
25
|
+
this function will then pull the component from the table.
|
|
26
26
|
|
|
27
27
|
Args:
|
|
28
28
|
EWR_table (pd.DataFrame): Dataframe of EWRs
|
|
@@ -302,7 +302,7 @@ def ctf_handle(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame, df_F: pd.
|
|
|
302
302
|
PU_df (pd.DataFrame): ewr results for the current planning unit iteration
|
|
303
303
|
|
|
304
304
|
Results:
|
|
305
|
-
tuple[pd.DataFrame,
|
|
305
|
+
tuple[pd.DataFrame, dict]: ewr results for the current planning unit iteration (updated); dictionary of ewr event information
|
|
306
306
|
|
|
307
307
|
'''
|
|
308
308
|
# Get information about ewr:
|
|
@@ -314,11 +314,11 @@ def ctf_handle(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame, df_F: pd.
|
|
|
314
314
|
water_years = wateryear_daily(df_F, EWR_info)
|
|
315
315
|
# Check flow data against ewr requirements and then perform analysis on the results:
|
|
316
316
|
if ((EWR_info['start_month'] == 7) and (EWR_info['end_month'] == 6)):
|
|
317
|
-
E
|
|
317
|
+
E = ctf_calc_anytime(EWR_info, df_F[gauge].values, water_years, df_F.index)
|
|
318
318
|
else:
|
|
319
|
-
E
|
|
320
|
-
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E,
|
|
321
|
-
return PU_df,
|
|
319
|
+
E = ctf_calc(EWR_info, df_F[gauge].values, water_years, df_F.index, masked_dates)
|
|
320
|
+
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E, water_years)
|
|
321
|
+
return PU_df, E
|
|
322
322
|
|
|
323
323
|
def lowflow_handle(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame) -> tuple:
|
|
324
324
|
'''For handling low flow type EWRs (Very low flows and baseflows)
|
|
@@ -332,7 +332,7 @@ def lowflow_handle(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame, df_F:
|
|
|
332
332
|
PU_df (pd.DataFrame): ewr results for the current planning unit iteration
|
|
333
333
|
|
|
334
334
|
Results:
|
|
335
|
-
tuple[pd.DataFrame,
|
|
335
|
+
tuple[pd.DataFrame, dict]: ewr results for the current planning unit iteration (updated); dictionary of ewr event information
|
|
336
336
|
|
|
337
337
|
'''
|
|
338
338
|
# Get information about ewr:
|
|
@@ -343,9 +343,9 @@ def lowflow_handle(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame, df_F:
|
|
|
343
343
|
# Extract a daily timeseries for water years
|
|
344
344
|
water_years = wateryear_daily(df_F, EWR_info)
|
|
345
345
|
# Check flow data against ewr requirements and then perform analysis on the results:
|
|
346
|
-
E
|
|
347
|
-
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E,
|
|
348
|
-
return PU_df,
|
|
346
|
+
E = lowflow_calc(EWR_info, df_F[gauge].values, water_years, df_F.index, masked_dates)
|
|
347
|
+
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E, water_years)
|
|
348
|
+
return PU_df, E
|
|
349
349
|
|
|
350
350
|
def flow_handle(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame) -> tuple:
|
|
351
351
|
'''For handling non low flow based flow EWRs (freshes, bankfulls, overbanks)
|
|
@@ -359,7 +359,7 @@ def flow_handle(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame, df_F: pd
|
|
|
359
359
|
PU_df (pd.DataFrame): ewr results for the current planning unit iteration
|
|
360
360
|
|
|
361
361
|
Results:
|
|
362
|
-
tuple[pd.DataFrame,
|
|
362
|
+
tuple[pd.DataFrame, dict]: ewr results for the current planning unit iteration (updated); dictionary of ewr event information
|
|
363
363
|
|
|
364
364
|
'''
|
|
365
365
|
# Get information about ewr:
|
|
@@ -370,9 +370,9 @@ def flow_handle(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame, df_F: pd
|
|
|
370
370
|
# Extract a daily timeseries for water years
|
|
371
371
|
water_years = wateryear_daily(df_F, EWR_info)
|
|
372
372
|
# Check flow data against ewr requirements and then perform analysis on the results:
|
|
373
|
-
E
|
|
374
|
-
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E,
|
|
375
|
-
return PU_df,
|
|
373
|
+
E = flow_calc(EWR_info, df_F[gauge].values, water_years, df_F.index, masked_dates)
|
|
374
|
+
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E, water_years)
|
|
375
|
+
return PU_df, E
|
|
376
376
|
|
|
377
377
|
def flow_handle_anytime(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame) -> tuple:
|
|
378
378
|
'''For handling flow based flow EWRs (freshes, bankfulls, overbanks) to allow flows to continue to record
|
|
@@ -388,7 +388,7 @@ def flow_handle_anytime(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame,
|
|
|
388
388
|
|
|
389
389
|
|
|
390
390
|
Results:
|
|
391
|
-
tuple[pd.DataFrame,
|
|
391
|
+
tuple[pd.DataFrame, dict]: ewr results for the current planning unit iteration (updated); dictionary of ewr event information
|
|
392
392
|
|
|
393
393
|
'''
|
|
394
394
|
# Get information about ewr:
|
|
@@ -400,11 +400,11 @@ def flow_handle_anytime(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame,
|
|
|
400
400
|
water_years = wateryear_daily(df_F, EWR_info)
|
|
401
401
|
# Check flow data against ewr requirements and then perform analysis on the results
|
|
402
402
|
if ((EWR_info['start_month'] == 7) and (EWR_info['end_month'] == 6)):
|
|
403
|
-
E
|
|
403
|
+
E = flow_calc_anytime(EWR_info, df_F[gauge].values, water_years, df_F.index)
|
|
404
404
|
else:
|
|
405
|
-
E
|
|
406
|
-
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E,
|
|
407
|
-
return PU_df,
|
|
405
|
+
E = flow_calc(EWR_info, df_F[gauge].values, water_years, df_F.index, masked_dates)
|
|
406
|
+
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E, water_years)
|
|
407
|
+
return PU_df, E
|
|
408
408
|
|
|
409
409
|
def flow_handle_check_ctf(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame) -> tuple:
|
|
410
410
|
'''For handling non low flow based flow EWRs
|
|
@@ -418,7 +418,7 @@ def flow_handle_check_ctf(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame
|
|
|
418
418
|
PU_df (pd.DataFrame): ewr results for the current planning unit iteration
|
|
419
419
|
|
|
420
420
|
Results:
|
|
421
|
-
tuple[pd.DataFrame,
|
|
421
|
+
tuple[pd.DataFrame, dict]: ewr results for the current planning unit iteration (updated); dictionary of ewr event information
|
|
422
422
|
|
|
423
423
|
'''
|
|
424
424
|
# Get information about ewr:
|
|
@@ -429,9 +429,9 @@ def flow_handle_check_ctf(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame
|
|
|
429
429
|
# Extract a daily timeseries for water years
|
|
430
430
|
water_years = wateryear_daily(df_F, EWR_info)
|
|
431
431
|
# Check flow data against ewr requirements and then perform analysis on the results:
|
|
432
|
-
E
|
|
433
|
-
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E,
|
|
434
|
-
return PU_df,
|
|
432
|
+
E = flow_calc_check_ctf(EWR_info, df_F[gauge].values, water_years, df_F.index, masked_dates)
|
|
433
|
+
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E, water_years)
|
|
434
|
+
return PU_df, E
|
|
435
435
|
|
|
436
436
|
def cumulative_handle(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame):
|
|
437
437
|
'''For handling cumulative flow EWRs (some large freshes and overbanks, wetland flows).
|
|
@@ -455,10 +455,10 @@ def cumulative_handle(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame, df
|
|
|
455
455
|
masked_dates = mask_dates(EWR_info, df_F)
|
|
456
456
|
# Extract a daily timeseries for water years
|
|
457
457
|
water_years = wateryear_daily(df_F, EWR_info)
|
|
458
|
-
E
|
|
459
|
-
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E,
|
|
458
|
+
E = cumulative_calc(EWR_info, df_F[gauge].values, water_years, df_F.index, masked_dates)
|
|
459
|
+
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E, water_years)
|
|
460
460
|
|
|
461
|
-
return PU_df,
|
|
461
|
+
return PU_df, E
|
|
462
462
|
|
|
463
463
|
def cumulative_handle_qld(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame):
|
|
464
464
|
'''For handling cumulative flow EWRs this to meet QLD requirements for bird breeding type 2.
|
|
@@ -482,10 +482,10 @@ def cumulative_handle_qld(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame
|
|
|
482
482
|
masked_dates = mask_dates(EWR_info, df_F)
|
|
483
483
|
# Extract a daily timeseries for water years
|
|
484
484
|
water_years = wateryear_daily(df_F, EWR_info)
|
|
485
|
-
E
|
|
486
|
-
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E,
|
|
485
|
+
E = cumulative_calc_qld(EWR_info, df_F[gauge].values, water_years, df_F.index, masked_dates)
|
|
486
|
+
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E, water_years)
|
|
487
487
|
|
|
488
|
-
return PU_df,
|
|
488
|
+
return PU_df, E
|
|
489
489
|
|
|
490
490
|
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):
|
|
491
491
|
'''For handling cumulative flow EWRs (for bird breeding ewr QLD).
|
|
@@ -517,10 +517,10 @@ def cumulative_handle_bbr(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame
|
|
|
517
517
|
return PU_df, None
|
|
518
518
|
# Extract a daily timeseries for water years
|
|
519
519
|
water_years = wateryear_daily(df_F, EWR_info)
|
|
520
|
-
E
|
|
521
|
-
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E,
|
|
520
|
+
E = cumulative_calc_bbr(EWR_info, df_F[gauge].values, levels, water_years, df_F.index, masked_dates)
|
|
521
|
+
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E, water_years)
|
|
522
522
|
|
|
523
|
-
return PU_df,
|
|
523
|
+
return PU_df, E
|
|
524
524
|
|
|
525
525
|
def water_stability_handle(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, df_L: pd.DataFrame,
|
|
526
526
|
PU_df: pd.DataFrame):
|
|
@@ -553,10 +553,10 @@ def water_stability_handle(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFram
|
|
|
553
553
|
return PU_df, None
|
|
554
554
|
# Extract a daily timeseries for water years
|
|
555
555
|
water_years = wateryear_daily(df_F, EWR_info)
|
|
556
|
-
E
|
|
557
|
-
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E,
|
|
556
|
+
E = water_stability_calc(EWR_info, df_F[gauge].values, levels, water_years, df_F.index, masked_dates)
|
|
557
|
+
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E, water_years)
|
|
558
558
|
|
|
559
|
-
return PU_df,
|
|
559
|
+
return PU_df, E
|
|
560
560
|
|
|
561
561
|
def water_stability_level_handle(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame, df_L: pd.DataFrame, PU_df: pd.DataFrame):
|
|
562
562
|
'''For handling Fish Recruitment with water stability requirement (QLD).
|
|
@@ -588,10 +588,10 @@ def water_stability_level_handle(pu: str, gauge: str, ewr: str, EWR_table: pd.Da
|
|
|
588
588
|
return PU_df, None
|
|
589
589
|
# Extract a daily timeseries for water years
|
|
590
590
|
water_years = wateryear_daily(df_L, EWR_info)
|
|
591
|
-
E
|
|
592
|
-
PU_df = event_stats(df_L, PU_df, gauge, ewr, EWR_info, E,
|
|
591
|
+
E = water_stability_level_calc(EWR_info, levels, water_years, df_L.index, masked_dates)
|
|
592
|
+
PU_df = event_stats(df_L, PU_df, gauge, ewr, EWR_info, E, water_years)
|
|
593
593
|
|
|
594
|
-
return PU_df,
|
|
594
|
+
return PU_df, E
|
|
595
595
|
|
|
596
596
|
def level_handle(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame, df_L: pd.DataFrame, PU_df: pd.DataFrame) -> tuple:
|
|
597
597
|
'''For handling level type EWRs (low, mid, high and very high level lake fills).
|
|
@@ -615,9 +615,9 @@ def level_handle(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame, df_L: p
|
|
|
615
615
|
masked_dates = mask_dates(EWR_info, df_L)
|
|
616
616
|
# Extract a daily timeseries for water years
|
|
617
617
|
water_years = wateryear_daily(df_L, EWR_info)
|
|
618
|
-
E
|
|
619
|
-
PU_df = event_stats(df_L, PU_df, gauge, ewr, EWR_info, E,
|
|
620
|
-
return PU_df,
|
|
618
|
+
E = lake_calc(EWR_info, df_L[gauge].values, water_years, df_L.index, masked_dates)
|
|
619
|
+
PU_df = event_stats(df_L, PU_df, gauge, ewr, EWR_info, E, water_years)
|
|
620
|
+
return PU_df, E
|
|
621
621
|
|
|
622
622
|
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:
|
|
623
623
|
'''For handling weirpool type EWRs.
|
|
@@ -632,7 +632,7 @@ def weirpool_handle(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame, df_F
|
|
|
632
632
|
PU_df (pd.DataFrame): ewr results for the current planning unit iteration
|
|
633
633
|
|
|
634
634
|
Results:
|
|
635
|
-
tuple[pd.DataFrame,
|
|
635
|
+
tuple[pd.DataFrame, dict]: ewr results for the current planning unit iteration (updated); dictionary of ewr event information
|
|
636
636
|
|
|
637
637
|
'''
|
|
638
638
|
|
|
@@ -656,9 +656,9 @@ def weirpool_handle(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame, df_F
|
|
|
656
656
|
also needs data for level gauge {EWR_info.get('weirpool_gauge', 'no wp gauge')}''')
|
|
657
657
|
return PU_df, None
|
|
658
658
|
# Check flow and level data against ewr requirements and then perform analysis on the results:
|
|
659
|
-
E
|
|
660
|
-
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E,
|
|
661
|
-
return PU_df,
|
|
659
|
+
E = weirpool_calc(EWR_info, df_F[gauge].values, levels, water_years, weirpool_type, df_F.index, masked_dates)
|
|
660
|
+
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E, water_years)
|
|
661
|
+
return PU_df, E
|
|
662
662
|
|
|
663
663
|
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:
|
|
664
664
|
'''For handling nest style EWRs.
|
|
@@ -673,7 +673,7 @@ def nest_handle(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame, df_F: pd
|
|
|
673
673
|
PU_df (pd.DataFrame): ewr results for the current planning unit iteration
|
|
674
674
|
|
|
675
675
|
Results:
|
|
676
|
-
tuple[pd.DataFrame,
|
|
676
|
+
tuple[pd.DataFrame, dict]: ewr results for the current planning unit iteration (updated); dictionary of ewr event information
|
|
677
677
|
|
|
678
678
|
'''
|
|
679
679
|
# Get information about ewr (changes depending on if theres a weirpool level gauge in the ewr)
|
|
@@ -691,7 +691,7 @@ def nest_handle(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame, df_F: pd
|
|
|
691
691
|
if not requires_weirpool_gauge:
|
|
692
692
|
try:
|
|
693
693
|
# calculate based on a trigger date and % drawdown drop
|
|
694
|
-
E
|
|
694
|
+
E = nest_calc_percent_trigger(EWR_info, df_F[gauge].values, water_years, df_F.index)
|
|
695
695
|
except ValueError:
|
|
696
696
|
log.info(f"""Please pass a value to TriggerMonth between 1..12 and TriggerDay you passed
|
|
697
697
|
TriggerMonth:{EWR_info['trigger_month']} TriggerDay:{EWR_info['trigger_day']} """)
|
|
@@ -707,13 +707,13 @@ def nest_handle(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame, df_F: pd
|
|
|
707
707
|
return PU_df, None
|
|
708
708
|
# handle any error in missing values in parameter sheet
|
|
709
709
|
try:
|
|
710
|
-
E
|
|
710
|
+
E = nest_calc_weirpool(EWR_info, df_F[gauge].values, levels, water_years, df_F.index, masked_dates)
|
|
711
711
|
except KeyError:
|
|
712
712
|
log.info(f'''Cannot evaluate this ewr for {gauge} {ewr}, due to missing parameter data. Specifically this ewr
|
|
713
713
|
also needs data for level threshold min or level threshold max''')
|
|
714
714
|
return PU_df, None
|
|
715
|
-
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E,
|
|
716
|
-
return PU_df,
|
|
715
|
+
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E, water_years)
|
|
716
|
+
return PU_df, E
|
|
717
717
|
|
|
718
718
|
def flow_handle_multi(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame) -> tuple:
|
|
719
719
|
'''For handling flow EWRs where flow needs to be combined at two gauges
|
|
@@ -727,7 +727,7 @@ def flow_handle_multi(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame, df
|
|
|
727
727
|
PU_df (pd.DataFrame): ewr results for the current planning unit iteration
|
|
728
728
|
|
|
729
729
|
Results:
|
|
730
|
-
tuple[pd.DataFrame,
|
|
730
|
+
tuple[pd.DataFrame, dict]: ewr results for the current planning unit iteration (updated); dictionary of ewr event information
|
|
731
731
|
|
|
732
732
|
'''
|
|
733
733
|
# Get information about the ewr:
|
|
@@ -749,9 +749,9 @@ def flow_handle_multi(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame, df
|
|
|
749
749
|
summed flows at these two gauges.''')
|
|
750
750
|
flows = flows1
|
|
751
751
|
|
|
752
|
-
E
|
|
753
|
-
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E,
|
|
754
|
-
return PU_df,
|
|
752
|
+
E = flow_calc(EWR_info, flows, water_years, df_F.index, masked_dates)
|
|
753
|
+
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E, water_years)
|
|
754
|
+
return PU_df, E
|
|
755
755
|
|
|
756
756
|
def lowflow_handle_multi(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame) -> tuple:
|
|
757
757
|
'''For handling low flow EWRs where flow needs to be combined at two gauges.
|
|
@@ -787,9 +787,9 @@ def lowflow_handle_multi(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame,
|
|
|
787
787
|
summed flows at these two gauges.''')
|
|
788
788
|
flows = flows1
|
|
789
789
|
# Check flow data against ewr requirements and then perform analysis on the results:
|
|
790
|
-
E
|
|
791
|
-
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E,
|
|
792
|
-
return PU_df,
|
|
790
|
+
E = lowflow_calc(EWR_info, flows, water_years, df_F.index, masked_dates)
|
|
791
|
+
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E, water_years)
|
|
792
|
+
return PU_df, E
|
|
793
793
|
|
|
794
794
|
def ctf_handle_multi(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame) -> tuple:
|
|
795
795
|
'''For handling cease to flow EWRs where flow needs to be combined at two gauges
|
|
@@ -826,11 +826,11 @@ def ctf_handle_multi(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame, df_
|
|
|
826
826
|
flows = flows1
|
|
827
827
|
# Check flow data against ewr requirements and then perform analysis on the results:
|
|
828
828
|
if ((EWR_info['start_month'] == 7) and (EWR_info['end_month'] == 6)):
|
|
829
|
-
E
|
|
829
|
+
E = ctf_calc_anytime(EWR_info, df_F[gauge].values, water_years, df_F.index)
|
|
830
830
|
else:
|
|
831
|
-
E
|
|
832
|
-
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E,
|
|
833
|
-
return PU_df,
|
|
831
|
+
E = ctf_calc(EWR_info, df_F[gauge].values, water_years, df_F.index, masked_dates)
|
|
832
|
+
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E, water_years)
|
|
833
|
+
return PU_df, E
|
|
834
834
|
|
|
835
835
|
def cumulative_handle_multi(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame) -> tuple:
|
|
836
836
|
'''For handling cumulative volume EWRs where flow needs to be combined at two gauges.
|
|
@@ -865,9 +865,9 @@ def cumulative_handle_multi(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFra
|
|
|
865
865
|
flow at the gauge {gauge}. If you are running a model scenario through please disregard this message - most hydrology models have already
|
|
866
866
|
summed flows at these two gauges.''')
|
|
867
867
|
flows = flows1
|
|
868
|
-
E
|
|
869
|
-
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E,
|
|
870
|
-
return PU_df,
|
|
868
|
+
E = cumulative_calc(EWR_info, flows, water_years, df_F.index, masked_dates)
|
|
869
|
+
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E, water_years)
|
|
870
|
+
return PU_df, E
|
|
871
871
|
|
|
872
872
|
|
|
873
873
|
def flow_handle_sa(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame) -> tuple:
|
|
@@ -895,9 +895,9 @@ def flow_handle_sa(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame, df_F:
|
|
|
895
895
|
# Extract a daily timeseries for water years:
|
|
896
896
|
water_years = wateryear_daily(df_F, EWR_info)
|
|
897
897
|
|
|
898
|
-
E
|
|
899
|
-
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E,
|
|
900
|
-
return PU_df,
|
|
898
|
+
E = flow_calc_sa(EWR_info, df_F[gauge].values, water_years, df_F.index, masked_dates)
|
|
899
|
+
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E, water_years)
|
|
900
|
+
return PU_df, E
|
|
901
901
|
|
|
902
902
|
def barrage_flow_handle(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame, df_F: pd.DataFrame, PU_df: pd.DataFrame) -> tuple:
|
|
903
903
|
"""handle function to calculate barrage flow type EWRs
|
|
@@ -927,9 +927,9 @@ def barrage_flow_handle(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame,
|
|
|
927
927
|
# If there is no level data loaded in, let user know and skip the analysis
|
|
928
928
|
df = df_F.copy(deep=True)
|
|
929
929
|
df['combined_flow'] = df[all_required_gauges].sum(axis=1)
|
|
930
|
-
E
|
|
931
|
-
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E,
|
|
932
|
-
return PU_df,
|
|
930
|
+
E = barrage_flow_calc(EWR_info, df['combined_flow'], water_years, df_F.index)
|
|
931
|
+
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E, water_years)
|
|
932
|
+
return PU_df, E
|
|
933
933
|
else:
|
|
934
934
|
print(f'Missing data for barrage gauges {" ".join(all_required_gauges)}')
|
|
935
935
|
return PU_df, None
|
|
@@ -969,12 +969,12 @@ def barrage_level_handle(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame,
|
|
|
969
969
|
df_5_day_averages['mean'] = df[all_required_gauges_in_df_L].mean(axis=1)
|
|
970
970
|
cllmm_type = what_cllmm_type(EWR_info)
|
|
971
971
|
if cllmm_type == 'c':
|
|
972
|
-
E
|
|
972
|
+
E = lower_lakes_level_calc(EWR_info, df_5_day_averages['mean'], water_years, df_L.index, masked_dates)
|
|
973
973
|
if cllmm_type == 'd':
|
|
974
|
-
E
|
|
974
|
+
E = coorong_level_calc(EWR_info, df_5_day_averages['mean'], water_years, df_L.index, masked_dates)
|
|
975
975
|
|
|
976
|
-
PU_df = event_stats(df_L, PU_df, gauge, ewr, EWR_info, E,
|
|
977
|
-
return PU_df,
|
|
976
|
+
PU_df = event_stats(df_L, PU_df, gauge, ewr, EWR_info, E, water_years)
|
|
977
|
+
return PU_df, E
|
|
978
978
|
|
|
979
979
|
else:
|
|
980
980
|
print(f'skipping calculation because gauge {" ".join(all_required_gauges)} is not the main barrage level gauge ') #TODO: improve error message
|
|
@@ -1006,17 +1006,17 @@ def rise_and_fall_handle(pu: str, gauge: str, ewr: str, EWR_table: pd.DataFrame,
|
|
|
1006
1006
|
water_years = wateryear_daily(df_F, EWR_info)
|
|
1007
1007
|
|
|
1008
1008
|
if 'RRF' in ewr:
|
|
1009
|
-
E
|
|
1009
|
+
E = rate_rise_flow_calc(EWR_info, df_F[gauge].values, water_years, df_F.index, masked_dates)
|
|
1010
1010
|
if 'RFF' in ewr:
|
|
1011
|
-
E
|
|
1011
|
+
E = rate_fall_flow_calc(EWR_info, df_F[gauge].values, water_years, df_F.index, masked_dates)
|
|
1012
1012
|
if 'RRL' in ewr:
|
|
1013
|
-
E
|
|
1013
|
+
E = rate_rise_level_calc(EWR_info, df_L[gauge].values, water_years, df_F.index, masked_dates)
|
|
1014
1014
|
if 'RFL' in ewr:
|
|
1015
|
-
E
|
|
1015
|
+
E = rate_fall_level_calc(EWR_info, df_L[gauge].values, water_years, df_F.index, masked_dates)
|
|
1016
1016
|
|
|
1017
|
-
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E,
|
|
1017
|
+
PU_df = event_stats(df_F, PU_df, gauge, ewr, EWR_info, E, water_years)
|
|
1018
1018
|
|
|
1019
|
-
return PU_df,
|
|
1019
|
+
return PU_df, E
|
|
1020
1020
|
|
|
1021
1021
|
|
|
1022
1022
|
#---------------------------------------- Checking EWRs ------------------------------------------#
|
|
@@ -2788,13 +2788,12 @@ def lowflow_calc(EWR_info: dict, flows: np.array, water_years: np.array, dates:
|
|
|
2788
2788
|
masked_dates (set): Dates within required date range
|
|
2789
2789
|
|
|
2790
2790
|
Results:
|
|
2791
|
-
|
|
2791
|
+
dict: dictionary of all events and event gaps in timeseries.
|
|
2792
2792
|
|
|
2793
2793
|
'''
|
|
2794
2794
|
# Declare variables:
|
|
2795
2795
|
event = []
|
|
2796
2796
|
all_events = construct_event_dict(water_years)
|
|
2797
|
-
durations = []
|
|
2798
2797
|
# Iterate over daily flow, sending to the lowflow_check function for each iteration
|
|
2799
2798
|
for i, flow in enumerate(flows[:-1]):
|
|
2800
2799
|
if dates[i] in masked_dates:
|
|
@@ -2805,7 +2804,6 @@ def lowflow_calc(EWR_info: dict, flows: np.array, water_years: np.array, dates:
|
|
|
2805
2804
|
if len(event) > 0:
|
|
2806
2805
|
all_events[water_years[i]].append(event)
|
|
2807
2806
|
event = [] # Reset at the end of the water year
|
|
2808
|
-
durations.append(EWR_info['duration'])
|
|
2809
2807
|
|
|
2810
2808
|
# Check the final iteration, saving any ongoing events/event gaps to their spots in the dictionaries
|
|
2811
2809
|
if dates[-1] in masked_dates:
|
|
@@ -2813,8 +2811,7 @@ def lowflow_calc(EWR_info: dict, flows: np.array, water_years: np.array, dates:
|
|
|
2813
2811
|
event, all_events = lowflow_check(EWR_info, -1, flows[-1], event, all_events, water_years, flow_date)
|
|
2814
2812
|
if len(event) > 0:
|
|
2815
2813
|
all_events[water_years[-1]].append(event)
|
|
2816
|
-
|
|
2817
|
-
return all_events, durations
|
|
2814
|
+
return all_events
|
|
2818
2815
|
|
|
2819
2816
|
def ctf_calc_anytime(EWR_info: dict, flows: np.array, water_years: np.array, dates: np.array) -> tuple:
|
|
2820
2817
|
'''For calculating cease to flow ewrs. These have a consecutive requirement on their durations
|
|
@@ -2828,30 +2825,23 @@ def ctf_calc_anytime(EWR_info: dict, flows: np.array, water_years: np.array, dat
|
|
|
2828
2825
|
dates (np.array): array of dates
|
|
2829
2826
|
|
|
2830
2827
|
Results:
|
|
2831
|
-
|
|
2828
|
+
dict: dictionary of all events and event gaps in timeseries.
|
|
2832
2829
|
|
|
2833
2830
|
'''
|
|
2834
2831
|
# Declare variables:
|
|
2835
2832
|
event = []
|
|
2836
2833
|
all_events = construct_event_dict(water_years)
|
|
2837
|
-
durations = []
|
|
2838
2834
|
# Iterate over daily flow, sending to the ctf_check function each iteration:
|
|
2839
2835
|
for i, flow in enumerate(flows[:-1]):
|
|
2840
2836
|
flow_date = dates[i]
|
|
2841
2837
|
event, all_events = ctf_check(EWR_info, i, flow, event, all_events, water_years, flow_date)
|
|
2842
|
-
# At the end of each water year, save any ongoing events and event gaps to the dictionaries, and reset the list and counter
|
|
2843
|
-
if water_years[i] != water_years[i+1]:
|
|
2844
|
-
durations.append(EWR_info['duration'])
|
|
2845
2838
|
# Check final iteration in the flow timeseries, saving any ongoing events/event gaps to their spots in the dictionaries:
|
|
2846
2839
|
flow_date = dates[-1]
|
|
2847
2840
|
event, all_events = ctf_check(EWR_info, -1, flows[-1], event, all_events, water_years, flow_date)
|
|
2848
2841
|
if len(event) > 0:
|
|
2849
2842
|
all_events[water_years[-1]].append(event)
|
|
2850
2843
|
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
return all_events, durations
|
|
2854
|
-
|
|
2844
|
+
return all_events
|
|
2855
2845
|
|
|
2856
2846
|
def ctf_calc(EWR_info: dict, flows: np.array, water_years: np.array, dates: np.array, masked_dates: set) -> tuple:
|
|
2857
2847
|
'''For calculating cease to flow ewrs. These have a consecutive requirement on their durations
|
|
@@ -2859,7 +2849,7 @@ def ctf_calc(EWR_info: dict, flows: np.array, water_years: np.array, dates: np.a
|
|
|
2859
2849
|
water year.
|
|
2860
2850
|
|
|
2861
2851
|
Args:
|
|
2862
|
-
EWR_info (dict): dictionary with the parameter info of the
|
|
2852
|
+
EWR_info (dict): dictionary with the parameter info of the EWR being calculated
|
|
2863
2853
|
flows (np.array): array of daily flows
|
|
2864
2854
|
water_years (np.array): array of daily water year values
|
|
2865
2855
|
dates (np.array): array of dates
|
|
@@ -2872,7 +2862,6 @@ def ctf_calc(EWR_info: dict, flows: np.array, water_years: np.array, dates: np.a
|
|
|
2872
2862
|
# Declare variables:
|
|
2873
2863
|
event = []
|
|
2874
2864
|
all_events = construct_event_dict(water_years)
|
|
2875
|
-
durations = []
|
|
2876
2865
|
# Iterate over daily flow, sending to the ctf_check function each iteration:
|
|
2877
2866
|
for i, flow in enumerate(flows[:-1]):
|
|
2878
2867
|
if dates[i] in masked_dates:
|
|
@@ -2883,16 +2872,14 @@ def ctf_calc(EWR_info: dict, flows: np.array, water_years: np.array, dates: np.a
|
|
|
2883
2872
|
if len(event) > 0:
|
|
2884
2873
|
all_events[water_years[i]].append(event)
|
|
2885
2874
|
event = []
|
|
2886
|
-
durations.append(EWR_info['duration'])
|
|
2887
2875
|
# Check final iteration in the flow timeseries, saving any ongoing events/event gaps to their spots in the dictionaries:
|
|
2888
2876
|
if dates[-1] in masked_dates:
|
|
2889
2877
|
flow_date = dates[-1]
|
|
2890
2878
|
event, all_events = ctf_check(EWR_info, -1, flows[-1], event, all_events, water_years, flow_date)
|
|
2891
2879
|
if len(event) > 0:
|
|
2892
2880
|
all_events[water_years[-1]].append(event)
|
|
2893
|
-
durations.append(EWR_info['duration'])
|
|
2894
2881
|
|
|
2895
|
-
return all_events
|
|
2882
|
+
return all_events
|
|
2896
2883
|
|
|
2897
2884
|
def flow_calc(EWR_info: dict, flows: np.array, water_years: np.array, dates: np.array, masked_dates: set) -> tuple:
|
|
2898
2885
|
'''For calculating flow EWRs with a time constraint within their requirements. Events are
|
|
@@ -2906,14 +2893,13 @@ def flow_calc(EWR_info: dict, flows: np.array, water_years: np.array, dates: np.
|
|
|
2906
2893
|
masked_dates (set): Dates within required date range
|
|
2907
2894
|
|
|
2908
2895
|
Results:
|
|
2909
|
-
|
|
2896
|
+
dict: dictionary of all events and event gaps in timeseries.
|
|
2910
2897
|
|
|
2911
2898
|
'''
|
|
2912
2899
|
# Declare variables:
|
|
2913
2900
|
event = []
|
|
2914
2901
|
total_event = 0
|
|
2915
2902
|
all_events = construct_event_dict(water_years)
|
|
2916
|
-
durations = []
|
|
2917
2903
|
gap_track = 0
|
|
2918
2904
|
# Iterate over flow timeseries, sending to the flow_check function each iteration:
|
|
2919
2905
|
for i, flow in enumerate(flows[:-1]):
|
|
@@ -2926,7 +2912,6 @@ def flow_calc(EWR_info: dict, flows: np.array, water_years: np.array, dates: np.
|
|
|
2926
2912
|
all_events[water_years[i]].append(event)
|
|
2927
2913
|
total_event = 0
|
|
2928
2914
|
event = []
|
|
2929
|
-
durations.append(EWR_info['duration'])
|
|
2930
2915
|
|
|
2931
2916
|
# Check final iteration in the flow timeseries, saving any ongoing events/event gaps to their spots in the dictionaries:
|
|
2932
2917
|
if dates[-1] in masked_dates:
|
|
@@ -2935,9 +2920,8 @@ def flow_calc(EWR_info: dict, flows: np.array, water_years: np.array, dates: np.
|
|
|
2935
2920
|
if len(event) > 0:
|
|
2936
2921
|
all_events[water_years[-1]].append(event)
|
|
2937
2922
|
total_event = 0
|
|
2938
|
-
durations.append(EWR_info['duration'])
|
|
2939
2923
|
|
|
2940
|
-
return all_events
|
|
2924
|
+
return all_events
|
|
2941
2925
|
|
|
2942
2926
|
def flow_calc_check_ctf(EWR_info: dict, flows: np.array, water_years: np.array, dates: np.array, masked_dates: set) -> tuple:
|
|
2943
2927
|
'''For calculating flow EWRs with a time constraint within their requirements. Events are
|
|
@@ -2952,30 +2936,26 @@ def flow_calc_check_ctf(EWR_info: dict, flows: np.array, water_years: np.array,
|
|
|
2952
2936
|
masked_dates (set): Dates within required date range
|
|
2953
2937
|
|
|
2954
2938
|
Results:
|
|
2955
|
-
|
|
2939
|
+
dict: dictionary of all events and event gaps in timeseries.
|
|
2956
2940
|
|
|
2957
2941
|
'''
|
|
2958
2942
|
# Declare variables:
|
|
2959
2943
|
event = []
|
|
2960
2944
|
all_events = construct_event_dict(water_years)
|
|
2961
|
-
durations = []
|
|
2962
2945
|
ctf_state = {'events':[], 'in_event': False}
|
|
2963
2946
|
# Iterate over flow timeseries, sending to the flow_check_ctf function each iteration:
|
|
2964
2947
|
for i, _ in enumerate(flows[:-1]):
|
|
2965
2948
|
if dates[i] in masked_dates:
|
|
2966
2949
|
flow_date = dates[i]
|
|
2967
|
-
all_events, ctf_state = flow_check_ctf(EWR_info,
|
|
2968
|
-
if water_years[i] != water_years[i+1]:
|
|
2969
|
-
durations.append(EWR_info['duration'])
|
|
2950
|
+
all_events, ctf_state = flow_check_ctf(EWR_info,i, flows, all_events, water_years, flow_date, ctf_state)
|
|
2970
2951
|
# Check final iteration in the flow timeseries, saving any ongoing events/event gaps to their spots in the dictionaries:
|
|
2971
2952
|
if dates[-1] in masked_dates:
|
|
2972
2953
|
flow_date = dates[-1]
|
|
2973
2954
|
if ctf_state['in_event']:
|
|
2974
2955
|
all_events, ctf_state = process_checks_once_ctf_period_over(EWR_info, -1, flows, water_years, all_events, ctf_state)
|
|
2975
2956
|
|
|
2976
|
-
durations.append(EWR_info['duration'])
|
|
2977
2957
|
|
|
2978
|
-
return all_events
|
|
2958
|
+
return all_events
|
|
2979
2959
|
|
|
2980
2960
|
def flow_calc_anytime(EWR_info: dict, flows: np.array, water_years: np.array, dates: np.array) -> tuple:
|
|
2981
2961
|
'''For calculating flow EWRs with no time constraint within their requirements. Events crossing
|
|
@@ -2988,30 +2968,26 @@ def flow_calc_anytime(EWR_info: dict, flows: np.array, water_years: np.array, da
|
|
|
2988
2968
|
dates (np.array): array of dates
|
|
2989
2969
|
|
|
2990
2970
|
Results:
|
|
2991
|
-
|
|
2971
|
+
dict: dictionary of all events and event gaps in timeseries.
|
|
2992
2972
|
|
|
2993
2973
|
'''
|
|
2994
2974
|
# Declare variables:
|
|
2995
2975
|
event = []
|
|
2996
2976
|
total_event = 0
|
|
2997
2977
|
all_events = construct_event_dict(water_years)
|
|
2998
|
-
durations = []
|
|
2999
2978
|
gap_track = 0
|
|
3000
2979
|
# Iterate over flows:
|
|
3001
2980
|
for i, flow in enumerate(flows[:-1]):
|
|
3002
2981
|
flow_date = dates[i]
|
|
3003
2982
|
event, all_events, gap_track, total_event = flow_check(EWR_info, i, flow, event, all_events, gap_track, water_years, total_event, flow_date)
|
|
3004
|
-
if water_years[i] != water_years[i+1]:
|
|
3005
|
-
durations.append(EWR_info['duration'])
|
|
3006
2983
|
# Check final iteration in the flow timeseries, saving any ongoing events/event gaps to their spots in the dictionaries:
|
|
3007
2984
|
flow_date = dates[-1]
|
|
3008
2985
|
event, all_events, gap_track, total_event = flow_check(EWR_info, -1, flows[-1], event, all_events, gap_track, water_years, total_event, flow_date)
|
|
3009
2986
|
if len(event) > 0:
|
|
3010
2987
|
water_year = which_water_year(-1, total_event, water_years)
|
|
3011
2988
|
all_events[water_year].append(event)
|
|
3012
|
-
durations.append(EWR_info['duration'])
|
|
3013
2989
|
|
|
3014
|
-
return all_events
|
|
2990
|
+
return all_events
|
|
3015
2991
|
|
|
3016
2992
|
|
|
3017
2993
|
def lake_calc(EWR_info: dict, levels: np.array, water_years: np.array, dates: np.array, masked_dates: set)-> tuple:
|
|
@@ -3029,14 +3005,13 @@ def lake_calc(EWR_info: dict, levels: np.array, water_years: np.array, dates: np
|
|
|
3029
3005
|
masked_dates (set): List of the dates that the ewr needs to be calculated i.e. the time window.
|
|
3030
3006
|
|
|
3031
3007
|
Returns:
|
|
3032
|
-
|
|
3008
|
+
dict: final output with the calculation of volume all_events
|
|
3033
3009
|
"""
|
|
3034
3010
|
|
|
3035
3011
|
# Declare variables:
|
|
3036
3012
|
event = []
|
|
3037
3013
|
total_event = 0
|
|
3038
3014
|
all_events = construct_event_dict(water_years)
|
|
3039
|
-
durations = []
|
|
3040
3015
|
gap_track = 0
|
|
3041
3016
|
# Iterate over flow timeseries, sending to the flow_check function each iteration:
|
|
3042
3017
|
for i, level in enumerate(levels[:-1]):
|
|
@@ -3052,7 +3027,6 @@ def lake_calc(EWR_info: dict, levels: np.array, water_years: np.array, dates: np
|
|
|
3052
3027
|
event_at_year_end = deepcopy(event)
|
|
3053
3028
|
all_events[water_years[i]].append(event_at_year_end)
|
|
3054
3029
|
total_event = 0
|
|
3055
|
-
durations.append(EWR_info['duration'])
|
|
3056
3030
|
|
|
3057
3031
|
# Check final iteration in the flow timeseries, saving any ongoing events/event gaps to their spots in the dictionaries:
|
|
3058
3032
|
if dates[-1] in masked_dates:
|
|
@@ -3063,9 +3037,8 @@ def lake_calc(EWR_info: dict, levels: np.array, water_years: np.array, dates: np
|
|
|
3063
3037
|
|
|
3064
3038
|
if len(event) >= EWR_info['duration'] and len(event) <= EWR_info['max_duration']:
|
|
3065
3039
|
all_events[water_years[-1]].append(event)
|
|
3066
|
-
durations.append(EWR_info['duration'])
|
|
3067
3040
|
|
|
3068
|
-
return all_events
|
|
3041
|
+
return all_events
|
|
3069
3042
|
|
|
3070
3043
|
def cumulative_calc(EWR_info: dict, flows: np.array, water_years: np.array, dates: np.array, masked_dates: set)-> tuple:
|
|
3071
3044
|
""" Calculate and manage state of the Volume ewr calculations. It delegates to volume_check function
|
|
@@ -3080,12 +3053,11 @@ def cumulative_calc(EWR_info: dict, flows: np.array, water_years: np.array, date
|
|
|
3080
3053
|
masked_dates (set): List of the dates that the ewr needs to be calculated i.e. the time window.
|
|
3081
3054
|
|
|
3082
3055
|
Returns:
|
|
3083
|
-
|
|
3056
|
+
dict: final output with the calculation of volume all_events
|
|
3084
3057
|
"""
|
|
3085
3058
|
event = []
|
|
3086
3059
|
total_event = 0
|
|
3087
3060
|
all_events = construct_event_dict(water_years)
|
|
3088
|
-
durations = []
|
|
3089
3061
|
gap_track = 0
|
|
3090
3062
|
# Iterate over flow timeseries, sending to the flow_check function each iteration:
|
|
3091
3063
|
roller = 0
|
|
@@ -3104,7 +3076,6 @@ def cumulative_calc(EWR_info: dict, flows: np.array, water_years: np.array, date
|
|
|
3104
3076
|
all_events[water_years[i]].append(event)
|
|
3105
3077
|
total_event = 0
|
|
3106
3078
|
event = []
|
|
3107
|
-
durations.append(EWR_info['duration'])
|
|
3108
3079
|
|
|
3109
3080
|
if dates[-1] in masked_dates:
|
|
3110
3081
|
roller = check_roller_reset_points(roller, dates[-1], EWR_info)
|
|
@@ -3112,10 +3083,9 @@ def cumulative_calc(EWR_info: dict, flows: np.array, water_years: np.array, date
|
|
|
3112
3083
|
event, all_events, gap_track, total_event, roller = volume_check(EWR_info, -1, flows[-1], event, all_events,
|
|
3113
3084
|
gap_track, water_years,
|
|
3114
3085
|
total_event, flow_date, roller, max_roller, flows)
|
|
3115
|
-
durations.append(EWR_info['duration'])
|
|
3116
3086
|
|
|
3117
3087
|
|
|
3118
|
-
return all_events
|
|
3088
|
+
return all_events
|
|
3119
3089
|
|
|
3120
3090
|
def cumulative_calc_qld(EWR_info: dict, flows: np.array, water_years: np.array, dates: np.array, masked_dates: set)-> tuple:
|
|
3121
3091
|
""" Calculate and manage state of the Volume ewr calculations. It delegates to volume_check function
|
|
@@ -3130,12 +3100,11 @@ def cumulative_calc_qld(EWR_info: dict, flows: np.array, water_years: np.array,
|
|
|
3130
3100
|
masked_dates (set): List of the dates that the ewr needs to be calculated i.e. the time window.
|
|
3131
3101
|
|
|
3132
3102
|
Returns:
|
|
3133
|
-
|
|
3103
|
+
dict: final output with the calculation of volume all_events
|
|
3134
3104
|
"""
|
|
3135
3105
|
event = []
|
|
3136
3106
|
total_event = 0
|
|
3137
3107
|
all_events = construct_event_dict(water_years)
|
|
3138
|
-
durations = []
|
|
3139
3108
|
# Iterate over flow timeseries, sending to the flow_check function each iteration:
|
|
3140
3109
|
roller = 0
|
|
3141
3110
|
max_roller = EWR_info['accumulation_period']
|
|
@@ -3146,19 +3115,15 @@ def cumulative_calc_qld(EWR_info: dict, flows: np.array, water_years: np.array,
|
|
|
3146
3115
|
event, all_events, total_event, roller = volume_check_qld(EWR_info, i, event, all_events,
|
|
3147
3116
|
water_years, total_event, flow_date,
|
|
3148
3117
|
roller, max_roller, flows)
|
|
3149
|
-
# At the end of each water year, save any ongoing events and event gaps to the dictionaries, and reset the list and counter
|
|
3150
|
-
if water_years[i] != water_years[i+1]:
|
|
3151
|
-
durations.append(EWR_info['duration'])
|
|
3152
3118
|
|
|
3153
3119
|
if dates[-1] in masked_dates:
|
|
3154
3120
|
roller = check_roller_reset_points(roller, dates[-1], EWR_info)
|
|
3155
3121
|
flow_date = dates[-1]
|
|
3156
3122
|
event, all_events, total_event, roller = volume_check_qld(EWR_info, -1, event, all_events,
|
|
3157
3123
|
water_years, total_event, flow_date,
|
|
3158
|
-
roller, max_roller, flows)
|
|
3159
|
-
durations.append(EWR_info['duration'])
|
|
3124
|
+
roller, max_roller, flows)
|
|
3160
3125
|
|
|
3161
|
-
return all_events
|
|
3126
|
+
return all_events
|
|
3162
3127
|
|
|
3163
3128
|
def cumulative_calc_bbr(EWR_info: dict, flows: np.array, levels: np.array, water_years: np.array, dates: np.array, masked_dates: set)-> tuple:
|
|
3164
3129
|
""" Calculate and manage state of the Volume ewr calculations. It delegates to volume_check function
|
|
@@ -3174,12 +3139,11 @@ def cumulative_calc_bbr(EWR_info: dict, flows: np.array, levels: np.array, water
|
|
|
3174
3139
|
masked_dates (set): List of the dates that the ewr needs to be calculated i.e. the time window.
|
|
3175
3140
|
|
|
3176
3141
|
Returns:
|
|
3177
|
-
|
|
3142
|
+
dict: final output with the calculation of volume all_events
|
|
3178
3143
|
"""
|
|
3179
3144
|
event = []
|
|
3180
3145
|
total_event = 0
|
|
3181
3146
|
all_events = construct_event_dict(water_years)
|
|
3182
|
-
durations = []
|
|
3183
3147
|
# Iterate over flow timeseries, sending to the flow_check function each iteration:
|
|
3184
3148
|
event_state = {}
|
|
3185
3149
|
event_state["level_crossed_up"] = False
|
|
@@ -3190,17 +3154,15 @@ def cumulative_calc_bbr(EWR_info: dict, flows: np.array, levels: np.array, water
|
|
|
3190
3154
|
flow_date = dates[i]
|
|
3191
3155
|
event, all_events, total_event, event_state = volume_level_check_bbr(EWR_info, i, flow, event, all_events,
|
|
3192
3156
|
water_years, total_event, flow_date, event_state, levels)
|
|
3193
|
-
|
|
3194
|
-
durations.append(EWR_info['duration'])
|
|
3157
|
+
|
|
3195
3158
|
|
|
3196
3159
|
if dates[-1] in masked_dates:
|
|
3197
3160
|
flow_date = dates[-1]
|
|
3198
3161
|
event, all_events, total_event, event_state = volume_level_check_bbr(EWR_info, -1, flows[-1], event, all_events,
|
|
3199
|
-
water_years, total_event, flow_date, event_state, levels)
|
|
3200
|
-
durations.append(EWR_info['duration'])
|
|
3162
|
+
water_years, total_event, flow_date, event_state, levels)
|
|
3201
3163
|
|
|
3202
3164
|
|
|
3203
|
-
return all_events
|
|
3165
|
+
return all_events
|
|
3204
3166
|
|
|
3205
3167
|
|
|
3206
3168
|
def water_stability_calc(EWR_info: dict, flows: np.array, levels: np.array, water_years: np.array, dates: np.array, masked_dates: set)-> tuple:
|
|
@@ -3216,21 +3178,21 @@ def water_stability_calc(EWR_info: dict, flows: np.array, levels: np.array, wate
|
|
|
3216
3178
|
masked_dates (set): List of the dates that the ewr needs to be calculated i.e. the time window.
|
|
3217
3179
|
|
|
3218
3180
|
Returns:
|
|
3219
|
-
|
|
3181
|
+
dict: final output with the calculation of volume all_events
|
|
3220
3182
|
"""
|
|
3221
3183
|
all_events = construct_event_dict(water_years)
|
|
3222
|
-
|
|
3184
|
+
|
|
3223
3185
|
|
|
3224
3186
|
|
|
3225
3187
|
for i, _ in enumerate(flows):
|
|
3226
3188
|
if dates[i] in masked_dates:
|
|
3227
3189
|
flow_date = dates[i]
|
|
3228
3190
|
all_events = water_stability_check(EWR_info, i, flows, all_events, water_years, flow_date, levels)
|
|
3229
|
-
|
|
3191
|
+
|
|
3230
3192
|
|
|
3231
|
-
|
|
3193
|
+
|
|
3232
3194
|
|
|
3233
|
-
return all_events
|
|
3195
|
+
return all_events
|
|
3234
3196
|
|
|
3235
3197
|
def water_stability_level_calc(EWR_info: dict, levels: np.array, water_years: np.array, dates: np.array, masked_dates: set)-> tuple:
|
|
3236
3198
|
""" Calculate the water stability EWRs (LEVEL VERSION)
|
|
@@ -3248,18 +3210,18 @@ def water_stability_level_calc(EWR_info: dict, levels: np.array, water_years: np
|
|
|
3248
3210
|
tuple: final output with the calculation of volume all_events, durations
|
|
3249
3211
|
"""
|
|
3250
3212
|
all_events = construct_event_dict(water_years)
|
|
3251
|
-
|
|
3213
|
+
|
|
3252
3214
|
|
|
3253
3215
|
|
|
3254
3216
|
for i, _ in enumerate(levels):
|
|
3255
3217
|
if dates[i] in masked_dates:
|
|
3256
3218
|
flow_date = dates[i]
|
|
3257
3219
|
all_events = water_stability_level_check(EWR_info, i, all_events, water_years, flow_date, levels)
|
|
3258
|
-
|
|
3220
|
+
|
|
3259
3221
|
|
|
3260
|
-
|
|
3222
|
+
|
|
3261
3223
|
|
|
3262
|
-
return all_events
|
|
3224
|
+
return all_events
|
|
3263
3225
|
|
|
3264
3226
|
|
|
3265
3227
|
def nest_calc_weirpool(EWR_info: dict, flows: list, levels: list, water_years: list,
|
|
@@ -3287,7 +3249,7 @@ def nest_calc_weirpool(EWR_info: dict, flows: list, levels: list, water_years: l
|
|
|
3287
3249
|
event = []
|
|
3288
3250
|
total_event = 0
|
|
3289
3251
|
all_events = construct_event_dict(water_years)
|
|
3290
|
-
|
|
3252
|
+
|
|
3291
3253
|
gap_track = 0
|
|
3292
3254
|
# Iterate over flow timeseries, sending to the weirpool_check function each iteration:
|
|
3293
3255
|
for i, flow in enumerate(flows[:-1]):
|
|
@@ -3304,9 +3266,6 @@ def nest_calc_weirpool(EWR_info: dict, flows: list, levels: list, water_years: l
|
|
|
3304
3266
|
all_events[water_years[i]].append(event)
|
|
3305
3267
|
total_event = 0
|
|
3306
3268
|
event = []
|
|
3307
|
-
if water_years[i] != water_years[i+1]:
|
|
3308
|
-
durations.append(EWR_info['duration'])
|
|
3309
|
-
|
|
3310
3269
|
# Check final iteration in the flow timeseries, saving any ongoing events/event gaps to their spots in the dictionaries:
|
|
3311
3270
|
if dates[-1] in masked_dates:
|
|
3312
3271
|
flow_date = dates[-1]
|
|
@@ -3318,9 +3277,9 @@ def nest_calc_weirpool(EWR_info: dict, flows: list, levels: list, water_years: l
|
|
|
3318
3277
|
all_events[water_years[-1]].append(event)
|
|
3319
3278
|
total_event = 0
|
|
3320
3279
|
|
|
3321
|
-
|
|
3280
|
+
|
|
3322
3281
|
|
|
3323
|
-
return all_events
|
|
3282
|
+
return all_events
|
|
3324
3283
|
|
|
3325
3284
|
|
|
3326
3285
|
def nest_calc_percent_trigger(EWR_info:Dict, flows:List, water_years:List, dates:List)->tuple:
|
|
@@ -3351,7 +3310,7 @@ def nest_calc_percent_trigger(EWR_info:Dict, flows:List, water_years:List, dates
|
|
|
3351
3310
|
event = []
|
|
3352
3311
|
total_event = 0
|
|
3353
3312
|
all_events = construct_event_dict(water_years)
|
|
3354
|
-
|
|
3313
|
+
|
|
3355
3314
|
gap_track = 0
|
|
3356
3315
|
for i, flow in enumerate(flows[:-1]):
|
|
3357
3316
|
flow_date = dates[i]
|
|
@@ -3387,10 +3346,6 @@ def nest_calc_percent_trigger(EWR_info:Dict, flows:List, water_years:List, dates
|
|
|
3387
3346
|
if is_in_trigger_window and iteration_no_event == 0:
|
|
3388
3347
|
event, all_events, gap_track, total_event, iteration_no_event = nest_flow_check(EWR_info, i, flow, event, all_events,
|
|
3389
3348
|
gap_track, water_years, total_event, flow_date, flow_percent_change, iteration_no_event)
|
|
3390
|
-
|
|
3391
|
-
# at end of water year record duration and min event values
|
|
3392
|
-
if water_years[i] != water_years[i+1]:
|
|
3393
|
-
durations.append(EWR_info['duration'])
|
|
3394
3349
|
|
|
3395
3350
|
# Check final iteration in the flow timeseries, saving any ongoing events/event gaps to their spots in the dictionaries:
|
|
3396
3351
|
# reset all variable to last flow
|
|
@@ -3423,8 +3378,8 @@ def nest_calc_percent_trigger(EWR_info:Dict, flows:List, water_years:List, dates
|
|
|
3423
3378
|
all_events[water_years[-1]].append(event)
|
|
3424
3379
|
total_event = 0
|
|
3425
3380
|
|
|
3426
|
-
|
|
3427
|
-
return all_events
|
|
3381
|
+
|
|
3382
|
+
return all_events
|
|
3428
3383
|
|
|
3429
3384
|
|
|
3430
3385
|
def weirpool_calc(EWR_info: Dict, flows: List, levels: List, water_years: List, weirpool_type: str,
|
|
@@ -3448,7 +3403,7 @@ def weirpool_calc(EWR_info: Dict, flows: List, levels: List, water_years: List,
|
|
|
3448
3403
|
event = []
|
|
3449
3404
|
total_event = 0
|
|
3450
3405
|
all_events = construct_event_dict(water_years)
|
|
3451
|
-
|
|
3406
|
+
|
|
3452
3407
|
gap_track = 0
|
|
3453
3408
|
# Iterate over flow timeseries, sending to the weirpool_check function each iteration:
|
|
3454
3409
|
for i, flow in enumerate(flows[:-1]):
|
|
@@ -3464,7 +3419,7 @@ def weirpool_calc(EWR_info: Dict, flows: List, levels: List, water_years: List,
|
|
|
3464
3419
|
all_events[water_years[i]].append(event)
|
|
3465
3420
|
total_event = 0
|
|
3466
3421
|
event = []
|
|
3467
|
-
|
|
3422
|
+
|
|
3468
3423
|
|
|
3469
3424
|
# Check final iteration in the flow timeseries, saving any ongoing events/event gaps to their spots in the dictionaries:
|
|
3470
3425
|
if dates[-1] in masked_dates:
|
|
@@ -3477,9 +3432,9 @@ def weirpool_calc(EWR_info: Dict, flows: List, levels: List, water_years: List,
|
|
|
3477
3432
|
all_events[water_years[-1]].append(event)
|
|
3478
3433
|
total_event = 0
|
|
3479
3434
|
|
|
3480
|
-
|
|
3435
|
+
|
|
3481
3436
|
|
|
3482
|
-
return all_events
|
|
3437
|
+
return all_events
|
|
3483
3438
|
|
|
3484
3439
|
def flow_calc_sa(EWR_info: Dict, flows: List, water_years: List,
|
|
3485
3440
|
dates:List, masked_dates:List)-> tuple:
|
|
@@ -3500,7 +3455,7 @@ def flow_calc_sa(EWR_info: Dict, flows: List, water_years: List,
|
|
|
3500
3455
|
event = []
|
|
3501
3456
|
total_event = 0
|
|
3502
3457
|
all_events = construct_event_dict(water_years)
|
|
3503
|
-
|
|
3458
|
+
|
|
3504
3459
|
gap_track = 0
|
|
3505
3460
|
for i, flow in enumerate(flows[:-1]):
|
|
3506
3461
|
if dates[i] in masked_dates:
|
|
@@ -3516,7 +3471,7 @@ def flow_calc_sa(EWR_info: Dict, flows: List, water_years: List,
|
|
|
3516
3471
|
all_events[water_years[i]].append(event)
|
|
3517
3472
|
total_event = 0
|
|
3518
3473
|
event = []
|
|
3519
|
-
|
|
3474
|
+
|
|
3520
3475
|
|
|
3521
3476
|
# Check final iteration in the flow timeseries, saving any ongoing events/event gaps to their spots in the dictionaries:
|
|
3522
3477
|
if dates[-1] in masked_dates:
|
|
@@ -3530,9 +3485,9 @@ def flow_calc_sa(EWR_info: Dict, flows: List, water_years: List,
|
|
|
3530
3485
|
all_events[water_years[-1]].append(event)
|
|
3531
3486
|
total_event = 0
|
|
3532
3487
|
|
|
3533
|
-
|
|
3488
|
+
|
|
3534
3489
|
|
|
3535
|
-
return all_events
|
|
3490
|
+
return all_events
|
|
3536
3491
|
|
|
3537
3492
|
def rate_rise_flow_calc(EWR_info: Dict, flows: List, water_years: List,
|
|
3538
3493
|
dates:List, masked_dates:List)-> tuple:
|
|
@@ -3552,7 +3507,7 @@ def rate_rise_flow_calc(EWR_info: Dict, flows: List, water_years: List,
|
|
|
3552
3507
|
event = []
|
|
3553
3508
|
total_event = 0
|
|
3554
3509
|
all_events = construct_event_dict(water_years)
|
|
3555
|
-
|
|
3510
|
+
|
|
3556
3511
|
gap_track = 0
|
|
3557
3512
|
for i, flow in enumerate(flows[1:-1]):
|
|
3558
3513
|
if dates[i] in masked_dates:
|
|
@@ -3560,9 +3515,6 @@ def rate_rise_flow_calc(EWR_info: Dict, flows: List, water_years: List,
|
|
|
3560
3515
|
event, all_events, gap_track, total_event = rate_rise_flow_check(EWR_info, i, event,
|
|
3561
3516
|
all_events, gap_track,
|
|
3562
3517
|
water_years, total_event, flow_date, flows)
|
|
3563
|
-
# At the end of each water year, save any ongoing events and event gaps to the dictionaries, and reset the list and counter
|
|
3564
|
-
if water_years[i] != water_years[i+1]:
|
|
3565
|
-
durations.append(EWR_info['duration'])
|
|
3566
3518
|
|
|
3567
3519
|
# Check final iteration in the flow timeseries, saving any ongoing events/event gaps to their spots in the dictionaries:
|
|
3568
3520
|
if dates[-1] in masked_dates:
|
|
@@ -3570,9 +3522,9 @@ def rate_rise_flow_calc(EWR_info: Dict, flows: List, water_years: List,
|
|
|
3570
3522
|
event, all_events, gap_track, total_event = rate_rise_flow_check(EWR_info, i, event,
|
|
3571
3523
|
all_events, gap_track,
|
|
3572
3524
|
water_years, total_event, flow_date, flows)
|
|
3573
|
-
durations.append(EWR_info['duration'])
|
|
3574
3525
|
|
|
3575
|
-
|
|
3526
|
+
|
|
3527
|
+
return all_events
|
|
3576
3528
|
|
|
3577
3529
|
def rate_fall_flow_calc(EWR_info: Dict, flows: List, water_years: List,
|
|
3578
3530
|
dates:List, masked_dates:List)-> tuple:
|
|
@@ -3592,7 +3544,7 @@ def rate_fall_flow_calc(EWR_info: Dict, flows: List, water_years: List,
|
|
|
3592
3544
|
event = []
|
|
3593
3545
|
total_event = 0
|
|
3594
3546
|
all_events = construct_event_dict(water_years)
|
|
3595
|
-
|
|
3547
|
+
|
|
3596
3548
|
gap_track = 0
|
|
3597
3549
|
for i, _ in enumerate(flows[:-1]):
|
|
3598
3550
|
if i == 0:
|
|
@@ -3603,8 +3555,7 @@ def rate_fall_flow_calc(EWR_info: Dict, flows: List, water_years: List,
|
|
|
3603
3555
|
all_events, gap_track,
|
|
3604
3556
|
water_years, total_event, flow_date, flows)
|
|
3605
3557
|
# At the end of each water year, save any ongoing events and event gaps to the dictionaries, and reset the list and counter
|
|
3606
|
-
|
|
3607
|
-
durations.append(EWR_info['duration'])
|
|
3558
|
+
|
|
3608
3559
|
|
|
3609
3560
|
# Check final iteration in the flow timeseries, saving any ongoing events/event gaps to their spots in the dictionaries:
|
|
3610
3561
|
if dates[-1] in masked_dates:
|
|
@@ -3612,9 +3563,9 @@ def rate_fall_flow_calc(EWR_info: Dict, flows: List, water_years: List,
|
|
|
3612
3563
|
event, all_events, gap_track, total_event = rate_fall_flow_check(EWR_info, -1, event,
|
|
3613
3564
|
all_events, gap_track,
|
|
3614
3565
|
water_years, total_event, flow_date, flows)
|
|
3615
|
-
|
|
3566
|
+
|
|
3616
3567
|
|
|
3617
|
-
return all_events
|
|
3568
|
+
return all_events
|
|
3618
3569
|
|
|
3619
3570
|
|
|
3620
3571
|
def rate_rise_level_calc(EWR_info: Dict, levels: List, water_years: List,
|
|
@@ -3635,7 +3586,7 @@ def rate_rise_level_calc(EWR_info: Dict, levels: List, water_years: List,
|
|
|
3635
3586
|
event = []
|
|
3636
3587
|
total_event = 0
|
|
3637
3588
|
all_events = construct_event_dict(water_years)
|
|
3638
|
-
|
|
3589
|
+
|
|
3639
3590
|
gap_track = 0
|
|
3640
3591
|
for i, _ in enumerate(levels[:-1]):
|
|
3641
3592
|
if i == 0:
|
|
@@ -3645,8 +3596,7 @@ def rate_rise_level_calc(EWR_info: Dict, levels: List, water_years: List,
|
|
|
3645
3596
|
event, all_events, gap_track, total_event = rate_rise_level_check(EWR_info, i, event,
|
|
3646
3597
|
all_events, gap_track,
|
|
3647
3598
|
water_years, total_event, flow_date, levels)
|
|
3648
|
-
|
|
3649
|
-
durations.append(EWR_info['duration'])
|
|
3599
|
+
|
|
3650
3600
|
|
|
3651
3601
|
# Check final iteration in the flow timeseries, saving any ongoing events/event gaps to their spots in the dictionaries:
|
|
3652
3602
|
if dates[-1] in masked_dates:
|
|
@@ -3654,9 +3604,9 @@ def rate_rise_level_calc(EWR_info: Dict, levels: List, water_years: List,
|
|
|
3654
3604
|
event, all_events, gap_track, total_event = rate_rise_level_check(EWR_info, i, event,
|
|
3655
3605
|
all_events, gap_track,
|
|
3656
3606
|
water_years, total_event, flow_date, levels)
|
|
3657
|
-
|
|
3607
|
+
|
|
3658
3608
|
|
|
3659
|
-
return all_events
|
|
3609
|
+
return all_events
|
|
3660
3610
|
|
|
3661
3611
|
def rate_fall_level_calc(EWR_info: Dict, levels: List, water_years: List,
|
|
3662
3612
|
dates:List, masked_dates:List)-> tuple:
|
|
@@ -3676,7 +3626,7 @@ def rate_fall_level_calc(EWR_info: Dict, levels: List, water_years: List,
|
|
|
3676
3626
|
event = []
|
|
3677
3627
|
total_event = 0
|
|
3678
3628
|
all_events = construct_event_dict(water_years)
|
|
3679
|
-
|
|
3629
|
+
|
|
3680
3630
|
gap_track = 0
|
|
3681
3631
|
for i, flow in enumerate(levels[1:-1]):
|
|
3682
3632
|
if i == 0:
|
|
@@ -3686,9 +3636,6 @@ def rate_fall_level_calc(EWR_info: Dict, levels: List, water_years: List,
|
|
|
3686
3636
|
event, all_events, gap_track, total_event = rate_fall_level_check(EWR_info, i, event,
|
|
3687
3637
|
all_events, gap_track,
|
|
3688
3638
|
water_years, total_event, flow_date, levels)
|
|
3689
|
-
# At the end of each water year, save any ongoing events and event gaps to the dictionaries, and reset the list and counter
|
|
3690
|
-
if water_years[i] != water_years[i+1]:
|
|
3691
|
-
durations.append(EWR_info['duration'])
|
|
3692
3639
|
|
|
3693
3640
|
# Check final iteration in the flow timeseries, saving any ongoing events/event gaps to their spots in the dictionaries:
|
|
3694
3641
|
if dates[-1] in masked_dates:
|
|
@@ -3696,9 +3643,9 @@ def rate_fall_level_calc(EWR_info: Dict, levels: List, water_years: List,
|
|
|
3696
3643
|
event, all_events, gap_track, total_event = rate_fall_level_check(EWR_info, i, event,
|
|
3697
3644
|
all_events, gap_track,
|
|
3698
3645
|
water_years, total_event, flow_date, levels)
|
|
3699
|
-
|
|
3646
|
+
|
|
3700
3647
|
|
|
3701
|
-
return all_events
|
|
3648
|
+
return all_events
|
|
3702
3649
|
|
|
3703
3650
|
|
|
3704
3651
|
def barrage_flow_calc(EWR_info: Dict, flows: pd.Series, water_years: List, dates:List)-> tuple:
|
|
@@ -3718,7 +3665,7 @@ def barrage_flow_calc(EWR_info: Dict, flows: pd.Series, water_years: List, dates
|
|
|
3718
3665
|
# declare variables:
|
|
3719
3666
|
event = []
|
|
3720
3667
|
all_events = construct_event_dict(water_years)
|
|
3721
|
-
|
|
3668
|
+
|
|
3722
3669
|
|
|
3723
3670
|
for i, _ in enumerate(flows.values[:-1]):
|
|
3724
3671
|
# At the end of each water year check last year barrage flow total if it above minimum threshold
|
|
@@ -3726,13 +3673,13 @@ def barrage_flow_calc(EWR_info: Dict, flows: pd.Series, water_years: List, dates
|
|
|
3726
3673
|
flow_date = dates[i]
|
|
3727
3674
|
event, all_events= barrage_flow_check(EWR_info, flows, event, all_events, flow_date)
|
|
3728
3675
|
event = []
|
|
3729
|
-
|
|
3676
|
+
|
|
3730
3677
|
|
|
3731
3678
|
# check final iteration in the flow timeseries, saving any ongoing events/event gaps to their spots in the dictionaries:
|
|
3732
3679
|
event, all_events = barrage_flow_check(EWR_info, flows, event, all_events, dates[-1])
|
|
3733
3680
|
event = []
|
|
3734
|
-
|
|
3735
|
-
return all_events
|
|
3681
|
+
|
|
3682
|
+
return all_events
|
|
3736
3683
|
|
|
3737
3684
|
def coorong_level_calc(EWR_info: Dict, levels: pd.Series, water_years: List, dates:List, masked_dates:List)-> tuple:
|
|
3738
3685
|
"""iterate level data for barrage combined levels are with in minimum levels
|
|
@@ -3750,7 +3697,7 @@ def coorong_level_calc(EWR_info: Dict, levels: pd.Series, water_years: List, dat
|
|
|
3750
3697
|
# declare variables:
|
|
3751
3698
|
event = []
|
|
3752
3699
|
all_events = construct_event_dict(water_years)
|
|
3753
|
-
|
|
3700
|
+
|
|
3754
3701
|
total_event = 0
|
|
3755
3702
|
|
|
3756
3703
|
for i, _ in enumerate(levels.values[:-1]):
|
|
@@ -3763,15 +3710,15 @@ def coorong_level_calc(EWR_info: Dict, levels: pd.Series, water_years: List, dat
|
|
|
3763
3710
|
all_events[water_years[i]].append(event)
|
|
3764
3711
|
total_event = 0
|
|
3765
3712
|
event = []
|
|
3766
|
-
|
|
3713
|
+
|
|
3767
3714
|
|
|
3768
3715
|
# check final iteration in the flow timeseries, saving any ongoing events/event gaps to their spots in the dictionaries:
|
|
3769
3716
|
event, all_events = coorong_check(EWR_info, levels, event, all_events, level_date, water_years, i, total_event)
|
|
3770
3717
|
event = []
|
|
3771
|
-
|
|
3772
|
-
return all_events
|
|
3718
|
+
|
|
3719
|
+
return all_events
|
|
3773
3720
|
|
|
3774
|
-
def lower_lakes_level_calc(EWR_info: Dict, levels: pd.Series, water_years: List, dates:List, masked_dates:List)->
|
|
3721
|
+
def lower_lakes_level_calc(EWR_info: Dict, levels: pd.Series, water_years: List, dates:List, masked_dates:List) -> dict:
|
|
3775
3722
|
"""iterate level data for barrage combined levels and check at the end of each year
|
|
3776
3723
|
if barrage level is at the required minimum as well as the seasonal peak levels threshold
|
|
3777
3724
|
|
|
@@ -3783,12 +3730,12 @@ def lower_lakes_level_calc(EWR_info: Dict, levels: pd.Series, water_years: List,
|
|
|
3783
3730
|
masked_dates (List): List of the dates that the ewr needs to be calculated i.e. the time window.
|
|
3784
3731
|
|
|
3785
3732
|
Returns:
|
|
3786
|
-
|
|
3733
|
+
dict: final output with the calculation of volume all_events
|
|
3787
3734
|
"""
|
|
3788
3735
|
# declare variables:
|
|
3789
3736
|
event = []
|
|
3790
3737
|
all_events = construct_event_dict(water_years)
|
|
3791
|
-
|
|
3738
|
+
|
|
3792
3739
|
|
|
3793
3740
|
for i, _ in enumerate(levels.values[:-1]):
|
|
3794
3741
|
# At the end of each water year check last year barrage flow total if it above minimum threshold
|
|
@@ -3796,13 +3743,13 @@ def lower_lakes_level_calc(EWR_info: Dict, levels: pd.Series, water_years: List,
|
|
|
3796
3743
|
flow_date = dates[i]
|
|
3797
3744
|
event, all_events = lower_lakes_level_check(EWR_info, levels, event, all_events, flow_date)
|
|
3798
3745
|
event = []
|
|
3799
|
-
|
|
3746
|
+
|
|
3800
3747
|
|
|
3801
3748
|
# check final iteration in the flow timeseries, saving any ongoing events/event gaps to their spots in the dictionaries:
|
|
3802
3749
|
event, all_events = lower_lakes_level_check(EWR_info, levels, event, all_events, flow_date)
|
|
3803
3750
|
event = []
|
|
3804
|
-
|
|
3805
|
-
return
|
|
3751
|
+
|
|
3752
|
+
return all_events
|
|
3806
3753
|
|
|
3807
3754
|
#------------------------------------ Stats on ewr events ----------------------------------------#
|
|
3808
3755
|
|
|
@@ -3823,7 +3770,7 @@ def filter_min_events(EWR_info:Dict, events:Dict)-> Dict:
|
|
|
3823
3770
|
|
|
3824
3771
|
return filtered_events
|
|
3825
3772
|
|
|
3826
|
-
def get_event_years(EWR_info:Dict, events:Dict, unique_water_years:set
|
|
3773
|
+
def get_event_years(EWR_info:Dict, events:Dict, unique_water_years:set) -> List:
|
|
3827
3774
|
'''Returns a list of years with events (represented by a 1), and years without events (0)
|
|
3828
3775
|
|
|
3829
3776
|
Args:
|
|
@@ -3842,7 +3789,7 @@ def get_event_years(EWR_info:Dict, events:Dict, unique_water_years:set, duration
|
|
|
3842
3789
|
combined_len = 0
|
|
3843
3790
|
for e in events_filtered[year]:
|
|
3844
3791
|
combined_len += len(e)
|
|
3845
|
-
if ((combined_len >=
|
|
3792
|
+
if ((combined_len >=EWR_info['duration'] and len(events_filtered[year])>=EWR_info['events_per_year'])):
|
|
3846
3793
|
event_years.append(1)
|
|
3847
3794
|
else:
|
|
3848
3795
|
event_years.append(0)
|
|
@@ -3850,7 +3797,7 @@ def get_event_years(EWR_info:Dict, events:Dict, unique_water_years:set, duration
|
|
|
3850
3797
|
return event_years
|
|
3851
3798
|
|
|
3852
3799
|
|
|
3853
|
-
def get_achievements(EWR_info:Dict, events:Dict, unique_water_years:set
|
|
3800
|
+
def get_achievements(EWR_info:Dict, events:Dict, unique_water_years:set) -> List:
|
|
3854
3801
|
'''Returns a list of number of events per year.
|
|
3855
3802
|
|
|
3856
3803
|
Args:
|
|
@@ -3869,7 +3816,7 @@ def get_achievements(EWR_info:Dict, events:Dict, unique_water_years:set, duratio
|
|
|
3869
3816
|
yearly_events = 0
|
|
3870
3817
|
for e in events_filtered[year]:
|
|
3871
3818
|
combined_len += len(e)
|
|
3872
|
-
if combined_len >=
|
|
3819
|
+
if combined_len >=EWR_info['duration']:
|
|
3873
3820
|
yearly_events += 1
|
|
3874
3821
|
combined_len = 0
|
|
3875
3822
|
total = yearly_events/EWR_info['events_per_year']
|
|
@@ -3903,7 +3850,7 @@ def get_achievements_connecting_events(events: Dict, unique_water_years:set)->Li
|
|
|
3903
3850
|
achievements_per_years.append(achievement_count)
|
|
3904
3851
|
return achievements_per_years
|
|
3905
3852
|
|
|
3906
|
-
def get_number_events(EWR_info:Dict, events:Dict, unique_water_years:set
|
|
3853
|
+
def get_number_events(EWR_info:Dict, events:Dict, unique_water_years:set) -> List:
|
|
3907
3854
|
'''Returns a list of number of events per year
|
|
3908
3855
|
|
|
3909
3856
|
Args:
|
|
@@ -3923,7 +3870,7 @@ def get_number_events(EWR_info:Dict, events:Dict, unique_water_years:set, durati
|
|
|
3923
3870
|
yearly_events = 0
|
|
3924
3871
|
for e in events_filtered[year]:
|
|
3925
3872
|
combined_len += len(e)
|
|
3926
|
-
if combined_len >=
|
|
3873
|
+
if combined_len >=EWR_info['duration']:
|
|
3927
3874
|
yearly_events += 1
|
|
3928
3875
|
combined_len = 0
|
|
3929
3876
|
total = yearly_events
|
|
@@ -4147,7 +4094,7 @@ def get_event_max_inter_event_achieved(EWR_info:Dict, no_events:Dict , unique_wa
|
|
|
4147
4094
|
log.error(e)
|
|
4148
4095
|
return [0 if (max_inter_event > EWR_info['max_inter-event']*365) else 1 for max_inter_event in max_inter_event_achieved]
|
|
4149
4096
|
|
|
4150
|
-
def get_max_rolling_duration_achievement(
|
|
4097
|
+
def get_max_rolling_duration_achievement(EWR_info:Dict, max_consecutive_days:List[int])-> List[int]:
|
|
4151
4098
|
"""test if in a given year the max rolling duration was equals or above the min duration.
|
|
4152
4099
|
|
|
4153
4100
|
Args:
|
|
@@ -4157,7 +4104,7 @@ def get_max_rolling_duration_achievement(durations:List[int], max_consecutive_da
|
|
|
4157
4104
|
Returns:
|
|
4158
4105
|
List[int]: a list of 1 and 0 where 1 is achievement and 0 is no achievement.
|
|
4159
4106
|
"""
|
|
4160
|
-
return [1 if (max_rolling >=
|
|
4107
|
+
return [1 if (max_rolling >=EWR_info['duration']) else 0 for index, max_rolling in enumerate(max_consecutive_days)]
|
|
4161
4108
|
|
|
4162
4109
|
def get_all_events(yearly_events:dict)-> List:
|
|
4163
4110
|
"""count the events in a collection of years
|
|
@@ -4226,7 +4173,7 @@ def get_total_series_days(water_years:List) -> pd.Series:
|
|
|
4226
4173
|
|
|
4227
4174
|
return intoSeries
|
|
4228
4175
|
|
|
4229
|
-
def event_stats(df:pd.DataFrame, PU_df:pd.DataFrame, gauge:str, ewr:str, EWR_info:Dict, events:Dict,
|
|
4176
|
+
def event_stats(df:pd.DataFrame, PU_df:pd.DataFrame, gauge:str, ewr:str, EWR_info:Dict, events:Dict, water_years:List) -> pd.DataFrame:
|
|
4230
4177
|
''' Produces statistics based on the event dictionaries and event gap dictionaries.
|
|
4231
4178
|
|
|
4232
4179
|
Args:
|
|
@@ -4246,7 +4193,7 @@ def event_stats(df:pd.DataFrame, PU_df:pd.DataFrame, gauge:str, ewr:str, EWR_inf
|
|
|
4246
4193
|
'''
|
|
4247
4194
|
unique_water_years = set(water_years)
|
|
4248
4195
|
# Years with events
|
|
4249
|
-
years_with_events = get_event_years(EWR_info, events, unique_water_years
|
|
4196
|
+
years_with_events = get_event_years(EWR_info, events, unique_water_years)
|
|
4250
4197
|
|
|
4251
4198
|
## reset the no_events to keep functionality but switched off
|
|
4252
4199
|
no_events = construct_event_dict(water_years)
|
|
@@ -4263,7 +4210,7 @@ def event_stats(df:pd.DataFrame, PU_df:pd.DataFrame, gauge:str, ewr:str, EWR_inf
|
|
|
4263
4210
|
YWE = pd.Series(name = str(ewr + '_eventYears'), data = years_with_events, index = unique_water_years)
|
|
4264
4211
|
# PU_df = pd.concat([PU_df, YWE], axis = 1)
|
|
4265
4212
|
# Number of event achievements:
|
|
4266
|
-
num_event_achievements = get_achievements(EWR_info, events, unique_water_years
|
|
4213
|
+
num_event_achievements = get_achievements(EWR_info, events, unique_water_years)
|
|
4267
4214
|
|
|
4268
4215
|
if EWR_info['Code'] in ['rANA']:
|
|
4269
4216
|
num_event_achievements = get_achievements_connecting_events(events, unique_water_years)
|
|
@@ -4271,7 +4218,7 @@ def event_stats(df:pd.DataFrame, PU_df:pd.DataFrame, gauge:str, ewr:str, EWR_inf
|
|
|
4271
4218
|
NEA = pd.Series(name = str(ewr + '_numAchieved'), data= num_event_achievements, index = unique_water_years)
|
|
4272
4219
|
# PU_df = pd.concat([PU_df, NEA], axis = 1)
|
|
4273
4220
|
# Total number of events THIS ONE IS ONLY ACHIEVED due to Filter Applied
|
|
4274
|
-
num_events = get_number_events(EWR_info, events, unique_water_years
|
|
4221
|
+
num_events = get_number_events(EWR_info, events, unique_water_years)
|
|
4275
4222
|
NE = pd.Series(name = str(ewr + '_numEvents'), data= num_events, index = unique_water_years)
|
|
4276
4223
|
# PU_df = pd.concat([PU_df, NE], axis = 1)
|
|
4277
4224
|
# Total number of events THIS ONE IS ALL EVENTS
|
|
@@ -4317,7 +4264,7 @@ def event_stats(df:pd.DataFrame, PU_df:pd.DataFrame, gauge:str, ewr:str, EWR_inf
|
|
|
4317
4264
|
# PU_df = pd.concat([PU_df, MR], axis = 1)
|
|
4318
4265
|
log.error(e)
|
|
4319
4266
|
# Max rolling duration achieved
|
|
4320
|
-
achieved_max_rolling_duration = get_max_rolling_duration_achievement(
|
|
4267
|
+
achieved_max_rolling_duration = get_max_rolling_duration_achievement(EWR_info, max_consecutive_days)
|
|
4321
4268
|
MRA = pd.Series(name = str(ewr + '_maxRollingAchievement'), data = achieved_max_rolling_duration, index = unique_water_years)
|
|
4322
4269
|
# PU_df = pd.concat([PU_df, MRA], axis = 1)
|
|
4323
4270
|
# Append information around available and missing data:
|