forked from HydrologicEngineeringCenter/hec-dss-python
-
Notifications
You must be signed in to change notification settings - Fork 1
/
hec_dss.py
94 lines (77 loc) · 3.1 KB
/
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from hec_dss_native import HecDssNative
from datetime import datetime
from dateconverter import DateConverter
from timeseries import TimeSeries
from catalog import Catalog
import os
class HecDss:
def __init__(self,filename):
self._native = HecDssNative()
self._native.hec_dss_open(filename)
def get(self,pathname,startDateTime, endDateTime):
# get sizes
startDate = startDateTime.strftime('%d%b%Y')
startTime = startDateTime.strftime('%H:%M')
endDate = endDateTime.strftime('%d%b%Y')
endTime = startDateTime.strftime('%H:%M')
numberValues = [0] # using array to allow modification
qualityElementSize = [0]
self._native.hec_dss_tsGetSizes(pathname,
startDate, startTime,
endDate, endTime,numberValues,qualityElementSize)
print("Number of values:", numberValues[0])
print("Quality element size:", qualityElementSize[0])
# tsRetrive
times=[0,1]
values=[]
numberValuesRead=[0]
quality=[]
julianBaseDate =[0]
timeGranularitySeconds =[0]
units = [""]
bufferLength=40
dataType =[""]
self._native.hec_dss_tsRetrieve(pathname,
startDate, startTime, endDate, endTime, times,
values, numberValues[0],
numberValuesRead, quality, qualityElementSize[0],
julianBaseDate, timeGranularitySeconds,
units, bufferLength, dataType, bufferLength)
#print("units = "+units[0])
#print("datatype = "+dataType[0])
#print("times: ")
#print(times)
#print(values)
print("julianBaseDate = "+str(julianBaseDate[0]))
print("timeGranularitySeconds = "+str(timeGranularitySeconds[0]))
ts = TimeSeries()
ts.times=DateConverter.date_times_from_julian_array(times,timeGranularitySeconds[0],julianBaseDate[0])
ts.values=values
ts.units=units[0]
ts.dataType=dataType[0]
ts.dsspath=pathname
return ts
def put(self,ts):
# TO DO.. save other types besides regular interval.
# TO DO. check data type..
# TO Do. is timezone needed?
#def hec_dss_tsStoreRegular(dss, pathname, startDate, startTime, valueArray, qualityArray,
# saveAsFloat, units, type):
startDate,startTime = DateConverter.dss_datetime_from_string(ts.times[0])
quality = [] # TO DO
self._native.hec_dss_tsStoreRegular(ts.pathname,startDate,startTime,ts.values,quality,False,ts.units,ts.dataType)
def getCatalog(self):
paths,recordTypes = self._native.hec_dss_catalog()
return Catalog(paths,recordTypes)
def recordCount(self):
return self._native.hec_dss_record_count()
def setDebugLevel(self,level):
return self._native.hec_dss_set_debug_level(level)
if __name__ == "__main__":
#import pdb;pdb.set_trace()
dss = HecDss("sample7.dss")
catalog = dss.getCatalog()
for p in catalog:
print(p)
#print(catalog[0:5])
#dss.setDebugLevel(15)