MESA

Functions for manipulating MESA input and output files.

tomso.mesa.load_history(filename, prune=False)[source]

Reads a MESA history file and returns the global data and history data a MESALog object. Uses builtin gzip module to read files ending with .gz.

Parameters:
  • filename (str) – Filename of the MESA history file to load.

  • prune (bool, optional) – If True, make the model number monotonic by only using the last model of with any given model number and restrict models to those with model number less than that of the last model. Useful for removing apparent reversals in time or model number because of backups and retries, and for models that finished with fewer models following a restart.

Returns:

history

Return type:

MESALog object

tomso.mesa.load_profile(filename)[source]

Reads a MESA profile and returns the global data and profile data in a :py:mesa:MESALog object. Uses builtin gzip module to read files ending with .gz.

Parameters:

filename (str) – Filename of the MESA profile to load.

Returns:

profile

Return type:

MESALog object

tomso.mesa.load_astero_results(filename)[source]

Reads a set of MESA results from one of the optimization routines in the astero module.

Parameters:

filename (str) – Filename of the file containing the results.

Returns:

data – Array with all the results.

Return type:

structured array

tomso.mesa.load_astero_sample(filename)[source]

Reads a MESA sample file that describes a model from one of the optimization routines in the astero module, and returns a MESAAsteroSample object.

Parameters:

filename (str) – Filename of the file containing the result.

Returns:

sample – A dictionary-like object containing all the results.

Return type:

MESAAsteroSample

tomso.mesa.load_astero_samples(filenames)[source]

Reads a list of MESA sample files that describe models from one of the optimization routines in the astero module, and returns a MESAAsteroSamples object.

Parameters:

filenames (iterable of strs) – Filenames of the files containing the result.

Returns:

samples – A list-like object containing all the results as MESAAsteroSample objects.

Return type:

MESAAsteroSamples

tomso.mesa.update_inlist(inlist, d)[source]

Updates parameter values in a MESA inlist file. The function searches the whole file for the parameter key. An IndexError usually means that one of the keys in dict d wasn’t found in inlist.

Parameters:
  • inlist (str) – Filename of the inlist file that will be updated.

  • d (dict) – Dictionary containing the parameter names and their new values. e.g. {‘initial_mass’: 1.0} or {‘use_Ledoux_criterion’: True}.

tomso.mesa.string_where(lines, expr)[source]

Returns list of indices of the lines in lines containing expr.

tomso.mesa.replace_value(line, value)[source]

Replaces the parameter value in the given line of a MESA inlist. Format is inferred from the type of value: float, str, int or bool.

class tomso.mesa.MESALog(header, data)[source]

A dict-like class that contains the data for a MESA history or profile. Variables in the header or the body can be accessed by the appropriate key. e.g. MESALog['star_age'] returns the star_age column.

This class also converts from (and to) logarithmic data if it is (not) stored in that form. e.g. if a history contains log_dt, you can still access dt with MESALog['dt'].

This object will normally be instantiated using mesa.load_history() or mesa.load_profile().

Parameters:
  • header (structured array) – Header data for the MESA history or profile. i.e. data for which there is only one value in the file.

  • data (structured array) – Columned data for the history or profile. i.e. data for which there are multiple values (one per timestep or mesh point).

class tomso.mesa.MESAAsteroSample(data_dict)[source]

A dict-like object that contains the data for a single sample from MESA’s astero module, usually created using mesa.load_astero_sample().

The frequency tables are accessed by the keys l0, l1, l2 and l3, which return NumPy record arrays with columns n, chi2term, freq, corr, obs, sigma and logE that correspond to the data in MESA’s astero sample files. The frequency data can also be accessed by the column names, in which case the data for all angular degrees is stacked. e.g. sample['freq'] returns a stack of the uncorrected model frequencies for angular degrees 0, 1, 2 and 3.

The remaining data is accessed by keys that correspond to each row of the sample data. e.g. model number, age, etc.

class tomso.mesa.MESAAsteroSamples(samples)[source]

A list-like object that contains a list of mesa.MESAAsteroSample objects. It can be sliced much like a NumPy array except that if you ask for a valid key from the samples in the list, it returns an array with the values of that key in all the samples. e.g. samples['model number'] will return an array containing the model number of each sample.