forked from dwr-psandhu/ann_calsim
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdssioutils.py
50 lines (44 loc) · 2.12 KB
/
dssioutils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#
import pyhecdss
import pandas as pd
import numpy as np
def add_pathnames(dssfile, paths):
'''
add the pathnames in the given HEC-DSS file and return the resulting dataframe
'''
sum = 0
for path in paths:
df = list(pyhecdss.get_ts(dssfile, path))[0][0]
# resample to daily, if daily this is no op
df = df.resample('D').ffill()
# then convert to time stamp
if isinstance(df.index, pd.PeriodIndex):
df.index = df.index.to_timestamp()
sum = sum+df.iloc[:, 0]
return sum
def collate_calsim_inputs_for_ann(dssfile):
'''
read inputs from given HEC-DSS File and has hardwired definitions of pathnames that have to be added to yield inputs
Parameters
----------
input HEC-DSS file with pathnames
Returns
------
returns a dataframe with named feature columns
'''
sac = add_pathnames(dssfile, ['/CALSIM-SMOOTH/C_SAC048/FLOW//1DAY/L2020A_1EX_DEC_CLOSED/',
'/CALSIM/C_CSL004A/CHANNEL//1MON/L2020A/',
'/CALSIM/C_CLV004/CHANNEL//1MON/L2020A/',
'/CALSIM/C_MOK019/CHANNEL//1MON/L2020A/'])
exports = add_pathnames(dssfile, ['/CALSIM/C_CAA003_TD/FLOW-DELIVERY//1MON/L2020A/',
'/CALSIM/C_DMC000_TD/FLOW-DELIVERY//1MON/L2020A/',
'/CALSIM/D408/FLOW-DELIVERY//1MON/L2020A/',
'/CALSIM/D_SJR028_WTPDWS/DIVERSION//1MON/L2020A/'])
dcc=add_pathnames(dssfile, ['/CALSIM/DXC/GATE-DAYS-OPEN//1MON/L2020A/'])
net_dcd=add_pathnames(dssfile, ['/CALSIM/NET_DICU/DICU_FLOW//1MON/L2020A/'])
sjr = add_pathnames(dssfile, ['/CALSIM-SMOOTH/C_SJR070/FLOW//1DAY/L2020A_1EX_DEC_CLOSED/'])
tide = add_pathnames(dssfile, ['/DWR/SAN_FRANCISCO/STAGE-MAX-MIN//1DAY/ASTRO_NAVD_20170607/'])
smscg = add_pathnames(dssfile, ['/CALSIM/SMSCG_OP/GATE-OP-RATIO//1DAY/L2020A_1EX_DEC_CLOSED/'])
df=pd.concat([dcc,exports,sac,sjr,tide,net_dcd,smscg],axis=1,join='inner')
df.columns=['dcc','exports','sac','sjr','tide','net_dcd','smscg']
return df