py-ewr 2.2.5__py3-none-any.whl → 2.2.7__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.
@@ -1,7 +1,7 @@
1
1
  from typing import Dict, List
2
2
  import csv
3
3
  import os
4
- import urllib
4
+ import urllib.request
5
5
  import re
6
6
  from datetime import datetime, date
7
7
  import logging
@@ -436,13 +436,63 @@ def extract_gauge_from_string(input_string: str) -> str:
436
436
  gauge = input_string.split('_')[0]
437
437
  return gauge
438
438
 
439
- # def match_MDBA_nodes_dev(input_df: pd.DataFrame, model_metadata: pd.DataFrame, ewr_table_path: str) -> tuple:
440
- # '''
441
- # Iterate over the gauges in the parameter sheet,
442
- # find all the occurences of that gauge in the ARWC column in the model metadata file,
443
- # for each match, search for the matching siteID in the model file,
444
- # append the column to the flow dataframe.
439
+ def match_MDBA_nodes(input_df: pd.DataFrame, model_metadata: pd.DataFrame, ewr_table_path: str) -> tuple:
440
+ '''
441
+ Iterate over the gauges in the parameter sheet,
442
+ find all the occurences of that gauge in the ARWC column in the model metadata file,
443
+ for each match, search for the matching siteID in the model file,
444
+ append the column to the flow dataframe.
445
+
446
+ Args:
447
+ input_df (pd.DataFrame): flow/water level dataframe
448
+ model_metadata (pd.DataFrame): dataframe linking model nodes to gauges
449
+
450
+ Returns:
451
+ tuple[pd.DataFrame, pd.DataFrame]: flow dataframe, water level dataframe
452
+
453
+ '''
454
+
455
+ df_flow = pd.DataFrame(index = input_df.index)
456
+ df_level = pd.DataFrame(index = input_df.index)
457
+
458
+ unique_gauges = data_inputs.get_gauges('all gauges')
459
+ flow_gauges = data_inputs.get_gauges('flow gauges', ewr_table_path=ewr_table_path)
460
+ level_gauges = data_inputs.get_gauges('level gauges', ewr_table_path=ewr_table_path)
461
+
462
+ report = pd.DataFrame(index = list(set(list(flow_gauges) + list(level_gauges))), columns = ['flow', 'level'])
463
+ report['flow'] = 'N'
464
+ report['level'] = 'N'
465
+ measurands = ['1', '35']
466
+ #Iterate over all gauges that have EWRs attached
467
+ for gauge in unique_gauges:
468
+ # Subset of the SiteID file with the gauges
469
+ subset_df = model_metadata[model_metadata['AWRC'] == gauge]
470
+ # Iterate over the unique measurands of interest (currently flow=1 and level/lake level=35)
471
+ for measure in measurands:
472
+ # Iterate over the occurences of the gauge and check if the matching SiteID file is in the model file with the correct measurand
473
+ for index, siteID in subset_df.iterrows():
474
+ site_mm = siteID['SITEID']
475
+ model_file_subset = input_df.filter(regex=rf"^{site_mm}-{measure}(?=-)", axis = 1)
476
+ # Just use the first column if there are multiple of the same siteID-measurand occurences
477
+ if not model_file_subset.empty:
478
+ if (measure == '1') and (gauge in flow_gauges):
479
+ df_flow[gauge] = model_file_subset.iloc[:,0]
480
+ report.at[gauge, 'flow'] = 'Y'
481
+ if (measure == '35') and (gauge in level_gauges):
482
+ df_level[gauge] = model_file_subset.iloc[:,0]
483
+ report.at[gauge, 'level'] = 'Y'
484
+
485
+ if df_flow.empty and df_level.empty:
486
+ raise ValueError('No relevant gauges and or measurands found in dataset, the EWR tool cannot evaluate this model output file')
487
+
488
+ # report.to_csv('report_v1.csv')
489
+ return df_flow, df_level
490
+
445
491
 
492
+ # def match_MDBA_nodes_old(input_df: pd.DataFrame, model_metadata: pd.DataFrame, ewr_table_path: str) -> tuple:
493
+ # '''Checks if the source file columns have EWRs available, returns a flow and level dataframe with only
494
+ # the columns with EWRs available. Renames columns to gauges
495
+
446
496
  # Args:
447
497
  # input_df (pd.DataFrame): flow/water level dataframe
448
498
  # model_metadata (pd.DataFrame): dataframe linking model nodes to gauges
@@ -451,67 +501,38 @@ def extract_gauge_from_string(input_string: str) -> str:
451
501
  # tuple[pd.DataFrame, pd.DataFrame]: flow dataframe, water level dataframe
452
502
 
453
503
  # '''
504
+
505
+ # flow_gauges = data_inputs.get_gauges('flow gauges', ewr_table_path=ewr_table_path)
506
+ # level_gauges = data_inputs.get_gauges('level gauges', ewr_table_path=ewr_table_path)
507
+ # measurands = ['1', '35']
454
508
  # df_flow = pd.DataFrame(index = input_df.index)
455
509
  # df_level = pd.DataFrame(index = input_df.index)
456
-
457
- # unique_gauges = #Get unique gauges from the parameter sheet
458
- # #TODO: include logic to have the measurand included
459
- # for i in unique_gauges:
460
- # # Subset of the SiteID file with the gauges
461
- # subset_df = model_metadata[model_metadata['AWRC'] == i]
462
- # # Iterate over the occurences of the gauge and check if the matching SiteID file is in the model file
463
- # for j in subset_df.iterrows:
464
- # site_mm = j['SITEID']
465
- # if site_mm in input_df.columns:
466
- # df_flow[i] = input_df[site_mm+INPUT_MEASURAND+ANY_QUALITY_CODE]
467
- # or
468
- # df_level[i] = input_df[site_mm+INPUT_MEASURAND+ANY_QUALITY_CODE]
510
+ # for col in input_df.columns:
511
+ # col_clean = col.replace(' ', '')
512
+ # site = col_clean.split('-')[0]
513
+ # measure = col_clean.split('-')[1]
514
+ # if ((measure in measurands) and (model_metadata['SITEID'] == site).any()):
515
+ # subset = model_metadata.query("SITEID==@site")
516
+ # for iset in range(len(subset)):
517
+ # gauge = subset["AWRC"].iloc[iset]
518
+ # if gauge in flow_gauges and measure == '1':
519
+ # df_flow[gauge] = input_df[col]
520
+ # if gauge in level_gauges and measure == '35':
521
+ # aa=input_df[[col]]
522
+ # if (len(aa.columns)>1):
523
+ # print('More than one site has been identified, the first site is used')
524
+ # print('Site info: ', col)
525
+ # df_level[gauge] = aa.iloc[:,0]
526
+ # else:
527
+ # df_level[gauge] = input_df[col]
469
528
 
470
529
  # if df_flow.empty and df_level.empty:
471
530
  # raise ValueError('No relevant gauges and or measurands found in dataset, the EWR tool cannot evaluate this model output file')
472
- # return df_flow, df_level
473
-
474
-
475
- def match_MDBA_nodes(input_df: pd.DataFrame, model_metadata: pd.DataFrame, ewr_table_path: str) -> tuple:
476
- '''Checks if the source file columns have EWRs available, returns a flow and level dataframe with only
477
- the columns with EWRs available. Renames columns to gauges
478
531
 
479
- Args:
480
- input_df (pd.DataFrame): flow/water level dataframe
481
- model_metadata (pd.DataFrame): dataframe linking model nodes to gauges
482
-
483
- Returns:
484
- tuple[pd.DataFrame, pd.DataFrame]: flow dataframe, water level dataframe
485
-
486
- '''
532
+ # df_flow.to_csv('existing_flow_mapped.csv')
533
+ # df_level.to_csv('existing_level_mapped.csv')
487
534
 
488
- flow_gauges = data_inputs.get_gauges('flow gauges', ewr_table_path=ewr_table_path)
489
- level_gauges = data_inputs.get_gauges('level gauges', ewr_table_path=ewr_table_path)
490
- measurands = ['1', '35']
491
- df_flow = pd.DataFrame(index = input_df.index)
492
- df_level = pd.DataFrame(index = input_df.index)
493
- for col in input_df.columns:
494
- col_clean = col.replace(' ', '')
495
- site = col_clean.split('-')[0]
496
- measure = col_clean.split('-')[1]
497
- if ((measure in measurands) and (model_metadata['SITEID'] == site).any()):
498
- subset = model_metadata.query("SITEID==@site")
499
- for iset in range(len(subset)):
500
- gauge = subset["AWRC"].iloc[iset]
501
- if gauge in flow_gauges and measure == '1':
502
- df_flow[gauge] = input_df[col]
503
- if gauge in level_gauges and measure == '35':
504
- aa=input_df[[col]]
505
- if (len(aa.columns)>1):
506
- print('More than one site has been identified, the first site is used')
507
- print('Site info: ', col)
508
- df_level[gauge] = aa.iloc[:,0]
509
- else:
510
- df_level[gauge] = input_df[col]
511
-
512
- if df_flow.empty:
513
- raise ValueError('No relevant gauges and or measurands found in dataset, the EWR tool cannot evaluate this model output file')
514
- return df_flow, df_level
535
+ # return df_flow, df_level
515
536
 
516
537
  def match_NSW_nodes(input_df: pd.DataFrame, model_metadata: pd.DataFrame) -> tuple:
517
538
  '''Checks if the source file columns have EWRs available, returns a flow and level dataframe with only
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: py_ewr
3
- Version: 2.2.5
3
+ Version: 2.2.7
4
4
  Summary: Environmental Water Requirement calculator
5
5
  Home-page: https://github.com/MDBAuth/EWR_tool
6
6
  Author: Martin Job
@@ -12,21 +12,21 @@ Classifier: Operating System :: OS Independent
12
12
  Classifier: Development Status :: 4 - Beta
13
13
  Classifier: Programming Language :: Python
14
14
  Classifier: Programming Language :: Python :: 3
15
- Classifier: Programming Language :: Python :: 3.8
16
15
  Classifier: Programming Language :: Python :: 3.9
17
16
  Classifier: Programming Language :: Python :: 3.10
18
17
  Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
19
20
  Classifier: Framework :: Pytest
20
21
  Description-Content-Type: text/markdown
21
22
  License-File: LICENSE
22
- Requires-Dist: ipython ==8.8.0
23
- Requires-Dist: ipywidgets ==7.7.0
24
- Requires-Dist: pandas ==2.0.3
25
- Requires-Dist: requests ==2.25.1
23
+ Requires-Dist: pandas >2
24
+ Requires-Dist: requests >2
26
25
  Requires-Dist: mdba-gauge-getter ==0.5.1
27
- Requires-Dist: cachetools ==5.2.0
28
- Requires-Dist: xarray ==2023.01.0
29
- Requires-Dist: netCDF4 ==1.6.4
26
+ Requires-Dist: cachetools >5
27
+ Requires-Dist: xarray
28
+ Requires-Dist: h5py
29
+ Requires-Dist: netCDF4
30
30
  Requires-Dist: numpy <2
31
31
 
32
32
  [![CI](https://github.com/MDBAuth/EWR_tool/actions/workflows/test-release.yml/badge.svg)]()
@@ -34,12 +34,16 @@ Requires-Dist: numpy <2
34
34
  [![PyPI](https://img.shields.io/pypi/v/py-ewr)](https://pypi.org/project/py-ewr/)
35
35
  [![DOI](https://zenodo.org/badge/342122359.svg)](https://zenodo.org/badge/latestdoi/342122359)
36
36
 
37
- ### **EWR tool version 2.2.5 README**
37
+ ### **EWR tool version 2.2.7 README**
38
38
 
39
39
  ### **Notes on recent version updates**
40
+ - Including draft objective mapping files in the package (see below sub heading **Objective mapping** for more information). Objective mapping has been therefore pulled out of the parameter sheet
41
+ - Including an example parallel processing script for running the EWR tool
42
+ - Adding handling for cases where there are single MDBA bigmod site IDs mapping to multiple different gauges
43
+ - Fix SDL resource unit mapping in the parameter sheet
44
+ - Adding lat and lon to the parameter sheet
40
45
  - ten thousand year handling - this has been brought back online.
41
46
  - Remove TQDM loading bars
42
- - Handle duplicate sites in MDBA siteID file - where a duplicate exists, the first match is used and the rest are skipped over
43
47
  - Adding new model format handling - 'IQQM - netcdf'
44
48
  - Standard time-series handling added - each column needs a gauge, followed by and underscore, followed by either flow or level (e.g. 409025_flow). This handling also has missing date filling - so any missing dates will be filled with NaN values in all columns.
45
49
  - bug fixes: spells of length equal to the minimum required spell length were getting filtered out of the successful events table and successful interevents table, fixed misclassification of some gauges to flow, level, and lake level categories
@@ -47,7 +51,7 @@ Requires-Dist: numpy <2
47
51
 
48
52
  ### **Installation**
49
53
 
50
- Note - requires Python 3.8 or newer
54
+ Note - requires Python 3.9 to 3.13 (inclusive)
51
55
 
52
56
  Step 1.
53
57
  Upgrade pip
@@ -109,7 +113,30 @@ all_successful_interEvents = ewr_oh.get_all_successful_interEvents()
109
113
  ### Option 2: Running model scenarios through the EWR tool
110
114
 
111
115
  1. Tell the tool where the model files are (can either be local or in a remote location)
112
- 2. Tell the tool what format the model files are in (Current model format options: 'Bigmod - MDBA', 'Source - NSW (res.csv)', 'Standard time-series' - see manual for formatting requirements)
116
+ 2. Tell the tool what format the model files are in. The current model format options are:
117
+ - 'Bigmod - MDBA'
118
+ Bigmod formatted outputs
119
+ - 'Source - NSW (res.csv)'
120
+ Source res.csv formatted outputs
121
+ - 'Standard time-series'
122
+ The first column header should be *Date* with the date values in the YYYY-MM-DD format.
123
+ The next columns should have the *gauge* followed by *_* followed by either *flow* or *level*
124
+ E.g.
125
+ | Date | 409025_flow | 409025_level | 414203_flow |
126
+ | --- | --- | --- | --- |
127
+ | 1895-07-01 | 8505 | 5.25 | 8500 |
128
+ | 1895-07-02 | 8510 | 5.26 | 8505 |
129
+
130
+ - 'ten thousand year'
131
+ This has the same formatting requirements as the 'Standard time-series'. This can handle ten thousand years worth of hydrology data.
132
+ The first column header should be *Date* with the date values in the YYYY-MM-DD format.
133
+ The next columns should have the *gauge* followed by *_* followed by either *flow* or *level*
134
+ E.g.
135
+ | Date | 409025_flow | 409025_level | 414203_flow |
136
+ | --- | --- | --- | --- |
137
+ | 105-07-01 | 8505 | 5.25 | 8500 |
138
+ | 105-07-02 | 8510 | 5.26 | 8505 |
139
+
113
140
 
114
141
  ```python
115
142
  #USER INPUT REQUIRED>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -199,11 +226,11 @@ For issues relating to the script, a tutorial, or feedback please contact Lara P
199
226
 
200
227
 
201
228
  **Disclaimer**
202
- Every effort has been taken to ensure the EWR database represents the original EWRs from state long term water plans as best as possible, and that the code within this tool has been developed to interpret and analyse these EWRs in an accurate way. However, there may still be unresolved bugs in the EWR parameter sheet and/or EWR tool. Please report any bugs to the issues tab under the GitHub project so we can investigate further.
229
+ Every effort has been taken to ensure the EWR database represents the original EWRs from state Long Term Water Plans (LTWPs) and Environmental Water Management Plans (EWMPs) as best as possible, and that the code within this tool has been developed to interpret and analyse these EWRs in an accurate way. However, there may still be unresolved bugs in the EWR parameter sheet and/or EWR tool. Please report any bugs to the issues tab under the GitHub project so we can investigate further.
203
230
 
204
231
 
205
232
  **Notes on development of the dataset of EWRs**
206
- The MDBA has worked with Basin state representatives to ensure scientific integrity of EWRs has been maintained when translating from raw EWRs in the Basin state Long Term Water Plans (LTWPs) to the machine readable format found in the parameter sheet within this tool.
233
+ The MDBA has worked with Basin state representatives to ensure scientific integrity of EWRs has been maintained when translating from raw EWRs in the Basin state LTWPs and EWMPs to the machine readable format found in the parameter sheet within this tool.
207
234
 
208
235
  **Compatibility**
209
236
 
@@ -226,11 +253,8 @@ NSW:
226
253
 
227
254
  Consult the user manual for instructions on how to run the tool. Please email the above email addresses for a copy of the user manual.
228
255
 
229
- To disable progress bars, as for example when running remote scripted runs, use
230
-
231
- ``` python
232
- import os
233
- os.environ["TQDM_DISABLE"] = "1"
234
- ```
235
- *before* importing py-ewr in your script.
236
-
256
+ **Objective mapping**
257
+ Objective mapping csv files are now included in the EWR tool package. Currently this objective mapping is in an early draft format. The objective mapping will be finalised after consultation with relevant state representatives. The files are intended to be used together to link EWRs to the detailed objectives, theme level targets and specific goals. The three sheets are located in the py_ewr/parameter_metadata folder:
258
+ - ewr2obj.csv: For each planning unit, gauge, ewr combination there are either one or many env_obj codes. These env_obj codes come under one of five different theme level targets (Native Fish, Native vegetation, Waterbirds, Other species or Ecosystem functions)
259
+ - obj2target.csv: env_obj's are unique to their planning unit in the LTWP (noting there are often a lot of similarities between env_obj's in the same states). The plain english wording of the env objectives is also contained in this csv. The LTWP, planning unit and env_obj rows are repeated for each specific goal related to that LTWP, planning unit and env_obj.
260
+ - obj2yrtarget.csv: The environmental objectives are related to 5, 10 and 20 year targets
@@ -1,20 +1,20 @@
1
1
  py_ewr/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- py_ewr/data_inputs.py,sha256=PtpFyikT_IoMj_Ont6UykSdyiZXapny_Yk1J9VxParQ,19494
3
- py_ewr/evaluate_EWRs.py,sha256=UlnNp4dR0sT5Y-Mp67kW7kYq9yEzpCg6SbCbBBb26ok,230950
2
+ py_ewr/data_inputs.py,sha256=OLIxqq15yoEqLSRmBJP37erldUGRRvSNn2XwO8LKZA8,20080
3
+ py_ewr/evaluate_EWRs.py,sha256=ahdcc6N37wc-e6-S6JSx6VFm9eNkef0JBPXz16-SAaU,231267
4
4
  py_ewr/io.py,sha256=Is0xPAzLx6-ylpTFyYJxMimkNVxxoTxUcknTk6bQbgs,840
5
5
  py_ewr/observed_handling.py,sha256=aVQYI8Qs-v5DZOA_r8bYluE3ilgM7Vjygs29jA6kpaA,17848
6
- py_ewr/scenario_handling.py,sha256=2U6hSDfclEmfmgP6baO_CQImnat3gH34W_PC0H3MO58,34328
6
+ py_ewr/scenario_handling.py,sha256=95HdNNPkY-w77hxnHRJxfzmn9fBu6OqHM5iyoQPwOXE,35498
7
7
  py_ewr/summarise_results.py,sha256=CEHsx6hC5UidgYy-dCJW_buiktGKkTH9D_Yl5QpSzh8,31499
8
- py_ewr/model_metadata/SiteID_MDBA.csv,sha256=DcwFmBBoLmv1lGik40IwTMSjSBPaDsTt8Nluh2s7wjM,183665
8
+ py_ewr/model_metadata/SiteID_MDBA.csv,sha256=GHDuO7pnk4JrlCOG5aBw77bD0HxvEU_-NQ0kT9CKDrU,167724
9
9
  py_ewr/model_metadata/SiteID_NSW.csv,sha256=UVBxN43Z5KWCvWhQ5Rh6TNEn35q4_sjPxKyHg8wPFws,6805
10
10
  py_ewr/model_metadata/iqqm_stations.csv,sha256=vl4CPtPslG5VplSzf_yLZulTrmab-mEBHOfzFtS1kf4,110
11
11
  py_ewr/parameter_metadata/ewr2obj.csv,sha256=TyUDM_lzTu2v50j-kx-cvcX4QpwC0Vbc5pGFMG6rtMQ,4583480
12
12
  py_ewr/parameter_metadata/ewr_calc_config.json,sha256=l1AgIRlf7UUmk3BNQ4r3kutU48pYHHVKmLELjoB-8rQ,17664
13
13
  py_ewr/parameter_metadata/obj2target.csv,sha256=DIcwrOyvNPhBdvplWb8GU-2Hu33NwYhrXenAbnRD-dM,1773425
14
14
  py_ewr/parameter_metadata/obj2yrtarget.csv,sha256=x-lvGTHMsXutSKfgN6_B0ujQueiu953lEk-_k8ybTNw,56681
15
- py_ewr/parameter_metadata/parameter_sheet.csv,sha256=IiYAvf0hG9fchuwqtfDZhI8WSPB5jgaaaJ0MLwfPYAw,899556
16
- py_ewr-2.2.5.dist-info/LICENSE,sha256=ogEPNDSH0_dhiv_lT3ifVIdgIzHAqNA_SemnxUfPBJk,7048
17
- py_ewr-2.2.5.dist-info/METADATA,sha256=aZBST6CZikIrr_ce3PTDYRrpw8I90TQDWRRy2mAisGM,10156
18
- py_ewr-2.2.5.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
19
- py_ewr-2.2.5.dist-info/top_level.txt,sha256=n3725d-64Cjyb-YMUMV64UAuIflzUh2_UZSxiIbrur4,7
20
- py_ewr-2.2.5.dist-info/RECORD,,
15
+ py_ewr/parameter_metadata/parameter_sheet.csv,sha256=Pm741CUDywFJ_Jd8LN41YcimKvne-ey-gJskI13wTIk,772287
16
+ py_ewr-2.2.7.dist-info/LICENSE,sha256=ogEPNDSH0_dhiv_lT3ifVIdgIzHAqNA_SemnxUfPBJk,7048
17
+ py_ewr-2.2.7.dist-info/METADATA,sha256=yNiDURx97CzSTLq5BIHTYYv-Z4-j-RwdDSX_IJe9460,12521
18
+ py_ewr-2.2.7.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
19
+ py_ewr-2.2.7.dist-info/top_level.txt,sha256=n3725d-64Cjyb-YMUMV64UAuIflzUh2_UZSxiIbrur4,7
20
+ py_ewr-2.2.7.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.1.0)
2
+ Generator: setuptools (75.3.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5