Skip to content

Commit ade1cb7

Browse files
doc: switch export examples to FlightDataExporter and note deprecations (KML, CSV)
1 parent 8282d05 commit ade1cb7

File tree

1 file changed

+38
-13
lines changed

1 file changed

+38
-13
lines changed

docs/user/first_simulation.rst

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -559,19 +559,27 @@ Visualizing the Trajectory in Google Earth
559559

560560
We can export the trajectory to ``.kml`` to visualize it in Google Earth:
561561

562+
Use the dedicated exporter class:
563+
562564
.. jupyter-input::
563565

564-
test_flight.export_kml(
566+
from rocketpy.simulation import FlightDataExporter
567+
568+
FlightDataExporter(test_flight).export_kml(
565569
file_name="trajectory.kml",
566570
extrude=True,
567-
altitude_mode="relative_to_ground",
571+
altitude_mode="relativetoground",
568572
)
569573

570574
.. note::
571575

572576
To learn more about the ``.kml`` format, see
573577
`KML Reference <https://developers.google.com/kml/documentation/kmlreference>`_.
574578

579+
.. note::
580+
581+
The legacy method ``Flight.export_kml`` is deprecated. Use
582+
:meth:`rocketpy.simulation.flight_data_exporter.FlightDataExporter.export_kml`.
575583

576584
Manipulating results
577585
--------------------
@@ -604,29 +612,41 @@ In this section, we will explore how to export specific data from your RocketPy
604612
simulations to CSV files. This is particularly useful if you want to insert the
605613
data into spreadsheets or other software for further analysis.
606614

607-
The main method that is used to export data is the :meth:`rocketpy.Flight.export_data` method. This method exports selected flight attributes to a CSV file. In this first example, we will export the rocket angle of attack (see :meth:`rocketpy.Flight.angle_of_attack`) and the rocket mach number (see :meth:`rocketpy.Flight.mach_number`) to the file ``calisto_flight_data.csv``.
615+
The recommended API is
616+
:meth:`rocketpy.simulation.flight_data_exporter.FlightDataExporter.export_data`,
617+
which exports selected flight attributes to a CSV file. In this first example,
618+
we export the rocket angle of attack (see :meth:`rocketpy.Flight.angle_of_attack`)
619+
and the rocket Mach number (see :meth:`rocketpy.Flight.mach_number`) to the file
620+
``calisto_flight_data.csv``.
608621

609622
.. jupyter-execute::
610623

611-
test_flight.export_data(
624+
from rocketpy.simulation import FlightDataExporter
625+
626+
exporter = FlightDataExporter(test_flight)
627+
exporter.export_data(
612628
"calisto_flight_data.csv",
613629
"angle_of_attack",
614630
"mach_number",
615631
)
616632

617-
| As you can see, the first argument of the method is the name of the file to be created. The following arguments are the attributes to be exported. We can check the file that was created by reading it with the :func:`pandas.read_csv` function:
633+
| As you can see, the first argument is the file name to be created. The following
634+
arguments are the attributes to be exported. We can check the file by reading it
635+
with :func:`pandas.read_csv`:
618636

619637
.. jupyter-execute::
620638

621639
import pandas as pd
622640

623641
pd.read_csv("calisto_flight_data.csv")
624642

625-
| The file header specifies the meaning of each column. The time samples are obtained from the simulation solver steps. Should you want to export the data at a different sampling rate, you can use the ``time_step`` argument of the :meth:`rocketpy.Flight.export_data` method as follows.
643+
| The file header specifies the meaning of each column. The time samples are
644+
obtained from the simulation solver steps. To export the data at a different
645+
sampling rate, use the ``time_step`` argument:
626646

627647
.. jupyter-execute::
628648

629-
test_flight.export_data(
649+
exporter.export_data(
630650
"calisto_flight_data.csv",
631651
"angle_of_attack",
632652
"mach_number",
@@ -635,24 +655,29 @@ The main method that is used to export data is the :meth:`rocketpy.Flight.export
635655

636656
pd.read_csv("calisto_flight_data.csv")
637657

638-
This will export the same data at a sampling rate of 1 second. The flight data will be interpolated to match the new sampling rate.
658+
This exports the same data at a sampling rate of 1 second. The flight data is
659+
interpolated to match the new sampling rate.
639660

640-
Finally, the :meth:`rocketpy.Flight.export_data` method also provides a convenient way to export the entire flight solution (see :meth:`rocketpy.Flight.solution_array`) to a CSV file. This is done by not passing any attributes names to the method.
661+
Finally, ``FlightDataExporter.export_data`` also provides a convenient way to
662+
export the entire flight solution (see :meth:`rocketpy.Flight.solution_array`)
663+
by not passing any attribute names:
641664

642665
.. jupyter-execute::
643666

644-
test_flight.export_data(
645-
"calisto_flight_data.csv",
646-
)
667+
exporter.export_data("calisto_flight_data.csv")
647668

648669
.. jupyter-execute::
649670
:hide-code:
650671
:hide-output:
651672

652673
# Sample file cleanup
653-
import os
674+
import ospython.exe -m pip install --upgrade pip
654675
os.remove("calisto_flight_data.csv")
655676

677+
.. note::
678+
679+
The legacy method ``Flight.export_data`` is deprecated. Use
680+
:meth:`rocketpy.simulation.flight_data_exporter.FlightDataExporter.export_data`.
656681

657682
Saving and Storing Plots
658683
------------------------

0 commit comments

Comments
 (0)