persephone.grids

The grids submodule provides a complete API to build and manage MESA stellar model grids, including GYRE oscillation analysis.

MESA and GYRE grid wrappers

persephone.grids.create_grid(grid_dir, model_dir_name_template=None, mstar_min=1.0, mstar_max=1.2, mstar_step=0.1, z_min=0.01, z_max=0.02, z_step=None, range_mstar=None, range_z=None, profile_columns=None, history_columns=None, parameters=None, compile_mesa=True, run_mesa=False, run_gyre=False, verbose=True, erase_existing=False, parameters_gyre=None, template_file_gyre=None, parallelise=False, nodes=2, add_details=False, rerun=False)

Create MESA models grid with a given range of mass and metallicity.

Parameters
  • grid_dir (str or Path object) – Directory of the grid.

  • model_dir_name_template (str) – Template to use for the model directories. If None, the template name will be mesa_model_mstar_{}_z_{} Optional, default None.

  • mstar_min (float) – Minimal mass (in solar mass) to consider in the grid.

  • mstar_max (float) – Maximal mass (in solar mass) to consider in the grid.

  • mstar_step (float) – Mass step (in solar mass) to consider in the grid.

  • z_min (float) – Minimal metallicity to consider in the grid.

  • z_max (float) – Minimal metallicity to consider in the grid.

  • z_step (float) – Metallicity step to consider in the grid.

  • range_mstar (array-like) – Range of mass to consider (in solar mass). If provided, mstar_min, mstar_max, and mstar_step will be ignored. Optional, default None.

  • range_z (array-like) – Range of metallicity to consider. If provided, z_min, z_max, and z_step will be ignored. Optional, default None.

  • profile_columns (str or Path object) – MESA profile columns file to replace the one used by default by persephone. Optional, default None.

  • history_columns (str or Path object) – MESA history columns file to replace the one used by default by persephone. Optional, default None.

  • parameters (dict) – MESA inlist parameter dictionary. Keys are MESA inlist namelists, each key contains a dictionary with parameter name as keys and selected status as element.

  • compile_mesa (bool) – Whether to compile MESA or not. Optional, default True.

  • run_mesa (bool) – Whether to run MESA or not. Optional, default False.

  • run_gyre – Whether to run GYRE on the computed MESA profiles or not. run_mesa needs to be set to True for this option to have effects. Optional, default False.

  • verbose (bool) – Output verbosity.

  • erase_existing (bool) – If set to True, existing model directories will be erased when existing, otherwise they will be ignored. Optional, default False.

  • parameters_gyre (dict) – Dictionary of parameters to add to the GYRE input file. Optional, default None.

  • template_file_gyre (dict) – Template GYRE input file to replace the one used by default by persephone. Optional, default None

  • parallelise (bool) – Whether to run the MESA and GYRE runs in parallel through pathos.multiprocess. Optional, default False.

  • nodes (int) – Number of nodes used in pathos.multiprocess.ProcessPool when parallelise=True. Optional, default 2.

  • add_details (bool) – Add a GYRE details output file template if set to True and create details output directories together with the GYRE input files.

  • rerun (bool) – If set to True, MESA and GYRE will be rerun in directories where they have already been run.

persephone.grids.compile_grid(grid_dir, verbose=True)

Compile MESA in model directories.

Parameters
  • grid_dir (str or Path object) – Directory of the grid.

  • verbose (bool) – Output verbosity.

persephone.grids.run_grid(grid_dir, verbose=True, rerun=False, parallelise=False, nodes=2)

Run MESA in model directories. Directories with run_mesa_done metadata set to True will be re-run only if rerun is set to True.

Parameters
  • grid_dir (str or Path object) – Directory of the grid.

  • verbose (bool) – Output verbosity.

  • rerun (bool) – If set to True, MESA will be rerun in directories where it has already been run.

  • parallelise (bool) – Whether to run the MESA and GYRE runs in parallel through pathos.multiprocess. Optional, default False.

  • nodes (int) – Number of nodes used in pathos.multiprocess.ProcessPool when parallelise=True. Optional, default 2.

persephone.grids.analyse_grid_gyre(grid_dir, template_file=None, parameters=None, verbose=True, add_details=False, rerun=False, parallelise=False, nodes=2)

Run GYRE for each profile in model directories. Directories with run_mesa_done metadata set to True will be re-run only if rerun is set to True.

Parameters
  • grid_dir (str or Path object) – Directory of the grid.

  • template_file (dict) – Template GYRE input file to replace the one used by default by persephone. Optional, default None

  • parameters (dict) – Dictionary of parameters to add to the GYRE input file. Optional, default None.

  • verbose (bool) – Output verbosity.

  • add_details (bool) – Add a GYRE details output file template if set to True and create details output directories together with the GYRE input files.

  • rerun (bool) – If set to True, GYRE will be rerun in directories where it has already been run. Optional, default False.

  • parallelise (bool) – Whether to run the MESA and GYRE runs in parallel through pathos.multiprocess. Optional, default False.

  • nodes (int) – Number of nodes used in pathos.multiprocess.ProcessPool when parallelise=True. Optional, default 2.

MESA and GYRE individual model wrappers

persephone.grids.create_mesa_model(path='.', model_dir='MESA_work_dir', profile_columns=None, history_columns=None, parameters=None, compile_mesa=True, run_mesa=False, run_gyre=False, parameters_gyre=None, template_file_gyre=None, verbose=True, erase_existing=False, add_details=False, rerun=False)

Create, initialise, and (optionally) run, repository for a given stellar evolution model.

Parameters
  • path (str or Path object) – Path where to create the model directory. Optional, default “.”.

  • model_dir (str or Path object) – Name of the model directory. Optional, default MESA_work_dir.

  • profile_columns (str or Path object) – MESA profile columns file to replace the one used by default by persephone. Optional, default None.

  • history_columns (str or Path object) – MESA history columns file to replace the one used by default by persephone. Optional, default None.

  • parameters (dict) – MESA inlist parameter dictionary. Keys are MESA inlist namelists, each key contains a dictionary with parameter name as keys and selected status as element.

  • compile_mesa (bool) – Whether to compile MESA or not. Optional, default True.

  • run_mesa (bool) – Whether to run MESA or not. Optional, default False.

  • run_gyre – Whether to run GYRE on the computed MESA profiles or not. run_mesa needs to be set to True for this option to have effects. Optional, default False.

  • parameters_gyre (dict) – Dictionary of parameters to add to the GYRE input file. Optional, default None.

  • template_file_gyre (dict) – Template GYRE input file to replace the one used by default by persephone. Optional, default None

  • verbose (bool) – Output verbosity.

  • erase_existing (bool) – If set to True, existing model directories will be erased when existing, otherwise they will be ignored. Optional, default False.

  • add_details (bool) – Add a GYRE details output file template if set to True and create details output directories together with the GYRE input files.

  • rerun (bool) – If set to True and the directory already existed, MESA will be rerun.

persephone.grids.analyse_gyre(star_dir, run=False, template_file=None, parameters=None, verbose=True, add_details=False, rerun=False)

Run GYRE for the profiles in the LOGS directory of a MESA work directory.

Parameters
  • star_dir (str or Path object) – MESA model directory.

  • run (bool) – Whether to run GYRE or to create only the input files. Optional, default False.

  • template_file (dict) – Template GYRE input file to replace the one used by default by persephone. Optional, default None

  • parameters (dict) – Dictionary of parameters to add to the GYRE input file. Optional, default None.

  • verbose (bool) – Output verbosity.

  • add_details (bool) – Add a GYRE details output file template if set to True and create details output directories together with the GYRE input files.

  • rerun (bool) – If set to True, GYRE will be rerun in directories where it has already been run. Optional, default False.

persephone.grids.compile_repository(star_dir, verbose=True)

Compile MESA work repository.

Parameters
  • star_dir (str or Path object) – MESA working directory to consider.

  • verbose (bool) – Output verbosity. Optional, default True.

persephone.grids.run_mesa_model(star_dir, verbose=True, rerun=False)

Run MESA in selected repository.

Parameters
  • star_dir (str or Path object) – MESA working directory to consider.

  • verbose (bool) – Output verbosity. Optional, default True.

  • rerun (bool) – If set to True, MESA will be run even if the status of run_mesa_done is True.

persephone convenience functions

persephone.grids.set_default_inlist(parameters=None)

Set default values for parameter dictionary.

Parameters

parameters (dict) – Input dictionary of MESA namelist. The function will not override parameters if already set.

Returns

Dictionary with the default set of parameters used by persephone.

Return type

dict

persephone.grids.set_default_gyre_namelist(parameters=None, filename='profile.data.GYRE', add_details=False)

Set default values for parameter dictionary to build GYRE input namelist. The filename file is the MESA output with the .GYRE extension.

Parameters
  • parameters (dict) – Dictionary of parameters to include in the GYRE input file.

  • filename (str or Path object) – Name of the .data.GYRE MESA-generated file to use for the GYRE run.

  • add_details (bool) – Add a GYRE details output file template if set to True.

Returns

Dictionary with the default set of parameters used by persephone.

Return type

dictionary

persephone.grids.get_mesa_dir()

Get MESA directory path through the MESA_DIR environment variable.

Returns

The path stored in the MESA_DIR environment variable.

Return type

str

persephone.grids.get_gyre_dir()

Get GYRE directory path through the GYRE_DIR environment variable.

Returns

The path stored in the GYRE_DIR environment variable.

Return type

str

persephone.grids.get_listdir_gyre_details(star_dir, sort=True)

Get absolute or relative list of GYRE details directories in a MESA model work directory.

star_dirstr or Path object

Path of the consider MESA working directory.

sortbool

Returned list will be sorted if True. Optional, default True.

Returns

The list of GYRE details directories in the LOGS directory of star_dir.

Return type

List

persephone.grids.get_detail_file(details_dir, n=1, l=0, m=0, detail_template=None)

Get the path of a detail file in a directory details_dir.

Parameters
  • details_dir (str or Path object) – Directory where GYRE details file are stored.

  • n (int) – mode order

  • l (int) – mode degree

  • m (int) – mode azimuthal number

  • detail_template (str) – Detail template of the detail files if not standard. Optional, default None.

Returns

A tuple with the path of the file and a boolean stating if the file actually exists.

Return type

tuple

persephone.grids.check_metadata(star_dir)

Check if the persephone metadata file exists

Parameters

star_dir (str or Path object) – MESA working directory to consider.

Returns

Return True if the file exists, False instead.

Return type

bool

persephone.grids.read_status_dir(star_dir, attribute='run_mesa_done')

Read status in metadata file in MESA directory.

Parameters
  • star_dir (str or Path object) – MESA working directory to consider.

  • attribute (str) – Keyword to read in the persephone_metadata.h5 file. Optional, default run_mesa_done.

Returns

The status of the considered directory relatively to the the attribute keyword``.

Return type

bool

persephone.grids.set_status_dir(star_dir, attribute='run_mesa_done', status=True)

Set status in metadata file in MESA directory.

Parameters
  • star_dir (str or Path object) – MESA working directory to consider.

  • attribute (str) – Keyword to set in the persephone_metadata.h5 file. Optional, default run_mesa_done.

  • status (bool) – Status to set. Optional, default True.