Skip to content

Commit d2c3691

Browse files
Fix some more pylint errors
1 parent 0ce4215 commit d2c3691

13 files changed

Lines changed: 83 additions & 137 deletions

File tree

.github/workflows/linters.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
runs-on: ubuntu-latest
1717
strategy:
1818
matrix:
19-
python-version: ["3.8"]
19+
python-version: ["3.9"]
2020
steps:
2121
- uses: actions/checkout@v3
2222
- name: Set up Python ${{ matrix.python-version }}

.pylintrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ good-names=FlightPhases,
225225
motor_I_11_derivative_at_t,
226226
M3_forcing,
227227
M3_damping,
228+
CM_to_CDM,
229+
CM_to_CPM,
228230

229231
# Good variable names regexes, separated by a comma. If names match any regex,
230232
# they will always be accepted

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ black:
3030
black rocketpy/ tests/ docs/
3131

3232
pylint:
33-
-pylint rocketpy tests --output=.pylint-report.txt
33+
-pylint rocketpy --output=.pylint-report.txt
3434

3535
build-docs:
3636
cd docs && $(PYTHON) -m pip install -r requirements.txt && make html

rocketpy/environment/environment_analysis.py

Lines changed: 33 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,9 +1273,7 @@ def precipitation_per_day(self):
12731273
List with total precipitation for each day in the dataset.
12741274
"""
12751275
return [
1276-
sum(
1277-
[day_dict[hour]["total_precipitation"] for hour in day_dict.keys()]
1278-
) # pylint: disable=consider-using-generator
1276+
sum(day_dict[hour]["total_precipitation"] for hour in day_dict.keys())
12791277
for day_dict in self.converted_surface_data.values()
12801278
]
12811279

@@ -2583,15 +2581,8 @@ def max_average_temperature_at_altitude(self):
25832581
Maximum average temperature.
25842582
"""
25852583
max_temp = float("-inf")
2586-
for (
2587-
hour
2588-
) in (
2589-
self.average_temperature_profile_by_hour.keys()
2590-
): # pylint: disable=consider-iterating-dictionary,consider-using-dict-items
2591-
max_temp = max(
2592-
max_temp,
2593-
np.max(self.average_temperature_profile_by_hour[hour][0]),
2594-
)
2584+
for temp_profile in self.average_temperature_profile_by_hour.values():
2585+
max_temp = max(max_temp, np.max(temp_profile[0]))
25952586
return max_temp
25962587

25972588
@cached_property
@@ -2607,15 +2598,8 @@ def min_average_temperature_at_altitude(self):
26072598
Minimum average temperature.
26082599
"""
26092600
min_temp = float("inf")
2610-
for (
2611-
hour
2612-
) in (
2613-
self.average_temperature_profile_by_hour.keys()
2614-
): # pylint: disable=consider-iterating-dictionary,consider-using-dict-items
2615-
min_temp = min(
2616-
min_temp,
2617-
np.min(self.average_temperature_profile_by_hour[hour][0]),
2618-
)
2601+
for temp_profile in self.average_temperature_profile_by_hour.values():
2602+
min_temp = min(min_temp, np.min(temp_profile[0]))
26192603
return min_temp
26202604

26212605
@cached_property
@@ -2632,15 +2616,8 @@ def max_average_wind_speed_at_altitude(self):
26322616
Maximum average wind speed.
26332617
"""
26342618
max_wind_speed = float("-inf")
2635-
for (
2636-
hour
2637-
) in (
2638-
self.average_wind_speed_profile_by_hour.keys()
2639-
): # pylint: disable=consider-iterating-dictionary,consider-using-dict-items
2640-
max_wind_speed = max(
2641-
max_wind_speed,
2642-
np.max(self.average_wind_speed_profile_by_hour[hour][0]),
2643-
)
2619+
for wind_speed_profile in self.average_wind_speed_profile_by_hour.values():
2620+
max_wind_speed = max(max_wind_speed, np.max(wind_speed_profile[0]))
26442621
return max_wind_speed
26452622

26462623
# Pressure level data - Average values
@@ -2816,35 +2793,31 @@ def export_mean_profiles(self, filename="export_env_analysis"):
28162793
flipped_pressure_dict = {}
28172794
flipped_wind_x_dict = {}
28182795
flipped_wind_y_dict = {}
2819-
# pylint: disable=consider-using-dict-items
2820-
for (
2821-
hour
2822-
) in (
2823-
self.average_temperature_profile_by_hour.keys()
2824-
): # pylint: disable=consider-iterating-dictionary
2796+
2797+
for hour, temp_profile in self.average_temperature_profile_by_hour.items():
28252798
flipped_temperature_dict[hour] = np.column_stack(
2826-
(
2827-
self.average_temperature_profile_by_hour[hour][1],
2828-
self.average_temperature_profile_by_hour[hour][0],
2829-
)
2799+
(temp_profile[1], temp_profile[0])
28302800
).tolist()
2801+
2802+
for hour, pressure_profile in self.average_pressure_profile_by_hour.items():
28312803
flipped_pressure_dict[hour] = np.column_stack(
2832-
(
2833-
self.average_pressure_profile_by_hour[hour][1],
2834-
self.average_pressure_profile_by_hour[hour][0],
2835-
)
2804+
(pressure_profile[1], pressure_profile[0])
28362805
).tolist()
2806+
2807+
for (
2808+
hour,
2809+
wind_x_profile,
2810+
) in self.average_wind_velocity_x_profile_by_hour.items():
28372811
flipped_wind_x_dict[hour] = np.column_stack(
2838-
(
2839-
self.average_wind_velocity_x_profile_by_hour[hour][1],
2840-
self.average_wind_velocity_x_profile_by_hour[hour][0],
2841-
)
2812+
(wind_x_profile[1], wind_x_profile[0])
28422813
).tolist()
2814+
2815+
for (
2816+
hour,
2817+
wind_y_profile,
2818+
) in self.average_wind_velocity_y_profile_by_hour.items():
28432819
flipped_wind_y_dict[hour] = np.column_stack(
2844-
(
2845-
self.average_wind_velocity_y_profile_by_hour[hour][1],
2846-
self.average_wind_velocity_y_profile_by_hour[hour][0],
2847-
)
2820+
(wind_y_profile[1], wind_y_profile[0])
28482821
).tolist()
28492822

28502823
self.export_dictionary = {
@@ -2865,23 +2838,15 @@ def export_mean_profiles(self, filename="export_env_analysis"):
28652838
"atmospheric_model_wind_velocity_y_profile": flipped_wind_y_dict,
28662839
}
28672840

2868-
# Convert to json
2869-
f = open(filename + ".json", "w") # pylint: disable=consider-using-with
2870-
2871-
# write json object to file
2872-
f.write(
2873-
json.dumps(self.export_dictionary, sort_keys=False, indent=4, default=str)
2874-
)
2875-
2876-
# close file
2877-
f.close()
2878-
print(
2879-
"Your Environment Analysis file was saved, check it out: "
2880-
+ filename
2881-
+ ".json"
2882-
)
2841+
with open(filename + ".json", "w") as f:
2842+
f.write(
2843+
json.dumps(
2844+
self.export_dictionary, sort_keys=False, indent=4, default=str
2845+
)
2846+
)
28832847
print(
2884-
"You can use it in the future by using the customAtmosphere atmospheric model."
2848+
f"Your Environment Analysis file was saved, check it out: {filename}.json\n"
2849+
"You can use it to set a `customAtmosphere` atmospheric model"
28852850
)
28862851

28872852
@classmethod

rocketpy/mathutils/function.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1539,7 +1539,7 @@ def compare_plots(
15391539
ax.scatter(points[0], points[1], marker="o")
15401540

15411541
# Setup legend
1542-
if any([plot[1] for plot in plots]):
1542+
if any(plot[1] for plot in plots):
15431543
ax.legend(loc="best", shadow=True)
15441544

15451545
# Turn on grid and set title and axis

rocketpy/plots/environment_analysis_plots.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,7 @@ def average_surface100m_wind_speed_evolution(self):
394394
# Format plot
395395
plt.gca().xaxis.set_major_locator(plt.MaxNLocator(integer=True))
396396
plt.gca().xaxis.set_major_formatter(
397-
lambda x, pos: "{0:02.0f}:{1:02.0f}".format(
398-
*divmod(x * 60, 60)
399-
) # pylint: disable=consider-using-f-string
397+
lambda x, pos: f"{int(x):02}:{int((x * 60) % 60):02}"
400398
)
401399
plt.autoscale(enable=True, axis="x", tight=True)
402400
plt.xlabel("Time (hours)")

rocketpy/plots/rocket_plots.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,8 @@ def _draw_tubes(self, ax, drawn_surfaces, vis_args):
352352
else:
353353
# If it is not the last surface, the tube goes to the beginning
354354
# of the next surface
355-
# pylint: disable=unused-variable
356-
next_surface, next_position, next_radius, next_last_x = drawn_surfaces[
357-
i + 1
358-
] # pylint: disable=unused-variable
355+
# [next_surface, next_position, next_radius, next_last_x]
356+
next_position = drawn_surfaces[i + 1][1]
359357
x_tube = [last_x, next_position]
360358
y_tube = [radius, radius]
361359
y_tube_negated = [-radius, -radius]

rocketpy/rocket/aero_surface.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,6 @@ def evaluate_k(self):
570570
"""
571571
if self.kind == "powerseries":
572572
self.k = (2 * self.power) / ((2 * self.power) + 1)
573-
return None
574573

575574
def evaluate_center_of_pressure(self):
576575
"""Calculates and returns the center of pressure of the nose cone in
@@ -876,19 +875,25 @@ def evaluate_lift_coefficient(self):
876875
clalpha2D = Function(lambda mach: clalpha2D_incompressible / self._beta(mach))
877876

878877
# Diederich's Planform Correlation Parameter
879-
FD = (
878+
planform_correlation_parameter = (
880879
2 * np.pi * self.AR / (clalpha2D * np.cos(self.gamma_c))
881880
) # pylint: disable=invalid-name
882881

883882
# Lift coefficient derivative for a single fin
884-
self.clalpha_single_fin = Function(
885-
lambda mach: (
883+
def lift_source(mach):
884+
return (
886885
clalpha2D(mach)
887-
* FD(mach)
886+
* planform_correlation_parameter(mach)
888887
* (self.Af / self.ref_area)
889888
* np.cos(self.gamma_c)
889+
) / (
890+
2
891+
+ planform_correlation_parameter(mach)
892+
* np.sqrt(1 + (2 / planform_correlation_parameter(mach)) ** 2)
890893
)
891-
/ (2 + FD(mach) * np.sqrt(1 + (2 / FD(mach)) ** 2)),
894+
895+
self.clalpha_single_fin = Function(
896+
lift_source,
892897
"Mach",
893898
"Lift coefficient derivative for a single fin",
894899
)
@@ -1515,9 +1520,9 @@ def evaluate_geometrical_parameters(self):
15151520
"""
15161521

15171522
# Compute auxiliary geometrical parameters
1518-
Af = (
1523+
Af = ( # Fin area # pylint: disable=invalid-name
15191524
np.pi * self.root_chord / 2 * self.span
1520-
) / 2 # Fin area # pylint: disable=invalid-name
1525+
) / 2
15211526
gamma_c = 0 # Zero for elliptical fins
15221527
AR = 2 * self.span**2 / Af # Fin aspect ratio # pylint: disable=invalid-name
15231528
Yma = ( # pylint: disable=invalid-name
@@ -1613,7 +1618,7 @@ def evaluate_geometrical_parameters(self):
16131618
self.Af = Af # Fin area # pylint: disable=invalid-name
16141619
self.AR = AR # Fin aspect ratio # pylint: disable=invalid-name
16151620
self.gamma_c = gamma_c # Mid chord angle
1616-
self.Yma = (
1621+
self.Yma = ( # pylint: disable=invalid-name
16171622
Yma # Span wise coord of mean aero chord # pylint: disable=invalid-name
16181623
)
16191624
self.roll_geometrical_constant = roll_geometrical_constant

rocketpy/rocket/rocket.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -716,12 +716,8 @@ def evaluate_inertias(self):
716716
dry_mass = self.dry_mass # Constant rocket mass with motor, without propellant
717717

718718
# Compute axes distances
719-
CM_to_CDM = (
720-
self.center_of_mass - self.center_of_dry_mass_position
721-
) # pylint: disable=invalid-name
722-
CM_to_CPM = (
723-
self.center_of_mass - self.center_of_propellant_position
724-
) # pylint: disable=invalid-name
719+
CM_to_CDM = self.center_of_mass - self.center_of_dry_mass_position
720+
CM_to_CPM = self.center_of_mass - self.center_of_propellant_position
725721

726722
# Compute inertias
727723
self.I_11 = parallel_axis_theorem_from_com(
@@ -894,13 +890,13 @@ def add_motor(self, motor, position):
894890
-------
895891
None
896892
"""
897-
if hasattr(self, "motor") and not isinstance(
898-
self.motor, EmptyMotor
899-
): # pylint: disable=access-member-before-definition
900-
print(
901-
"Only one motor per rocket is currently supported. "
902-
+ "Overwriting previous motor."
903-
)
893+
if hasattr(self, "motor"):
894+
# pylint: disable=access-member-before-definition
895+
if not isinstance(self.motor, EmptyMotor):
896+
print(
897+
"Only one motor per rocket is currently supported. "
898+
+ "Overwriting previous motor."
899+
)
904900
self.motor = motor
905901
self.motor_position = position
906902
_ = self._csys * self.motor._csys

rocketpy/simulation/flight.py

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -635,13 +635,10 @@ def __repr__(self):
635635
f"name= {self.name})>"
636636
)
637637

638-
def __simulate(
639-
self, verbose
640-
): # pylint: disable=too-many-branches # pylint: disable=too-many-locals,too-many-statements
638+
# pylint: disable=too-many-nested-blocks, too-many-branches, too-many-locals,too-many-statements
639+
def __simulate(self, verbose):
641640
"""Simulate the flight trajectory."""
642-
for phase_index, phase in self.time_iterator(
643-
self.flight_phases
644-
): # pylint: disable=too-many-nested-blocks
641+
for phase_index, phase in self.time_iterator(self.flight_phases):
645642
# Determine maximum time for this flight phase
646643
phase.time_bound = self.flight_phases[phase_index + 1].t
647644

@@ -775,29 +772,21 @@ def __simulate(
775772
self.solution[-1][3] -= self.env.elevation
776773
# Get points
777774
y0 = (
778-
sum(
779-
[self.solution[-2][i] ** 2 for i in [1, 2, 3]]
780-
) # pylint: disable=consider-using-generator
775+
sum(self.solution[-2][i] ** 2 for i in [1, 2, 3])
781776
- self.effective_1rl**2
782777
)
783-
yp0 = 2 * sum( # pylint: disable=consider-using-generator
784-
[
785-
self.solution[-2][i] * self.solution[-2][i + 3]
786-
for i in [1, 2, 3]
787-
]
778+
yp0 = 2 * sum(
779+
self.solution[-2][i] * self.solution[-2][i + 3]
780+
for i in [1, 2, 3]
788781
)
789782
t1 = self.solution[-1][0] - self.solution[-2][0]
790783
y1 = (
791-
sum(
792-
[self.solution[-1][i] ** 2 for i in [1, 2, 3]]
793-
) # pylint: disable=consider-using-generator
784+
sum(self.solution[-1][i] ** 2 for i in [1, 2, 3])
794785
- self.effective_1rl**2
795786
)
796-
yp1 = 2 * sum( # pylint: disable=consider-using-generator
797-
[
798-
self.solution[-1][i] * self.solution[-1][i + 3]
799-
for i in [1, 2, 3]
800-
]
787+
yp1 = 2 * sum(
788+
self.solution[-1][i] * self.solution[-1][i + 3]
789+
for i in [1, 2, 3]
801790
)
802791
# Put elevation back
803792
self.solution[-2][3] += self.env.elevation

0 commit comments

Comments
 (0)