py-ewr 2.0.0__py3-none-any.whl → 2.1.2__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
@@ -12,28 +12,6 @@ log.addHandler(logging.NullHandler())
12
12
 
13
13
  BASE_PATH = Path(__file__).resolve().parent
14
14
 
15
- # Importing the climate cat data - to be replaced by RAS data once available:
16
-
17
- def get_climate_cats(climate_file:str) -> pd.DataFrame:
18
- '''Uses standard climate categorisation unless user selects the 10,000 year climate sequence,
19
- in which case this is used
20
-
21
- Args:
22
- climate_file (str): location of the climate categoration file
23
-
24
- Returns:
25
- pd.DataFrame: Returns a dataframe showing annual climate categories for catchments
26
-
27
- '''
28
-
29
- if climate_file == 'Standard - 1911 to 2018 climate categorisation':
30
- climate_cats = pd.read_csv( BASE_PATH / 'climate_data/climate_cats.csv', index_col = 0)
31
-
32
- elif climate_file == 'NSW 10,000 year climate sequence':
33
- climate_cats = pd.read_csv(BASE_PATH / 'climate_data/climate_cats_10000year.csv', index_col = 0)
34
-
35
- return climate_cats
36
-
37
15
  @cached(cache=TTLCache(maxsize=1024, ttl=1800))
38
16
  def get_ewr_calc_config(file_path:str = None) -> dict:
39
17
  '''Loads the EWR calculation configuration file from repository or local file
@@ -134,96 +112,6 @@ def get_EWR_table(file_path:str = None) -> dict:
134
112
 
135
113
  return okay_EWRs, bad_EWRs
136
114
 
137
- @cached(cache=TTLCache(maxsize=1024, ttl=1800))
138
- def map_gauge_to_catchment(my_url:str = "parameter_metadata/parameter_sheet.csv") -> dict:
139
- ''' Allocates all the locations in the ewr table with catchments, as indicated by the
140
- first three numbers for each gauge
141
-
142
- Args:
143
- my_url (str): location of the EWR dataset
144
- Returns:
145
- dict[dict]: Dictinoary of catchments, for each catchment a dictionary of gauge number and name key value pairs
146
- '''
147
-
148
- lower_darling_gauges = ['425054', '425010', '425011', '425052', '425013', '425056', '425007',
149
- '425057', '425005', '425050', '425048', '425019', '425014', '425023',
150
- '425012', '425044', '425049', '425001', '425022', '42510037', '42510036',
151
- '425034', '425046', '425020', ]
152
-
153
- EWR_table, bad_EWRs = get_EWR_table(os.path.join(BASE_PATH, my_url))
154
-
155
- gauge_number = EWR_table['Gauge'].values
156
- gauge_name = EWR_table['CompliancePoint/Node'].values
157
-
158
- gauge_to_name = dict()
159
- for iteration, value in enumerate(gauge_number):
160
- if type(value) == str:
161
- gauge_to_name[value] = gauge_name[iteration]
162
-
163
- gauge_to_catchment = dict()
164
- namoi_catchment = dict()
165
- gwydir_catchment = dict()
166
- macquarie_catchment = dict()
167
- lachlan_catchment = dict()
168
- murray_catchment = dict()
169
- lower_darling_catchment = dict()
170
- barwon_darling_catchment = dict()
171
- murrumbidgee_catchment = dict()
172
- border_rivers_catchment = dict()
173
- moonie_catchment = dict()
174
- condamine_balonne = dict()
175
- warrego_catchment = dict()
176
- paroo_catchment = dict()
177
- other_catchment = dict()
178
-
179
- for k, v in gauge_to_name.items():
180
- if k.startswith('419'):
181
- namoi_catchment.update({k: v})
182
- elif k.startswith('418'):
183
- gwydir_catchment.update({k: v})
184
- elif (k.startswith('421') or k.startswith('420')):
185
- macquarie_catchment.update({k: v})
186
- elif k.startswith('412'):
187
- lachlan_catchment.update({k: v})
188
- elif (k.startswith('401') or k.startswith('409') or k.startswith('A426') or k.startswith('414')):
189
- murray_catchment.update({k: v})
190
- elif k.startswith('425'):
191
- if k in lower_darling_gauges:
192
- lower_darling_catchment.update({k: v})
193
- else:
194
- barwon_darling_catchment.update({k: v})
195
- elif k.startswith('410'):
196
- murrumbidgee_catchment.update({k: v})
197
- elif k.startswith('416'):
198
- border_rivers_catchment.update({k: v})
199
- elif k.startswith('417'):
200
- moonie_catchment.update({k: v})
201
- elif k.startswith('422'):
202
- condamine_balonne.update({k: v})
203
- elif k.startswith('423'):
204
- warrego_catchment.update({k: v})
205
- elif k.startswith('424'):
206
- paroo_catchment.update({k: v})
207
- else:
208
- other_catchment.update({k: v})
209
-
210
- gauge_to_catchment.update({'Namoi': namoi_catchment,
211
- 'Gwydir': gwydir_catchment,
212
- 'Macquarie-Castlereagh': macquarie_catchment,
213
- 'Lachlan': lachlan_catchment,
214
- 'Lower Darling': lower_darling_catchment,
215
- 'Barwon-Darling': barwon_darling_catchment,
216
- 'Murray': murray_catchment,
217
- 'Murrumbidgee': murrumbidgee_catchment,
218
- 'Border Rivers': border_rivers_catchment,
219
- 'Moonie' : moonie_catchment,
220
- 'Condamine-Balonne': condamine_balonne,
221
- 'Warrego': warrego_catchment,
222
- 'Paroo': paroo_catchment,
223
- 'Other': other_catchment
224
- })
225
- return gauge_to_catchment
226
-
227
115
  def get_MDBA_codes() -> pd.DataFrame:
228
116
  '''
229
117
  Load MDBA model metadata file containing model nodes
@@ -250,56 +138,6 @@ def get_NSW_codes() -> pd.DataFrame:
250
138
 
251
139
  return metadata
252
140
 
253
- def gauge_to_catchment(input_gauge:str) -> str:
254
- '''
255
- Takes in a gauge, maps it to the catchment
256
- returns the catchment
257
-
258
- Args:
259
- input_gauge (str): Gauge string
260
-
261
- Returns:
262
- str: The catchment name that the input gauge is located in
263
-
264
- '''
265
- catchments_gauges = map_gauge_to_catchment()
266
- for catchment in catchments_gauges:
267
- if input_gauge in catchments_gauges[catchment]:
268
- return catchment
269
-
270
- def wy_to_climate(water_years: np.array, catchment: str, climate_file: str) -> np.array:
271
- '''
272
- The function assigns a climate categorisation for every day, depending on the water year and catchment in the climate file
273
-
274
- Args:
275
- water_years (np.array): Daily water year array
276
- catchment (str): The catchment that the gauge is in
277
- climate file (str) = Which climate data to use
278
-
279
- Returns:
280
- np.array: Daily climate categorisation
281
-
282
- '''
283
- # Get the climate categorisation:
284
- climate_cats = get_climate_cats(climate_file)
285
-
286
- # Get the unique years covered in the flow dataframe, and how many days are in each year:
287
- unique_years, count_years = np.unique(water_years, return_counts=True)
288
-
289
- # Get the years covered by the climate cats, and filter them to those of interest (using min and max from flow dataframe)
290
- if not catchment:
291
- catchment = 'Total MDB'
292
- climateCatchment = climate_cats[catchment]
293
- climateFiltered = climateCatchment[(climateCatchment.index>=min(unique_years)) & (climateCatchment.index<=max(unique_years))].values
294
- # Repeating the climate result for that year over the total days in each year
295
- def mapper(climate, count):
296
- return np.repeat(climate, count)
297
-
298
- climateDailyYear = list(map(mapper, climateFiltered, count_years))
299
- climateDaily = np.concatenate(climateDailyYear)
300
-
301
- return climateDaily
302
-
303
141
  def get_level_gauges() -> tuple:
304
142
  '''Returning level gauges with EWRs
305
143
 
@@ -348,45 +186,6 @@ def get_multi_gauges(dataType: str) -> dict:
348
186
 
349
187
  return returnData
350
188
 
351
- def get_simultaneous_gauges(dataType: str) -> dict:
352
- '''
353
- Call function to return a dictionary of simultaneous gauges.
354
- Simultaneous gauges are for EWRs that need to be met simultaneously with EWRs at another location
355
-
356
- Args:
357
- dataType (str): Pass 'all' to get simultaneous gauges and their planning units, pass 'gauges' to get only gauges.
358
- Returns:
359
- dict: if 'all', nested dict returned with a level for planning units.
360
-
361
- '''
362
-
363
- all = {'PU_0000131': {'421090': '421022', '421022': '421090'},
364
- 'PU_0000132': {'421090': '421022', '421022': '421090'},
365
- 'PU_0000133': {'421090': '421022', '421022': '421090'}
366
- }
367
- returnData = {}
368
- if dataType == 'all':
369
- returnData = all
370
- if dataType == 'gauges':
371
- for i in all:
372
- returnData = {**returnData, **all[i]}
373
-
374
- return returnData
375
-
376
- def get_complex_calcs() -> dict:
377
- '''
378
- Returns a dictionary of the complex EWRs, and the type of analysis that needs to be undertaken
379
- These EWRs cannot be calculated using the standard suite of functions
380
-
381
- Returns:
382
- dict[dict]
383
- '''
384
- complexCalcs = {'409025': {'OB2_S': 'flowDurPostReq', 'OB2_P': 'flowDurPostReq',
385
- 'OB3_S': 'flowDurOutsideReq', 'OB3_P': 'flowDurOutsideReq'}}
386
-
387
- return complexCalcs
388
-
389
-
390
189
  def get_EWR_components(category):
391
190
  '''
392
191
  Ingests EWR category, returns the components required to analyse this type of EWR.
@@ -404,9 +203,9 @@ def get_EWR_components(category):
404
203
  if category == 'flow':
405
204
  pull = ['SM', 'EM', 'MINF', 'MAXF', 'DUR', 'ME', 'GP', 'EPY', 'MIE', 'FLV']
406
205
  elif category == 'low flow':
407
- pull = ['SM', 'EM', 'MINF', 'MAXF', 'DUR', 'ME', 'EPY', 'DURVD', 'MIE', 'FLV']
206
+ pull = ['SM', 'EM', 'MINF', 'MAXF', 'DUR', 'ME', 'EPY', 'MIE', 'FLV']
408
207
  elif category == 'cease to flow':
409
- pull = ['SM', 'EM', 'MINF', 'MAXF', 'DUR', 'ME', 'EPY', 'DURVD', 'MIE', 'FLV']
208
+ pull = ['SM', 'EM', 'MINF', 'MAXF', 'DUR', 'ME', 'EPY', 'MIE', 'FLV']
410
209
  elif category == 'cumulative':
411
210
  pull = ['SM', 'EM', 'MINV', 'DUR', 'ME', 'EPY', 'MINF', 'MAXF', 'MIE','AP','GP', 'FLV']
412
211
  elif category == 'cumulative_bbr':
@@ -428,19 +227,11 @@ def get_EWR_components(category):
428
227
  elif category == 'multi-gauge-flow':
429
228
  pull = ['SM', 'EM', 'MINF', 'MAXF', 'DUR', 'ME', 'GP', 'EPY', 'MG', 'MIE', 'FLV']
430
229
  elif category == 'multi-gauge-low flow':
431
- pull = ['SM', 'EM', 'MINF', 'MAXF', 'DUR', 'ME', 'EPY', 'DURVD', 'MG', 'MIE', 'FLV']
230
+ pull = ['SM', 'EM', 'MINF', 'MAXF', 'DUR', 'ME', 'EPY', 'MG', 'MIE', 'FLV']
432
231
  elif category == 'multi-gauge-cease to flow':
433
- pull = ['SM', 'EM', 'MINF', 'MAXF', 'DUR', 'ME', 'EPY', 'DURVD', 'MG', 'MIE', 'FLV']
232
+ pull = ['SM', 'EM', 'MINF', 'MAXF', 'DUR', 'ME', 'EPY', 'MG', 'MIE', 'FLV']
434
233
  elif category == 'multi-gauge-cumulative':
435
234
  pull = ['SM', 'EM', 'MINV', 'DUR', 'ME', 'EPY', 'MINF', 'MAXF','MG', 'MIE','AP','GP', 'FLV']
436
- elif category == 'simul-gauge-flow':
437
- pull = ['SM', 'EM', 'MINF', 'MAXF', 'DUR', 'ME', 'GP', 'EPY', 'DURVD', 'SG', 'MIE', 'FLV']
438
- elif category == 'simul-gauge-low flow':
439
- pull = ['SM', 'EM', 'MINF', 'MAXF', 'DUR', 'ME', 'GP', 'EPY', 'DURVD', 'SG', 'MIE', 'FLV']
440
- elif category == 'simul-gauge-cease to flow':
441
- pull = ['SM', 'EM', 'MINF', 'MAXF', 'DUR', 'ME', 'GP', 'EPY', 'DURVD', 'SG', 'MIE', 'FLV']
442
- elif category == 'complex':
443
- pull = ['SM', 'EM', 'MINF', 'MAXF', 'DUR', 'ME', 'GP', 'EPY', 'MIE', 'FLV']
444
235
  elif category == 'flood-plains':
445
236
  pull=['SM', 'EM', 'MINF', 'MAXF', 'MAXL', 'DUR', 'ME', 'MD', 'ML','EPY','WPG', 'MIE', 'FLV', 'GP']
446
237
  elif category == 'barrage-flow':
@@ -586,13 +377,11 @@ def get_gauges(category: str, ewr_table_path: str = None) -> set:
586
377
  vic_level_gauges = get_vic_level_gauges()
587
378
 
588
379
  multi_gauges = get_multi_gauges('gauges')
589
- simul_gauges = get_simultaneous_gauges('gauges')
590
380
  multi_gauges = list(multi_gauges.values())
591
- simul_gauges = list(simul_gauges.values())
592
381
  if category == 'all gauges':
593
- return set(EWR_table['Gauge'].to_list() + menindee_gauges + wp_gauges + multi_gauges + simul_gauges)
382
+ return set(EWR_table['Gauge'].to_list() + menindee_gauges + wp_gauges + multi_gauges)
594
383
  elif category == 'flow gauges':
595
- return set(EWR_table['Gauge'].to_list() + multi_gauges + simul_gauges + flow_barrage_gauges + qld_flow_gauges)
384
+ return set(EWR_table['Gauge'].to_list() + multi_gauges + flow_barrage_gauges + qld_flow_gauges)
596
385
  elif category == 'level gauges':
597
386
  level_gauges = EWR_table[EWR_table['FlowLevelVolume']=='L']['Gauge'].to_list()
598
387
  return set(menindee_gauges + wp_gauges + level_barrage_gauges + qld_level_gauges + level_gauges)