The model
module
A module which contains various classes relevant to the grid of models:
Track
: an evolutionary trackModel_grid
: a grid of evolutionary tracks
These different classes allow the program to store a grid of models and perform a number of operations, such as:
retrieving model properties
interpolate within the grid models
sort the models within a given evolutionary track
…
- class model.Model_grid[source]
A grid of models.
- age_range(pt)[source]
Find age range for a given set of structural parameters in the grid.
- Parameters:
pt (1D numpy float array) – input set of parameters (age is included for convenience but not used)
- Returns:
the age range (min and max value)
- Return type:
1D numpy float array
- all_params
All of the parameters of the grid (including age parameters).
- all_params_fundamental
All of the fundamental parameters of the grid (i.e. without application of functions).
- all_params_latex
Latex version of all of the parameters of the grid (including age parameters).
- distort_grid()[source]
Define distortion matrix with which to distort grid to break its Cartesian character prior to tessellation. This can cause find_simplex to run much faster.
- distort_mat
Transformation matrix used to break the Cartesian character of the grid and reduce computation time
- find_isochrone(parameters, npts)[source]
This calculates an isochrone and writes it to a file.
- Parameters:
parameters (dict) – the parameters used in determining the isochrone (typically all of grid parameters except for mass)
npts (int) – maximum number of points in isochrone. The actual number of points may be less as a result of the target age being outside the evolutionary tracks for some of the masses.
- Returns:
table of interpolated models along isochrone
- Return type:
2D numpy float array
- find_partition()[source]
Find a partition of the grid for use with
Model_grid.test_interpolation()
- Returns:
a random partition of [0 … n-1] into two equal halves, where n is the number of tracks in the grid
- Return type:
two lists of int
- grid
Array containing the grid parameters for each evolutionary track (excluding age parameters).
- grid_params
Set of parameters (excluding age parameters) used to construct the grid and do interpolations.
Note
For best interpolation results, these parameters should be comparable.
- ndim
Number of dimensions for the grid (excluding age parameters), as based on the
Model_grid.grid_params
variable
- ndx
List containing track indices.
- plot_tessellation()[source]
Plot the grid tessellation.
Warning
This only works for two-dimensional tessellations.
- prepare_interpolation()[source]
Initialise the variables nmodelsmax, age_array, and age_adim_array which are needed for interpolation.
- print_header()[source]
Print the header for the grid, namely the variables all_params, all_params_latex, and grid_params.
- range(aParam)[source]
Find range of values for the input parameter.
- Parameters:
aParam (str) – name of the parameter for which to find the range
- read_model_list(filename)[source]
Read list of model parameters from a file and construct a grid.
- Parameters:
filename (string) – name of the file with the list.
- replace_age_adim()[source]
This replaces the dimensionless ages in the tracks according to the
replace_age_adim
option chosen inAIMS_configure.py
.
- string_to_index(string)[source]
Find array/list index which corresponds to the parameter represented by the string, by looking in the self.all_params_latex list.
- Parameters:
string (str) – the string representing the parameter
- Returns:
the index corresponding to the parameter
- Return type:
int
- string_to_latex(string)[source]
Find latex string representation of input string by looking in the self.all_params_latex list.
- Parameters:
string (str) – the string for which a latex representation is needed
- Returns:
the latex representation of the input string
- Return type:
str
- string_to_param(string)[source]
Find array/list index which corresponds to the parameter represented by the string, by looking in the self.all_params_latex list, as well as the list of functions needed to convert a model quantity to the quantity represented by the string.
- Parameters:
string (str) – the string representing the parameter
- Returns:
the index corresponding to the parameter, and a list of functions
- Return type:
int, list of functions
- string_to_param_extended(string)[source]
Find array/list index which corresponds to the parameter represented by the string, by looking in the self.all_params_latex list, as well as the list of functions needed to convert a model quantity to the quantity represented by the string and the inverted list of functions. Also provides the set of derivative functions (used for a change of variables in probability theory), and the inverted set of functions.
- Parameters:
string (str) – the string representing the parameter
- Returns:
the index corresponding to the parameter, list of functions to produce string, list of derivative functions, and inverted list of functions
- Return type:
int, list of functions, list of functions, list of functions
- tessellation
Object containing the tessellation of the grid used for interpolation.
- test_interpolation()[source]
Test interpolation between different evolutionary tracks in a given grid.
- Returns:
The following four items are returned:
the interpolation errors
the first half of the partition (where the interpolation is tested)
the second half of the partition (used to carry out the interpolation)
the tessellation associated with the second half of the partition
- Return type:
np.array, list, list, tessellation object
- tracks
List of evolutionary tracks contained in the grid.
- class model.Track(models, params)[source]
An evolutionary track.
- Parameters:
models (2D float np.array) – models to be included in the evolutionary track.
params (1D float np.array) – parameters which describe the evolutionary track.
- age_adim_to_scaled_param(iparam, forward=True)[source]
Replace dimensionless age parameter by a scaled version of a parameter as given by the index iparam.
- Parameters:
iparam (int) – index of the parameter which will replace the dimensionless age parameter
forward (boolean) – set this to True if the parameter increases with age, and to False in the opposite situation
- append_track(aTrack)[source]
- Parameters:
aTrack (2D float np.array) – an evolutionary track to be appended to (and hence merged with) the present track.
- duplicate_ages()[source]
Check to see if the track contains models with duplicate values for the age parameter.
- Returns:
True
if there are duplicate age(s)- Return type:
boolean
Note
The dimensionless age is used as this is what is involved in the interpolation.
Warning
This method should only be applied after the track has been sorted.
- interpolate_model(age_adim)[source]
Return a model at a given non-dimensional age which is obtained using linear interpolation.
- Parameters:
age_adim (float) – non-dimensional age of desired model
- Returns:
the interpolated model
- Return type:
np.array
Warning
This method assumes the track is sorted, since it applies a dichotomy for increased efficiency.
- is_sorted()[source]
Check to see of models are in ascending order according to physical age. The physical age is used as it is assumed that the track is already sorted according to age parameter. Hence this is a sanity check on the dimensionless age parameter.
- Returns:
True
if the models ar in order of increasing age- Return type:
boolean
- models
Properties of the models in this evolutionary track
- params
Parameters which characterise this evolutionary track
- remove_duplicates()[source]
Removes models with duplicate age parameters from the track and notifies the user.
Note
The dimensionless age is used as this is what is involved in the interpolation.
Warning
This method should only be applied after the track has been sorted.
- test_interpolation(nincr)[source]
Test accuracy of interpolation along evolutionary track.
This method compares each model on a track with a linear combination of the adjacent models nincr increments away. Specifically, it compares the original and interpolated global parameters.
- Parameters:
nincr (int) – increment with which to carry out the interpolation. By comparing results for different values of
nincr
, one can evaluate how the interpolation error depends on the size of the interval over which the interpolation is carried out.- Returns:
the interpolation errors
- Return type:
np.array
Note
The dimensionless age is used as this is what is involved in the interpolation.
- model.age_adim_array = None
Workspace needed for interpolation which will contain non-dimensional age parameters
- model.age_adim_str = 'Age_adim'
Name of the non-dimensional age parameter used in the interpolation
- model.age_array = None
Workspace needed for interpolation which will contain physical ages
- model.age_str = 'Age'
Name of the physical age parameter used in the interpolation
- model.apply_functions(funcs, x)[source]
Apply a set of functions to array x.
- Parameters:
funcs (list of functions) – list of functions to apply to x
x (float) – value to which to apply the function
- Returns:
the functions applied to x
- Return type:
float
- model.apply_functions_der(funcs, funcs_der, x)[source]
Apply a set of functions to array x. Find corresponding derivative (as a function of x).
- Parameters:
funcs (list of functions) – list of functions to apply to x
funcs_der (list of functions) – list of derivatives to apply to x
x (float) – value to which to apply the function
- Returns:
the functions applied to x and the derivative
- Return type:
(float, float)
- model.combine_models(model1, coef1, model2, coef2)[source]
Do linear combination of two models.
This method returns a new model which is the weighted sum or average of two models for the purposes of model interpolation.
- Parameters:
model1 (np.array) – first model
coef1 (float) – weighting coefficient applied to first model
model2 (np.array) – second model
coef2 (float) – weighting coefficient applied to second model
- Returns:
the combined model
- Return type:
np.array
- model.compare_models(model1, model2)[source]
Compare two models and find the largest frequency different for radial and non-radial modes.
- Parameters:
model1 (
Model
) – first modelmodel2 (
Model
) – second model
- Returns:
a 1D array with the differences on the global parameters
- Return type:
np.array
- model.eps = 1e-06
relative tolerance on parameters used for setting up evolutionary tracks
- model.extract_function_latex(name_latex)[source]
Extract a fancy latex function name (if any) from a latex representation of a variable in a string.
- Parameters:
name_latex – the string variable with the latex part
- Returns:
a string with the extracted function (or None), and and a string representation of the variable without the function
- Return type:
str,str
- model.extract_functions(name)[source]
Extract the functions applied within the “name” variable.
- Parameters:
name (str) – the name of the variable to be split
- Returns:
a list with the string representation of functions to be applied and the name of the fundamental quantity
- Return type:
list of str
- model.extract_functions_latex(name_latex)[source]
Extract fancy latex function names (if any) from a latex representation of a variable in a string.
- Parameters:
name_latex – the string variable with the latex part
- Returns:
a list of extracted functions, and and a string representation of the variable without the functions
- Return type:
list of str,str
- model.extract_fundamental_parameter(name)[source]
Extracts the fundamental parameter from the “name” variable, i.e. the quantity obtained after removal of different functions applied to it.
- Parameters:
name (str) – the name of the variable from which to extract the fundamental quantity
- Returns:
the fundamental quantity
- Return type:
list of str
- model.find_interpolation_coefficients(grid, pt, tessellation, ndx)[source]
Find interpolation weights from the corresponding simplex.
Linear interpolation weights are obtained with the simplex by finding the barycentric coordinates of the point given by
pt
.- Parameters:
grid (
Model_grid
) – grid of models in which we’re carrying out the interpolationpt (array-like) – set of parameters used for finding the interpolation weights. The first part contains the grid parameters (relevant to this interpolation), whereas the last element is the age (not used here). If the provided set of parameters lies outside the grid, then
None
is returned instead of an interpolated model.tessellation (tessellation object) – tessellation with which to carry out the interpolation.
ndx (list of int) – indices of the grid points associated with the tessellation
- Returns:
lists of interpolation coefficients and tracks
- Return type:
list of floats, list of
Track
- model.find_point_in_convex_hull(pt, ref_pt, tessellation, distort_mat=None)[source]
For a given point, find point within the convex hull of a tessellation, which lies on the segment connecting this point to another reference point, and is closest to the original point.
This uses dichotomy to find the boundary between the inside and outside of the convex hull, if needed.
- Parameters:
pt (1D numpy float array) – input point for which we are searching for a corresponding point in the convex hull
ref_pt (1D numpy float array) – reference point used to define relevant segment
tessellation (tessellation object) – tessellation in which we are searching for point in convex hull
distort_mat (2D numpy float array) – distortion matrix that was used prior to the tessellation (or None if there is no distortion)
- Returns:
the point within the convex hull nearest to the input point
- Return type:
1D numpy float array
Note
If the original point is already in the convex hull, this point is simply returned.
- model.gtype
type used for grid data
- model.iage = 1
index for physical age (this will be reset later on)
- model.iage_adim = 0
index for dimensionless age parameter (this will be reset later on)
- model.indices_along_track = None
Workspace which will contain indices along tracks right below input age
- model.insert_function_latex(func, name_latex)[source]
Insert a fancy latex function name into a latex representation of a variable in a string.
- Parameters:
func (str) – the name of the function
name_latex – the string variable with the latex part
- Returns:
a modified string variable
- Return type:
str
- model.insert_functions_latex(funcs, name_latex)[source]
Insert fancy latex function names into a latex representation of a variable in a string.
- Parameters:
funcs (list of str) – the names of the functions
name_latex – the string variable with the latex part
- Returns:
a modified string variable
- Return type:
str
- model.interpolate_model(grid, pt, tessellation, ndx)[source]
Interpolate model in grid using provided parameters.
The interpolation is carried out in two steps. First, linear interpolation according to age is carried out on each node of the simplex containing the set of parameters. This interpolation is done using the
Track.interpolate_model
method. Then, linear interpolation is carried out within the simplex. This achieved by finding the barycentric coordinates of the model (i.e. the weights), before combining the age-interpolated models form the nodes using thecombine_models
method. In this manner, the weights are only calculated once, thereby increasing computational efficiency.- Parameters:
grid (
Model_grid
) – grid of models in which we’re carrying out the interpolationpt (array-like) – set of parameters used for the interpolation. The first part contains the grid parameters, whereas the last element is the age. If the provided set of parameters lies outside the grid, then
None
is returned instead of an interpolated model.tessellation (tessellation object) – tessellation with which to carry out the interpolation.
ndx (list of int) – indices of the grid points associated with the tessellation
- Returns:
the interpolated model
- Return type:
Model
- model.invert_functions(funcs)[source]
Produces a list of inversed functions in reverse order. Hence, the composition of the input argument with the result leads to the identity function.
- Parameters:
funcs (list of str) – list of functions to be inverted and reversed
- Returns:
reversed list of inverted functions
- Return type:
list of str
- model.make_distort_matrix(d, theta=0.157)[source]
Create a distortion matrix which can be used to make the grid more “tessellation-friendly”, i.e. which leads to much shorter computation times for finding simplices.
- Parameters:
d (int) – number of dimensions
theta (float) – a small angle
- Returns:
a distortion matrix
- Return type:
2D float array
- model.make_scale_matrix(grid)[source]
Create a distortion matrix which can be used to make the grid more “tessellation-friendly”, i.e. which leads to much shorter computation times for finding simplices.
- Parameters:
grid – set of points used in the construction of the tessellation
- Returns:
a distortion matrix
- Return type:
2D float array
- model.nglb = 0
total number of global quantities in a model (including age parameter).
- model.nmodelsmax = 0
Maximum number of models in a track
- model.simplify_functions(lst)[source]
Go through a list of string representations of functions and simplify consecutive functions which are the inverse of each other.
- Parameters:
lst (list of str) – a list of functions and the fundamental quantity
- Returns:
a simplified list of functions with the fundamental quantity
- Return type:
list of str
- model.simplify_name(string)[source]
Simplify a string representation of a variable including functions, by cancelling out inverse functions.
- Parameters:
string (str) – the string to be simplified
- Returns:
the simplified string
- Return type:
str
- model.tol = 1e-10
tolerance level for slightly negative interpolation coefficients
- model.weights_along_track = None
Workspace which will contain interpolation weights along tracks