From b0c7b57ca5427ff2943f6fc93e585aec73b78405 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Fri, 5 Jul 2024 22:07:40 -0300 Subject: [PATCH 1/6] DEV: configure flake8 for RocketPy repo --- Makefile | 9 ++++++++- pyproject.toml | 13 ++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 4ec6513b3..d0c198873 100644 --- a/Makefile +++ b/Makefile @@ -23,12 +23,19 @@ install: pip install -r requirements-optional.txt pip install -e . +format: isort black + isort: isort --profile black rocketpy/ tests/ docs/ black: black rocketpy/ tests/ docs/ - + +lint: flake8 pylint + +flake8: + flake8 rocketpy/ tests/ + pylint: -pylint rocketpy --output=.pylint-report.txt diff --git a/pyproject.toml b/pyproject.toml index 1fcb31707..5e541a8ed 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -75,11 +75,14 @@ exclude_also = [ max-line-length = 88 max-module-lines = 3000 ignore = [ - 'W503', # conflicts with black - 'E203', # conflicts with black - 'E501', # line too long, already checked by black and pylint - 'E266', # too many leading '#' for block comment, this is pointless - 'F401', # imported but unused, already checked by pylint + 'W503', # conflicts with black (line break before binary operator) + 'E203', # conflicts with black (whitespace before ':') + 'E501', # ignored now because it is hard to fix the whole code (line too long) + 'E266', # this is pointless (too many leading '#' for block comment) + 'F401', # too many errors on __init__.py files (imported but unused) + 'E722', # pylint already checks for bare except + 'E226', # black does not adjust errors like this + 'E731', # pylint already checks for this (lambda functions) ] exclude = [ '.git,__pycache__', From 0077faa26fe4b42094622ce6ebc7cf5de3494dee Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Fri, 5 Jul 2024 22:08:56 -0300 Subject: [PATCH 2/6] MNT: fixes flake8 warnings --- rocketpy/environment/environment.py | 8 ++++---- rocketpy/mathutils/function.py | 2 +- rocketpy/prints/environment_prints.py | 2 +- rocketpy/prints/hybrid_motor_prints.py | 6 ++++-- rocketpy/simulation/flight.py | 6 +++--- rocketpy/simulation/monte_carlo.py | 8 ++++---- tests/acceptance/test_bella_lui_rocket.py | 10 +++++----- tests/acceptance/test_ndrt_2020_rocket.py | 17 ++++++----------- tests/fixtures/rockets/rocket_fixtures.py | 8 ++++---- tests/integration/test_flight.py | 2 +- tests/unit/test_environment.py | 8 ++++---- tests/unit/test_function.py | 2 +- tests/unit/test_plots.py | 2 +- tests/unit/test_rocket.py | 2 +- tests/unit/test_tank.py | 4 ---- 15 files changed, 40 insertions(+), 47 deletions(-) diff --git a/rocketpy/environment/environment.py b/rocketpy/environment/environment.py index 63705a65d..8e4fb6fc4 100644 --- a/rocketpy/environment/environment.py +++ b/rocketpy/environment/environment.py @@ -3658,14 +3658,14 @@ def geodesic_to_utm( F = (1 - e2 / 4 - 3 * A / 64 - 5 * B / 256) * lat G = (3 * e2 / 8 + 3 * A / 32 + 45 * B / 1024) * C H = (15 * A / 256 + 45 * B / 1024) * D - I = (35 * B / 3072) * E + aux_i = (35 * B / 3072) * E # Evaluate other reference parameters n = semi_major_axis / ((1 - e2 * (np.sin(lat) ** 2)) ** 0.5) t = np.tan(lat) ** 2 c = e2lin * (np.cos(lat) ** 2) ag = (lon - lon_mc) * np.cos(lat) - m = semi_major_axis * (F - G + H - I) + m = semi_major_axis * (F - G + H - aux_i) # Evaluate new auxiliary parameters J = (1 - t + c) * ag * ag * ag / 6 @@ -3764,7 +3764,7 @@ def utm_to_geodesic( d = (x - 500000) / (n1 * K0) # Calculate other auxiliary values - I = (5 + 3 * t1 + 10 * c1 - 4 * c1 * c1 - 9 * e2lin) * d * d * d * d / 24 + aux_i = (5 + 3 * t1 + 10 * c1 - 4 * c1 * c1 - 9 * e2lin) * d * d * d * d / 24 J = ( (61 + 90 * t1 + 298 * c1 + 45 * t1 * t1 - 252 * e2lin - 3 * c1 * c1) * (d**6) @@ -3778,7 +3778,7 @@ def utm_to_geodesic( ) # Finally calculate the coordinates in lat/lot - lat = lat1 - (n1 * np.tan(lat1) / r1) * (d * d / 2 - I + J) + lat = lat1 - (n1 * np.tan(lat1) / r1) * (d * d / 2 - aux_i + J) lon = central_meridian * np.pi / 180 + (K + L) / np.cos(lat1) # Convert final lat/lon to Degrees diff --git a/rocketpy/mathutils/function.py b/rocketpy/mathutils/function.py index 9c6dc388f..d10ffe89a 100644 --- a/rocketpy/mathutils/function.py +++ b/rocketpy/mathutils/function.py @@ -3034,7 +3034,7 @@ def __validate_inputs(self, inputs): ) if self.__dom_dim__ > 1: if inputs is None: - return [f"Input {i+1}" for i in range(self.__dom_dim__)] + return [f"Input {i + 1}" for i in range(self.__dom_dim__)] if isinstance(inputs, list): if len(inputs) == self.__dom_dim__ and all( isinstance(i, str) for i in inputs diff --git a/rocketpy/prints/environment_prints.py b/rocketpy/prints/environment_prints.py index 6838559b4..ecbdcab7c 100644 --- a/rocketpy/prints/environment_prints.py +++ b/rocketpy/prints/environment_prints.py @@ -39,7 +39,7 @@ def gravity_details(self): print("\nGravity Details\n") print(f"Acceleration of gravity at surface level: {surface_gravity:9.4f} m/s²") print( - f"Acceleration of gravity at {max_expected_height/1000:7.3f} " + f"Acceleration of gravity at {max_expected_height / 1000:7.3f} " f"km (ASL): {ceiling_gravity:.4f} m/s²\n" ) diff --git a/rocketpy/prints/hybrid_motor_prints.py b/rocketpy/prints/hybrid_motor_prints.py index e73f96c7b..4dcd7b113 100644 --- a/rocketpy/prints/hybrid_motor_prints.py +++ b/rocketpy/prints/hybrid_motor_prints.py @@ -39,8 +39,10 @@ def nozzle_details(self): print("Nozzle Details") print(f"Outlet Radius: {self.hybrid_motor.nozzle_radius} m") print(f"Throat Radius: {self.hybrid_motor.solid.throat_radius} m") - print(f"Outlet Area: {np.pi*self.hybrid_motor.nozzle_radius**2:.6f} m²") - print(f"Throat Area: {np.pi*self.hybrid_motor.solid.throat_radius**2:.6f} m²") + print(f"Outlet Area: {np.pi * self.hybrid_motor.nozzle_radius ** 2:.6f} m²") + print( + f"Throat Area: {np.pi * self.hybrid_motor.solid.throat_radius ** 2:.6f} m²" + ) print(f"Position: {self.hybrid_motor.nozzle_position} m\n") def grain_details(self): diff --git a/rocketpy/simulation/flight.py b/rocketpy/simulation/flight.py index 99e21f00d..f5bfc8666 100644 --- a/rocketpy/simulation/flight.py +++ b/rocketpy/simulation/flight.py @@ -1670,13 +1670,13 @@ def u_dot_generalized( ## Nozzle gyration tensor S_nozzle = self.rocket.nozzle_gyration_tensor ## Inertia tensor - I = self.rocket.get_inertia_tensor_at_time(t) + inertia_tensor = self.rocket.get_inertia_tensor_at_time(t) ## Inertia tensor time derivative in the body frame I_dot = self.rocket.get_inertia_tensor_derivative_at_time(t) # Calculate the Inertia tensor relative to CM H = (r_CM.cross_matrix @ -r_CM.cross_matrix) * total_mass - I_CM = I - H + I_CM = inertia_tensor - H # Prepare transformation matrices K = Matrix.transformation(e) @@ -1820,7 +1820,7 @@ def u_dot_generalized( ) T21 = ( - ((I @ w) ^ w) + ((inertia_tensor @ w) ^ w) + T05 @ w - (weight_in_body_frame ^ r_CM) + Vector([M1, M2, M3]) diff --git a/rocketpy/simulation/monte_carlo.py b/rocketpy/simulation/monte_carlo.py index 8b7e7f0f0..0e3a06bd3 100644 --- a/rocketpy/simulation/monte_carlo.py +++ b/rocketpy/simulation/monte_carlo.py @@ -2,14 +2,14 @@ Monte Carlo Simulation Module for RocketPy This module defines the `MonteCarlo` class, which is used to perform Monte Carlo -simulations of rocket flights. The Monte Carlo simulation is a powerful tool for -understanding the variability and uncertainty in the performance of rocket flights +simulations of rocket flights. The Monte Carlo simulation is a powerful tool for +understanding the variability and uncertainty in the performance of rocket flights by running multiple simulations with varied input parameters. Notes ----- -This module is still under active development, and some features or attributes may -change in future versions. Users are encouraged to check for updates and read the +This module is still under active development, and some features or attributes may +change in future versions. Users are encouraged to check for updates and read the latest documentation. """ diff --git a/tests/acceptance/test_bella_lui_rocket.py b/tests/acceptance/test_bella_lui_rocket.py index 0041074a8..42041bf42 100644 --- a/tests/acceptance/test_bella_lui_rocket.py +++ b/tests/acceptance/test_bella_lui_rocket.py @@ -4,6 +4,7 @@ # Importing libraries import matplotlib as mpl import numpy as np +from scipy.signal import savgol_filter from rocketpy import Environment, Flight, Function, Rocket, SolidMotor @@ -103,20 +104,20 @@ def test_bella_lui_rocket_data_asserts_acceptance(): ) BellaLui.set_rail_buttons(0.1, -0.5) BellaLui.add_motor(K828FJ, parameters.get("distance_rocket_nozzle")[0]) - NoseCone = BellaLui.add_nose( + BellaLui.add_nose( length=parameters.get("nose_length")[0], kind="tangent", position=parameters.get("nose_distance_to_cm")[0] + parameters.get("nose_length")[0], ) - fin_set = BellaLui.add_trapezoidal_fins( + BellaLui.add_trapezoidal_fins( 3, span=parameters.get("fin_span")[0], root_chord=parameters.get("fin_root_chord")[0], tip_chord=parameters.get("fin_tip_chord")[0], position=parameters.get("fin_distance_to_cm")[0], ) - tail = BellaLui.add_tail( + BellaLui.add_tail( top_radius=parameters.get("tail_top_radius")[0], bottom_radius=parameters.get("tail_bottom_radius")[0], length=parameters.get("tail_length")[0], @@ -130,7 +131,7 @@ def drogue_trigger(p, h, y): # activate drogue when vz < 0 m/s. return True if y[5] < 0 else False - Drogue = BellaLui.add_parachute( + BellaLui.add_parachute( "Drogue", cd_s=parameters.get("CdS_drogue")[0], trigger=drogue_trigger, @@ -213,7 +214,6 @@ def drogue_trigger(p, h, y): acceleration_rcp.append(test_flight.az(test_flight.t_final)) # Acceleration comparison (will not be used in our publication) - from scipy.signal import savgol_filter # Calculate the acceleration as a velocity derivative acceleration_kalt = [0] diff --git a/tests/acceptance/test_ndrt_2020_rocket.py b/tests/acceptance/test_ndrt_2020_rocket.py index a0b812f10..9cc66c897 100644 --- a/tests/acceptance/test_ndrt_2020_rocket.py +++ b/tests/acceptance/test_ndrt_2020_rocket.py @@ -2,7 +2,7 @@ import pandas as pd from scipy.signal import savgol_filter -from rocketpy import Environment, Flight, Function, Rocket, SolidMotor +from rocketpy import Environment, Flight, Rocket, SolidMotor def test_ndrt_2020_rocket_data_asserts_acceptance(): @@ -17,11 +17,6 @@ def test_ndrt_2020_rocket_data_asserts_acceptance(): # Drift: 2275 ft # Importing libraries - import numpy as np - import pandas as pd - from scipy.signal import savgol_filter - - from rocketpy import Environment, Flight, Function, Rocket, SolidMotor # Defining all parameters parameters = { @@ -118,20 +113,20 @@ def test_ndrt_2020_rocket_data_asserts_acceptance(): ) NDRT2020.set_rail_buttons(0.2, -0.5, 45) NDRT2020.add_motor(L1395, parameters.get("distance_rocket_nozzle")[0]) - nose_cone = NDRT2020.add_nose( + NDRT2020.add_nose( length=parameters.get("nose_length")[0], kind="tangent", position=parameters.get("nose_distance_to_cm")[0] + parameters.get("nose_length")[0], ) - fin_set = NDRT2020.add_trapezoidal_fins( + NDRT2020.add_trapezoidal_fins( 3, span=parameters.get("fin_span")[0], root_chord=parameters.get("fin_root_chord")[0], tip_chord=parameters.get("fin_tip_chord")[0], position=parameters.get("fin_distance_to_cm")[0], ) - transition = NDRT2020.add_tail( + NDRT2020.add_tail( top_radius=parameters.get("transition_top_radius")[0], bottom_radius=parameters.get("transition_bottom_radius")[0], length=parameters.get("transition_length")[0], @@ -151,7 +146,7 @@ def main_trigger(p, h, y): # activate main when vz < 0 m/s and z < 167.64 m (AGL) or 550 ft (AGL) return True if y[5] < 0 and h < 167.64 else False - Drogue = NDRT2020.add_parachute( + NDRT2020.add_parachute( "Drogue", cd_s=parameters.get("cd_s_drogue")[0], trigger=drogue_trigger, @@ -159,7 +154,7 @@ def main_trigger(p, h, y): lag=parameters.get("lag_rec")[0], noise=(0, 8.3, 0.5), ) - Main = NDRT2020.add_parachute( + NDRT2020.add_parachute( "Main", cd_s=parameters.get("cd_s_main")[0], trigger=main_trigger, diff --git a/tests/fixtures/rockets/rocket_fixtures.py b/tests/fixtures/rockets/rocket_fixtures.py index bfc4c2473..702506d06 100644 --- a/tests/fixtures/rockets/rocket_fixtures.py +++ b/tests/fixtures/rockets/rocket_fixtures.py @@ -335,8 +335,8 @@ def prometheus_cd_at_ma(mach): prometheus.set_rail_buttons(0.69, 0.21, 60) prometheus.add_motor(motor=generic_motor_cesaroni_M1520, position=0) - nose_cone = prometheus.add_nose(length=0.742, kind="Von Karman", position=2.229) - fin_set = prometheus.add_trapezoidal_fins( + prometheus.add_nose(length=0.742, kind="Von Karman", position=2.229) + prometheus.add_trapezoidal_fins( n=3, span=0.13, root_chord=0.268, @@ -344,12 +344,12 @@ def prometheus_cd_at_ma(mach): position=0.273, sweep_length=0.066, ) - drogue_chute = prometheus.add_parachute( + prometheus.add_parachute( "Drogue", cd_s=1.6 * np.pi * 0.3048**2, # Cd = 1.6, D_chute = 24 in trigger="apogee", ) - main_chute = prometheus.add_parachute( + prometheus.add_parachute( "Main", cd_s=2.2 * np.pi * 0.9144**2, # Cd = 2.2, D_chute = 72 in trigger=457.2, # 1500 ft diff --git a/tests/integration/test_flight.py b/tests/integration/test_flight.py index b119e69bb..fd8625435 100644 --- a/tests/integration/test_flight.py +++ b/tests/integration/test_flight.py @@ -327,7 +327,7 @@ def test_rolling_flight( test_rocket.set_rail_buttons(0.082, -0.618) test_rocket.add_motor(cesaroni_m1670, position=-1.373) - fin_set = test_rocket.add_trapezoidal_fins( + test_rocket.add_trapezoidal_fins( 4, span=0.100, root_chord=0.120, diff --git a/tests/unit/test_environment.py b/tests/unit/test_environment.py index 58c0203cd..a06b92fdb 100644 --- a/tests/unit/test_environment.py +++ b/tests/unit/test_environment.py @@ -79,8 +79,8 @@ def test_geodesic_coordinate_geodesic_to_utm_converts_coordinate(): semi_major_axis=6378137.0, # WGS84 flattening=1 / 298.257223563, # WGS84 ) - assert np.isclose(x, 315468.64, atol=1e-5) == True - assert np.isclose(y, 3651938.65, atol=1e-5) == True + assert np.isclose(x, 315468.64, atol=1e-5) + assert np.isclose(y, 3651938.65, atol=1e-5) assert utm_zone == 13 assert utm_letter == "S" assert hemis == "N" @@ -101,8 +101,8 @@ class and checks the conversion results from UTM to geodesic semi_major_axis=6378137.0, # WGS84 flattening=1 / 298.257223563, # WGS84 ) - assert np.isclose(lat, 32.99025, atol=1e-5) == True - assert np.isclose(lon, -106.9750, atol=1e-5) == True + assert np.isclose(lat, 32.99025, atol=1e-5) + assert np.isclose(lon, -106.9750, atol=1e-5) @pytest.mark.parametrize( diff --git a/tests/unit/test_function.py b/tests/unit/test_function.py index 101fb81ff..3c1934f9f 100644 --- a/tests/unit/test_function.py +++ b/tests/unit/test_function.py @@ -1,4 +1,4 @@ -"""Unit tests for the Function class. Each method in tis module tests an +"""Unit tests for the Function class. Each method in tis module tests an individual method of the Function class. The tests are made on both the expected behaviour and the return instances.""" diff --git a/tests/unit/test_plots.py b/tests/unit/test_plots.py index cafd7cf8b..db36264d8 100644 --- a/tests/unit/test_plots.py +++ b/tests/unit/test_plots.py @@ -39,4 +39,4 @@ def test_compare(mock_show, flight_calisto): x_attributes=["time"], ) - assert isinstance(fig, plt.Figure) == True + assert isinstance(fig, plt.Figure) diff --git a/tests/unit/test_rocket.py b/tests/unit/test_rocket.py index 06839603f..876f5024d 100644 --- a/tests/unit/test_rocket.py +++ b/tests/unit/test_rocket.py @@ -245,7 +245,7 @@ def test_add_fins_assert_cp_cm_plus_fins(calisto, dimensionless_calisto, m): @pytest.mark.parametrize( - """cdm_position, grain_cm_position, nozzle_position, coord_direction, + """cdm_position, grain_cm_position, nozzle_position, coord_direction, motor_position, expected_motor_cdm, expected_motor_cpp""", [ (0.317, 0.397, 0, "nozzle_to_combustion_chamber", -1.373, -1.056, -0.976), diff --git a/tests/unit/test_tank.py b/tests/unit/test_tank.py index 7d4b3884f..13c7b6cb8 100644 --- a/tests/unit/test_tank.py +++ b/tests/unit/test_tank.py @@ -131,10 +131,6 @@ def test_mass_based_tank(): tank and a simplified tank. """ lox = Fluid(name="LOx", density=1141.7) - propane = Fluid( - name="Propane", - density=493, - ) n2 = Fluid( name="Nitrogen Gas", density=51.75, From 1addd37d2ed1bcdfd65958953fa505ffc4c91a99 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Fri, 5 Jul 2024 22:10:27 -0300 Subject: [PATCH 3/6] DEV: modifies CI to execute flake8 on PR updates --- .github/workflows/linters.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index 4c7f81140..0c20918ab 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -28,7 +28,7 @@ jobs: python -m pip install --upgrade pip pip install .[all] pip install .[tests] - pip install pylint isort + pip install pylint isort flake8 black - name: Run isort run: isort --check-only rocketpy/ tests/ docs/ --profile black - name: Run black @@ -36,6 +36,8 @@ jobs: with: options: "--check rocketpy/ tests/ docs/" jupyter: true + - name: Run flake8 + run: flake8 rocketpy/ tests/ - name: Run pylint run: | pylint rocketpy/ From 0256ac8c2c23c4984bc3c705d3e3a99de72f1b85 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Fri, 5 Jul 2024 22:07:40 -0300 Subject: [PATCH 4/6] DEV: configure flake8 for RocketPy repo --- Makefile | 9 ++++++++- pyproject.toml | 13 ++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 4ec6513b3..d0c198873 100644 --- a/Makefile +++ b/Makefile @@ -23,12 +23,19 @@ install: pip install -r requirements-optional.txt pip install -e . +format: isort black + isort: isort --profile black rocketpy/ tests/ docs/ black: black rocketpy/ tests/ docs/ - + +lint: flake8 pylint + +flake8: + flake8 rocketpy/ tests/ + pylint: -pylint rocketpy --output=.pylint-report.txt diff --git a/pyproject.toml b/pyproject.toml index 1fcb31707..5e541a8ed 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -75,11 +75,14 @@ exclude_also = [ max-line-length = 88 max-module-lines = 3000 ignore = [ - 'W503', # conflicts with black - 'E203', # conflicts with black - 'E501', # line too long, already checked by black and pylint - 'E266', # too many leading '#' for block comment, this is pointless - 'F401', # imported but unused, already checked by pylint + 'W503', # conflicts with black (line break before binary operator) + 'E203', # conflicts with black (whitespace before ':') + 'E501', # ignored now because it is hard to fix the whole code (line too long) + 'E266', # this is pointless (too many leading '#' for block comment) + 'F401', # too many errors on __init__.py files (imported but unused) + 'E722', # pylint already checks for bare except + 'E226', # black does not adjust errors like this + 'E731', # pylint already checks for this (lambda functions) ] exclude = [ '.git,__pycache__', From 121e56b8d97d2c18091c01806ede709c22d96aa1 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Fri, 5 Jul 2024 22:08:56 -0300 Subject: [PATCH 5/6] MNT: fixes flake8 warnings --- rocketpy/environment/environment.py | 8 ++++---- rocketpy/mathutils/function.py | 2 +- rocketpy/prints/environment_prints.py | 2 +- rocketpy/prints/hybrid_motor_prints.py | 6 ++++-- rocketpy/simulation/flight.py | 6 +++--- rocketpy/simulation/monte_carlo.py | 8 ++++---- tests/acceptance/test_bella_lui_rocket.py | 10 +++++----- tests/acceptance/test_ndrt_2020_rocket.py | 17 ++++++----------- tests/fixtures/rockets/rocket_fixtures.py | 8 ++++---- tests/integration/test_flight.py | 2 +- tests/unit/test_environment.py | 8 ++++---- tests/unit/test_function.py | 2 +- tests/unit/test_plots.py | 2 +- tests/unit/test_rocket.py | 2 +- tests/unit/test_tank.py | 4 ---- 15 files changed, 40 insertions(+), 47 deletions(-) diff --git a/rocketpy/environment/environment.py b/rocketpy/environment/environment.py index 63705a65d..8e4fb6fc4 100644 --- a/rocketpy/environment/environment.py +++ b/rocketpy/environment/environment.py @@ -3658,14 +3658,14 @@ def geodesic_to_utm( F = (1 - e2 / 4 - 3 * A / 64 - 5 * B / 256) * lat G = (3 * e2 / 8 + 3 * A / 32 + 45 * B / 1024) * C H = (15 * A / 256 + 45 * B / 1024) * D - I = (35 * B / 3072) * E + aux_i = (35 * B / 3072) * E # Evaluate other reference parameters n = semi_major_axis / ((1 - e2 * (np.sin(lat) ** 2)) ** 0.5) t = np.tan(lat) ** 2 c = e2lin * (np.cos(lat) ** 2) ag = (lon - lon_mc) * np.cos(lat) - m = semi_major_axis * (F - G + H - I) + m = semi_major_axis * (F - G + H - aux_i) # Evaluate new auxiliary parameters J = (1 - t + c) * ag * ag * ag / 6 @@ -3764,7 +3764,7 @@ def utm_to_geodesic( d = (x - 500000) / (n1 * K0) # Calculate other auxiliary values - I = (5 + 3 * t1 + 10 * c1 - 4 * c1 * c1 - 9 * e2lin) * d * d * d * d / 24 + aux_i = (5 + 3 * t1 + 10 * c1 - 4 * c1 * c1 - 9 * e2lin) * d * d * d * d / 24 J = ( (61 + 90 * t1 + 298 * c1 + 45 * t1 * t1 - 252 * e2lin - 3 * c1 * c1) * (d**6) @@ -3778,7 +3778,7 @@ def utm_to_geodesic( ) # Finally calculate the coordinates in lat/lot - lat = lat1 - (n1 * np.tan(lat1) / r1) * (d * d / 2 - I + J) + lat = lat1 - (n1 * np.tan(lat1) / r1) * (d * d / 2 - aux_i + J) lon = central_meridian * np.pi / 180 + (K + L) / np.cos(lat1) # Convert final lat/lon to Degrees diff --git a/rocketpy/mathutils/function.py b/rocketpy/mathutils/function.py index 9c6dc388f..d10ffe89a 100644 --- a/rocketpy/mathutils/function.py +++ b/rocketpy/mathutils/function.py @@ -3034,7 +3034,7 @@ def __validate_inputs(self, inputs): ) if self.__dom_dim__ > 1: if inputs is None: - return [f"Input {i+1}" for i in range(self.__dom_dim__)] + return [f"Input {i + 1}" for i in range(self.__dom_dim__)] if isinstance(inputs, list): if len(inputs) == self.__dom_dim__ and all( isinstance(i, str) for i in inputs diff --git a/rocketpy/prints/environment_prints.py b/rocketpy/prints/environment_prints.py index 6838559b4..ecbdcab7c 100644 --- a/rocketpy/prints/environment_prints.py +++ b/rocketpy/prints/environment_prints.py @@ -39,7 +39,7 @@ def gravity_details(self): print("\nGravity Details\n") print(f"Acceleration of gravity at surface level: {surface_gravity:9.4f} m/s²") print( - f"Acceleration of gravity at {max_expected_height/1000:7.3f} " + f"Acceleration of gravity at {max_expected_height / 1000:7.3f} " f"km (ASL): {ceiling_gravity:.4f} m/s²\n" ) diff --git a/rocketpy/prints/hybrid_motor_prints.py b/rocketpy/prints/hybrid_motor_prints.py index e73f96c7b..4dcd7b113 100644 --- a/rocketpy/prints/hybrid_motor_prints.py +++ b/rocketpy/prints/hybrid_motor_prints.py @@ -39,8 +39,10 @@ def nozzle_details(self): print("Nozzle Details") print(f"Outlet Radius: {self.hybrid_motor.nozzle_radius} m") print(f"Throat Radius: {self.hybrid_motor.solid.throat_radius} m") - print(f"Outlet Area: {np.pi*self.hybrid_motor.nozzle_radius**2:.6f} m²") - print(f"Throat Area: {np.pi*self.hybrid_motor.solid.throat_radius**2:.6f} m²") + print(f"Outlet Area: {np.pi * self.hybrid_motor.nozzle_radius ** 2:.6f} m²") + print( + f"Throat Area: {np.pi * self.hybrid_motor.solid.throat_radius ** 2:.6f} m²" + ) print(f"Position: {self.hybrid_motor.nozzle_position} m\n") def grain_details(self): diff --git a/rocketpy/simulation/flight.py b/rocketpy/simulation/flight.py index 99e21f00d..f5bfc8666 100644 --- a/rocketpy/simulation/flight.py +++ b/rocketpy/simulation/flight.py @@ -1670,13 +1670,13 @@ def u_dot_generalized( ## Nozzle gyration tensor S_nozzle = self.rocket.nozzle_gyration_tensor ## Inertia tensor - I = self.rocket.get_inertia_tensor_at_time(t) + inertia_tensor = self.rocket.get_inertia_tensor_at_time(t) ## Inertia tensor time derivative in the body frame I_dot = self.rocket.get_inertia_tensor_derivative_at_time(t) # Calculate the Inertia tensor relative to CM H = (r_CM.cross_matrix @ -r_CM.cross_matrix) * total_mass - I_CM = I - H + I_CM = inertia_tensor - H # Prepare transformation matrices K = Matrix.transformation(e) @@ -1820,7 +1820,7 @@ def u_dot_generalized( ) T21 = ( - ((I @ w) ^ w) + ((inertia_tensor @ w) ^ w) + T05 @ w - (weight_in_body_frame ^ r_CM) + Vector([M1, M2, M3]) diff --git a/rocketpy/simulation/monte_carlo.py b/rocketpy/simulation/monte_carlo.py index 8b7e7f0f0..0e3a06bd3 100644 --- a/rocketpy/simulation/monte_carlo.py +++ b/rocketpy/simulation/monte_carlo.py @@ -2,14 +2,14 @@ Monte Carlo Simulation Module for RocketPy This module defines the `MonteCarlo` class, which is used to perform Monte Carlo -simulations of rocket flights. The Monte Carlo simulation is a powerful tool for -understanding the variability and uncertainty in the performance of rocket flights +simulations of rocket flights. The Monte Carlo simulation is a powerful tool for +understanding the variability and uncertainty in the performance of rocket flights by running multiple simulations with varied input parameters. Notes ----- -This module is still under active development, and some features or attributes may -change in future versions. Users are encouraged to check for updates and read the +This module is still under active development, and some features or attributes may +change in future versions. Users are encouraged to check for updates and read the latest documentation. """ diff --git a/tests/acceptance/test_bella_lui_rocket.py b/tests/acceptance/test_bella_lui_rocket.py index 0041074a8..42041bf42 100644 --- a/tests/acceptance/test_bella_lui_rocket.py +++ b/tests/acceptance/test_bella_lui_rocket.py @@ -4,6 +4,7 @@ # Importing libraries import matplotlib as mpl import numpy as np +from scipy.signal import savgol_filter from rocketpy import Environment, Flight, Function, Rocket, SolidMotor @@ -103,20 +104,20 @@ def test_bella_lui_rocket_data_asserts_acceptance(): ) BellaLui.set_rail_buttons(0.1, -0.5) BellaLui.add_motor(K828FJ, parameters.get("distance_rocket_nozzle")[0]) - NoseCone = BellaLui.add_nose( + BellaLui.add_nose( length=parameters.get("nose_length")[0], kind="tangent", position=parameters.get("nose_distance_to_cm")[0] + parameters.get("nose_length")[0], ) - fin_set = BellaLui.add_trapezoidal_fins( + BellaLui.add_trapezoidal_fins( 3, span=parameters.get("fin_span")[0], root_chord=parameters.get("fin_root_chord")[0], tip_chord=parameters.get("fin_tip_chord")[0], position=parameters.get("fin_distance_to_cm")[0], ) - tail = BellaLui.add_tail( + BellaLui.add_tail( top_radius=parameters.get("tail_top_radius")[0], bottom_radius=parameters.get("tail_bottom_radius")[0], length=parameters.get("tail_length")[0], @@ -130,7 +131,7 @@ def drogue_trigger(p, h, y): # activate drogue when vz < 0 m/s. return True if y[5] < 0 else False - Drogue = BellaLui.add_parachute( + BellaLui.add_parachute( "Drogue", cd_s=parameters.get("CdS_drogue")[0], trigger=drogue_trigger, @@ -213,7 +214,6 @@ def drogue_trigger(p, h, y): acceleration_rcp.append(test_flight.az(test_flight.t_final)) # Acceleration comparison (will not be used in our publication) - from scipy.signal import savgol_filter # Calculate the acceleration as a velocity derivative acceleration_kalt = [0] diff --git a/tests/acceptance/test_ndrt_2020_rocket.py b/tests/acceptance/test_ndrt_2020_rocket.py index a0b812f10..9cc66c897 100644 --- a/tests/acceptance/test_ndrt_2020_rocket.py +++ b/tests/acceptance/test_ndrt_2020_rocket.py @@ -2,7 +2,7 @@ import pandas as pd from scipy.signal import savgol_filter -from rocketpy import Environment, Flight, Function, Rocket, SolidMotor +from rocketpy import Environment, Flight, Rocket, SolidMotor def test_ndrt_2020_rocket_data_asserts_acceptance(): @@ -17,11 +17,6 @@ def test_ndrt_2020_rocket_data_asserts_acceptance(): # Drift: 2275 ft # Importing libraries - import numpy as np - import pandas as pd - from scipy.signal import savgol_filter - - from rocketpy import Environment, Flight, Function, Rocket, SolidMotor # Defining all parameters parameters = { @@ -118,20 +113,20 @@ def test_ndrt_2020_rocket_data_asserts_acceptance(): ) NDRT2020.set_rail_buttons(0.2, -0.5, 45) NDRT2020.add_motor(L1395, parameters.get("distance_rocket_nozzle")[0]) - nose_cone = NDRT2020.add_nose( + NDRT2020.add_nose( length=parameters.get("nose_length")[0], kind="tangent", position=parameters.get("nose_distance_to_cm")[0] + parameters.get("nose_length")[0], ) - fin_set = NDRT2020.add_trapezoidal_fins( + NDRT2020.add_trapezoidal_fins( 3, span=parameters.get("fin_span")[0], root_chord=parameters.get("fin_root_chord")[0], tip_chord=parameters.get("fin_tip_chord")[0], position=parameters.get("fin_distance_to_cm")[0], ) - transition = NDRT2020.add_tail( + NDRT2020.add_tail( top_radius=parameters.get("transition_top_radius")[0], bottom_radius=parameters.get("transition_bottom_radius")[0], length=parameters.get("transition_length")[0], @@ -151,7 +146,7 @@ def main_trigger(p, h, y): # activate main when vz < 0 m/s and z < 167.64 m (AGL) or 550 ft (AGL) return True if y[5] < 0 and h < 167.64 else False - Drogue = NDRT2020.add_parachute( + NDRT2020.add_parachute( "Drogue", cd_s=parameters.get("cd_s_drogue")[0], trigger=drogue_trigger, @@ -159,7 +154,7 @@ def main_trigger(p, h, y): lag=parameters.get("lag_rec")[0], noise=(0, 8.3, 0.5), ) - Main = NDRT2020.add_parachute( + NDRT2020.add_parachute( "Main", cd_s=parameters.get("cd_s_main")[0], trigger=main_trigger, diff --git a/tests/fixtures/rockets/rocket_fixtures.py b/tests/fixtures/rockets/rocket_fixtures.py index bfc4c2473..702506d06 100644 --- a/tests/fixtures/rockets/rocket_fixtures.py +++ b/tests/fixtures/rockets/rocket_fixtures.py @@ -335,8 +335,8 @@ def prometheus_cd_at_ma(mach): prometheus.set_rail_buttons(0.69, 0.21, 60) prometheus.add_motor(motor=generic_motor_cesaroni_M1520, position=0) - nose_cone = prometheus.add_nose(length=0.742, kind="Von Karman", position=2.229) - fin_set = prometheus.add_trapezoidal_fins( + prometheus.add_nose(length=0.742, kind="Von Karman", position=2.229) + prometheus.add_trapezoidal_fins( n=3, span=0.13, root_chord=0.268, @@ -344,12 +344,12 @@ def prometheus_cd_at_ma(mach): position=0.273, sweep_length=0.066, ) - drogue_chute = prometheus.add_parachute( + prometheus.add_parachute( "Drogue", cd_s=1.6 * np.pi * 0.3048**2, # Cd = 1.6, D_chute = 24 in trigger="apogee", ) - main_chute = prometheus.add_parachute( + prometheus.add_parachute( "Main", cd_s=2.2 * np.pi * 0.9144**2, # Cd = 2.2, D_chute = 72 in trigger=457.2, # 1500 ft diff --git a/tests/integration/test_flight.py b/tests/integration/test_flight.py index b119e69bb..fd8625435 100644 --- a/tests/integration/test_flight.py +++ b/tests/integration/test_flight.py @@ -327,7 +327,7 @@ def test_rolling_flight( test_rocket.set_rail_buttons(0.082, -0.618) test_rocket.add_motor(cesaroni_m1670, position=-1.373) - fin_set = test_rocket.add_trapezoidal_fins( + test_rocket.add_trapezoidal_fins( 4, span=0.100, root_chord=0.120, diff --git a/tests/unit/test_environment.py b/tests/unit/test_environment.py index 58c0203cd..a06b92fdb 100644 --- a/tests/unit/test_environment.py +++ b/tests/unit/test_environment.py @@ -79,8 +79,8 @@ def test_geodesic_coordinate_geodesic_to_utm_converts_coordinate(): semi_major_axis=6378137.0, # WGS84 flattening=1 / 298.257223563, # WGS84 ) - assert np.isclose(x, 315468.64, atol=1e-5) == True - assert np.isclose(y, 3651938.65, atol=1e-5) == True + assert np.isclose(x, 315468.64, atol=1e-5) + assert np.isclose(y, 3651938.65, atol=1e-5) assert utm_zone == 13 assert utm_letter == "S" assert hemis == "N" @@ -101,8 +101,8 @@ class and checks the conversion results from UTM to geodesic semi_major_axis=6378137.0, # WGS84 flattening=1 / 298.257223563, # WGS84 ) - assert np.isclose(lat, 32.99025, atol=1e-5) == True - assert np.isclose(lon, -106.9750, atol=1e-5) == True + assert np.isclose(lat, 32.99025, atol=1e-5) + assert np.isclose(lon, -106.9750, atol=1e-5) @pytest.mark.parametrize( diff --git a/tests/unit/test_function.py b/tests/unit/test_function.py index 101fb81ff..3c1934f9f 100644 --- a/tests/unit/test_function.py +++ b/tests/unit/test_function.py @@ -1,4 +1,4 @@ -"""Unit tests for the Function class. Each method in tis module tests an +"""Unit tests for the Function class. Each method in tis module tests an individual method of the Function class. The tests are made on both the expected behaviour and the return instances.""" diff --git a/tests/unit/test_plots.py b/tests/unit/test_plots.py index cafd7cf8b..db36264d8 100644 --- a/tests/unit/test_plots.py +++ b/tests/unit/test_plots.py @@ -39,4 +39,4 @@ def test_compare(mock_show, flight_calisto): x_attributes=["time"], ) - assert isinstance(fig, plt.Figure) == True + assert isinstance(fig, plt.Figure) diff --git a/tests/unit/test_rocket.py b/tests/unit/test_rocket.py index 06839603f..876f5024d 100644 --- a/tests/unit/test_rocket.py +++ b/tests/unit/test_rocket.py @@ -245,7 +245,7 @@ def test_add_fins_assert_cp_cm_plus_fins(calisto, dimensionless_calisto, m): @pytest.mark.parametrize( - """cdm_position, grain_cm_position, nozzle_position, coord_direction, + """cdm_position, grain_cm_position, nozzle_position, coord_direction, motor_position, expected_motor_cdm, expected_motor_cpp""", [ (0.317, 0.397, 0, "nozzle_to_combustion_chamber", -1.373, -1.056, -0.976), diff --git a/tests/unit/test_tank.py b/tests/unit/test_tank.py index 7d4b3884f..13c7b6cb8 100644 --- a/tests/unit/test_tank.py +++ b/tests/unit/test_tank.py @@ -131,10 +131,6 @@ def test_mass_based_tank(): tank and a simplified tank. """ lox = Fluid(name="LOx", density=1141.7) - propane = Fluid( - name="Propane", - density=493, - ) n2 = Fluid( name="Nitrogen Gas", density=51.75, From af9057b134dbd489b1297a6a2cd36c174682568d Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Fri, 5 Jul 2024 22:10:27 -0300 Subject: [PATCH 6/6] DEV: modifies CI to execute flake8 on PR updates --- .github/workflows/linters.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index 4c7f81140..0c20918ab 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -28,7 +28,7 @@ jobs: python -m pip install --upgrade pip pip install .[all] pip install .[tests] - pip install pylint isort + pip install pylint isort flake8 black - name: Run isort run: isort --check-only rocketpy/ tests/ docs/ --profile black - name: Run black @@ -36,6 +36,8 @@ jobs: with: options: "--check rocketpy/ tests/ docs/" jupyter: true + - name: Run flake8 + run: flake8 rocketpy/ tests/ - name: Run pylint run: | pylint rocketpy/