ENH: Built-in flight comparison tool (`FlightComparator`) to validate simulations against external data by Monta120 · Pull Request #888 · RocketPy-Team/RocketPy

Pull request type

  • Code changes (bugfix, features)
  • Code maintenance (refactoring, formatting, tests)
  • ReadMe, Docs and GitHub updates

Checklist

  • Tests for the changes have been added (if needed)
  • Docs have been reviewed and added / updated
  • Lint (black rocketpy/ tests/) has passed locally
  • All tests (pytest tests -m slow --runslow) have passed locally
  • CHANGELOG.md has been updated (if relevant)

Current behavior

Currently, users who want to compare RocketPy simulations against real flight data (avionics logs) or other simulators (OpenRocket, RAS Aero) face significant obstacles. They must:

1- Manually extract arrays from RocketPy objects.

2- Write custom code to interpolate their external data to match RocketPy's time steps (or vice versa) to calculate errors.

3- Write custom Matplotlib code to visualize the differences.

New behavior

This PR introduces a built-in Flight Comparison architecture that automates the validation process.

  1. New Class FlightComparator: A dedicated class in rocketpy/simulation/flight_comparator.py that:
  • Ingests external data (dictionaries of tuples or RocketPy Functions).

  • Automatically Interpolates disparate datasets onto a shared time grid (1,000 points) to allow point-by-point comparison.

  • Calculates error metrics: RMSE (Root Mean Square Error), MAE (Mean Absolute Error), and Max Deviation.

  • Generates comparison tables for Key Events (Apogee, Max Velocity, Impact Velocity) with relative error percentages.

  1. Visualization:
  • Comparison Plots: Standardized plots showing Simulation vs. External Data (Top) and Residuals/Error (Bottom).

  • 2D Trajectories: Visual comparison of flight paths (e.g., X vs Z) to analyze drift.

Breaking change

  • Yes
  • No

Additional information

Testing: Added exhaustive unit tests (tests/unit/simulation/test_flight_comparator.py) covering initialization, data conversion, metric calculation, and plotting logic.