-
-
Notifications
You must be signed in to change notification settings - Fork 228
Description
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.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
# 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
- Implement export functionality for
.csv. - Implement export functionality for
.json. - Ensure that
export_listand customdata_collectorvariables are included in the export. - Add unit tests in
tests/ensuring the files are created and contain correct data. - Update the documentation to include examples of how to export 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-in csv and json libraries is preferred for lightweight implementation.