Skip to content

Commit c84e58f

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

5 files changed

Lines changed: 28 additions & 13 deletions

File tree

CHANGELOG.md

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

4242
### Changed
4343

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

4646
### Fixed
4747

rocketpy/plots/flight_plots.py

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

658658
ax3 = plt.subplot(413)
659+
# Handle both array-based and callable-based Functions
660+
thrust_power = self.flight.thrust_power
661+
if callable(thrust_power.source):
662+
# For callable sources, discretize based on speed
663+
thrust_power = thrust_power.set_discrete_based_on_model(
664+
self.flight.speed, mutate_self=False
665+
)
659666
ax3.plot(
660-
self.flight.thrust_power[:, 0],
661-
self.flight.thrust_power[:, 1],
667+
thrust_power[:, 0],
668+
thrust_power[:, 1],
662669
label="|Thrust Power|",
663670
)
664671
ax3.set_xlim(0, self.flight.rocket.motor.burn_out_time)
@@ -670,9 +677,16 @@ def energy_data(self, *, filename=None): # pylint: disable=too-many-statements
670677
ax3.grid()
671678

672679
ax4 = plt.subplot(414)
680+
# Handle both array-based and callable-based Functions
681+
drag_power = self.flight.drag_power
682+
if callable(drag_power.source):
683+
# For callable sources, discretize based on speed
684+
drag_power = drag_power.set_discrete_based_on_model(
685+
self.flight.speed, mutate_self=False
686+
)
673687
ax4.plot(
674-
self.flight.drag_power[:, 0],
675-
-self.flight.drag_power[:, 1],
688+
drag_power[:, 0],
689+
-drag_power[:, 1],
676690
label="|Drag Power|",
677691
)
678692
ax4.set_xlim(

rocketpy/simulation/flight.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ def __simulate(self, verbose):
665665
)
666666

667667
# Initialize phase time nodes
668-
self.__setup_phase_time_nodes(phase, phase_index)
668+
self.__setup_phase_time_nodes(phase)
669669

670670
# Iterate through time nodes
671671
for node_index, node in self.time_iterator(phase.time_nodes):
@@ -799,15 +799,13 @@ def __simulate(self, verbose):
799799
if verbose:
800800
print(f"\n>>> Simulation Completed at Time: {self.t:3.4f} s")
801801

802-
def __setup_phase_time_nodes(self, phase, phase_index):
802+
def __setup_phase_time_nodes(self, phase):
803803
"""Set up time nodes for the current phase.
804804
805805
Parameters
806806
----------
807807
phase : FlightPhase
808808
The current flight phase.
809-
phase_index : int
810-
The index of the current phase.
811809
"""
812810
phase.time_nodes = self.TimeNodes()
813811

@@ -929,8 +927,11 @@ def __check_and_handle_parachute_triggers(
929927
):
930928
continue # Check next parachute
931929

932-
# Remove parachute from flight parachutes
933-
self.parachutes.remove(parachute)
930+
# Remove parachute from flight parachutes (if not already removed)
931+
if parachute in self.parachutes:
932+
self.parachutes.remove(parachute)
933+
else:
934+
continue # Parachute already triggered, skip to next
934935

935936
# Create phase for time after detection and before inflation
936937
# Must only be created if parachute has any lag
@@ -1569,7 +1570,6 @@ def __init_controllers(self):
15691570
"""Initialize controllers and sensors"""
15701571
self._controllers = self.rocket._controllers[:]
15711572
self.sensors = self.rocket.sensors.get_components()
1572-
# Note: time_overshoot now supports both controllers and sensors
15731573

15741574
# reset controllable object to initial state (only airbrakes for now)
15751575
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)