MesaLogDir¶

MesaLogDir is a class that contains information about the LOGS directory as a whole. In addition to giving easy access to the history data, you can easily find profiles by profile number, model number, or by selecting according to a more flexible history criteria.

class mesa_reader.MesaLogDir(log_path='LOGS', profile_prefix='profile', profile_suffix='data', history_file='history.data', index_file='profiles.index', memoize_profiles=True)[source]

Provides access for accessing the history and profile data of a MESA run by linking profiles to the history through model numbers.

Parameters: log_path (str, optional) – Path to the logs directory, default is ‘LOGS’ profile_prefix (str, optional) – Prefix before profile number in profile file names, default is ‘profile’ profile_suffix (str, optional) – Suffix after profile number and period for profile file names, default is ‘data’ history_file (str, optional) – Name of the history file in the logs directory, default is ‘history.data’ index_file (str, optional) – Name of the profiles index file in the logs directory, default is ‘profiles.index’ memoize_profiles (bool, optional) – Determines whether or not profiles will be “memo-ized”, default is True. If memoized, once a profile is called into existence, it is saved so that it need not be read in again. Good for quick, clean, repeated access of a profile, but bad for reading in many profiles for one-time uses as it will hog memory.
log_path

str – Path to the logs directory; used (re-)reading data in

profile_prefix

str – Prefix before profile number in profile file names

profile_suffix

str – Suffix after profile number and period for profile file names

history_file

str – Base name (not path) of the history file in the logs directory

index_file

str – Base name (not path) of the profiles index file in the logs directory

memoize_profiles

bool – Determines whether or not profiles will be “memo-ized”. Setting this after initialization will not delete profiles from memory. It will simply start/stop memoizing them. To clear out memoized profiles, re-read the data with self.read_logs()

history_path

str – Path to the history data file

index_path

str – Path to the profile index file

history

history_data

profiles

mesa_reader.MesaProfileIndex – MesaProfileIndex from profiles in self.index_path

profile_numbers

numpy.ndarray – Result of calling self.profiles.profile_numbers. Just the profile numbers of the simulation in order of corresponding model numbers.

model_numbers

numpy.ndarray – Result of calling self.profiles.model_numbers. Just the model numbers of the simulations that have corresponding profiles in ascending order.

profile_dict

dict – Stores MesaData objects from profiles. Keys to this dictionary are profile numbers, so presumably self.profile_dict(5) would yield the MesaData object obtained from the file profile5.data (assuming reasonable defaults) if such a profile was ever accessed. Will remain empty if memoization is shut off.

have_profile_with_model_number(m_num)[source]

Checks to see if a model number has a corresponding profile number.

Parameters: m_num (int) – model number to be checked True if the model number is in self.model_numbers, otherwise False. bool
have_profile_with_profile_number(p_num)[source]

Checks to see if a given number is a valid profile number.

Parameters: p_num (int) – profile number to be checked True if profile number is in self.profile_numbers, otherwise False. bool
model_with_profile_number(p_num)[source]

Converts a profile number to a corresponding model number

Parameters: p_num (int) – profile number to be converted model number that corresponds to p_num. int
profile_data(model_number=-1, profile_number=-1)[source]

Generate or retrieve MesaData from a model or profile number.

If both a model number and a profile number is given, the model number takes precedence. If neither are given, the default is to return a MesaData object of the last profile (biggest model number). In either case, this generates (if it doesn’t already exist) or retrieves (if it has already been generated and memoized) a MesaData object from the corresponding profile data.

Parameters: model_number (int, optional) – model number for the profile MesaData object desired. Default is -1, corresponding to the last model number. profile_number (int, optional) – profile number for the profile MesaData object desired. Default is -1, corresponding to the last model number. If both model_number and profile_number are given, profile_number is ignored. Data for profile with desired model/profile number. mesa_reader.MesaData
profile_with_model_number(m_num)[source]

Converts a model number to a corresponding profile number

Parameters: m_num (int) – model number to be converted profile number that corresponds to m_num. int
read_logs()[source]

Reads in self.history_path and self.index_file for use in getting history data and profile information. This is automatically called at instantiation, but can be recalled by the user if for some reason the data needs to be refreshed (for instance, after changing some of the reader methods to read in specially-formatted output.)

Returns: None

Note

This, if called after initialization, will empty self.profile_dict, erasing all memo-ized profiles.

select_models(f, *keys)[source]

Yields model numbers for profiles that satisfy a given criteria.

Given a function f of various time-domain (history) variables, *keys (i.e., categories in self.history.bulk_names), filters self.model_numbers and returns all model numbers that satisfy the criteria.

Parameters: f (function) – A function of the same number of parameters as strings given for keys that returns a boolean. Should evaluate to True when condition is met and False otherwise. keys (str) – Name of data categories from self.history.bulk_names whose values are to be used in the arguments to f, in the same order that they appear as arguments in f. Array of model numbers that have corresponding profiles where the condition given by f is True. numpy.ndarray KeyError – If any of the keys are invalid history keys.

Examples

>>> l = MesaLogDir()
>>> def is_old_and_bright(age, log_lum):
>>>     return age > 1e9 and log_lum > 3
>>> m_nums = l.select_models(is_old_and_bright, 'star_age', 'log_L')


Here, m_nums will contain all model numbers that have profiles where the age is greater than a billion years and the luminosity is greater than 1000 Lsun, provided that ‘star_age’ and ‘log_L’ are in self.history.bulk_names.