conversion to new python3

This commit is contained in:
Markus Rosenstihl
2026-02-27 22:09:44 +01:00
parent 0b152b31fd
commit 29f003c99e
6 changed files with 78 additions and 73 deletions
+28 -28
View File
@@ -131,19 +131,19 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
return error (std.dev/sqrt(n)) of mean
"""
if not self.uses_statistics(): return numpy.zeros((len(self.y[0]),),dtype="Float64")
if not self.uses_statistics(): return numpy.zeros((len(self.y[0]),),dtype="float64")
if not self.contains_data(): return []
self.lock.acquire()
if self.n < 2:
retval=numpy.zeros((len(self.y[0]),),dtype="Float64")
retval=numpy.zeros((len(self.y[0]),),dtype="float64")
self.lock.release()
return retval
try:
variance_over_n = (self.y_square[channel] - (self.y[channel]**2 / float(self.n)))/float((self.n-1)*self.n)
except IndexError:
print("Warning Accumulation.get_ydata(channel): Channel index does not exist.")
variance_over_n = numpy.zeros((len(self.y[0]),), dtype="Float64")
variance_over_n = numpy.zeros((len(self.y[0]),), dtype="float64")
self.lock.release()
# sample standard deviation / sqrt(n)
return numpy.nan_to_num(numpy.sqrt(variance_over_n))
@@ -160,7 +160,7 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
tmp_y = self.y[channel] / self.n
except IndexError:
print("Warning Accumulation.get_ydata(channel): Channel index does not exist.")
tmp_y = numpy.zeros((len(self.y[0]),), dtype="Float64")
tmp_y = numpy.zeros((len(self.y[0]),), dtype="float64")
self.lock.release()
return tmp_y
@@ -466,13 +466,13 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
# prepare saving data
channel_no=len(self.y)
timedata=numpy.empty((len(self.y[0]),channel_no*2), dtype = "Float64")
timedata=numpy.empty((len(self.y[0]),channel_no*2), dtype = "float64")
for ch in range(channel_no):
timedata[:,ch*2]=self.get_ydata(ch)
if self.uses_statistics():
timedata[:,ch*2+1]=self.get_yerr(ch)
else:
timedata[:,ch*2+1]=numpy.zeros((len(self.y[0]),),dtype = "Float64")
timedata[:,ch*2+1]=numpy.zeros((len(self.y[0]),),dtype = "float64")
# save data
time_slice_data=None
@@ -564,9 +564,9 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
tmp_y.append(self.y[i] + (other*self.n))
if self.uses_statistics():
r = Accumulation(x = numpy.array(self.x, dtype="Float64"), y = tmp_y, y_2 = tmp_ysquare, n = self.n, index = self.index, sampl_freq = self.sampling_rate, error = self.use_error)
r = Accumulation(x = numpy.array(self.x, dtype="float64"), y = tmp_y, y_2 = tmp_ysquare, n = self.n, index = self.index, sampl_freq = self.sampling_rate, error = self.use_error)
else:
r = Accumulation(x = numpy.array(self.x, dtype="Float64"), y = tmp_y, n = self.n, index = self.index, sampl_freq = self.sampling_rate, error = self.use_error)
r = Accumulation(x = numpy.array(self.x, dtype="float64"), y = tmp_y, n = self.n, index = self.index, sampl_freq = self.sampling_rate, error = self.use_error)
r.job_id = self.job_id # added by Oleg Petrov
self.lock.release()
return r
@@ -587,14 +587,14 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
self.lock.acquire()
for i in range(other.get_number_of_channels()):
tmp_y.append(numpy.array(other.y[i], dtype="Float64"))
tmp_y.append(numpy.array(other.y[i], dtype="float64"))
if self.uses_statistics(): tmp_ysquare.append(tmp_y[i] ** 2)
if self.uses_statistics():
r = Accumulation(x = numpy.array(other.x, dtype="Float64"), y = tmp_y, y_2 = tmp_ysquare, n = 1, index = other.index, sampl_freq = other.sampling_rate, error = True)
r = Accumulation(x = numpy.array(other.x, dtype="float64"), y = tmp_y, y_2 = tmp_ysquare, n = 1, index = other.index, sampl_freq = other.sampling_rate, error = True)
else:
r = Accumulation(x = numpy.array(other.x, dtype="Float64"), y = tmp_y, index = other.index, sampl_freq = other.sampling_rate, n = 1, error = False)
r = Accumulation(x = numpy.array(other.x, dtype="float64"), y = tmp_y, index = other.index, sampl_freq = other.sampling_rate, n = 1, error = False)
r.time_period=[other.job_date,other.job_date]
r.job_id = other.job_id # added by Oleg Petrov
r.common_descriptions=other.description.copy()
@@ -616,12 +616,12 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
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="Float64") ** 2))
if self.uses_statistics(): tmp_ysquare.append(self.y_square[i] + (numpy.array(other.y[i], dtype="float64") ** 2))
if self.uses_statistics():
r = Accumulation(x = numpy.array(self.x, dtype="Float64"), 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="float64"), y = tmp_y, y_2 = tmp_ysquare, n = self.n + 1, index = self.index, sampl_freq = self.sampling_rate, error = True)
else:
r = Accumulation(x = numpy.array(self.x, dtype="Float64"), y = tmp_y, n = self.n + 1, index = self.index, sampl_freq = self.sampling_rate, error = False)
r = Accumulation(x = numpy.array(self.x, dtype="float64"), y = tmp_y, n = self.n + 1, index = self.index, sampl_freq = self.sampling_rate, error = False)
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 # added by Oleg Petrov
@@ -649,9 +649,9 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
self.lock.acquire()
if self.uses_statistics():
r = Accumulation(x = numpy.array(other.x, dtype="Float64"), y = tmp_y, y_2 = tmp_ysquare, n = other.n, index = other.index, sampl_freq = other.sampling_rate, error = True)
r = Accumulation(x = numpy.array(other.x, dtype="float64"), y = tmp_y, y_2 = tmp_ysquare, n = other.n, index = other.index, sampl_freq = other.sampling_rate, error = True)
else:
r = Accumulation(x = numpy.array(other.x, dtype="Float64"), y = tmp_y, n = other.n, index = other.index, sampl_freq = other.sampling_rate, error = False)
r = Accumulation(x = numpy.array(other.x, dtype="float64"), y = tmp_y, n = other.n, index = other.index, sampl_freq = other.sampling_rate, error = False)
for i in range(other.get_number_of_channels()):
tmp_y.append(other.y[i])
tmp_ysquare.append(other.y_square[i])
@@ -684,9 +684,9 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
tmp_ysquare.append(self.y_square[i] + other.y_square[i])
if self.uses_statistics():
r = Accumulation(x = numpy.array(self.x, dtype="Float64"), y = tmp_y, y_2 = tmp_ysquare, n = other.n + self.n, index = self.index, sampl_freq = self.sampling_rate, error = True)
r = Accumulation(x = numpy.array(self.x, dtype="float64"), y = tmp_y, y_2 = tmp_ysquare, n = other.n + self.n, index = self.index, sampl_freq = self.sampling_rate, error = True)
else:
r = Accumulation(x = numpy.array(self.x, dtype="Float64"), y = tmp_y, n = other.n + self.n, index = self.index, sampl_freq = self.sampling_rate, error = False)
r = Accumulation(x = numpy.array(self.x, dtype="float64"), y = tmp_y, n = other.n + self.n, index = self.index, sampl_freq = self.sampling_rate, error = False)
r.time_period=[min(self.time_period[0],other.time_period[0]),
max(self.time_period[1],other.time_period[1])]
@@ -745,11 +745,11 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
self.n += 1
self.index = other.index[0:]
self.sampling_rate = other.sampling_rate
self.x = numpy.array(other.x, dtype="Float64")
self.x = numpy.array(other.x, dtype="float64")
self.cont_data = True
for i in range(other.get_number_of_channels()):
self.y.append(numpy.array(other.y[i], dtype="Float64"))
self.y.append(numpy.array(other.y[i], dtype="float64"))
if self.uses_statistics(): self.y_square.append(self.y[i] ** 2)
self.set_title(self.__title_pattern % self.n)
@@ -774,7 +774,7 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
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="Float64") ** 2
if self.uses_statistics(): self.y_square[i] += numpy.array(other.y[i], dtype="float64") ** 2
self.n += 1
self.time_period=[min(self.time_period[0],other.job_date),
@@ -804,11 +804,11 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
self.n += other.n
self.index = other.index[0:]
self.sampling_rate = other.sampling_rate
self.x = numpy.array(other.x, dtype="Float64")
self.x = numpy.array(other.x, dtype="float64")
self.cont_data = True
for i in range(other.get_number_of_channels()):
self.y.append(numpy.array(other.y[i], dtype="Float64"))
self.y.append(numpy.array(other.y[i], dtype="float64"))
if self.uses_statistics(): self.y_square.append(self.y[i] ** 2)
self.set_title(self.__title_pattern % self.n)
@@ -869,12 +869,12 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
self.lock.acquire()
for i in range(self.get_number_of_channels()):
tmp_y.append(numpy.array(-self.y[i], dtype="Float64"))
tmp_y.append(numpy.array(-self.y[i], dtype="float64"))
if self.uses_statistics():
r = Accumulation(x = numpy.array(self.x, dtype="Float64"), y = tmp_y, y_2 = numpy.array(self.y_square), n = self.n, index = self.index, sampl_freq = self.sampling_rate, error = True)
r = Accumulation(x = numpy.array(self.x, dtype="float64"), y = tmp_y, y_2 = numpy.array(self.y_square), n = self.n, index = self.index, sampl_freq = self.sampling_rate, error = True)
else:
r = Accumulation(x = numpy.array(self.x, dtype="Float64"), y = tmp_y, n = self.n, index = self.index, sampl_freq = self.sampling_rate, error = False)
r = Accumulation(x = numpy.array(self.x, dtype="float64"), y = tmp_y, n = self.n, index = self.index, sampl_freq = self.sampling_rate, error = False)
self.lock.release()
return r
@@ -951,7 +951,7 @@ def read_from_hdf(hdf_node):
# now do the real data
accu_data=hdf_node.accu_data.read()
accu.x=numpy.arange(accu_data.shape[0], dtype="Float64")/accu.sampling_rate
accu.x=numpy.arange(accu_data.shape[0], dtype="float64")/accu.sampling_rate
# assume error information, todo: save this information explicitly
accu.y_square=[]
accu.use_error=False
@@ -959,7 +959,7 @@ def read_from_hdf(hdf_node):
for ch in range(accu_data.shape[1]/2):
accu.y.append(accu_data[:,ch*2]*accu.n)
if accu.n<2 or numpy.all(accu_data[:,ch*2+1]==0.0):
accu.y_square.append(numpy.zeros((accu_data.shape[0]) ,dtype="Float64"))
accu.y_square.append(numpy.zeros((accu_data.shape[0]) ,dtype="float64"))
else:
accu.use_error=True
accu.y_square.append((accu_data[:,ch*2+1]**2)*float((accu.n-1.0)*accu.n)+(accu_data[:,ch*2]**2)*accu.n)