From 84b4e5a14db1935fc4a4fa61dc653c0f43e85af0 Mon Sep 17 00:00:00 2001 From: Pedro Bressan Date: Wed, 15 Nov 2023 10:50:00 -0300 Subject: [PATCH 1/4] DOC: add documentation for flight data export. --- docs/user/first_simulation.rst | 51 ++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/docs/user/first_simulation.rst b/docs/user/first_simulation.rst index bcc842b74..248951433 100644 --- a/docs/user/first_simulation.rst +++ b/docs/user/first_simulation.rst @@ -356,6 +356,57 @@ To see a very large summary of the results, we can call the ``all_info`` method: altitude_mode="relative_to_ground", ) +Exporting Flight Data +--------------------- + +In this section, we will explore how to export specific data from your RocketPy simulations to CSV files. This is particularly useful if you want to insert the data into spreadsheets or other software for further analysis. + +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``. + +.. jupyter-execute:: + + test_flight.export_data( + "calisto_flight_data.csv", + "angle_of_attack", + "mach_number", + ) + +| 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: + +.. jupyter-execute:: + + import pandas as pd + + pd.read_csv("calisto_flight_data.csv") + +| 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. + +.. jupyter-execute:: + + test_flight.export_data( + "calisto_flight_data.csv", + "angle_of_attack", + "mach_number", + time_step=1.0, + ) + + pd.read_csv("calisto_flight_data.csv") + +This will export the same data at a sampling rate of 1 second. The flight data will be linearly interpolated to match the new sampling rate. + +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. + +.. jupyter-execute:: + + test_flight.export_data( + "calisto_flight_data.csv", + ) + + # Sample file cleanup + import os + os.remove("calisto_flight_data.csv") + + Further Analysis ---------------- From 46bcf9931da528d713338b92ce015d20db1da886 Mon Sep 17 00:00:00 2001 From: Pedro Bressan Date: Fri, 17 Nov 2023 19:33:55 -0300 Subject: [PATCH 2/4] DOC: add pandas to docs requirements. --- docs/requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index 247c75a94..7d45029bb 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -3,4 +3,5 @@ pydata-sphinx-theme==0.13.3 m2r2>=0.2.1 jupyter-sphinx==0.4.0 sphinx_design==0.5.0 -ipykernel>=6.25.0 \ No newline at end of file +ipykernel>=6.25.0 +pandas>=1.4.4 \ No newline at end of file From 2ddcd8b931c4b266c8dffc0700c85bfd14db099f Mon Sep 17 00:00:00 2001 From: Pedro Henrique Marinho Bressan <87212571+phmbressan@users.noreply.github.com> Date: Fri, 17 Nov 2023 21:54:28 -0300 Subject: [PATCH 3/4] Update docs/user/first_simulation.rst Co-authored-by: MateusStano <69485049+MateusStano@users.noreply.github.com> --- docs/user/first_simulation.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/user/first_simulation.rst b/docs/user/first_simulation.rst index 248951433..b92466d7a 100644 --- a/docs/user/first_simulation.rst +++ b/docs/user/first_simulation.rst @@ -402,6 +402,10 @@ Finally, the :meth:`rocketpy.Flight.export_data` method also provides a convenie "calisto_flight_data.csv", ) +.. jupyter-execute:: + :hide-code: + :hide-output: + # Sample file cleanup import os os.remove("calisto_flight_data.csv") From 43f4217a890e880263ede19c4bbace292559613b Mon Sep 17 00:00:00 2001 From: Pedro Henrique Marinho Bressan <87212571+phmbressan@users.noreply.github.com> Date: Fri, 17 Nov 2023 21:54:49 -0300 Subject: [PATCH 4/4] Update docs/user/first_simulation.rst Co-authored-by: MateusStano <69485049+MateusStano@users.noreply.github.com> --- docs/user/first_simulation.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/user/first_simulation.rst b/docs/user/first_simulation.rst index b92466d7a..5e322dac5 100644 --- a/docs/user/first_simulation.rst +++ b/docs/user/first_simulation.rst @@ -392,7 +392,7 @@ The main method that is used to export data is the :meth:`rocketpy.Flight.export pd.read_csv("calisto_flight_data.csv") -This will export the same data at a sampling rate of 1 second. The flight data will be linearly interpolated to match the new sampling rate. +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. 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.