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 threading
import types
import tables
import numpy
import datetime # added by Oleg Petrov
@@ -102,10 +101,11 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
def get_ysquare(self, channel):
if self.uses_statistics():
try:
return self.y_square[channel]
return (self.y_square)[channel]
except:
raise
else: return None
else:
return None
def contains_data(self):
return self.cont_data
@@ -124,15 +124,17 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
def uses_statistics(self):
return self.use_error
# Schnittstellen nach Außen --------------------------------------------------------------------
# external interface --------------------------------------------------------------------
def get_yerr(self, channel):
"""
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.contains_data(): return []
if not self.uses_statistics():
return numpy.zeros((len(self.y[0]),),dtype="float32")
if not self.contains_data():
return []
self.lock.acquire()
if self.n < 2:
@@ -153,9 +155,9 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
return mean data
"""
if not self.contains_data(): return []
if not self.contains_data():
return []
self.lock.acquire()
try:
tmp_y = self.y[channel] / self.n
except IndexError:
@@ -167,8 +169,8 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
def get_ymin(self):
if not self.contains_data(): return 0
if not self.contains_data():
return 0
tmp_min = []
self.lock.acquire()
@@ -185,7 +187,8 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
def get_ymax(self):
if not self.contains_data(): return 0
if not self.contains_data():
return 0
tmp_max = []
self.lock.acquire()
@@ -210,7 +213,7 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
"""
the_destination=destination
if type(destination) in (str,):
if isinstance(destination, str):
the_destination=open(destination, "w")
the_destination.write("# accumulation %d\n"%self.n)
@@ -222,9 +225,11 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
the_destination.write("# t")
ch_no=self.get_number_of_channels()
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:
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")
xdata=self.get_xdata()
ydata=list(map(self.get_ydata, range(ch_no)))
@@ -239,8 +244,6 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
else:
the_destination.write("%s%e"%(delimiter,ydata[j][i]))
the_destination.write("\n")
the_destination=None
xdata=yerr=ydata=None
finally:
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
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")
else:
record = (self.job_id/self.n)%nrecords + 1
@@ -527,13 +530,15 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
def __repr__(self):
"Redefining repr(Accumulation)"
if not self.contains_data(): return "Empty"
if not self.contains_data():
return "Empty"
tmp_string = "X: " + repr(self.x) + "\n"
for i in range(self.get_number_of_channels()):
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"
@@ -549,7 +554,8 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
"Redefining self + other"
# Float or int
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:
tmp_y = []
@@ -559,7 +565,8 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
self.lock.acquire()
for i in range(self.get_number_of_channels()):
# 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))
if self.uses_statistics():
@@ -575,7 +582,8 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
# Other empty (return)
# todo: this is seems to be bugy!!!! (Achim)
if not other.contains_data(): return
if not other.contains_data():
return
# Self empty (copy)
if not self.contains_data():
@@ -587,7 +595,8 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
for i in range(other.get_number_of_channels()):
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():
@@ -604,18 +613,23 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
else:
self.lock.acquire()
if self.sampling_rate != other.get_sampling_rate(): raise ValueError("Accumulation: You cant add ADC-Results with diffrent sampling-rates")
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")
if self.sampling_rate != other.get_sampling_rate():
raise ValueError("Accumulation: You cant add ADC-Results with diffrent sampling-rates")
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)):
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_ysquare = []
for i in range(self.get_number_of_channels()):
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():
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={}
for key in list(self.common_descriptions.keys()):
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()
return r
@@ -637,7 +651,8 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
elif str(other.__class__) == "damaris.data.Accumulation.Accumulation":
# Other empty (return)
if not other.contains_data(): return
if not other.contains_data():
return
# Self empty (copy)
if not self.contains_data():
@@ -668,12 +683,17 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
else:
self.lock.acquire()
if self.sampling_rate != other.get_sampling_rate(): raise ValueError("Accumulation: You cant add accumulations with diffrent sampling-rates")
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")
if self.sampling_rate != other.get_sampling_rate():
raise ValueError("Accumulation: You cant add accumulations with diffrent sampling-rates")
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)):
if self.index[i] != other.get_index_bounds(i): 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")
if self.index[i] != other.get_index_bounds(i):
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_ysquare = []
@@ -695,7 +715,7 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
for key in list(self.common_descriptions.keys()):
if (key in other.common_descriptions and
self.common_descriptions[key]==other.common_descriptions[key]):
r.common_descriptions[key]=value
r.common_descriptions[key]=self.common_descriptions[key]
self.lock.release()
return r
@@ -720,13 +740,15 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
"Redefining self += other"
# Float or int
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:
self.lock.acquire()
for i in range(self.get_number_of_channels()):
#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.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":
# Other empty (return)
if not other.contains_data(): return self
if not other.contains_data():
return self
# Self empty (copy)
if not self.contains_data():
@@ -749,7 +772,8 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
for i in range(other.get_number_of_channels()):
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.lock.release()
@@ -765,15 +789,20 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
else:
self.lock.acquire()
if self.sampling_rate != other.get_sampling_rate(): raise ValueError("Accumulation: You cant add ADC-Results with diffrent sampling-rates")
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")
if self.sampling_rate != other.get_sampling_rate():
raise ValueError("Accumulation: You cant add ADC-Results with diffrent sampling-rates")
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)):
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()):
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.time_period=[min(self.time_period[0],other.job_date),
@@ -791,13 +820,14 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
# Accumulation
elif type(other).__module__+"."+type(other).__name__ == "damaris.data.Accumulation.Accumulation":
# Other empty (return)
if not other.contains_data(): return
if not other.contains_data():
return
# Self empty (copy)
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.n += other.n
@@ -808,7 +838,8 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
for i in range(other.get_number_of_channels()):
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.common_descriptions=other.common_desriptions.copy()
@@ -821,16 +852,22 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
# Other and self not empty (self + other)
else:
self.lock.acquire()
if self.sampling_rate != other.get_sampling_rate(): raise ValueError("Accumulation: You cant add accumulations with diffrent sampling-rates")
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")
if self.sampling_rate != other.get_sampling_rate():
raise ValueError("Accumulation: You cant add accumulations with diffrent sampling-rates")
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)):
if self.index[i] != other.get_index_bounds(i): 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")
if self.index[i] != other.get_index_bounds(i):
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()):
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.time_period=[min(self.time_period[0],other.time_period[0]),
@@ -862,7 +899,8 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
def __neg__(self):
"Redefining -self"
if not self.contains_data(): return
if not self.contains_data():
return
tmp_y = []
@@ -902,7 +940,7 @@ def read_from_hdf(hdf_node):
if attrname.startswith("description_"):
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):
timestring=hdf_node._v_attrs.__getattr__("earliest_time")
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):
"""
Specialised class of Resultable
Contains error-messages from the core
"""
def __init__(self, error_msg = None, desc = {}, job_id = None, job_date = None):
Resultable.__init__(self)
Drawable.__init__(self)
@@ -49,7 +53,7 @@ class Error_Result(Resultable, Drawable):
def get_xdata(self):
return [0.0]
# Überladen von Operatoren und Built-Ins -------------------------------------------------------
#overload of operators und built-ins -------------------------------------------------------
def __repr__(self):
tmp_string = "Core error-message: %s" % self.error_message