Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC: add documentation for flight data export. #464

Merged
merged 4 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
ipykernel>=6.25.0
pandas>=1.4.4
51 changes: 51 additions & 0 deletions docs/user/first_simulation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
phmbressan marked this conversation as resolved.
Show resolved Hide resolved

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")

phmbressan marked this conversation as resolved.
Show resolved Hide resolved

Further Analysis
----------------

Expand Down
Loading