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, mesa_version='r15140', 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, default_history='persephone', default_profile='persephone', 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 bemesa_model_mstar_{}_z_{}Optional, defaultNone.mesa_version (str) – MESA version installed on the system. Optional, default “r15140”.
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, andmstar_stepwill be ignored. Optional, defaultNone.range_z (array-like) – Range of metallicity to consider. If provided,
z_min,z_max, andz_stepwill be ignored. Optional, defaultNone.default_history (str) – Where to take the default history file: from the
persephoneinstallation (“persephone” option) or from the MESA installation (“MESA” option). Optional, default"persephone".default_profile (str) – Where to take the default profile file: from the
persephoneinstallation (“persephone” option) or from the MESA installation (“MESA” option). Optional, default"persephone".profile_columns (str or Path object) – MESA profile columns file to replace the one used by default by
persephone. Optional, defaultNone.history_columns (str or Path object) – MESA history columns file to replace the one used by default by
persephone. Optional, defaultNone.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_mesaneeds to be set toTruefor this option to have effects. Optional, defaultFalse.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, defaultFalse.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, defaultNoneparallelise (bool) – Whether to run the MESA and GYRE runs in parallel through
pathos.multiprocess. Optional, defaultFalse.nodes (int) – Number of nodes used in
pathos.multiprocess.ProcessPoolwhenparallelise=True. Optional, default2.add_details (bool) – Add a GYRE details output file template if set to
Trueand createdetailsoutput 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
Truewill be re-run only ifrerunis set toTrue.- 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, defaultFalse.nodes (int) – Number of nodes used in
pathos.multiprocess.ProcessPoolwhenparallelise=True. Optional, default2.
- 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
Truewill be re-run only ifrerunis set toTrue.- 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, defaultNoneparameters (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
Trueand createdetailsoutput 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, defaultFalse.parallelise (bool) – Whether to run the MESA and GYRE runs in parallel through
pathos.multiprocess. Optional, defaultFalse.nodes (int) – Number of nodes used in
pathos.multiprocess.ProcessPoolwhenparallelise=True. Optional, default2.
MESA and GYRE individual model wrappers#
- persephone.grids.create_mesa_model(path='.', model_dir='MESA_work_dir', mesa_version='r15140', default_history='persephone', default_profile='persephone', 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.mesa_version (str) – MESA version installed on the system. Optional, default “r15140”.
default_history (str) – Where to take the default history file: from the
persephoneinstallation (“persephone” option) or from the MESA installation (“MESA” option). Optional, default"persephone".default_profile (str) – Where to take the default profile file: from the
persephoneinstallation (“persephone” option) or from the MESA installation (“MESA” option). Optional, default"persephone".profile_columns (str or Path object) – MESA profile columns file to replace the one used by default by
persephone. Optional, defaultNone.history_columns (str or Path object) – MESA history columns file to replace the one used by default by
persephone. Optional, defaultNone.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_mesaneeds to be set toTruefor this option to have effects. Optional, defaultFalse.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, defaultNoneverbose (bool) – Output verbosity.
erase_existing (bool) – If set to
True, existing model directories will be erased when existing, otherwise they will be ignored. Optional, defaultFalse.add_details (bool) – Add a GYRE details output file template if set to
Trueand createdetailsoutput directories together with the GYRE input files.rerun (bool) – If set to
Trueand 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, defaultNoneparameters (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
Trueand createdetailsoutput 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, defaultFalse.
- 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 ofrun_mesa_doneisTrue.
persephone convenience functions#
- persephone.grids.set_default_inlist(parameters=None, mesa_version='r15140')#
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
filenamefile is the MESA output with the.GYREextension.- Parameters:
parameters (dict) – Dictionary of parameters to include in the GYRE input file.
filename (str or Path object) – Name of the
.data.GYREMESA-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_DIRenvironment variable.- Returns:
The path stored in the
MESA_DIRenvironment variable.- Return type:
str
- persephone.grids.get_gyre_dir()#
Get GYRE directory path through the
GYRE_DIRenvironment variable.- Returns:
The path stored in the
GYRE_DIRenvironment 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, defaultTrue.
- Returns:
The list of GYRE details directories in the
LOGSdirectory ofstar_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
persephonemetadata file exists- Parameters:
star_dir (str or Path object) – MESA working directory to consider.
- Returns:
Return
Trueif the file exists,Falseinstead.- 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.h5file. Optional, defaultrun_mesa_done.
- Returns:
The status of the considered directory relatively to the the
attributekeyword``.- 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.h5file. Optional, defaultrun_mesa_done.status (bool) – Status to set. Optional, default
True.