fix test errors
This commit is contained in:
+38
-10
@@ -15,8 +15,7 @@ from .Errorable import Errorable
|
||||
from .Drawable import Drawable
|
||||
from .DamarisFFT import DamarisFFT
|
||||
from .Signalpath import Signalpath
|
||||
|
||||
from data.ADC_Result import ADC_Result
|
||||
from .ADC_Result import ADC_Result
|
||||
|
||||
import sys
|
||||
import threading
|
||||
@@ -65,7 +64,8 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
|
||||
|
||||
self.common_descriptions=None
|
||||
self.time_period=[]
|
||||
self.job_id = None
|
||||
self.job_id = None # this does not make sense for an object accumulated from multiple job_ids
|
||||
self.job_ids = []
|
||||
|
||||
self.use_error = error
|
||||
if self.uses_statistics():
|
||||
@@ -452,13 +452,16 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
|
||||
for (key,value) in self.common_descriptions.items():
|
||||
accu_group._v_attrs.__setattr__("description_"+key,str(value))
|
||||
accu_group._v_attrs.__setattr__("sampling_rate",self.sampling_rate)
|
||||
# save interval information
|
||||
|
||||
|
||||
filter=None
|
||||
if complib is not None:
|
||||
if complevel is None:
|
||||
complevel=9
|
||||
complevel=3
|
||||
filter=tables.Filters(complevel=complevel,complib=complib,shuffle=1)
|
||||
|
||||
# save interval information
|
||||
# start save index_table
|
||||
# tried compression filter, but no effect...
|
||||
index_table=hdffile.create_table(where=accu_group,
|
||||
name="indices",
|
||||
@@ -468,7 +471,7 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
|
||||
"dwelltime": tables.Float64Col(),
|
||||
"number": tables.UInt64Col()},
|
||||
title="indices of adc data intervals",
|
||||
filters=filter,
|
||||
filters=tables.Filters(complib="zlib"),
|
||||
expectedrows=len(self.index))
|
||||
index_table.flavor="numpy"
|
||||
# save interval data
|
||||
@@ -482,8 +485,24 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
|
||||
new_row.append()
|
||||
|
||||
index_table.flush()
|
||||
new_row=None
|
||||
index_table=None
|
||||
# end save index_table
|
||||
|
||||
# start save job_ids
|
||||
jobid_table=hdffile.create_table(where=accu_group,
|
||||
name="job_ids",
|
||||
description={"job_id": tables.UInt64Col(),
|
||||
"job_date": tables.StringCol(128),
|
||||
},
|
||||
title="job_ids used for accumulation",
|
||||
filters=filter,
|
||||
expectedrows=len(self.job_ids))
|
||||
new_row=jobid_table.row
|
||||
for i,job_id in enumerate(self.job_ids):
|
||||
new_row["job_id"]=job_id
|
||||
new_row["job_date"]="Not Implemented"
|
||||
new_row.append()
|
||||
jobid_table.flush()
|
||||
# end save job_ids
|
||||
|
||||
# prepare saving data
|
||||
channel_no=len(self.y)
|
||||
@@ -563,7 +582,8 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
|
||||
tmp_string += "Samples per Channel: " + str(len(self.y[0])) + "\n"
|
||||
tmp_string += "Samplingfrequency: " + str(self.sampling_rate) + "\n"
|
||||
|
||||
tmp_string += "n: " + str(self.n)
|
||||
tmp_string += "n: " + str(self.n) + "\n"
|
||||
tmp_string += "jobids: " + str(self.job_ids) + "\n"
|
||||
|
||||
return tmp_string
|
||||
|
||||
@@ -625,6 +645,7 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
|
||||
r.time_period=[other.job_date,other.job_date]
|
||||
r.job_id = other.job_id
|
||||
r.common_descriptions=other.description.copy()
|
||||
r.job_ids.append(other.job_id)
|
||||
self.lock.release()
|
||||
return r
|
||||
|
||||
@@ -657,6 +678,9 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
|
||||
r.time_period=[min(self.time_period[0],other.job_date),
|
||||
max(self.time_period[1],other.job_date)]
|
||||
r.job_id = other.job_id
|
||||
r.job_ids = self.job_ids
|
||||
r.job_ids.append(other.job_id)
|
||||
|
||||
if self.common_descriptions is not None:
|
||||
r.common_descriptions={}
|
||||
for key in list(self.common_descriptions.keys()):
|
||||
@@ -793,6 +817,7 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
|
||||
|
||||
self.time_period=[other.job_date,other.job_date]
|
||||
self.job_id = other.job_id # added by Oleg Petrov
|
||||
self.job_ids.append(other.job_id)
|
||||
self.common_descriptions=other.description.copy()
|
||||
|
||||
return self
|
||||
@@ -820,7 +845,9 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
|
||||
self.n += 1
|
||||
self.time_period=[min(self.time_period[0],other.job_date),
|
||||
max(self.time_period[1],other.job_date)]
|
||||
self.job_id = other.job_id # added by Oleg Petrov
|
||||
|
||||
self.job_id = other.job_id
|
||||
self.job_ids.append(other.job_id)
|
||||
if self.common_descriptions is not None:
|
||||
for key in list(self.common_descriptions.keys()):
|
||||
if not (key in other.description and self.common_descriptions[key]==other.description[key]):
|
||||
@@ -858,6 +885,7 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
|
||||
self.common_descriptions=other.common_desriptions.copy()
|
||||
self.time_period=other.time_period[:]
|
||||
self.job_id = other.job_id # added by Oleg Petrov
|
||||
self.job_ids += other.job_ids
|
||||
self.lock.release()
|
||||
|
||||
return self
|
||||
|
||||
@@ -145,7 +145,8 @@ class TestADCResult(unittest.TestCase):
|
||||
# read back data with h5dump utility (apt-get -y install hdf5-tools)
|
||||
h5dump = subprocess.run(["h5dump", "-d", "/name/adc_data", "test.hdf5"], capture_output=True)
|
||||
content = h5dump.stdout.decode("utf-8")
|
||||
with open("tests/h5dump1_adc_data.ascii", "r") as f:
|
||||
test_dir = os.path.dirname(__file__)
|
||||
with open(os.path.join(test_dir, "h5dump1_adc_data.ascii"), "r") as f:
|
||||
expected = f.read()
|
||||
self.assertEqual(content, expected)
|
||||
os.unlink("test.hdf5")
|
||||
|
||||
@@ -5,7 +5,7 @@ from datetime import datetime
|
||||
|
||||
import numpy as np
|
||||
|
||||
from data.ADC_Result import ADC_Result
|
||||
from src.data.ADC_Result import ADC_Result
|
||||
from src.data.Accumulation import Accumulation
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ class TestAccumulation(unittest.TestCase):
|
||||
# TODO make testing strict with array types!
|
||||
np.testing.assert_array_equal(accu.x, np.array(x, dtype="float32"), strict=False)
|
||||
np.testing.assert_array_equal(accu.y[0], np.array(y[0], dtype="int16"), strict=False)
|
||||
np.testing.assert_equal(accu.y[1], np.array(y[1], dtype="int16"), strict=False)
|
||||
np.testing.assert_array_equal(accu.y[1], np.array(y[1], dtype="int16"), strict=False)
|
||||
|
||||
def test_add_adc_result(self):
|
||||
"""Test adding sample space."""
|
||||
@@ -180,7 +180,9 @@ class TestAccumulation(unittest.TestCase):
|
||||
# read back data with h5dump utility (apt-get -y install hdf5-tools)
|
||||
h5dump = subprocess.run(["h5dump", "-d", "/name/accu_data", "testaccu.hdf5"], capture_output=True)
|
||||
content = h5dump.stdout.decode("utf-8")
|
||||
with open("tests/h5dump1_accu.ascii", "r") as f:
|
||||
# Use path relative to project root
|
||||
test_dir = os.path.dirname(__file__)
|
||||
with open(os.path.join(test_dir, "h5dump1_accu.ascii"), "r") as f:
|
||||
expected = f.read()
|
||||
self.assertEqual(content, expected)
|
||||
os.unlink("testaccu.hdf5")
|
||||
|
||||
Reference in New Issue
Block a user