From a591dfc161cc896f3a5831243df214b0182e0091 Mon Sep 17 00:00:00 2001 From: Markus Rosenstihl Date: Thu, 19 Mar 2026 13:03:25 +0100 Subject: [PATCH] fixed a lot of Ruff errors and incorrect Accumulation returns in the overloaded operators --- .gitignore | 1 + src/data/ADC_Result.py | 10 ++++++--- src/data/Accumulation.py | 9 ++++---- src/data/Config_Result.py | 19 +++++++++------- src/data/Errorable.py | 24 +++++++++++---------- src/data/{Temp_Result.py => Temperature.py} | 13 +++++------ src/data/__init__.py | 3 ++- src/data/autophase.py | 2 +- src/gui/ResultReader.py | 2 +- 9 files changed, 45 insertions(+), 38 deletions(-) rename src/data/{Temp_Result.py => Temperature.py} (81%) diff --git a/.gitignore b/.gitignore index b391c49..b931629 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ spool __pycache__ *.egg-info *.whl +.idea diff --git a/src/data/ADC_Result.py b/src/data/ADC_Result.py index 9ea0f3d..8dee868 100644 --- a/src/data/ADC_Result.py +++ b/src/data/ADC_Result.py @@ -7,7 +7,6 @@ from .DamarisFFT import DamarisFFT import threading import numpy import sys -import types import datetime import tables ############################################################################# @@ -69,8 +68,10 @@ class ADC_Result(Resultable, Drawable, DamarisFFT, Signalpath): print("Warning ADC-Result: Tried to run \"create_data_space()\" more than once.") return - if channels <= 0: raise ValueError("ValueError: You cant create an ADC-Result with less than 1 channel!") - if samples <= 0: raise ValueError("ValueError: You cant create an ADC-Result with less than 1 sample!") + if channels <= 0: + raise ValueError("ValueError: You cant create an ADC-Result with less than 1 channel!") + if samples <= 0: + raise ValueError("ValueError: You cant create an ADC-Result with less than 1 sample!") for i in range(channels): self.y.append(numpy.zeros((samples,), dtype="int16")) @@ -398,6 +399,8 @@ class ADC_Result(Resultable, Drawable, DamarisFFT, Signalpath): r = ADC_Result(x = self.x[:], y = tmp_y, index = self.index[:], sampl_freq = self.sampling_rate, desc = self.description, job_id = self.job_id, job_date = self.job_date) self.lock.release() + return r + else: raise ValueError("ValueError: Cannot multiply \"%s\" to ADC-Result!") % str(other.__class__) @@ -450,6 +453,7 @@ class ADC_Result(Resultable, Drawable, DamarisFFT, Signalpath): r = ADC_Result(x = self.x[:], y = tmp_y, index = self.index[:], sampl_freq = self.sampling_rate, desc = self.description, job_id = self.job_id, job_date = self.job_date) self.lock.release() + return r else: raise ValueError("ValueError: Cannot multiply \"%s\" to ADC-Result!") % str(other.__class__) diff --git a/src/data/Accumulation.py b/src/data/Accumulation.py index 891b080..01b7612 100644 --- a/src/data/Accumulation.py +++ b/src/data/Accumulation.py @@ -41,7 +41,7 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath): self.common_descriptions=None self.time_period=[] - self.job_id = None # added by Oleg Petrov + self.job_id = None self.use_error = error @@ -513,9 +513,8 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath): accu_group=None self.lock.release() - # / Schnittstellen nach Außen ------------------------------------------------------------------ - - # Überladen von Operatoren --------------------------------------------------------------------- + # External interfaces ------------------------------------------------------------------ + # Overloaded operators ----------------------------------------------------------------- def __len__(self): """ @@ -658,7 +657,7 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath): r.time_period=other.time_period[:] r.job_id = other.job_id # added by Oleg Petrov if other.common_descriptions is not None: - r.common_descriptions=othter.common_descriptions.copy() + r.common_descriptions=other.common_descriptions.copy() else: r.common_descriptions=None diff --git a/src/data/Config_Result.py b/src/data/Config_Result.py index 563692a..627058a 100644 --- a/src/data/Config_Result.py +++ b/src/data/Config_Result.py @@ -13,10 +13,12 @@ from .Resultable import Resultable class Config_Result(Resultable): def __init__(self, config = None, desc = None, job_id = None, job_date = None): - Resultable.__init__(self) + Resultable.__init__(self) - if config is None: self.config = { } - if desc is None: self.description = { } + if config is None: + self.config = { } + if desc is None: + self.description = { } self.job_id = job_id self.job_date = job_date @@ -31,18 +33,19 @@ class Config_Result(Resultable): def get_config(self, key): - if key in self.config: return self.config[key] - else: return None + if key in self.config: + return self.config[key] + else: + return None def set_config(self, key, value): if key in self.config: print("Warning Config_Result: Key \"%s\" will be overwritten with \"%s\"" % (key, value)) - self.config[key] = value - + self.config[key] = value - # Überladen von Operatoren und Built-Ins ------------------------------------------------------- + # Ueberladen von Operatoren und Built-Ins ------------------------------------------------------- def __repr__(self): return str(self.config) diff --git a/src/data/Errorable.py b/src/data/Errorable.py index 3e578a3..44243dd 100644 --- a/src/data/Errorable.py +++ b/src/data/Errorable.py @@ -9,6 +9,9 @@ ############################################################################# class Errorable: + """ + Base class for data objects that can have data with errors. + """ def __init__(self): # Will be determined in one of the subclasses @@ -22,12 +25,12 @@ class Errorable: def get_xerr(self): - "Returns a reference to x-Error (array)" + """Returns a reference to x-Error (array)""" return self.xerr def set_xerr(self, pos, value): - "Sets a point in x-Error" + """Sets a point in x-Error""" try: self.xerr[pos] = value except: @@ -35,7 +38,7 @@ class Errorable: def get_yerr(self, channel): - "Returns a list of y-Errors (list of arrays, corresponding channels)" + """Returns a list of y-Errors (list of arrays, corresponding channels)""" try: return self.yerr[channel] except: @@ -43,7 +46,7 @@ class Errorable: def set_yerr(self, channel, pos, value): - "Sets a point in y-Error" + """Sets a point in y-Error""" try: self.yerr[channel][pos] = value except: @@ -51,26 +54,25 @@ class Errorable: def get_error_color(self): - "Returns the error-bar color" + """Returns the error-bar color""" return self.error_color def set_error_color(self, color): - "Sets the error-bar color" + """Sets the error-bar color""" self.error_color = color def get_bars_above(self): - "Gets bars-above property of errorplot" + """Gets bars-above property of errorplot""" return self.bars_above def set_bars_above(self, bars_above): - "Sets bars-above property of errorplot" + """Sets bars-above property of errorplot""" self.bars_above = bool(bars_above) def ready_for_drawing_error(self): - "Returns true if more than one result have been accumulated" - if self.n >= 2: return True - else: return False + """Returns true if more than one result have been accumulated""" + return self.n >= 2 diff --git a/src/data/Temp_Result.py b/src/data/Temperature.py similarity index 81% rename from src/data/Temp_Result.py rename to src/data/Temperature.py index d9041e7..400d018 100644 --- a/src/data/Temp_Result.py +++ b/src/data/Temperature.py @@ -3,8 +3,6 @@ from .Resultable import Resultable from .Drawable import Drawable -from types import * - ############################################################################# # # # Name: Class Temp_Result # @@ -14,7 +12,11 @@ from types import * # # ############################################################################# -class Temp_Result(Resultable, Drawable): +class TemperatureResult(Resultable, Drawable): + """ + Specialised class of Resultable and Drawable + Contains recorded temperature data + """ def __init__(self, x = None, y = None, desc = None, job_id = None, job_date = None): Resultable.__init__(self) Drawable.__init__(self) @@ -27,8 +29,3 @@ class Temp_Result(Resultable, Drawable): else: raise ValueError("Wrong usage of __init__!") - - - # Überladen von Operatoren und Built-Ins ------------------------------------------------------- - - # / Überladen von Operatoren und Built-Ins ----------------------------------------------------- diff --git a/src/data/__init__.py b/src/data/__init__.py index f0c222b..86bb2ca 100644 --- a/src/data/__init__.py +++ b/src/data/__init__.py @@ -4,6 +4,7 @@ from damaris.data.MeasurementResult import MeasurementResult, AccumulatedValue from damaris.data.DataPool import DataPool from damaris.data.Error_Result import Error_Result from damaris.data.Config_Result import Config_Result +from damaris.data.Temperature import TemperatureResult -__all__=["ADC_Result", "Accumulation", "MeasurementResult", "AccumulatedValue", "DataPool", "FFT", "Error_Result", "Config_Result" ] +__all__=["ADC_Result", "Accumulation", "MeasurementResult", "AccumulatedValue", "DataPool", "FFT", "Error_Result", "Config_Result", "TemperatureResult" ] diff --git a/src/data/autophase.py b/src/data/autophase.py index 467fc60..f9b0567 100644 --- a/src/data/autophase.py +++ b/src/data/autophase.py @@ -1,4 +1,4 @@ -from scipy.optimize import fmin_powell, bisect, ridder, brentq +from scipy.optimize import fmin_powell import numpy as N def calculate_entropy(phi, real, imag, gamma, dwell): diff --git a/src/gui/ResultReader.py b/src/gui/ResultReader.py index 981d5d4..562fbb3 100644 --- a/src/gui/ResultReader.py +++ b/src/gui/ResultReader.py @@ -26,7 +26,7 @@ from datetime import datetime from damaris.data import ADC_Result from damaris.data import Error_Result -from damaris.data import Temp_Result +from damaris.data import TemperatureResult from damaris.data import Config_Result class ResultReader: