From e7f3180902a6389c8a73d0c88fa3ac418784a7d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Boisselier?= Date: Sat, 23 Nov 2024 23:11:21 +0100 Subject: [PATCH] inline computation results in the return statement directly --- shaketune/graph_creators/axes_map_graph_creator.py | 5 +---- shaketune/graph_creators/belts_graph_creator.py | 5 +---- shaketune/graph_creators/shaper_graph_creator.py | 5 +---- shaketune/graph_creators/static_graph_creator.py | 4 +--- shaketune/graph_creators/vibrations_graph_creator.py | 4 +--- 5 files changed, 5 insertions(+), 18 deletions(-) diff --git a/shaketune/graph_creators/axes_map_graph_creator.py b/shaketune/graph_creators/axes_map_graph_creator.py index d934d0b..a250da2 100644 --- a/shaketune/graph_creators/axes_map_graph_creator.py +++ b/shaketune/graph_creators/axes_map_graph_creator.py @@ -138,8 +138,7 @@ def compute(self): formatted_direction_vector = self._format_direction_vector(direction_vectors) ConsoleOutput.print(f'--> Detected axes_map: {formatted_direction_vector}') - # Prepare data for plotting - computation_result = { + return { 'acceleration_data_0': [d[0] for d in acceleration_data], 'acceleration_data_1': [d[1] for d in acceleration_data], 'gravity': gravity, @@ -153,8 +152,6 @@ def compute(self): 'st_version': self.st_version, } - return computation_result - def _wavelet_denoise(self, data: np.ndarray, wavelet: str = 'db1', level: int = 1) -> Tuple[np.ndarray, np.ndarray]: coeffs = pywt.wavedec(data, wavelet, mode='smooth') threshold = np.median(np.abs(coeffs[-level])) / 0.6745 * np.sqrt(2 * np.log(len(data))) diff --git a/shaketune/graph_creators/belts_graph_creator.py b/shaketune/graph_creators/belts_graph_creator.py index 7dbe267..28195cf 100644 --- a/shaketune/graph_creators/belts_graph_creator.py +++ b/shaketune/graph_creators/belts_graph_creator.py @@ -120,8 +120,7 @@ def compute(self): mhi = self._compute_mhi(similarity_factor, signal1, signal2) ConsoleOutput.print(f'Mechanical health: {mhi}') - # Prepare data for plotting - computation_result = { + return { 'signal1': signal1, 'signal2': signal2, 'similarity_factor': similarity_factor, @@ -135,8 +134,6 @@ def compute(self): 'max_freq': self.max_freq, } - return computation_result - def _compute_signal_data(self, data: np.ndarray, common_freqs: np.ndarray, max_freq: float): helper = get_shaper_calibrate_module().ShaperCalibrate(printer=None) calibration_data = helper.process_accelerometer_data(data) diff --git a/shaketune/graph_creators/shaper_graph_creator.py b/shaketune/graph_creators/shaper_graph_creator.py index e9d0e17..1b8c248 100644 --- a/shaketune/graph_creators/shaper_graph_creator.py +++ b/shaketune/graph_creators/shaper_graph_creator.py @@ -196,8 +196,7 @@ def compute(self): shaper_choices = [klipper_shaper_choice.upper()] ConsoleOutput.print(f'{shaper_string} (with a damping ratio of {zeta:.3f})') - # And finally setup the results to return them - computation_result = { + return { 'measurements': self.measurements, 'compat': compat, 'max_smoothing_computed': max_smoothing_computed, @@ -221,8 +220,6 @@ def compute(self): 'st_version': self.st_version, } - return computation_result - # Find the best shaper parameters using Klipper's official algorithm selection with # a proper precomputed damping ratio (zeta) and using the configured printer SQV value # This function also sweep around the smoothing values to help you find the best compromise diff --git a/shaketune/graph_creators/static_graph_creator.py b/shaketune/graph_creators/static_graph_creator.py index 7a9cc22..cc8f3b7 100644 --- a/shaketune/graph_creators/static_graph_creator.py +++ b/shaketune/graph_creators/static_graph_creator.py @@ -78,7 +78,7 @@ def compute(self): pdata, bins, t = compute_spectrogram(datas[0]) del datas - computation_result = { + return { 'freq': self.freq, 'duration': self.duration, 'accel_per_hz': self.accel_per_hz, @@ -89,5 +89,3 @@ def compute(self): 'pdata': pdata, 'max_freq': self.max_freq, } - - return computation_result diff --git a/shaketune/graph_creators/vibrations_graph_creator.py b/shaketune/graph_creators/vibrations_graph_creator.py index ddf6f1b..0208dc2 100644 --- a/shaketune/graph_creators/vibrations_graph_creator.py +++ b/shaketune/graph_creators/vibrations_graph_creator.py @@ -211,7 +211,7 @@ def compute(self): f'Motors have a main resonant frequency at {motor_fr:.1f}Hz but it was impossible to estimate a damping ratio.' ) - computation_results = { + return { 'measurements': self.measurements, 'all_speeds': all_speeds, 'all_angles': all_angles, @@ -241,8 +241,6 @@ def compute(self): 'st_version': self.st_version, } - return computation_results - # Calculate motor frequency profiles based on the measured Power Spectral Density (PSD) measurements for the machine kinematics # main angles and then create a global motor profile as a weighted average (from their own vibrations) of all calculated profiles def _compute_motor_profiles(