Skip to content

Commit fb64171

Browse files
MNT: Extract noise initialization to fix pylint too-many-statements in Parachute.__init__
Co-authored-by: Gui-FernandesBR <63590233+Gui-FernandesBR@users.noreply.github.com>
1 parent d184146 commit fb64171

1 file changed

Lines changed: 21 additions & 13 deletions

File tree

rocketpy/rocket/parachute.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,6 @@ def __init__(
215215
self.sampling_rate = sampling_rate
216216
self.lag = lag
217217
self.noise = noise
218-
self.noise_signal = [[-1e-6, np.random.normal(noise[0], noise[1])]]
219-
self.noisy_pressure_signal = []
220-
self.clean_pressure_signal = []
221-
self.noise_bias = noise[0]
222-
self.noise_deviation = noise[1]
223-
self.noise_corr = (noise[2], (1 - noise[2] ** 2) ** 0.5)
224-
self.clean_pressure_signal_function = Function(0)
225-
self.noisy_pressure_signal_function = Function(0)
226-
self.noise_signal_function = Function(0)
227218
self.drag_coefficient = drag_coefficient
228219
# Estimate radius from cd_s if not provided.
229220
# cd_s = Cd * S = Cd * π * R² => R = sqrt(cd_s / (Cd * π))
@@ -240,16 +231,33 @@ def __init__(
240231
+ 1.2626 * self.porosity**3
241232
)
242233

234+
self.__init_noise(noise)
235+
self.prints = _ParachutePrints(self)
236+
self.__evaluate_trigger_function(trigger)
237+
238+
def __init_noise(self, noise):
239+
"""Initializes all noise-related attributes.
240+
241+
Parameters
242+
----------
243+
noise : tuple, list
244+
List in the format (mean, standard deviation, time-correlation).
245+
"""
246+
self.noise_signal = [[-1e-6, np.random.normal(noise[0], noise[1])]]
247+
self.noisy_pressure_signal = []
248+
self.clean_pressure_signal = []
249+
self.noise_bias = noise[0]
250+
self.noise_deviation = noise[1]
251+
self.noise_corr = (noise[2], (1 - noise[2] ** 2) ** 0.5)
252+
self.clean_pressure_signal_function = Function(0)
253+
self.noisy_pressure_signal_function = Function(0)
254+
self.noise_signal_function = Function(0)
243255
alpha, beta = self.noise_corr
244256
self.noise_function = lambda: (
245257
alpha * self.noise_signal[-1][1]
246258
+ beta * np.random.normal(noise[0], noise[1])
247259
)
248260

249-
self.prints = _ParachutePrints(self)
250-
251-
self.__evaluate_trigger_function(trigger)
252-
253261
def __evaluate_trigger_function(self, trigger):
254262
"""This is used to set the triggerfunc attribute that will be used to
255263
interact with the Flight class.

0 commit comments

Comments
 (0)