Skip to content

Commit 30ae32a

Browse files
committed
MNT: ruff update
1 parent 6316c9a commit 30ae32a

8 files changed

Lines changed: 98 additions & 87 deletions

File tree

rocketpy/environment/environment.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2444,22 +2444,26 @@ def add_wind_gust(self, wind_gust_x, wind_gust_y):
24442444

24452445
# Reset wind heading and velocity magnitude
24462446
self.wind_heading = Function(
2447-
lambda h: (180 / np.pi)
2448-
* np.arctan2(
2449-
self.wind_velocity_x.get_value_opt(h),
2450-
self.wind_velocity_y.get_value_opt(h),
2451-
)
2452-
% 360,
2447+
lambda h: (
2448+
(180 / np.pi)
2449+
* np.arctan2(
2450+
self.wind_velocity_x.get_value_opt(h),
2451+
self.wind_velocity_y.get_value_opt(h),
2452+
)
2453+
% 360
2454+
),
24532455
"Height (m)",
24542456
"Wind Heading (degrees)",
24552457
extrapolation="constant",
24562458
)
24572459
self.wind_speed = Function(
24582460
lambda h: (
2459-
self.wind_velocity_x.get_value_opt(h) ** 2
2460-
+ self.wind_velocity_y.get_value_opt(h) ** 2
2461-
)
2462-
** 0.5,
2461+
(
2462+
self.wind_velocity_x.get_value_opt(h) ** 2
2463+
+ self.wind_velocity_y.get_value_opt(h) ** 2
2464+
)
2465+
** 0.5
2466+
),
24632467
"Height (m)",
24642468
"Wind Speed (m/s)",
24652469
extrapolation="constant",

rocketpy/rocket/aero_surface/nose_cone.py

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,16 @@ def theta_lvhaack(x):
238238
return np.arccos(1 - 2 * max(min(x / self.length, 1), 0))
239239

240240
self.y_nosecone = Function(
241-
lambda x: self.base_radius
242-
* (
243-
theta_lvhaack(x)
244-
- np.sin(2 * theta_lvhaack(x)) / 2
245-
+ (np.sin(theta_lvhaack(x)) ** 3) / 3
241+
lambda x: (
242+
self.base_radius
243+
* (
244+
theta_lvhaack(x)
245+
- np.sin(2 * theta_lvhaack(x)) / 2
246+
+ (np.sin(theta_lvhaack(x)) ** 3) / 3
247+
)
248+
** (0.5)
249+
/ (np.pi**0.5)
246250
)
247-
** (0.5)
248-
/ (np.pi**0.5)
249251
)
250252

251253
case "tangent" | "tangentogive" | "ogive":
@@ -258,15 +260,19 @@ def theta_lvhaack(x):
258260
area = np.pi * self.base_radius**2
259261
self.k = 1 - volume / (area * self.length)
260262
self.y_nosecone = Function(
261-
lambda x: np.sqrt(rho**2 - (min(x - self.length, 0)) ** 2)
262-
+ (self.base_radius - rho)
263+
lambda x: (
264+
np.sqrt(rho**2 - (min(x - self.length, 0)) ** 2)
265+
+ (self.base_radius - rho)
266+
)
263267
)
264268

265269
case "elliptical":
266270
self.k = 1 / 3
267271
self.y_nosecone = Function(
268-
lambda x: self.base_radius
269-
* np.sqrt(1 - ((x - self.length) / self.length) ** 2)
272+
lambda x: (
273+
self.base_radius
274+
* np.sqrt(1 - ((x - self.length) / self.length) ** 2)
275+
)
270276
)
271277

272278
case "vonkarman":
@@ -276,15 +282,20 @@ def theta_vonkarman(x):
276282
return np.arccos(1 - 2 * max(min(x / self.length, 1), 0))
277283

278284
self.y_nosecone = Function(
279-
lambda x: self.base_radius
280-
* (theta_vonkarman(x) - np.sin(2 * theta_vonkarman(x)) / 2) ** (0.5)
281-
/ (np.pi**0.5)
285+
lambda x: (
286+
self.base_radius
287+
* (theta_vonkarman(x) - np.sin(2 * theta_vonkarman(x)) / 2)
288+
** (0.5)
289+
/ (np.pi**0.5)
290+
)
282291
)
283292
case "parabolic":
284293
self.k = 0.5
285294
self.y_nosecone = Function(
286-
lambda x: self.base_radius
287-
* ((2 * x / self.length - (x / self.length) ** 2) / (2 - 1))
295+
lambda x: (
296+
self.base_radius
297+
* ((2 * x / self.length - (x / self.length) ** 2) / (2 - 1))
298+
)
288299
)
289300
case "powerseries":
290301
self.k = (2 * self.power) / ((2 * self.power) + 1)

rocketpy/rocket/aero_surface/tail.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,12 @@ def evaluate_lift_coefficient(self):
164164
"""
165165
# Calculate clalpha
166166
self.clalpha = Function(
167-
lambda mach: 2
168-
* (
169-
(self.bottom_radius / self.rocket_radius) ** 2
170-
- (self.top_radius / self.rocket_radius) ** 2
167+
lambda mach: (
168+
2
169+
* (
170+
(self.bottom_radius / self.rocket_radius) ** 2
171+
- (self.top_radius / self.rocket_radius) ** 2
172+
)
171173
),
172174
"Mach",
173175
f"Lift coefficient derivative for {self.name}",

rocketpy/rocket/parachute.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,10 @@ def __init__(
211211
)
212212

213213
alpha, beta = self.noise_corr
214-
self.noise_function = lambda: alpha * self.noise_signal[-1][
215-
1
216-
] + beta * np.random.normal(noise[0], noise[1])
214+
self.noise_function = lambda: (
215+
alpha * self.noise_signal[-1][1]
216+
+ beta * np.random.normal(noise[0], noise[1])
217+
)
217218

218219
self.prints = _ParachutePrints(self)
219220

rocketpy/rocket/rocket.py

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -677,12 +677,14 @@ def evaluate_stability_margin(self):
677677
self.stability_margin.set_source(
678678
lambda mach, time: (
679679
(
680-
self.center_of_mass.get_value_opt(time)
681-
- self.cp_position.get_value_opt(mach)
680+
(
681+
self.center_of_mass.get_value_opt(time)
682+
- self.cp_position.get_value_opt(mach)
683+
)
684+
/ (2 * self.radius)
682685
)
683-
/ (2 * self.radius)
686+
* self._csys
684687
)
685-
* self._csys
686688
)
687689
return self.stability_margin
688690

@@ -699,10 +701,12 @@ def evaluate_static_margin(self):
699701
# Calculate static margin
700702
self.static_margin.set_source(
701703
lambda time: (
702-
self.center_of_mass.get_value_opt(time)
703-
- self.cp_position.get_value_opt(0)
704+
(
705+
self.center_of_mass.get_value_opt(time)
706+
- self.cp_position.get_value_opt(0)
707+
)
708+
/ (2 * self.radius)
704709
)
705-
/ (2 * self.radius)
706710
)
707711
# Change sign if coordinate system is upside down
708712
self.static_margin *= self._csys
@@ -2180,13 +2184,9 @@ def __process_drag_input(self, input_data, coeff_name):
21802184
# Helper: lift a 1D Mach-only source into the required 7D signature.
21812185
def _wrap_mach_only_source(mach_source):
21822186
return Function(
2183-
lambda alpha,
2184-
beta,
2185-
mach,
2186-
reynolds,
2187-
pitch_rate,
2188-
yaw_rate,
2189-
roll_rate: mach_source(mach),
2187+
lambda alpha, beta, mach, reynolds, pitch_rate, yaw_rate, roll_rate: (
2188+
mach_source(mach)
2189+
),
21902190
inputs,
21912191
[coeff_name],
21922192
interpolation="linear",
@@ -2262,13 +2262,9 @@ def _count_positional_args(callable_obj):
22622262
# Case 4: scalar input means a constant drag coefficient in all conditions.
22632263
if isinstance(input_data, (int, float)):
22642264
return Function(
2265-
lambda alpha,
2266-
beta,
2267-
mach,
2268-
reynolds,
2269-
pitch_rate,
2270-
yaw_rate,
2271-
roll_rate: float(input_data),
2265+
lambda alpha, beta, mach, reynolds, pitch_rate, yaw_rate, roll_rate: (
2266+
float(input_data)
2267+
),
22722268
inputs,
22732269
[coeff_name],
22742270
interpolation="linear",

rocketpy/simulation/flight.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -759,11 +759,12 @@ def __simulate(self, verbose):
759759
lambda self, parachute_porosity=parachute.porosity: setattr(
760760
self, "parachute_porosity", parachute_porosity
761761
),
762-
lambda self,
763-
added_mass_coefficient=parachute.added_mass_coefficient: setattr(
764-
self,
765-
"parachute_added_mass_coefficient",
766-
added_mass_coefficient,
762+
lambda self, added_mass_coefficient=parachute.added_mass_coefficient: (
763+
setattr(
764+
self,
765+
"parachute_added_mass_coefficient",
766+
added_mass_coefficient,
767+
)
767768
),
768769
]
769770
self.flight_phases.add_phase(
@@ -981,11 +982,12 @@ def __check_and_handle_parachute_triggers(
981982
lambda self, parachute_porosity=parachute.porosity: setattr(
982983
self, "parachute_porosity", parachute_porosity
983984
),
984-
lambda self,
985-
added_mass_coefficient=parachute.added_mass_coefficient: setattr(
986-
self,
987-
"parachute_added_mass_coefficient",
988-
added_mass_coefficient,
985+
lambda self, added_mass_coefficient=parachute.added_mass_coefficient: (
986+
setattr(
987+
self,
988+
"parachute_added_mass_coefficient",
989+
added_mass_coefficient,
990+
)
989991
),
990992
]
991993
self.flight_phases.add_phase(
@@ -1387,11 +1389,12 @@ def __check_overshootable_parachute_triggers(
13871389
lambda self, parachute_porosity=parachute.porosity: setattr(
13881390
self, "parachute_porosity", parachute_porosity
13891391
),
1390-
lambda self,
1391-
added_mass_coefficient=parachute.added_mass_coefficient: setattr(
1392-
self,
1393-
"parachute_added_mass_coefficient",
1394-
added_mass_coefficient,
1392+
lambda self, added_mass_coefficient=parachute.added_mass_coefficient: (
1393+
setattr(
1394+
self,
1395+
"parachute_added_mass_coefficient",
1396+
added_mass_coefficient,
1397+
)
13951398
),
13961399
]
13971400
self.flight_phases.add_phase(

tests/acceptance/test_bella_lui_rocket.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,9 @@ def drogue_trigger(p, h, y):
172172
"constant",
173173
)
174174
BellaLui.power_off_drag_7d = Function(
175-
lambda alpha,
176-
beta,
177-
mach,
178-
reynolds,
179-
pitch_rate,
180-
yaw_rate,
181-
roll_rate: power_off_drag_by_mach.get_value_opt(mach),
175+
lambda alpha, beta, mach, reynolds, pitch_rate, yaw_rate, roll_rate: (
176+
power_off_drag_by_mach.get_value_opt(mach)
177+
),
182178
[
183179
"alpha",
184180
"beta",
@@ -193,13 +189,9 @@ def drogue_trigger(p, h, y):
193189
extrapolation="constant",
194190
)
195191
BellaLui.power_on_drag_7d = Function(
196-
lambda alpha,
197-
beta,
198-
mach,
199-
reynolds,
200-
pitch_rate,
201-
yaw_rate,
202-
roll_rate: power_on_drag_by_mach.get_value_opt(mach),
192+
lambda alpha, beta, mach, reynolds, pitch_rate, yaw_rate, roll_rate: (
193+
power_on_drag_by_mach.get_value_opt(mach)
194+
),
203195
[
204196
"alpha",
205197
"beta",

tests/unit/rocket/test_rocket.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -776,8 +776,9 @@ def test_drag_input_types_supported_for_power_on_and_power_off(tmp_path):
776776
interpolation="linear",
777777
)
778778
function_7d = Function(
779-
lambda alpha, beta, mach, reynolds, pitch_rate, yaw_rate, roll_rate: mach
780-
+ reynolds,
779+
lambda alpha, beta, mach, reynolds, pitch_rate, yaw_rate, roll_rate: (
780+
mach + reynolds
781+
),
781782
inputs=[
782783
"alpha",
783784
"beta",
@@ -811,8 +812,9 @@ def test_drag_input_types_supported_for_power_on_and_power_off(tmp_path):
811812
),
812813
(
813814
"callable_7d",
814-
lambda alpha, beta, mach, reynolds, pitch_rate, yaw_rate, roll_rate: mach
815-
+ reynolds,
815+
lambda alpha, beta, mach, reynolds, pitch_rate, yaw_rate, roll_rate: (
816+
mach + reynolds
817+
),
816818
query,
817819
0.95,
818820
),

0 commit comments

Comments
 (0)