YAML Configuration File Parser

mesalab.io.config_parser.deep_update(original, updates)[source]
mesalab.io.config_parser.parsing_options(args: list | None = None)[source]

Parses and consolidates application configuration from multiple sources.

The function applies a tiered approach to configuration, with each subsequent source overriding the previous one: default settings, a YAML file, environment variables, and finally, command-line arguments. It also performs critical path validation for MESA and GYRE directories.

Parameters:

args (list, optional) – A list of command-line arguments to parse. If None, the function will use sys.argv[1:]. This is useful for testing or specific calls like –help.

Returns:

A nested dictionary-like object containing the final,

resolved configuration settings.

Return type:

addict.Dict

MESA inlist Parser

mesalab.io.inlist_parser.get_mesa_params_from_inlist(run_path, inlist_filename='inlist', inlist_alternatives=None)[source]

Extracts ‘initial_mass’, ‘initial_z’, and ‘initial_y’ from a MESA inlist file in a given run directory.

This function looks for the specified inlist file or alternatives in the provided directory, and parses the initial mass, metallicity, and helium abundance values using regular expressions.

Parameters:
  • run_path (str) – Path to the MESA run directory.

  • inlist_filename (str) – Primary inlist filename to search for (default: “inlist”).

  • inlist_alternatives (list, optional) – Additional filenames to try. Defaults to an empty list.

Returns:

Dictionary with keys ‘initial_mass’, ‘initial_z’, and ‘initial_y’ (if found).

Returns None if critical parameters like mass or Z are not found, or if no inlist file is found.

Return type:

dict or None

Example

>>> from mesalab.io import inlist_parser
>>> result = inlist_parser.get_mesa_params_from_inlist("runs/model_001", inlist_filename=["inlist"])
>>> print(result)
{'initial_mass': 5.0, 'initial_z': 0.0152, 'initial_y': 0.28}

Output Manager

mesalab.io.output_manager.create_output_directories(output_dir, analyze_blue_loop, should_generate_plots, should_generate_blue_loop_plots_with_bc)[source]

Creates all necessary output subdirectories.

Parameters:
  • output_dir (str) – Base output directory.

  • analyze_blue_loop (bool) – Flag to determine if the ‘detail_files’ directory should be created.

  • should_generate_plots (bool) – Flag to determine if the general ‘plots’ directory should be created.

  • should_generate_blue_loop_plots_with_bc (bool) – Flag to determine if ‘blue_loop_plots_bc’ directory should be created.

Returns:

Paths to (analysis_results_sub_dir, plots_sub_dir, blue_loop_plots_bc_sub_dir, detail_files_output_dir)

Return type:

tuple

Example

>>> from mesalab.io import output_manager
>>> output_manager.create_output_directories("output", True, True, False)
('output/analysis_results', 'output/plots', 'output/blue_loop_plots_bc', 'output/detail_files')
mesalab.io.output_manager.get_analysis_file_paths(analysis_results_sub_dir)[source]

Returns the full paths for the main analysis CSV files.

Parameters:

analysis_results_sub_dir (str) – Path to the analysis results subdirectory.

Returns:

(summary_csv_path, cross_csv_path)

Return type:

tuple

Example

>>> from mesalab.io import output_manager
>>> output_manager.get_analysis_file_paths("output/analysis_results")
('output/analysis_results/mesa_grid_analysis_summary.csv',
 'output/analysis_results/mesa_grid_cross.csv')