You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -604,29 +612,41 @@ In this section, we will explore how to export specific data from your RocketPy
604
612
simulations to CSV files. This is particularly useful if you want to insert the
605
613
data into spreadsheets or other software for further analysis.
606
614
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``.
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``.
608
621
609
622
.. jupyter-execute::
610
623
611
-
test_flight.export_data(
624
+
from rocketpy.simulation import FlightDataExporter
625
+
626
+
exporter = FlightDataExporter(test_flight)
627
+
exporter.export_data(
612
628
"calisto_flight_data.csv",
613
629
"angle_of_attack",
614
630
"mach_number",
615
631
)
616
632
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`:
618
636
619
637
.. jupyter-execute::
620
638
621
639
import pandas as pd
622
640
623
641
pd.read_csv("calisto_flight_data.csv")
624
642
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:
626
646
627
647
.. jupyter-execute::
628
648
629
-
test_flight.export_data(
649
+
exporter.export_data(
630
650
"calisto_flight_data.csv",
631
651
"angle_of_attack",
632
652
"mach_number",
@@ -635,24 +655,29 @@ The main method that is used to export data is the :meth:`rocketpy.Flight.export
635
655
636
656
pd.read_csv("calisto_flight_data.csv")
637
657
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.
639
660
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:
641
664
642
665
.. jupyter-execute::
643
666
644
-
test_flight.export_data(
645
-
"calisto_flight_data.csv",
646
-
)
667
+
exporter.export_data("calisto_flight_data.csv")
647
668
648
669
.. jupyter-execute::
649
670
:hide-code:
650
671
:hide-output:
651
672
652
673
# Sample file cleanup
653
-
import os
674
+
import ospython.exe -m pip install --upgrade pip
654
675
os.remove("calisto_flight_data.csv")
655
676
677
+
.. note::
678
+
679
+
The legacy method ``Flight.export_data`` is deprecated. Use
0 commit comments