Skip to content

Commit ff83e2a

Browse files
fix tests
fix slow tests update CHANGELOG Update rocketpy/simulation/flight.py fix lint
1 parent e420709 commit ff83e2a

File tree

5 files changed

+28
-13
lines changed

5 files changed

+28
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Attention: The newest changes should be on top -->
4545

4646
### Changed
4747

48-
-
48+
- ENH: Refactor Flight class to improve time node handling and sensor/controllers [#843](https://github.com/RocketPy-Team/RocketPy/pull/843)
4949

5050
### Fixed
5151

rocketpy/plots/flight_plots.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -720,9 +720,16 @@ def energy_data(self, *, filename=None): # pylint: disable=too-many-statements
720720
ax2.grid()
721721

722722
ax3 = plt.subplot(413)
723+
# Handle both array-based and callable-based Functions
724+
thrust_power = self.flight.thrust_power
725+
if callable(thrust_power.source):
726+
# For callable sources, discretize based on speed
727+
thrust_power = thrust_power.set_discrete_based_on_model(
728+
self.flight.speed, mutate_self=False
729+
)
723730
ax3.plot(
724-
self.flight.thrust_power[:, 0],
725-
self.flight.thrust_power[:, 1],
731+
thrust_power[:, 0],
732+
thrust_power[:, 1],
726733
label="|Thrust Power|",
727734
)
728735
ax3.set_xlim(0, self.flight.rocket.motor.burn_out_time)
@@ -734,9 +741,16 @@ def energy_data(self, *, filename=None): # pylint: disable=too-many-statements
734741
ax3.grid()
735742

736743
ax4 = plt.subplot(414)
744+
# Handle both array-based and callable-based Functions
745+
drag_power = self.flight.drag_power
746+
if callable(drag_power.source):
747+
# For callable sources, discretize based on speed
748+
drag_power = drag_power.set_discrete_based_on_model(
749+
self.flight.speed, mutate_self=False
750+
)
737751
ax4.plot(
738-
self.flight.drag_power[:, 0],
739-
-self.flight.drag_power[:, 1],
752+
drag_power[:, 0],
753+
-drag_power[:, 1],
740754
label="|Drag Power|",
741755
)
742756
ax4.set_xlim(

rocketpy/simulation/flight.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ def __simulate(self, verbose):
677677
)
678678

679679
# Initialize phase time nodes
680-
self.__setup_phase_time_nodes(phase, phase_index)
680+
self.__setup_phase_time_nodes(phase)
681681

682682
# Iterate through time nodes
683683
for node_index, node in self.time_iterator(phase.time_nodes):
@@ -811,15 +811,13 @@ def __simulate(self, verbose):
811811
if verbose:
812812
print(f"\n>>> Simulation Completed at Time: {self.t:3.4f} s")
813813

814-
def __setup_phase_time_nodes(self, phase, phase_index):
814+
def __setup_phase_time_nodes(self, phase):
815815
"""Set up time nodes for the current phase.
816816
817817
Parameters
818818
----------
819819
phase : FlightPhase
820820
The current flight phase.
821-
phase_index : int
822-
The index of the current phase.
823821
"""
824822
phase.time_nodes = self.TimeNodes()
825823

@@ -941,8 +939,11 @@ def __check_and_handle_parachute_triggers(
941939
):
942940
continue # Check next parachute
943941

944-
# Remove parachute from flight parachutes
945-
self.parachutes.remove(parachute)
942+
# Remove parachute from flight parachutes (if not already removed)
943+
if parachute in self.parachutes:
944+
self.parachutes.remove(parachute)
945+
else:
946+
continue # Parachute already triggered, skip to next
946947

947948
# Create phase for time after detection and before inflation
948949
# Must only be created if parachute has any lag
@@ -1581,7 +1582,6 @@ def __init_controllers(self):
15811582
"""Initialize controllers and sensors"""
15821583
self._controllers = self.rocket._controllers[:]
15831584
self.sensors = self.rocket.sensors.get_components()
1584-
# Note: time_overshoot now supports both controllers and sensors
15851585

15861586
# reset controllable object to initial state (only airbrakes for now)
15871587
for air_brakes in self.rocket.air_brakes:

tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def pytest_collection_modifyitems(config, items):
7676
item.add_marker(skip_slow)
7777

7878

79+
# TODO: move this to Environment fixtures when possible
7980
@pytest.fixture
8081
def merra2_file_path(tmp_path): # pylint: disable=too-many-statements
8182
"""

tests/integration/environment/test_environment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def test_merra2_full_specification_compliance(merra2_file_path, example_plain_en
280280
# Input: 9806.65 m2/s2
281281
# Expected: 1000.0 m
282282
print(f"Calculated Elevation: {env.elevation} m")
283-
assert abs(env.elevation - 1000.0) < 1e-6, (
283+
assert abs(env.elevation - 1000.0) < 1e-4, (
284284
f"Failed to convert PHIS (m2/s2) to meters. Got {env.elevation}, expected 1000.0"
285285
)
286286

0 commit comments

Comments
 (0)