pyhcal 1.1.2__tar.gz → 1.1.4__tar.gz
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.
- {pyhcal-1.1.2 → pyhcal-1.1.4}/PKG-INFO +1 -1
- pyhcal-1.1.4/demo.py +52 -0
- pyhcal-1.1.4/examples/PstFrom.log +8 -0
- {pyhcal-1.1.2 → pyhcal-1.1.4}/pyproject.toml +1 -1
- {pyhcal-1.1.2 → pyhcal-1.1.4}/src/pyhcal/calibrators.py +2 -1
- {pyhcal-1.1.2 → pyhcal-1.1.4}/src/pyhcal/mappers.py +2 -2
- {pyhcal-1.1.2 → pyhcal-1.1.4}/src/pyhcal/setup_utils.py +4 -25
- {pyhcal-1.1.2 → pyhcal-1.1.4}/.gitattributes +0 -0
- {pyhcal-1.1.2 → pyhcal-1.1.4}/.gitignore +0 -0
- {pyhcal-1.1.2 → pyhcal-1.1.4}/ERROR.FIL +0 -0
- {pyhcal-1.1.2 → pyhcal-1.1.4}/src/pyhcal/ERROR.FIL +0 -0
- {pyhcal-1.1.2 → pyhcal-1.1.4}/src/pyhcal/__init__.py +0 -0
- {pyhcal-1.1.2 → pyhcal-1.1.4}/src/pyhcal/data/HUC_Names.csv +0 -0
- {pyhcal-1.1.2 → pyhcal-1.1.4}/src/pyhcal/figures.py +0 -0
- {pyhcal-1.1.2 → pyhcal-1.1.4}/src/pyhcal/metrics.py +0 -0
- {pyhcal-1.1.2 → pyhcal-1.1.4}/src/pyhcal/repository.py +0 -0
pyhcal-1.1.4/demo.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
#%%
|
|
2
|
+
from pyhcal.calibrators import calibrator
|
|
3
|
+
from pyhcal import metrics
|
|
4
|
+
from pyhcal import figures
|
|
5
|
+
#%%
|
|
6
|
+
cal = calibrator('C:/Users/mfratki/Documents/Calibrations/Nemadji')
|
|
7
|
+
cal.load_model(0)
|
|
8
|
+
|
|
9
|
+
# %% Outlets
|
|
10
|
+
|
|
11
|
+
cal.get_outlets()
|
|
12
|
+
|
|
13
|
+
station_ids = ['S007-571', 'W28068001', 'S005-671', 'S008-051', 'S012-414']
|
|
14
|
+
reach_ids = [417]
|
|
15
|
+
|
|
16
|
+
df = cal.compare_simulated_observed(station_ids,reach_ids,'WT','h')
|
|
17
|
+
#
|
|
18
|
+
|
|
19
|
+
figures.contTimeseries(df.dropna(subset=['observed']),station_ids,'WT','degf')
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
#%% Mapping
|
|
23
|
+
cal.mapper.map_parameter('PERLND',
|
|
24
|
+
'PWAT-PARM2',
|
|
25
|
+
'LZSN')
|
|
26
|
+
cal.mapper.map_parameter('PERLND',
|
|
27
|
+
'PWAT-PARM2',
|
|
28
|
+
'LZSN',
|
|
29
|
+
weight_by_area=False)
|
|
30
|
+
|
|
31
|
+
cal.mapper.map_output('PERLND','PERO')
|
|
32
|
+
|
|
33
|
+
#%% Reports
|
|
34
|
+
|
|
35
|
+
# loading at catchment and watershed
|
|
36
|
+
cal.reports
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
# Total amount of constituent contributed from the landscape to channels
|
|
40
|
+
|
|
41
|
+
cal.model.reports.contributions('Q',630)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
cal.model.reports.landcover_contributions('Q',417)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
#%% Data
|
|
49
|
+
|
|
50
|
+
cal.dm.constituent_summary('Q','h')
|
|
51
|
+
cal.dm.reports.outlet_summary()
|
|
52
|
+
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
2026-02-04 16:48:27.489460 starting: opening PstFrom.log for logging
|
|
2
|
+
2026-02-04 16:48:27.489629 starting PstFrom process
|
|
3
|
+
2026-02-04 16:48:27.489740 starting: setting up dirs
|
|
4
|
+
2026-02-04 16:48:27.489948 starting: removing existing new_d 'C:\Users\mfratki\Documents\Projects\Tests\Nemadji\pest'
|
|
5
|
+
2026-02-04 16:48:27.492489 finished: removing existing new_d 'C:\Users\mfratki\Documents\Projects\Tests\Nemadji\pest' took: 0:00:00.002541
|
|
6
|
+
2026-02-04 16:48:27.492551 starting: copying original_d 'C:\Users\mfratki\Documents\Projects\Tests\Nemadji\model' to new_d 'C:\Users\mfratki\Documents\Projects\Tests\Nemadji\pest'
|
|
7
|
+
2026-02-04 16:48:27.919204 finished: copying original_d 'C:\Users\mfratki\Documents\Projects\Tests\Nemadji\model' to new_d 'C:\Users\mfratki\Documents\Projects\Tests\Nemadji\pest' took: 0:00:00.426653
|
|
8
|
+
2026-02-04 16:48:27.920766 finished: setting up dirs took: 0:00:00.431026
|
|
@@ -159,7 +159,8 @@ class calibrator:
|
|
|
159
159
|
outlets[int(outlet_id)] = {}
|
|
160
160
|
df_outlet = df.loc[df['outlet_id'] == outlet_id]
|
|
161
161
|
outlets[int(outlet_id)]['station_ids'] = list(set(df_outlet['station_id']))
|
|
162
|
-
outlets[int(outlet_id)]['reach_ids'] = list(set(df_outlet['reach_id']))
|
|
162
|
+
outlets[int(outlet_id)]['reach_ids'] = list([int(reach_id) for reach_id in set(df_outlet['reach_id'])])
|
|
163
|
+
outlets[int(outlet_id)]['true_reach_id'] = list([int(reach_id) for reach_id in set(df_outlet['reach_id'])])
|
|
163
164
|
outlets[int(outlet_id)]['model_name'] = df_outlet['repository_name'].iloc[0]
|
|
164
165
|
return outlets
|
|
165
166
|
|
|
@@ -47,7 +47,7 @@ class uciMapper():
|
|
|
47
47
|
tables = [mapper.join_table(operation,table_name,table_id) for mapper in self.mappers]
|
|
48
48
|
table = pd.concat(tables)
|
|
49
49
|
return table
|
|
50
|
-
|
|
50
|
+
|
|
51
51
|
class Mapper():
|
|
52
52
|
def __init__(self,model_name,uci,subwatershed_gdf,hbn = None):
|
|
53
53
|
self.model_name = model_name
|
|
@@ -63,7 +63,7 @@ class Mapper():
|
|
|
63
63
|
|
|
64
64
|
def map_parameter(self,operation,table_name,parameter,table_id=0,weight_by_area = True):
|
|
65
65
|
fig, ax = plt.subplots()
|
|
66
|
-
self.join_table(operation,table_name,parameter,table_id).plot(column = parameter,ax = ax,cmap='viridis',legend=True)
|
|
66
|
+
self.join_table(operation,table_name,parameter,table_id,weight_by_area).plot(column = parameter,ax = ax,cmap='viridis',legend=True)
|
|
67
67
|
plt.title(parameter)
|
|
68
68
|
|
|
69
69
|
def join_table(self,operation,table_name,parameter,table_id=0,weight_by_area = True):
|
|
@@ -4,9 +4,11 @@ Created on Wed Jun 15 15:21:35 2022
|
|
|
4
4
|
|
|
5
5
|
@author: mfratki
|
|
6
6
|
"""
|
|
7
|
+
from operator import mod
|
|
7
8
|
from mpcaHydro.data_manager import dataManager
|
|
8
9
|
from hspf.wdmReader import readWDM
|
|
9
10
|
from hspf.uci import UCI
|
|
11
|
+
from hspf.hspfModel import hspfModel
|
|
10
12
|
from pyhcal.repository import Repository
|
|
11
13
|
from mpcaHydro import outlets
|
|
12
14
|
|
|
@@ -41,7 +43,7 @@ class Builder():
|
|
|
41
43
|
self.new_uci = None
|
|
42
44
|
self.uci = None
|
|
43
45
|
self.dm = None
|
|
44
|
-
self.calibration_reaches = outlets.wplmn_station_opnids(model_name)
|
|
46
|
+
self.calibration_reaches = [abs(opnid) for opnid in outlets.wplmn_station_opnids(model_name)]
|
|
45
47
|
self.oracle_username = oracle_username
|
|
46
48
|
self.oracle_password = oracle_password
|
|
47
49
|
|
|
@@ -113,32 +115,10 @@ class Builder():
|
|
|
113
115
|
copy_path.joinpath(wdm_file.name.replace('.wdm','.hdf5').replace('.WDM','hdf5')))
|
|
114
116
|
|
|
115
117
|
def run_model(self, wait_for_completion=True):
|
|
116
|
-
#run_model(self.new_uci, wait_for_completion)
|
|
117
118
|
# Run the uci file
|
|
118
|
-
winHSPF =
|
|
119
|
+
winHSPF = hspfModel.winHSPF #TODO: fix this hardcoding
|
|
119
120
|
subprocess.run([winHSPF,self.new_uci]) #, stdout=subprocess.PIPE, creationflags=0x08000000)
|
|
120
121
|
|
|
121
|
-
def run_model(uci_file, wait_for_completion=True):
|
|
122
|
-
winHSPF = str(Path(__file__).resolve().parent.parent) + '\\bin\\WinHSPFlt\\WinHspfLt.exe'
|
|
123
|
-
|
|
124
|
-
# Arguments for the subprocess
|
|
125
|
-
args = [winHSPF, uci_file.as_posix()]
|
|
126
|
-
|
|
127
|
-
if wait_for_completion:
|
|
128
|
-
# Use subprocess.run to wait for the process to complete (original behavior)
|
|
129
|
-
subprocess.run(args)
|
|
130
|
-
else:
|
|
131
|
-
# Use subprocess.Popen to run the process in the background without waiting
|
|
132
|
-
# On Windows, you can use creationflags to prevent a console window from appearing
|
|
133
|
-
if sys.platform.startswith('win'):
|
|
134
|
-
# Use a variable for the flag to ensure it's only used on Windows
|
|
135
|
-
creationflags = subprocess.CREATE_NO_WINDOW
|
|
136
|
-
subprocess.Popen(args, creationflags=creationflags)
|
|
137
|
-
else:
|
|
138
|
-
# For other platforms (like Linux/macOS), Popen without special flags works fine
|
|
139
|
-
subprocess.Popen(args)
|
|
140
|
-
|
|
141
|
-
|
|
142
122
|
|
|
143
123
|
### functions for setting up the UCI file properly
|
|
144
124
|
def setup(uci,name,run = 0,reach_ids = None,n = 1,time_step = 3):
|
|
@@ -222,7 +202,6 @@ def setup_binaryinfo(uci,default_output = 4,reach_ids = None):
|
|
|
222
202
|
uci.update_table(2,'RCHRES','BINARY-INFO',0,columns = ['HEATPR','HYDRPR'],opnids = reach_ids,operator = 'set')
|
|
223
203
|
return uci
|
|
224
204
|
|
|
225
|
-
|
|
226
205
|
def setup_qualid(uci):
|
|
227
206
|
#### Standardize QUAL-ID Names
|
|
228
207
|
# Perlands
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|