-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport_txt_hec_dss.py
67 lines (65 loc) · 2 KB
/
import_txt_hec_dss.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#INSERT THIS CODE IN HEC_DSSVue Script Editor.
#Created on 06/04/2019
#I will try to take this code up to date.
from hec.script import *
from hec.heclib.dss import *
from hec.heclib.util import *
from hec.io import *
import java
import os
#START PROGRAM
try :
try :
#IF IT DOES NOT EXIST IT CREATES IT
myDss = HecDss.open(PATH_TO_DSS")
path=PATH_TO_TXTFILES
list_files=os.listdir(path)
for line in list_files: #LOOP OVER THE FILES
file=path+'/'+line; #READ A FILE
staz_name= ''.join([i for i in line if not i.isdigit()])
#DELETE SOME ISSUES
staz_name=staz_name.replace('.txt','')
staz_name=staz_name.replace('_','')
#CREATE TIMESERIES
tsc = TimeSeriesContainer()
#CHANGE THE 15MIN INTERVAL FOR YOUR NEEDS
#SETUP PATHNAME
tsc.fullName = "/BASIN/"+staz_name+"/PRECIP-CUM//15MIN/OBSERVATION/"
station_file=open(file,'r')
#JUMP THE HEADERS
header1 = station_file.readline()
header2 = station_file.readline()
header3 = station_file.readline()
header4 = station_file.readline()
data=[]
ora=[]
cum=[]
rain=[]
for line in station_file:
columns=line.split()
dates=columns[0][3:6]+columns[0][0:3]+columns[0][6:10]
data.append(dates)
ora.append(columns[1])
cum.append(columns[2])
precipitation=float(columns[3])
rain.append(precipitation)
station_file.close()
#SETUP THE INTERVAL
tsc.interval = 15
times = []
start = HecTime(data[0],ora[0])
for value in rain :
times.append(start.value())
start.add(tsc.interval)
tsc.times = times
tsc.values = rain
tsc.numberValues = len(rain)
tsc.units = "mm"
tsc.type = "INST-CUM"
myDss.put(tsc)#HERE IT WILL UPDATE THE DSS FILE
except Exception, e :
MessageBox.showError(' '.join(e.args), "Python Error")
except java.lang.Exception, e :
MessageBox.showError(e.getMessage(), "Error")
finally :
myDss.close()