Skip to content

Commit

Permalink
Merge branch 'feature/grid'
Browse files Browse the repository at this point in the history
remove comments and fixed test_gridded_data
  • Loading branch information
oskarhurst committed May 14, 2024
1 parent 142a93b commit 7174a6a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 149 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish-to-test-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ jobs:
run: pip install numpy

- name: Run tests
run: pytest tests/test_pairedData.py
run: pytest tests/test_paired_data.py

# The development distribution is a snapshot of the package and is deployed each time
# changes are merged into the main branch.
Expand Down
86 changes: 0 additions & 86 deletions src/hecdss/native.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ def __init__(self):
)
self.dll = ctypes.CDLL(libc_path)
elif sys.platform == "win32":
this_dir = os.path.dirname(os.path.realpath(__file__))
# sys.path.append(this_dir+r"\lib")
# self.dll = ctypes.CDLL(this_dir+r"\lib\hecdss.dll")
# with resources.open_binary('hecdss', "hecdss.dll") as fp:
# dll = fp.read()
# self.dll = ctypes.CDLL(io.BytesIO(dll))

# dll_dir = os.path.join(os.path.dirname(__file__), 'lib')
dll_dir = os.path.join(os.path.dirname(sys.modules["hecdss"].__file__), 'lib')
dll_path = os.path.join(dll_dir, 'hecdss.dll')

Expand Down Expand Up @@ -445,10 +437,6 @@ def hec_dss_pdRetrieveInfo(self, pathname,
unitsDependent[0] = c_unitsDependent.value.decode('utf-8')
typeIndependent[0] = c_typeIndependent.value.decode('utf-8')
typeDependent[0] = c_typeDependent.value.decode('utf-8')
# print("Function call successful:")
# print("Number of ordinates:", numberOrdinates[0])
# print("Number of curves:", numberCurves[0])
# print("Labels length:", labelsLength[0])
else:
print("Function call failed with result:", result)

Expand Down Expand Up @@ -511,10 +499,6 @@ def hec_dss_pdRetrieve(self, pathname:str,
numberCurves[0] = c_numberCurves
print(numberCurves[0])
labels.extend(c_labels.raw.decode('utf-8').split("\0")[:c_numberCurves.value])
# print("Function call successful:")
# print("ordinates:", doubleOrdinates)
# print("curves:", doubleValues)
# print("Labels length:", labels)
else:
print("Function call failed with result:", result)

Expand Down Expand Up @@ -616,9 +600,6 @@ def hec_dss_tsGetSizes(
if result == 0:
numberValues[0] = nv.value
qualityElementSize[0] = qes.value
# print("Function call successful:")
# print("Number of values:", numberValues[0])
# print("Quality element size:", qualityElementSize[0])
else:
print("Function call failed with result:", result)

Expand Down Expand Up @@ -782,72 +763,5 @@ def hec_dss_recordType(self, pathname):
return f(self.handle,c_str)


# def test():
# dss = HecDssNative()
# outputFile = b"output.txt"
#
# dss.hec_dss_open(b"sample7.dss")
# nnn = dss.hec_dss_record_count()
# print("record count = " + str(nnn))
#
# times = [0, 0, 0, 0, 0]
# numberValues = len(times)
# times_int = (c_int * numberValues)(*times)
# values = [0, 0, 0, 0, 0]
# values_double = (c_double * numberValues)(*values)
#
# numberValuesRead = c_int()
# quality = []
# qualityLength = c_int(len(quality))
# quality_int = (c_int * len(quality))(*quality)
#
# julianBaseDate = c_int()
# timeGranularitySeconds = c_int()
# buffer_size = 20
# units = ctypes.create_string_buffer(buffer_size)
# dataType = ctypes.create_string_buffer(buffer_size)
#
# result = dss.hec_dss_tsRetrieve(
# b"//SACRAMENTO/PRECIP-INC//1Day/OBS/",
# b"01Jan1924",
# b"0100",
# b"01Jan2005",
# b"2400",
# times_int,
# values_double,
# numberValues,
# ctypes.byref(numberValuesRead),
# quality_int,
# qualityLength,
# ctypes.byref(julianBaseDate),
# ctypes.byref(timeGranularitySeconds),
# units,
# buffer_size,
# dataType,
# buffer_size,
# )
#
# if result == 0:
# print("Function call successful.")
# else:
# print("Function call failed." + str(result))
#
# print(units.value.decode("utf-8"))

# ppp = b"/AMERICAN/FOLSOM/FLOW-RES IN/01JAN2006/1Day/OBS/"
# sd = b"12MAR2006"
# ed = b"05APR2006"
# st = b"1200"
# et = b"1200"
# dss = HecDss()
# outputFile=b"output.txt"
#
# dss.open("sample7.dss")
# nnn = dss.record_count()
# print ("record count = "+str(nnn))
# ttt = dss.hec_dss_export_to_file(ppp,outputFile,sd,st,ed,et)
# dss.close()




67 changes: 6 additions & 61 deletions tests/test_gridded_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,9 @@
from hecdss import Catalog, HecDss
from datetime import datetime

TEST_DIR="tests/data/"
TEST_DIR = "tests/data/"

# update MODIFIED_TEST_DIR to be the path the folder containing dss files
# "sample7.dss" and "R703F3-PF_v7.dss" which are modified within these tests
MODIFIED_TEST_DIR=r"C:\Users\oskar\Documents\dss"

class Test_Grid_Data(unittest.TestCase):
class TestGriddedData(unittest.TestCase):

def setUp(self) -> None:
self.test_files = TestFileManager(TEST_DIR)
Expand Down Expand Up @@ -77,31 +73,7 @@ def test_gridded_data_create_store(self):
dss.close()

assert (status == 0), f"status should be 0. is {status}"
#
# def test_paired_data_create_store_read(self):
# """
# Generates a PairedData object then stores data on disk
# """
# dss = HecDss(self.test_files.get_copy("sample7.dss"))
# # dss = HecDss(MODIFIED_TEST_DIR+r"\sample7.dss")
# x_values = [00, 11, 22, 33, 44]
# y_values = [[j + i for j in range(3)] for i in x_values]
# path = "/MY BASIN/DEER CREEK/STAGE-FLOW///USGS-create/"
# pd = PairedData.create(x_values, y_values, path=path)
#
# pd.labels = ["x plus 0", "x plus 1", "x plus 2"]
# pd.units_independent = "cm"
#
# dss.put(pd)
#
# pd2 = dss.get(path)
# dss.close()
#
# assert (pd.values == pd2.values), f"pd.values contents is not equal to that of pd2.values. pd is {pd.values} and pd2 is {pd2.values}"
# assert (pd.labels == pd2.labels), f"pd.labels contents is not equal to that of pd2.labels. pd is {pd.labels} and pd2 is {pd2.labels}"
# assert (pd.ordinates == pd2.ordinates), f"pd.ordinates contents is not equal to that of pd2.ordinates. pd is {pd.ordinates} and pd2 is {pd2.ordinates}"
#
def test_paired_data_read_store_read(self):
def test_gridded_data_read_store_read(self):
"""
Generates a PairedData object then stores data on disk
"""
Expand All @@ -118,38 +90,11 @@ def test_paired_data_read_store_read(self):

gd2 = dss.get(path)

# assert (pd.values == pd3.values), f"pd.values contents is not equal to that of pd2.values. pd is {pd.values} and pd2 is {pd3.values}"
# assert (pd.labels[0] == "Flow"), f"pd.labels is not equal to 'Flow'. pd.labels[0] is {pd.labels[0]}"
# assert (pd3.labels[0] == "Flow2"), f"pd3.labels[0] is not equal to 'Flow2'. pd3.labels[0] is {pd3.labels[0]}"
# assert (pd.ordinates == pd3.ordinates), f"pd.ordinates contents is not equal to that of pd2.ordinates. pd is {pd.ordinates} and pd2 is {pd3.ordinates}"

assert (np.array_equal(gd.data, gd2.data)), f"gd.data contents is not equal to that of gd2.data. gd is {gd.data} and gd2 is {gd2.data}"
assert (gd.dataUnits == gd2.dataUnits), f"gd2.dataUnits is not equal to {gd.dataUnits}. gd2.dataUnits is {gd2.dataUnits}"

dss.close()
#
# def test_paired_data_labels_bug(self):
# """
# Generates a PairedData object then stores data on disk
# """
# dss = HecDss(self.test_files.get_copy("R703F3-PF_v7.dss"))
# # dss = HecDss(MODIFIED_TEST_DIR + r"\R703F3-PF_v7.dss")
# path = "/FOLSOM/AUXILIARY SPILLWAY-GATE RATING/ELEV-FLOW/PAIREDVALUESEXT///"
# pd = dss.get(path)
#
# path2 = "/FOLSOM/AUXILIARY SPILLWAY-GATE RATING/ELEV-FLOW/PAIREDVALUESEXT//modified/"
# pd2 = copy.deepcopy(pd)
# pd2.id = path2
# pd2.labels[3] = "New Label"
#
# status = dss.put(pd2) # save
#
# pd3 = dss.get(path2)
#
# assert (pd.values == pd3.values), f"pd.values contents is not equal to that of pd2.values. pd is {pd.values} and pd2 is {pd3.values}"
# assert (pd3.labels[3] == "New Label"), f"pd3.labels[3] is not equal to 'New Label'. pd3.labels[3] is {pd3.labels[3]}"
# assert (pd.ordinates == pd3.ordinates), f"pd.ordinates contents is not equal to that of pd2.ordinates. pd is {pd.ordinates} and pd2 is {pd3.ordinates}"
#
#
# dss.close()


if __name__ == "__main__":
unittest.main()
2 changes: 1 addition & 1 deletion tests/test_pairedData.py → tests/test_paired_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# "sample7.dss" and "R703F3-PF_v7.dss" which are modified within these tests
MODIFIED_TEST_DIR=r"C:\Users\oskar\Documents\dss"

class TestBasics(unittest.TestCase):
class TestPairedData(unittest.TestCase):

def setUp(self) -> None:
self.test_files = TestFileManager(TEST_DIR)
Expand Down

0 comments on commit 7174a6a

Please sign in to comment.