Skip to content

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

Merged
Gui-FernandesBR merged 4 commits into
RocketPy-Team:developfrom
thatrandomasiandev:enh/954-cp-evolution-plot
Sep 9, 2026
Merged

ENH: plot flight center-of-pressure evolution (#954)#1130
Gui-FernandesBR merged 4 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 90.56%. Comparing base (e0ff281) to head (2ed76d3).
⚠️ Report is 93 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1130      +/-   ##
===========================================
+ Coverage    82.18%   90.56%   +8.38%     
===========================================
  Files          122      131       +9     
  Lines        16355    17554    +1199     
===========================================
+ Hits         13441    15898    +2457     
+ Misses        2914     1656    -1258     

☔ 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.

@Gui-FernandesBR Gui-FernandesBR left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to commit docs/static/pr_examples/cp_evolution_calisto_like.png file

These two PNGs were committed only to illustrate the plot in the pull
request description. Nothing in the docs or the code references them, so
they added ~345 kB of binaries to the tree for no reader.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@Gui-FernandesBR
Gui-FernandesBR merged commit 3bd6505 into RocketPy-Team:develop Sep 9, 2026
9 checks passed
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