Is your feature request related to a problem? Please describe.
Currently, the MonteCarlo class saves simulation outputs (results, inputs, and errors) primarily to .txt files. While this works for internal storage, it makes post-processing difficult for users who want to analyze their data in external tools like Excel, MATLAB, or generic Python scripts without loading RocketPy.
As discussed in PR #229, users need a way to easily export their dispersion results to standard data exchange formats to perform comparative analysis between different rocket configurations.
Describe the solution you'd like
I would like to implement a method (or extend the existing functionality) in the MonteCarlo class to export results to .csv and .json files.
The goal is to allow the user to choose the output format easily.
Implementation Details
The changes should likely be made in rocketpy/simulation/monte_carlo.py.
-
New Methods: We need methods to handle the export logic. For example:
export_results_to_csv(filename)
export_results_to_json(filename)
- Alternatively, a single unified method:
export_data(filename, format="csv").
-
Data to Export: The export should include the data currently stored in the self.results dictionary (e.g., apogee, max_mach, impact coordinates).
-
JSON Structure: Should map keys (variable names) to lists of values.
-
CSV Structure: Should have headers (variable names) and rows corresponding to each simulation iteration.
Proposed Usage
# After running the simulation
analysis = MonteCarlo(filename="my_flight_data", ...)
analysis.simulate(number_of_simulations=1000)
# The user should be able to do this:
analysis.export_results("simulation_data.csv", format="csv")
analysis.export_results("simulation_data.json", format="json")
Acceptance Criteria
Additional Context
Please avoid using heavy dependencies (like pandas) inside the class methods if possible, unless the team decides it is a required dependency. Using Python's built-in csv and json libraries is preferred for lightweight implementation.
Is your feature request related to a problem? Please describe.
Currently, the
MonteCarloclass saves simulation outputs (results, inputs, and errors) primarily to.txtfiles. While this works for internal storage, it makes post-processing difficult for users who want to analyze their data in external tools like Excel, MATLAB, or generic Python scripts without loading RocketPy.As discussed in PR #229, users need a way to easily export their dispersion results to standard data exchange formats to perform comparative analysis between different rocket configurations.
Describe the solution you'd like
I would like to implement a method (or extend the existing functionality) in the
MonteCarloclass to export results to.csvand.jsonfiles.The goal is to allow the user to choose the output format easily.
Implementation Details
The changes should likely be made in
rocketpy/simulation/monte_carlo.py.New Methods: We need methods to handle the export logic. For example:
export_results_to_csv(filename)export_results_to_json(filename)export_data(filename, format="csv").Data to Export: The export should include the data currently stored in the
self.resultsdictionary (e.g., apogee, max_mach, impact coordinates).JSON Structure: Should map keys (variable names) to lists of values.
CSV Structure: Should have headers (variable names) and rows corresponding to each simulation iteration.
Proposed Usage
Acceptance Criteria
.csv..json.export_listand customdata_collectorvariables are included in the export.tests/ensuring the files are created and contain correct data.Additional Context
Please avoid using heavy dependencies (like
pandas) inside the class methods if possible, unless the team decides it is a required dependency. Using Python's built-incsvandjsonlibraries is preferred for lightweight implementation.