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.compile_grid(grid_dir, verbose=True, parallelise=True, nodes=2)#
Compile MESA in model directories.
- Parameters:
grid_dir (str or Path object) – Directory of the grid.
verbose (bool) – Output verbosity.
parallelise (bool) – Whether to compile MESA in parallel through
pathos.multiprocess. Optional, defaultFalse.nodes (int) – Number of nodes used in
pathos.multiprocess.ProcessPoolwhenparallelise=True. Optional, default2.
- persephone.grids.run_grid(grid_dir, verbose=True, rerun=False, resume=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.resume (bool) – If set to
True, MESA will be executed through therecommand and not therncommand (requiring the photo directory not to be empty). In this case, the function will behave automatically as ifrerunisTrue. 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.
- persephone.grids.analyse_grid_gyre(grid_dir, template_file=None, parameters=None, verbose=True, add_details=False, input_template=None, summary_template=None, details_template=None, 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.input_template (str) – Template name to use for the GYRE input file. Optional, default
None.summary_template (str) – Template name to use for the summary file created by GYRE. Optional, default
None.details_template (str) – Template name to use for the detail files created by GYRE. Optional, default
None.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=None, default_history='MESA', default_profile='MESA', profile_columns=None, history_columns=None, run_star_extras=None, parameters=None, inlist_default=False, 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, resume=False, mesa_metadata=None, input_template=None, summary_template=None, details_template=None)#
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
None.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"MESA".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.run_star_extras (str or Path object) – MESA
run_star_extras.f90file to override the default. 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.resume (bool) – If set to
True, MESA will be executed through therecommand and not therncommand (requiring the photo directory not to be empty). In this case, the function will behave automatically as ifrerunisTrue. Optional, defaultFalse.mesa_metadata (dict) – MESA metadata to include in the metadata file.
input_template (str) – Template name to use for the GYRE input file. Optional, default
None.summary_template (str) – Template name to use for the summary file created by GYRE. Optional, default
None.details_template (str) – Template name to use for the detail files created by GYRE. Optional, default
None.
- persephone.grids.analyse_gyre(star_dir, run=False, template_file=None, parameters=None, verbose=True, add_details=False, rerun=False, input_template=None, summary_template=None, details_template=None)#
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.input_template (str) – Template name to use for the GYRE input file. Optional, default
None.summary_template (str) – Template name to use for the summary file created by GYRE. Optional, default
None.details_template (str) – Template name to use for the detail files created by GYRE. Optional, default
None.
- 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, resume=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.resume (bool) – If set to
True, MESA will be executed through therecommand and not therncommand (requiring the photo directory not to be empty). In this case, the function will behave automatically as ifrerunisTrue. Optional, defaultFalse.
persephone convenience functions#
The functions are sorted by alphabetical order.
- 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.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.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_gyre_summary(profile_name, template_filename=None)#
Get GYRE summary file path from corresponding profile name.
- Parameters:
profile_name (str or Path instance) – Path to the model profile for which to recover GYRE summary path.
- Returns:
The path for the GYRE summary file.
- Return type:
str
- 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_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.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_list_gyre_summary(star_dir, sort=True, template_filename=None)#
Get absolute or relative list of GYRE summary files in a MESA model work directory.
- Parameters:
star_dir (str or Path object) – Path of the consider MESA working directory.
sort (bool) – Returned list will be sorted if
True. Optional, defaultTrue.
- Returns:
In this order: the list of MESA profile, the corresponding list of model numbers in the
history.datafile, the list of GYRE summary files in theLOGSdirectory ofstar_dir.- Return type:
tuple of Lists
- persephone.grids.get_list_profiles(star_dir, sort=True)#
Get absolute or relative list of MESA profiles in a MESA model work directory.
- Parameters:
star_dir (str or Path object) – Path of the consider MESA working directory.
sort (bool) – Returned list will be sorted if
True. Optional, defaultTrue.
- Returns:
The list of MESA profile files in the
LOGSdirectory ofstar_dir.- Return type:
List
- persephone.grids.get_list_profiles_grid(grid_dir, sort=True)#
Get absolute or relative list of MESA profiles in a whole model grid.
- Parameters:
grid_dir (str or Path object) – Path of the grid.
sort (bool) – Returned list will be sorted if
True. Optional, defaultTrue.
- Returns:
The list of MESA profile files in the whole grid.
- Return type:
List
- persephone.grids.get_profile(filename)#
Read the profile located at
filenameas aMesaDataobject.- Parameters:
filename (str or Path instance) – The path to the file with the profile to read.
- Returns:
A MesaData object as constructed by
pymesa_reader.- Return type:
MesaData
- persephone.grids.get_profile_model_number(star_dir)#
Return list of model numbers corresponding to the profile saved in the MESA
LOGSdirectory.
- persephone.grids.initialise_inlist(parameters=None, mesa_version=None)#
If
parametersisNone, create an empty inlist with only namelist names. Otherwise complete theparametersinput with missing namelists.- Returns:
Dictionary with empty sub-dictionaries.
- Return type:
dict
- persephone.grids.parse_inlist(filename)#
Parse a MESA inlist file and return a
parametersdictionary as used as input bypersephone.- Returns:
A dictionary of dictionaries that can be passed
as the
parametersinput topersephonefunctions.
- persephone.grids.plot_evolutionary_tracks(grid_dir, diagram='Kiel', min_age=None, ax=None, figsize=(6, 6), colors=None, cmap='tab10', show_legend=True, kwargs_legend={}, mass_to_select=None, z_to_select=None, alpha_mlt_to_select=None, **kwargs)#
Plot evolutionary tracks of the model of the grid.
- Parameters:
grid_dir (str or Path object) – Directory of the grid.
diagram (str) – Type of diagram. May be
KielorHR. Optional, defaultKiel.min_age (float) – Minimum age to consider for the tracks. Optional, default
None.figsize (tuple) – Figure size.
colors (array-like or str) – List of colors to consider for the tracks. Must match the total number of tracks of the grid. It is also possible to give a single color as a string, the tracks will all be drawn with the same color in this case. Optional, default
None. If not provided, thecmapargument will be automatically used to attribute a color the tracks.cmap (str or Path object) – Color map to use. Optional, default
tab10.show_legend (bool) – Whether to show legend or not. Optional, default
True.kwargs_legend (dict) – Keywords arguments to pass to
matplotlib.pyplot.legend.mass_to_select (array-like) – If provided, only tracks matching one of the stellar masses listed in the argument will be plotted.
z_to_select (array-like) – If provided, only tracks matching one of the metallicity listed in the argument will be plotted.
alpha_mlt_to_select (array-like) – If provided, only tracks matching one of the MLT parameter listed in the argument will be plotted.
**kwargs – Arguments to pass to
matplotlib.pyplot.plot.
- Returns:
The created figure.
- Return type:
matplotlib.pyplot.figure
- 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_default_inlist(parameters=None, mesa_version=None, initialisation_only=False)#
Set default values for parameter dictionary.
- Parameters:
parameters (dict) – Input dictionary of MESA namelist. The function will not override parameters if already set.
mesa_version (str) – MESA version to consider to fill the defaults, if provided and if
initialisation_onlyis set toFalse. Optional, defaultNone.initialisation_only (bool) – If set to
True, sub-dictionaries will be returned empty.
- 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, summary_template=None, details_template=None)#
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.summary_template (str) – Template name to use for the summary file created by GYRE. Optional, default
None.details_template (str) – Template name to use for the detail files created by GYRE. Optional, default
None.
- Returns:
Dictionary with the default set of parameters used by
persephone.- Return type:
dictionary
- persephone.grids.set_parametrised(param_to_set, fun, param_fun, parameters)#
Set a parameter that depends on other input parameter of the model.
- Parameters:
param_to_set (tuple) – Must be given as a tuple (
namelist,name).fun (function) – The function defining the relation between the parameter to set and other parameters. Must have the same number of elements as
param_fun.param_fun (list of tuple) – List of parameters on which the parameter to set depends. For each parameter, must be given as a tuple (
namelist,name).parameters (dict) – The complete dictionary of parameters set for the model.
- Return type:
The updated parameter dictionary.
- 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.