Skip to content

Commit 9faab97

Browse files
authored
Misc updates (#80)
* Preserve case in catalogs * Use title-case for matching intervals * Remove misc print statements
1 parent b54d5fd commit 9faab97

6 files changed

Lines changed: 20 additions & 9 deletions

File tree

src/hecdss/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from hecdss.catalog import Catalog
33
from hecdss.hecdss import HecDss
44
from hecdss.dsspath import DssPath
5+
from hecdss.irregular_timeseries import IrregularTimeSeries
56
from hecdss.regular_timeseries import RegularTimeSeries
67
from hecdss.array_container import ArrayContainer
78
from hecdss.paired_data import PairedData

src/hecdss/catalog.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,23 @@ def __create_condensed_catalog(self):
3737
time-series records must match all parts except the D (date) part to be combined.
3838
"""
3939
self.items = []
40+
raw_paths = {}
4041
for i in range(len(self.uncondensed_paths)):
4142
rawPath = self.uncondensed_paths[i]
4243
recordType = RecordType.RecordTypeFromInt(self.rawRecordTypes[i])
4344
path = DssPath(rawPath,recordType)
4445
# if timeseries - accumulate dates within a dataset
4546
if path.is_time_series():
4647
cleanPath = str(path.path_without_date())
48+
raw_paths[cleanPath.lower()] = rawPath
4749
self.recordTypeDict[cleanPath.lower()] = recordType
4850
if(path.D != "TS-Pattern"):
4951
tsRecords = self.timeSeriesDictNoDates.setdefault(cleanPath.lower(), [])
5052
t = datetime.strptime(path.D,"%d%b%Y")
5153
tsRecords.append(t)
5254
elif recordType in [RecordType.PairedData, RecordType.Grid, RecordType.Text,
5355
RecordType.LocationInfo, RecordType.Array]:
56+
raw_paths[rawPath] = rawPath
5457
self.recordTypeDict[str(path).lower()] = recordType
5558
self.items.append(path)
5659
else:
@@ -67,7 +70,7 @@ def __create_condensed_catalog(self):
6770
condensedDpart +="-"+ dateList[-1].strftime("%d%b%Y")
6871
# insert condensed D part into path used as key
6972
rt = self.recordTypeDict[key]
70-
p = DssPath(key,rt)
73+
p = DssPath(raw_paths[key],rt)
7174
p.D = condensedDpart
7275
self.items.append(p)
7376

src/hecdss/dateconverter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ def julian_array_from_date_times(date_times, time_granularity_seconds=60, start_
144144
return [int(((i-start_date_base).days*86400 + i.hour * 3600 + i.minute * 60 + i.second)/time_granularity_seconds) for i in date_times]
145145
@staticmethod
146146
def intervalString_to_sec(interval):
147-
147+
if isinstance(interval, str):
148+
interval = interval.title()
148149
if _time_string.__contains__(interval):
149150
i = _time_string.index(interval)
150151
return _sec[i]

src/hecdss/hecdss.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ def __exit__(self, exc_type, exc_val, exc_tb):
5454
exc_tb (traceback): The traceback object.
5555
"""
5656
self.close()
57+
@staticmethod
58+
def set_global_debug_level(level: int) -> None:
59+
"""
60+
Sets the library debug level
61+
62+
Args:
63+
level (int): a value between 0 and 15. Larger for more output
64+
"""
65+
_Native().hec_dss_set_debug_level(level)
5766
def close(self):
5867
"""closes the DSS file and releases any locks
5968
"""
@@ -506,7 +515,7 @@ def put(self, container) -> int:
506515
raise Exception("Time Series has an empty times array")
507516

508517
startDate, startTime = DateConverter.dss_datetime_strings_from_datetime(ts.times[0])
509-
quality = [] # TO DO
518+
quality = container.quality
510519

511520
status = self._native.hec_dss_tsStoreRegular(
512521
ts.id,
@@ -525,7 +534,7 @@ def put(self, container) -> int:
525534
# saveAsFloat, units, type):
526535
start_date_base = (datetime(1900, 1, 1)+timedelta(days=its.julian_base_date))
527536
startDate, startTime = DateConverter.dss_datetime_strings_from_datetime(start_date_base)
528-
quality = [] # TO DO
537+
quality = container.quality
529538
julian_times = DateConverter.julian_array_from_date_times(its.times, its.time_granularity_seconds, start_date_base)
530539
if max(julian_times) >= 2147483647:
531540
raise Exception("Julian times contains value larger than 2147483647, increase granularity or change "

src/hecdss/native.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ def hec_dss_open(self, dss_filename: str) -> int:
5959
f.restype = c_int
6060
self.handle = c_void_p()
6161
rval = f(dss_filename.encode("utf-8"), ctypes.byref(self.handle))
62-
if rval == 0:
63-
print("DSS file opened successfully.")
64-
else:
62+
if rval != 0:
6563
raise Exception("Error opening DSS file.")
6664
return rval
6765

@@ -524,7 +522,6 @@ def hec_dss_pdRetrieve(self, pathname: str,
524522
doubleValues.extend(list(c_doubleValues))
525523
numberOrdinates[0] = c_numberOrdinates
526524
numberCurves[0] = c_numberCurves
527-
print(numberCurves[0])
528525
labels.extend(c_labels.raw.decode('utf-8').split("\0")[:c_numberCurves.value])
529526
else:
530527
print("Function call failed with result:", result)

src/hecdss/regular_timeseries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def __init__(self):
1717
self.interval = ""
1818
self.start_date = ""
1919
self.time_granularity_seconds = 1
20+
self.julian_base_date = 0
2021
self.id = ""
2122
self.location_info = None
2223

@@ -167,7 +168,6 @@ def _generate_times(self):
167168

168169
x = [self._get_interval_times(), self._get_interval_path(), self._get_interval_interval()]
169170
x = [i for i in x if i != "empty"]
170-
print(x)
171171
if(not all(i == x[0] for i in x)):
172172
raise ValueError("inconsistent interval within arguments")
173173
elif len(x) != 3 and len(x) != 0:

0 commit comments

Comments
 (0)