Skip to content

ENH: plot flight center-of-pressure evolution (#954) - #1130

Open
thatrandomasiandev wants to merge 3 commits into
RocketPy-Team:developfrom
thatrandomasiandev:enh/954-cp-evolution-plot
Open

ENH: plot flight center-of-pressure evolution (#954)#1130
thatrandomasiandev wants to merge 3 commits into
RocketPy-Team:developfrom
thatrandomasiandev:enh/954-cp-evolution-plot

Conversation

@thatrandomasiandev

Copy link
Copy Markdown

Summary

  • Add Flight.plots.center_of_pressure() to plot CP position vs time, evaluated at the flight Mach number at each step
  • Overlay center of mass on the same axis and static margin on a twin axis, with out-of-rail / burnout / apogee markers
  • Wire the new plot into Flight.plots.all() and cover show/save paths in unit tests

Fixes #954

Test plan

  • PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 MPLBACKEND=Agg python -m pytest tests/unit/test_plots.py::test_flight_center_of_pressure_plot -q
  • Manual: flight.plots.center_of_pressure() on a Calisto flight shows CP/CM/static-margin curves through first event time

@thatrandomasiandev
thatrandomasiandev requested a review from a team as a code owner August 11, 2026 01:38
@Gui-FernandesBR

Copy link
Copy Markdown
Member

we need to see one or two examples of the new plot before merging it please

@codecov

codecov Bot commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.83%. Comparing base (e0ff281) to head (8207282).
⚠️ Report is 75 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1130      +/-   ##
===========================================
+ Coverage    82.18%   82.83%   +0.65%     
===========================================
  Files          122      129       +7     
  Lines        16355    16839     +484     
===========================================
+ Hits         13441    13949     +508     
+ Misses        2914     2890      -24     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@thatrandomasiandev

Copy link
Copy Markdown
Author

@Gui-FernandesBR here are two examples from this branch:

  1. Full-ish ascent (rail → burnout → apogee window), truncated at first_event_time like other stability plots:
    cp evolution

  2. terminate_on_apogee=True:
    cp to apogee

Both generated with flight.plots.center_of_pressure(filename=...) under MPLBACKEND=Agg. Happy to tweak axis limits / twin-axis layout if you want something closer to the existing stability plots.

@Gui-FernandesBR

Copy link
Copy Markdown
Member

the example plots don't really make sense

@Gui-FernandesBR Gui-FernandesBR linked an issue Aug 15, 2026 that may be closed by this pull request
@Gui-FernandesBR

Copy link
Copy Markdown
Member

Following up on my "the example plots don't really make sense" comment — I found why, and it is not the plotting code.

static_margin is only ever discretized over the burn:

self.static_margin.set_discrete(lower=0, upper=self.motor.burn_out_time, samples=200)

With extrapolation="constant", every query past burn_out_time returns the value frozen at the edge of that range. So for the whole coast, apogee and descent the curve is not a computed static margin at all — it is one number repeated, which is exactly the flat/implausible shape in the plots you posted.

For a flight-long quantity, use Flight.stability_margin, which is a function of Mach and time and is evaluated over the whole flight. If you really want the static margin specifically, it has to be re-discretized over the flight's own time span before plotting.

Two other notes:

  • The workflow runs on this PR had been stuck in action_required and never actually executed, so this PR has never had real CI. I approved them, so you will get results now.
  • Once the curve is right, please post the regenerated plots again so we can compare.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ENH: Flight CP evolution plot

2 participants