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 CHANGED
@@ -433,7 +433,7 @@ def get_barrage_level_gauges()-> dict:
433
433
  dict: dictionary of level gauges associated with each barrage.
434
434
  """
435
435
 
436
- level_barrage_gauges = {'A4260527': ['A4260527','A4261133', 'A4260524', 'A4260574', 'A4260575' ],
436
+ level_barrage_gauges = {'A4260524': ['A4260527','A4261133', 'A4260524', 'A4260574', 'A4260575' ],
437
437
  'A4260633' : ['A4260633','A4261209', 'A4261165']}
438
438
 
439
439
  return level_barrage_gauges
@@ -466,7 +466,7 @@ def get_vic_level_gauges()-> list:
466
466
 
467
467
 
468
468
  def get_cllmm_gauges()->list:
469
- return ["A4261002", "A4260527", "A4260633"]
469
+ return ["A4261002", "A4260524", "A4260633"]
470
470
 
471
471
 
472
472
  def get_gauges(category: str, ewr_table_path: str = None) -> set:
@@ -542,16 +542,43 @@ def gauge_groups(parameter_sheet: pd.DataFrame) -> dict:
542
542
 
543
543
  # def gauges_to_measurand()
544
544
 
545
- def get_causal_ewr() -> dict:
546
545
 
547
- ewr2obj_path = os.path.join(BASE_PATH, "parameter_metadata/ewr2obj.csv")
548
- obj2target_path = os.path.join(BASE_PATH, "parameter_metadata/obj2target.csv")
549
- obj2yrtarget_path = os.path.join(BASE_PATH, "parameter_metadata/obj2yrtarget.csv")
546
+ def get_obj_mapping(
547
+ parameter_sheet_path=None,
548
+ objective_reference_path=None
549
+ ) -> pd.DataFrame:
550
+ '''
551
+ Retrieves objective mapping and merges with parameter sheet on Gauge, Planning Unit, Code, and LTWPShortName
552
+ to create a longform table that lists the associations between each EWR and ecological objectives.
553
+ Returns a DataFrame with the merged result.
554
+ Args:
555
+ param_sheet_path (str) = file path to parameter sheet. If None, default parameter_sheet.csv inside the tool is selected
556
+ obj_ref_path (str) = file path to objective mapping csv. If Not, default objective_reference.csv inside EWR tool is selected
557
+ '''
558
+ param_sheet_cols = [
559
+ 'PlanningUnitName', 'LTWPShortName', 'SWSDLName', 'State', 'Gauge', 'Code', 'EcoObj'
560
+ ]
550
561
 
551
- causal_ewr = {
552
- "ewr2obj": pd.read_csv(ewr2obj_path),
553
- "obj2target": pd.read_csv(obj2target_path),
554
- "obj2yrtarget":pd.read_csv(obj2yrtarget_path)
555
- }
562
+ if not objective_reference_path:
563
+ objective_reference_path = os.path.join(BASE_PATH, "parameter_metadata/obj_reference.csv")
564
+
556
565
 
557
- return causal_ewr
566
+ obj_ref = pd.read_csv(objective_reference_path)
567
+
568
+
569
+ okay_EWRs, _ = get_EWR_table(file_path=parameter_sheet_path)
570
+ okay_EWRs_sub = okay_EWRs[param_sheet_cols]
571
+
572
+ # Split 'EnvObj' by '+' and explode to long format
573
+ longform_ewr = okay_EWRs_sub.assign(
574
+ EnvObj=okay_EWRs_sub['EcoObj'].str.split('+')
575
+ ).explode('EnvObj').drop_duplicates()
576
+
577
+ merged_df = longform_ewr.merge(
578
+ obj_ref,
579
+ left_on= ['LTWPShortName', 'PlanningUnitName', 'Gauge', 'Code', 'EcoObj', 'SWSDLName', 'State'],
580
+ right_on=['LTWPShortName', 'PlanningUnitName', 'Gauge', 'Code', 'EcoObj', 'SWSDLName', 'State'],
581
+ how='left'
582
+ )
583
+
584
+ return merged_df