Skip to content

Commit 34a1175

Browse files
authored
Merge pull request HydrologicEngineeringCenter#93 from HydrologicEngineeringCenter/bugfix/paired_data_mulit-curve
Bugfix/paired data mulit curve
2 parents bd9f227 + 3e16570 commit 34a1175

3 files changed

Lines changed: 21 additions & 6 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.22"
3+
version = "0.1.23"
44
description = "Python wrapper for the HEC-DSS file database C library."
55
authors = ["Hydrologic Engineering Center"]
66
license = "MIT"

src/hecdss/hecdss.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,13 @@ def _get_paired_data(self, pathname):
301301
pd.ordinates = np.array(doubleOrdinates)
302302

303303
n = numberCurves2[0].value
304+
ordinateCount = len(doubleOrdinates)
305+
if n > 1:
306+
# ---------------------------------------------------------------------------------------- #
307+
# rearrange from consecutive values for each curve to consecutive curves for each ordinate #
308+
# ---------------------------------------------------------------------------------------- #
309+
groups = [doubleValues[i*ordinateCount:(i+1)*ordinateCount] for i in range(n)]
310+
doubleValues = list(map(list, zip(*groups)))
304311
pd.values = np.array(doubleValues).reshape((len(doubleOrdinates), n))
305312
# pd.values = [doubleValues[i:i+n] for i in range(0, len(doubleValues), n)]
306313
pd.labels = labels
@@ -515,7 +522,7 @@ def _get_location_info(self, pathname: str):
515522
)
516523

517524
if status != 0:
518-
print("Function call failed with result:", status)
525+
# print("Function call failed with result:", status)
519526
return None
520527

521528
location_info = LocationInfo.create(

src/hecdss/native.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -559,14 +559,22 @@ def hec_dss_pdStore(
559559
c_char_p, # timeZoneName (const char*) - New argument
560560
]
561561

562+
numberCurves = len(pd.values[0])
563+
if numberCurves > 1:
564+
_values = pd.values.tolist()
565+
if len(_values[0]) > 1:
566+
_values = [[_values[i][j] for i in range(len(_values))] for j in range(len(_values[0]))]
567+
values2 = np.array(_values)
568+
else:
569+
values2 = pd.values
562570
c_pathname = c_char_p(pd.id.encode("utf-8"))
563571
c_Ordinates = (c_double * len(pd.ordinates))(*pd.ordinates)
564572
c_OrdinatesLength = len(pd.ordinates)
565-
flat_list = pd.values.flatten()
573+
flat_list = values2.flatten()
566574
c_Values = (c_double * len(flat_list))(*flat_list)
567575
c_ValuesLength = len(flat_list)
568576
c_numberOrdinates = len(pd.ordinates)
569-
c_numberCurves = len(pd.values[0])
577+
c_numberCurves = numberCurves
570578
c_unitsIndependent = c_char_p(pd.units_independent.encode("utf-8"))
571579
c_typeIndependent = c_char_p(pd.type_independent.encode("utf-8"))
572580
c_unitsDependent = c_char_p(pd.units_dependent.encode("utf-8"))
@@ -1094,8 +1102,8 @@ def hec_dss_locationRetrieve(self, fullPath: str, x: List[float], y: List[float]
10941102
verticalDatum[0] = c_verticalDatum.value
10951103
timeZoneName[0] = c_timeZoneName.value.decode("utf-8")
10961104
supplemental[0] = c_supplemental.value.decode("utf-8")
1097-
else:
1098-
print("Unable to read location information, Function call failed with result:", result)
1105+
# else:
1106+
# print("Unable to read location information, Function call failed with result:", result)
10991107

11001108
return result
11011109

0 commit comments

Comments
 (0)