Skip to content

Commit b72c90a

Browse files
committed
finalize tests and TS-pattern support for regular timeseries
1 parent 3aa494a commit b72c90a

5 files changed

Lines changed: 33 additions & 13 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "hec-dss-python"
3-
version = "0.1.21"
3+
version = "0.1.22"
44
description = "Python wrapper for the HEC-DSS file database C library."
55
authors = ["Hydrologic Engineering Center"]
66
license = "MIT"

setup.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = hecdss
3-
version = 0.1.21
3+
version = 0.1.22
44
author = Hydrologic Engineering Center
55
author_email =hec.dss@usace.army.mil
66
description = Python wrapper for the HEC-DSS file database C library.
@@ -20,6 +20,7 @@ python_requires = >=3.8
2020
include_package_data = True
2121
install_requires =
2222
numpy
23+
tzdata
2324

2425
[options.packages.find]
2526
where=src

src/hecdss/download_hecdss.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def download_and_unzip(url, zip_file, destination_dir):
3636
print(f"Failed to download zip file. Status code: {response.status_code}")
3737

3838
base_url = "https://www.hec.usace.army.mil/nexus/repository/maven-public/mil/army/usace/hec/hecdss/"
39-
version = "7-IU-11"
39+
version = "7-IU-16"
4040

4141
destination_dir = Path(__file__).parent.joinpath("lib")
4242
zip_url = f"{base_url}{version}-win-x86_64/hecdss-{version}-win-x86_64.zip"

src/hecdss/hecdss.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ def get(self, pathname: str, startdatetime=None, enddatetime=None, trim=False):
108108
new_pathname = pathname
109109
if(DssPath(pathname).D.lower() != "ts-pattern"):
110110
new_pathname = DssPath(pathname).path_without_date().__str__()
111+
elif type == RecordType.IrregularTimeSeries:
112+
raise ValueError("ts-pattern is not fully supported for irregular time series")
111113
ts = self._get_timeseries(new_pathname, startdatetime, enddatetime, trim)
112114
return ts
113115
elif type == RecordType.PairedData:
@@ -317,7 +319,7 @@ def _get_julian_time_range(self, pathname, boolFullSet):
317319
firstSeconds = [0]
318320
lastValidJulian = [0]
319321
lastSeconds = [0]
320-
self._native.hec_dss_tsGetDateTimeRange(
322+
status = self._native.hec_dss_tsGetDateTimeRange(
321323
pathname,
322324
boolFullSet,
323325
firstValidJulian,
@@ -340,8 +342,7 @@ def _get_date_time_range(self, pathname, boolFullSet):
340342

341343
def _get_timeseries(self, pathname, startDateTime, endDateTime, trim):
342344
# get sizes
343-
if (DssPath(pathname).D.lower() != "ts-pattern"):
344-
firstValidJulian, firstSeconds, lastValidJulian, lastSeconds = self._get_julian_time_range(pathname, 1)
345+
firstValidJulian, firstSeconds, lastValidJulian, lastSeconds = self._get_julian_time_range(pathname, 1)
345346
if startDateTime is None:
346347
_startDateTime = DateConverter.date_time_from_julian_second(firstValidJulian[0], firstSeconds[0])
347348
firstSeconds, firstJulian = firstSeconds, firstValidJulian
@@ -467,8 +468,17 @@ def _get_timeseries(self, pathname, startDateTime, endDateTime, trim):
467468
timeZoneName = timeZoneName[0]
468469
if(timeZoneName):
469470
new_times = [i.replace(tzinfo=ZoneInfo(timeZoneName)) for i in new_times]
471+
elif (DssPath(pathname).D.lower() == "ts-pattern"):
472+
new_times = []
473+
start_date = _startDateTime - timedelta(seconds=interval_seconds)
474+
470475
location_info = self._get_location_info(pathname)
471476
ts = ts.create(values=values, times=new_times, quality=quality, units=units, data_type=data_type, start_date=start_date, time_granularity_seconds=time_granularity_seconds, julian_base_date=julian_base_date, time_zone_name=timeZoneName, path=pathname, location_info=location_info)
477+
478+
if (DssPath(pathname).D.lower() == "ts-pattern"):
479+
new_interval = ts._get_interval_path()
480+
ts._interval_to_times(new_interval)
481+
472482
return ts
473483

474484
def _get_location_info(self, pathname: str):
@@ -564,6 +574,8 @@ def put(self, container) -> int:
564574
self._catalog = None
565575
elif type(container) is IrregularTimeSeries:
566576
its = container
577+
if (DssPath(its.id).D.lower() == "ts-pattern"):
578+
raise ValueError("ts-pattern is not fully supported for irregular time series")
567579
# def hec_dss_tsStoreRegular(dss, pathname, startDate, startTime, valueArray, qualityArray,
568580
# saveAsFloat, units, type):
569581
start_date_base = (datetime(1900, 1, 1)+timedelta(days=its.julian_base_date))

tests/test_basics.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,21 +209,28 @@ def test_delete_range(self):
209209
dss.delete(path, False, t1, t2)
210210
assert (not("//SACRAMENTO/PRECIP-INC/01Jan1882/1Day/OBS/" in dss.get_catalog().uncondensed_paths))
211211

212-
def test_TS_Pattern(self):
212+
def test_Read_TS_Pattern_Regular(self):
213213
with HecDss(self.test_files.get_copy("Depth_Area_01.dss")) as dss:
214-
paths = dss.get_catalog().uncondensed_paths
215-
for path in paths:
216-
if "TS-Pattern" in path:
217-
print(path)
218-
dss.set_debug_level(14)
219214
path = "//010010-B/FLOW-UNIT GRAPH/TS-Pattern/5Minute/DAA:Depth-Area 01>010005-C/"
220-
tsc = dss.get(path, datetime(2023, 1, 1), datetime(2023, 1, 2))
215+
tsc = dss.get(path)
221216
assert(len(tsc.values) > 0)
222217

218+
def test_Write_TS_Pattern_Regular(self):
219+
with HecDss(self.test_files.get_copy("Depth_Area_01.dss")) as dss:
220+
path = "//010010-B/FLOW-UNIT GRAPH/TS-Pattern/5Minute/DAA:Depth-Area 01>010005-C/"
221+
tsc = dss.get(path)
222+
tsc.id = "//010010-B/FLOW-UNIT GRAPH/TS-Pattern/5Minute/DAA:Depth-Area 01>010005-C-modified2/"
223+
tsc.times = [i.replace(year=2023) for i in tsc.times]
224+
tsc.start_date = tsc.start_date.replace(year=2023)
225+
dss.put(tsc)
226+
tsc2 = dss.get(tsc.id)
227+
assert(len(tsc2.values) > 0)
228+
223229
def test_path_empty_parts(self):
224230
with HecDss(self.test_files.get_copy("Depth_Area_01.dss")) as dss:
225231
path = "//010020-R/STORAGE-FLOW///DAA:Depth-Area 01>010025-R/"
226232
tsc = dss.get(path)
233+
assert (len(tsc.values) > 0)
227234

228235
if __name__ == "__main__":
229236
unittest.main()

0 commit comments

Comments
 (0)