Skip to content

ENH: Support multiple export formats (CSV, JSON) in MonteCarlo class #945

@MateusStano

Description

@MateusStano

Description

Following the progress made in #242 and #912, the MonteCarlo class currently relies primarily on .txt files for exporting and reloading simulation data. To increase interoperability with data analysis tools, I propose adding native support for .csv and .json formats directly within the class constructor and its file-handling logic.

Proposed Changes

1. Update MonteCarlo.__init__

Introduce an export_type parameter to allow users to specify the desired output format at initialization.

def __init__(
    self,
    filename,
    environment,
    rocket,
    flight,
    export_list=None,
    data_collector=None,
    export_type="txt"  # New parameter
):
  • Supported types: "txt", "csv", "json".
  • Behavior: The class should internalize this preference to determine how results are written to disk.

2. Standardize Export Logic

The implementation should ensure that the resulting files are consistent with the output currently generated by:

  • export_results_to_csv()
  • export_results_to_json()

3. Enhanced File Loading

When a filename is passed to the constructor that points to an existing file, the class should detect the extension and handle the data ingestion accordingly.

  • If filename="results.csv", the class should parse it as a CSV.
  • If filename="results.json", it should parse it as JSON.
  • Maintain compatibility with existing .txt parsing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementNew feature or request, including adjustments in current codesGood first issueGood for newcomersMonte CarloMonte Carlo and related contents

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions