fixed typos and other hidden bugs

This commit is contained in:
2026-03-19 13:23:46 +01:00
parent a591dfc161
commit aba78a0b53
2 changed files with 100 additions and 58 deletions
+95 -57
View File
@@ -18,7 +18,6 @@ from .Signalpath import Signalpath
import sys import sys
import threading import threading
import types
import tables import tables
import numpy import numpy
import datetime # added by Oleg Petrov import datetime # added by Oleg Petrov
@@ -102,10 +101,11 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
def get_ysquare(self, channel): def get_ysquare(self, channel):
if self.uses_statistics(): if self.uses_statistics():
try: try:
return self.y_square[channel] return (self.y_square)[channel]
except: except:
raise raise
else: return None else:
return None
def contains_data(self): def contains_data(self):
return self.cont_data return self.cont_data
@@ -124,15 +124,17 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
def uses_statistics(self): def uses_statistics(self):
return self.use_error return self.use_error
# Schnittstellen nach Außen -------------------------------------------------------------------- # external interface --------------------------------------------------------------------
def get_yerr(self, channel): def get_yerr(self, channel):
""" """
return error (std.dev/sqrt(n)) of mean return error (std.dev/sqrt(n)) of mean
""" """
if not self.uses_statistics(): return numpy.zeros((len(self.y[0]),),dtype="float32") if not self.uses_statistics():
if not self.contains_data(): return [] return numpy.zeros((len(self.y[0]),),dtype="float32")
if not self.contains_data():
return []
self.lock.acquire() self.lock.acquire()
if self.n < 2: if self.n < 2:
@@ -153,9 +155,9 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
return mean data return mean data
""" """
if not self.contains_data(): return [] if not self.contains_data():
return []
self.lock.acquire() self.lock.acquire()
try: try:
tmp_y = self.y[channel] / self.n tmp_y = self.y[channel] / self.n
except IndexError: except IndexError:
@@ -167,8 +169,8 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
def get_ymin(self): def get_ymin(self):
if not self.contains_data():
if not self.contains_data(): return 0 return 0
tmp_min = [] tmp_min = []
self.lock.acquire() self.lock.acquire()
@@ -185,7 +187,8 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
def get_ymax(self): def get_ymax(self):
if not self.contains_data(): return 0 if not self.contains_data():
return 0
tmp_max = [] tmp_max = []
self.lock.acquire() self.lock.acquire()
@@ -210,7 +213,7 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
""" """
the_destination=destination the_destination=destination
if type(destination) in (str,): if isinstance(destination, str):
the_destination=open(destination, "w") the_destination=open(destination, "w")
the_destination.write("# accumulation %d\n"%self.n) the_destination.write("# accumulation %d\n"%self.n)
@@ -222,9 +225,11 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
the_destination.write("# t") the_destination.write("# t")
ch_no=self.get_number_of_channels() ch_no=self.get_number_of_channels()
if self.use_error: if self.use_error:
for i in range(ch_no): the_destination.write(" ch%d_mean ch%d_err"%(i,i)) for i in range(ch_no):
the_destination.write(" ch%d_mean ch%d_err"%(i,i))
else: else:
for i in range(ch_no): the_destination.write(" ch%d_mean"%i) for i in range(ch_no):
the_destination.write(" ch%d_mean"%i)
the_destination.write("\n") the_destination.write("\n")
xdata=self.get_xdata() xdata=self.get_xdata()
ydata=list(map(self.get_ydata, range(ch_no))) ydata=list(map(self.get_ydata, range(ch_no)))
@@ -239,8 +244,6 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
else: else:
the_destination.write("%s%e"%(delimiter,ydata[j][i])) the_destination.write("%s%e"%(delimiter,ydata[j][i]))
the_destination.write("\n") the_destination.write("\n")
the_destination=None
xdata=yerr=ydata=None
finally: finally:
self.lock.release() self.lock.release()
@@ -291,7 +294,7 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
#TODO: Function is most likely broken in Python 3 because Strings are now unicode and binary files cannot write unicode #TODO: Function is most likely broken in Python 3 because Strings are now unicode and binary files cannot write unicode
if self.job_id == None or self.n == 0: if self.job_id is None or self.n == 0:
raise ValueError("write_to_tecmag: cannot get a record number") raise ValueError("write_to_tecmag: cannot get a record number")
else: else:
record = (self.job_id/self.n)%nrecords + 1 record = (self.job_id/self.n)%nrecords + 1
@@ -527,13 +530,15 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
def __repr__(self): def __repr__(self):
"Redefining repr(Accumulation)" "Redefining repr(Accumulation)"
if not self.contains_data(): return "Empty" if not self.contains_data():
return "Empty"
tmp_string = "X: " + repr(self.x) + "\n" tmp_string = "X: " + repr(self.x) + "\n"
for i in range(self.get_number_of_channels()): for i in range(self.get_number_of_channels()):
tmp_string += ("Y(%d): " % i) + repr(self.y[i]) + "\n" tmp_string += ("Y(%d): " % i) + repr(self.y[i]) + "\n"
if self.uses_statistics(): tmp_string += "y_square(%d): " % i + str(self.y_square[i]) + "\n" if self.uses_statistics():
tmp_string += "y_square(%d): " % i + str(self.y_square[i]) + "\n"
tmp_string += "Indexes: " + str(self.index) + "\n" tmp_string += "Indexes: " + str(self.index) + "\n"
@@ -549,7 +554,8 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
"Redefining self + other" "Redefining self + other"
# Float or int # Float or int
if isinstance(other, int) or isinstance(other, float): if isinstance(other, int) or isinstance(other, float):
if not self.contains_data(): raise ValueError("Accumulation: You cant add integers/floats to an empty accumulation") if not self.contains_data():
raise ValueError("Accumulation: You cant add integers/floats to an empty accumulation")
else: else:
tmp_y = [] tmp_y = []
@@ -559,7 +565,8 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
self.lock.acquire() self.lock.acquire()
for i in range(self.get_number_of_channels()): for i in range(self.get_number_of_channels()):
# Dont change errors and mean value # Dont change errors and mean value
if self.uses_statistics(): tmp_ysquare.append(self.y_square[i] + ( (2*self.y[i]*other) + ((other**2)*self.n) )) if self.uses_statistics():
tmp_ysquare.append(self.y_square[i] + ( (2*self.y[i]*other) + ((other**2)*self.n) ))
tmp_y.append(self.y[i] + (other*self.n)) tmp_y.append(self.y[i] + (other*self.n))
if self.uses_statistics(): if self.uses_statistics():
@@ -575,7 +582,8 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
# Other empty (return) # Other empty (return)
# todo: this is seems to be bugy!!!! (Achim) # todo: this is seems to be bugy!!!! (Achim)
if not other.contains_data(): return if not other.contains_data():
return
# Self empty (copy) # Self empty (copy)
if not self.contains_data(): if not self.contains_data():
@@ -587,7 +595,8 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
for i in range(other.get_number_of_channels()): for i in range(other.get_number_of_channels()):
tmp_y.append(numpy.array(other.y[i], dtype="float32")) tmp_y.append(numpy.array(other.y[i], dtype="float32"))
if self.uses_statistics(): tmp_ysquare.append(tmp_y[i] ** 2) if self.uses_statistics():
tmp_ysquare.append(tmp_y[i] ** 2)
if self.uses_statistics(): if self.uses_statistics():
@@ -604,18 +613,23 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
else: else:
self.lock.acquire() self.lock.acquire()
if self.sampling_rate != other.get_sampling_rate(): raise ValueError("Accumulation: You cant add ADC-Results with diffrent sampling-rates") if self.sampling_rate != other.get_sampling_rate():
if len(self.y[0]) != len(other): raise ValueError("Accumulation: You cant add ADC-Results with diffrent number of samples") raise ValueError("Accumulation: You cant add ADC-Results with diffrent sampling-rates")
if len(self.y) != other.get_number_of_channels(): raise ValueError("Accumulation: You cant add ADC-Results with diffrent number of channels") if len(self.y[0]) != len(other):
raise ValueError("Accumulation: You cant add ADC-Results with diffrent number of samples")
if len(self.y) != other.get_number_of_channels():
raise ValueError("Accumulation: You cant add ADC-Results with diffrent number of channels")
for i in range(len(self.index)): for i in range(len(self.index)):
if self.index[i] != other.get_index_bounds(i): raise ValueError("Accumulation: You cant add ADC-Results with diffrent indexing") if self.index[i] != other.get_index_bounds(i):
raise ValueError("Accumulation: You cant add ADC-Results with diffrent indexing")
tmp_y = [] tmp_y = []
tmp_ysquare = [] tmp_ysquare = []
for i in range(self.get_number_of_channels()): for i in range(self.get_number_of_channels()):
tmp_y.append(self.y[i] + other.y[i]) tmp_y.append(self.y[i] + other.y[i])
if self.uses_statistics(): tmp_ysquare.append(self.y_square[i] + (numpy.array(other.y[i], dtype="float32") ** 2)) if self.uses_statistics():
tmp_ysquare.append(self.y_square[i] + (numpy.array(other.y[i], dtype="float32") ** 2))
if self.uses_statistics(): if self.uses_statistics():
r = Accumulation(x = numpy.array(self.x, dtype="float32"), y = tmp_y, y_2 = tmp_ysquare, n = self.n + 1, index = self.index, sampl_freq = self.sampling_rate, error = True) r = Accumulation(x = numpy.array(self.x, dtype="float32"), y = tmp_y, y_2 = tmp_ysquare, n = self.n + 1, index = self.index, sampl_freq = self.sampling_rate, error = True)
@@ -628,7 +642,7 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
r.common_descriptions={} r.common_descriptions={}
for key in list(self.common_descriptions.keys()): for key in list(self.common_descriptions.keys()):
if (key in other.description and self.common_descriptions[key]==other.description[key]): if (key in other.description and self.common_descriptions[key]==other.description[key]):
r.common_descriptions[key]=value r.common_descriptions[key]=self.common_descriptions[key]
self.lock.release() self.lock.release()
return r return r
@@ -637,7 +651,8 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
elif str(other.__class__) == "damaris.data.Accumulation.Accumulation": elif str(other.__class__) == "damaris.data.Accumulation.Accumulation":
# Other empty (return) # Other empty (return)
if not other.contains_data(): return if not other.contains_data():
return
# Self empty (copy) # Self empty (copy)
if not self.contains_data(): if not self.contains_data():
@@ -668,12 +683,17 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
else: else:
self.lock.acquire() self.lock.acquire()
if self.sampling_rate != other.get_sampling_rate(): raise ValueError("Accumulation: You cant add accumulations with diffrent sampling-rates") if self.sampling_rate != other.get_sampling_rate():
if len(self.y[0]) != len(other): raise ValueError("Accumulation: You cant add accumulations with diffrent number of samples") raise ValueError("Accumulation: You cant add accumulations with diffrent sampling-rates")
if len(self.y) != other.get_number_of_channels(): raise ValueError("Accumulation: You cant add accumulations with diffrent number of channels") if len(self.y[0]) != len(other):
raise ValueError("Accumulation: You cant add accumulations with diffrent number of samples")
if len(self.y) != other.get_number_of_channels():
raise ValueError("Accumulation: You cant add accumulations with diffrent number of channels")
for i in range(len(self.index)): for i in range(len(self.index)):
if self.index[i] != other.get_index_bounds(i): raise ValueError("Accumulation: You cant add accumulations with diffrent indexing") if self.index[i] != other.get_index_bounds(i):
if self.uses_statistics() and not other.uses_statistics(): raise ValueError("Accumulation: You cant add non-error accumulations to accumulations with error") raise ValueError("Accumulation: You cant add accumulations with diffrent indexing")
if self.uses_statistics() and not other.uses_statistics():
raise ValueError("Accumulation: You cant add non-error accumulations to accumulations with error")
tmp_y = [] tmp_y = []
tmp_ysquare = [] tmp_ysquare = []
@@ -695,7 +715,7 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
for key in list(self.common_descriptions.keys()): for key in list(self.common_descriptions.keys()):
if (key in other.common_descriptions and if (key in other.common_descriptions and
self.common_descriptions[key]==other.common_descriptions[key]): self.common_descriptions[key]==other.common_descriptions[key]):
r.common_descriptions[key]=value r.common_descriptions[key]=self.common_descriptions[key]
self.lock.release() self.lock.release()
return r return r
@@ -720,13 +740,15 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
"Redefining self += other" "Redefining self += other"
# Float or int # Float or int
if isinstance(other, int) or isinstance(other, float): if isinstance(other, int) or isinstance(other, float):
if not self.contains_data(): raise ValueError("Accumulation: You cant add integers/floats to an empty accumulation") if not self.contains_data():
raise ValueError("Accumulation: You cant add integers/floats to an empty accumulation")
else: else:
self.lock.acquire() self.lock.acquire()
for i in range(self.get_number_of_channels()): for i in range(self.get_number_of_channels()):
#Dont change errors and mean value #Dont change errors and mean value
if self.uses_statistics(): self.y_square[i] += (2*self.y[i]*other) + ((other**2)*self.n) if self.uses_statistics():
self.y_square[i] += (2*self.y[i]*other) + ((other**2)*self.n)
self.y[i] += other*self.n self.y[i] += other*self.n
self.lock.release() self.lock.release()
@@ -736,7 +758,8 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
elif type(other).__module__+"."+type(other).__name__ == "damaris.data.ADC_Result.ADC_Result": elif type(other).__module__+"."+type(other).__name__ == "damaris.data.ADC_Result.ADC_Result":
# Other empty (return) # Other empty (return)
if not other.contains_data(): return self if not other.contains_data():
return self
# Self empty (copy) # Self empty (copy)
if not self.contains_data(): if not self.contains_data():
@@ -749,7 +772,8 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
for i in range(other.get_number_of_channels()): for i in range(other.get_number_of_channels()):
self.y.append(numpy.array(other.y[i], dtype="float32")) self.y.append(numpy.array(other.y[i], dtype="float32"))
if self.uses_statistics(): self.y_square.append(self.y[i] ** 2) if self.uses_statistics():
self.y_square.append(self.y[i] ** 2)
self.set_title(self.__title_pattern % self.n) self.set_title(self.__title_pattern % self.n)
self.lock.release() self.lock.release()
@@ -765,15 +789,20 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
else: else:
self.lock.acquire() self.lock.acquire()
if self.sampling_rate != other.get_sampling_rate(): raise ValueError("Accumulation: You cant add ADC-Results with diffrent sampling-rates") if self.sampling_rate != other.get_sampling_rate():
if len(self.y[0]) != len(other): raise ValueError("Accumulation: You cant add ADC-Results with diffrent number of samples") raise ValueError("Accumulation: You cant add ADC-Results with diffrent sampling-rates")
if len(self.y) != other.get_number_of_channels(): raise ValueError("Accumulation: You cant add ADC-Results with diffrent number of channels") if len(self.y[0]) != len(other):
raise ValueError("Accumulation: You cant add ADC-Results with diffrent number of samples")
if len(self.y) != other.get_number_of_channels():
raise ValueError("Accumulation: You cant add ADC-Results with diffrent number of channels")
for i in range(len(self.index)): for i in range(len(self.index)):
if self.index[i] != other.get_index_bounds(i): raise ValueError("Accumulation: You cant add ADC-Results with diffrent indexing") if self.index[i] != other.get_index_bounds(i):
raise ValueError("Accumulation: You cant add ADC-Results with diffrent indexing")
for i in range(self.get_number_of_channels()): for i in range(self.get_number_of_channels()):
self.y[i] += other.y[i] self.y[i] += other.y[i]
if self.uses_statistics(): self.y_square[i] += numpy.array(other.y[i], dtype="float32") ** 2 if self.uses_statistics():
self.y_square[i] += numpy.array(other.y[i], dtype="float32") ** 2
self.n += 1 self.n += 1
self.time_period=[min(self.time_period[0],other.job_date), self.time_period=[min(self.time_period[0],other.job_date),
@@ -791,13 +820,14 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
# Accumulation # Accumulation
elif type(other).__module__+"."+type(other).__name__ == "damaris.data.Accumulation.Accumulation": elif type(other).__module__+"."+type(other).__name__ == "damaris.data.Accumulation.Accumulation":
# Other empty (return) # Other empty (return)
if not other.contains_data(): return if not other.contains_data():
return
# Self empty (copy) # Self empty (copy)
if not self.contains_data(): if not self.contains_data():
if self.uses_statistics() and not other.uses_statistics(): raise ValueError("Accumulation: You cant add non-error accumulations to accumulations with error") if self.uses_statistics() and not other.uses_statistics():
raise ValueError("Accumulation: You cant add non-error accumulations to accumulations with error")
self.lock.acquire() self.lock.acquire()
self.n += other.n self.n += other.n
@@ -808,7 +838,8 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
for i in range(other.get_number_of_channels()): for i in range(other.get_number_of_channels()):
self.y.append(numpy.array(other.y[i], dtype="float32")) self.y.append(numpy.array(other.y[i], dtype="float32"))
if self.uses_statistics(): self.y_square.append(self.y[i] ** 2) if self.uses_statistics():
self.y_square.append(self.y[i] ** 2)
self.set_title(self.__title_pattern % self.n) self.set_title(self.__title_pattern % self.n)
self.common_descriptions=other.common_desriptions.copy() self.common_descriptions=other.common_desriptions.copy()
@@ -821,16 +852,22 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
# Other and self not empty (self + other) # Other and self not empty (self + other)
else: else:
self.lock.acquire() self.lock.acquire()
if self.sampling_rate != other.get_sampling_rate(): raise ValueError("Accumulation: You cant add accumulations with diffrent sampling-rates") if self.sampling_rate != other.get_sampling_rate():
if len(self.y[0]) != len(other): raise ValueError("Accumulation: You cant add accumulations with diffrent number of samples") raise ValueError("Accumulation: You cant add accumulations with diffrent sampling-rates")
if len(self.y) != other.get_number_of_channels(): raise ValueError("Accumulation: You cant add accumulations with diffrent number of channels") if len(self.y[0]) != len(other):
raise ValueError("Accumulation: You cant add accumulations with diffrent number of samples")
if len(self.y) != other.get_number_of_channels():
raise ValueError("Accumulation: You cant add accumulations with diffrent number of channels")
for i in range(len(self.index)): for i in range(len(self.index)):
if self.index[i] != other.get_index_bounds(i): raise ValueError("Accumulation: You cant add accumulations with diffrent indexing") if self.index[i] != other.get_index_bounds(i):
if self.uses_statistics() and not other.uses_statistics(): raise ValueError("Accumulation: You cant add non-error accumulations to accumulations with error") raise ValueError("Accumulation: You cant add accumulations with diffrent indexing")
if self.uses_statistics() and not other.uses_statistics():
raise ValueError("Accumulation: You cant add non-error accumulations to accumulations with error")
for i in range(self.get_number_of_channels()): for i in range(self.get_number_of_channels()):
self.y[i] += other.y[i] self.y[i] += other.y[i]
if self.uses_statistics(): self.y_square[i] += other.y_square[i] if self.uses_statistics():
self.y_square[i] += other.y_square[i]
self.n += other.n self.n += other.n
self.time_period=[min(self.time_period[0],other.time_period[0]), self.time_period=[min(self.time_period[0],other.time_period[0]),
@@ -862,7 +899,8 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
def __neg__(self): def __neg__(self):
"Redefining -self" "Redefining -self"
if not self.contains_data(): return if not self.contains_data():
return
tmp_y = [] tmp_y = []
@@ -902,7 +940,7 @@ def read_from_hdf(hdf_node):
if attrname.startswith("description_"): if attrname.startswith("description_"):
accu.common_descriptions[attrname[12:]]=hdf_node._v_attrs.__getattr__(attrname) accu.common_descriptions[attrname[12:]]=hdf_node._v_attrs.__getattr__(attrname)
eariliest_time=None earliest_time=None
if "earliest_time" in dir(hdf_node._v_attrs): if "earliest_time" in dir(hdf_node._v_attrs):
timestring=hdf_node._v_attrs.__getattr__("earliest_time") timestring=hdf_node._v_attrs.__getattr__("earliest_time")
earliest_time=datetime.datetime(int(timestring[:4]), # year earliest_time=datetime.datetime(int(timestring[:4]), # year
+5 -1
View File
@@ -13,6 +13,10 @@ from .Drawable import Drawable
############################################################################# #############################################################################
class Error_Result(Resultable, Drawable): class Error_Result(Resultable, Drawable):
"""
Specialised class of Resultable
Contains error-messages from the core
"""
def __init__(self, error_msg = None, desc = {}, job_id = None, job_date = None): def __init__(self, error_msg = None, desc = {}, job_id = None, job_date = None):
Resultable.__init__(self) Resultable.__init__(self)
Drawable.__init__(self) Drawable.__init__(self)
@@ -49,7 +53,7 @@ class Error_Result(Resultable, Drawable):
def get_xdata(self): def get_xdata(self):
return [0.0] return [0.0]
# Überladen von Operatoren und Built-Ins ------------------------------------------------------- #overload of operators und built-ins -------------------------------------------------------
def __repr__(self): def __repr__(self):
tmp_string = "Core error-message: %s" % self.error_message tmp_string = "Core error-message: %s" % self.error_message