Generation
The generation subpackage provides tools for generating material structures at various scales.
matengine.generation.decisiontree
- class matengine.generation.decisiontree.decision_tree[source]
Bases:
objectA class to represent a decision tree for making decisions based on user-defined criteria.
- class DecisionNode(func, args, yes_branch=None, no_branch=None)[source]
Bases:
objectA class to represent a decision node in the decision tree.
- class LeafNode(action)[source]
Bases:
objectA class to represent a leaf node in the decision tree.
- build_tree(instructions)[source]
Build a decision tree based on the given instructions.
- Parameters:
- instructions: dict
A dictionary containing details about the nodes, including type, function, arguments, and branches.
- Notes:
Nodes can be either decision nodes or leaf nodes.
The ‘root’ node is assumed to be the starting point.
- matengine.generation.decisiontree.ellipse(data, key1, key2, cx, cy, sx, sy, angle=0)[source]
Determine if a point lies inside or on the boundary of an ellipse.
- Parameters:
- data: dict
The input data.
- key1: str
The key representing the x-coordinate of the point.
- key2: str
The key representing the y-coordinate of the point.
- cx: float
The x-coordinate of the ellipse center.
- cy: float
The y-coordinate of the ellipse center.
- sx: float
The semi-axis length in the x-direction.
- sy: float
The semi-axis length in the y-direction.
- angle: float, optional
The rotation angle of the ellipse in degrees. Default is 0.
- Returns:
- bool:
True if the point lies within or on the ellipse, False otherwise.
- matengine.generation.decisiontree.ellipsoid(data, key1, key2, key3, cx, cy, cz, sx, sy, sz)[source]
Determine if a point lies inside or on the boundary of an ellipsoid.
- Parameters:
- data: dict
The input data.
- key1: str
The key representing the x-coordinate of the point.
- key2: str
The key representing the y-coordinate of the point.
- key3: str
The key representing the z-coordinate of the point.
- cx: float
The x-coordinate of the ellipsoid center.
- cy: float
The y-coordinate of the ellipsoid center.
- cz: float
The z-coordinate of the ellipsoid center.
- sx: float
The semi-axis length in the x-direction.
- sy: float
The semi-axis length in the y-direction.
- sz: float
The semi-axis length in the z-direction.
- Returns:
- bool:
True if the point lies within or on the ellipsoid, False otherwise.
- matengine.generation.decisiontree.greater_than(data, key, threshold)[source]
Determine if the value in the data is greater than the threshold.
- Parameters:
- data: dict
The input data.
- key: str
The key whose value is being compared.
- threshold: numeric
The threshold value.
- Returns:
- bool:
True if the value is greater than the threshold, False otherwise.
- matengine.generation.decisiontree.less_than(data, key, threshold)[source]
Determine if the value in the data is less than or equal to the threshold.
- Parameters:
- data: dict
The input data.
- key: str
The key whose value is being compared.
- threshold: numeric
The threshold value.
- Returns:
- bool:
True if the value is less than or equal to the threshold, False otherwise.
- matengine.generation.decisiontree.linear(data, key1, key2, m, c)[source]
Determine if the value lies on or above the line defined by the equation y = mx + c.
- Parameters:
- data: dict
The input data.
- key1: str
The key representing the x-value.
- key2: str`
The key representing the y-value.
- m: float
The slope of the line.
- c: float
The y-intercept of the line.
- Returns:
- bool:
True if the point is on or above the line, False otherwise.
matengine.generation.filters
- matengine.generation.filters.convex_hull(pluri, thresh=5)[source]
Apply a convex hull transformation to each connected component in an image that exceeds a specified size threshold.
- Parameters:
- pluri: ndarray
A multi-dimensional numpy array representing an image. The function supports both 2D and 3D images.
- thresh: int, optional
The threshold value for the minimum number of voxels/pixels a connected component must have to be considered for the convex hull transformation. Defaults to 5.
- Returns:
- ndarray:
A new image array of the same dimensions as pluri where each significant connected component (as determined by thresh) has been transformed using the convex hull operation.
- Notes:
For 2D images, the function calculates the convex hull for each connected component directly.
For 3D images, the convex hull is applied slice by slice and then accumulated, assuming that pluri represents a stack of 2D slices.
The function uses scipy’s label function to identify connected components and skimage’s convex_hull_image for the convex hull transformation.
matengine.generation.generators
- matengine.generation.generators.create_covariance_model(kernel, dim, variance, length_scale)[source]
Create a covariance model based on the specified kernel type.
- Parameters:
- kernelstr
- The type of kernel to use for the covariance model. Options are:
‘gau’: Gaussian kernel
‘mat’: Matern kernel
- dimlist or tuple
The dimensions for the covariance model.
- variancefloat
The variance parameter for the covariance model.
- length_scalefloat
The length scale parameter for the covariance model.
- Returns:
- modelgstools.Gaussian or gstools.Matern
The created covariance model using the specified kernel, dimension, variance, and length scale parameters.
- matengine.generation.generators.random_field(model, dim, seed=0, mode_no=250)[source]
Generates a random field using a stochastic random field (SRF) model from gstools.
- Parameters:
- model:
A geostatistical model from gstools to be used for generating the random field. Typically, this is an instance of a Gaussian process model.
- dim: tuple or list
A tuple or list representing the dimensions of the random field. It should contain either two or three elements for 2D or 3D fields respectively.
- seed: int, optional
A seed value for the random number generator to ensure reproducibility. Default is 0.
- mode_no: int, optional
The number of modes to use for the stochastic simulation. Default is 250.
- Returns:
- numpy.ndarray:
The generated random field, either 2D or 3D depending on the input dimensions.
matengine.generation.plurigaussian
- matengine.generation.plurigaussian.plurigaussian_simulation(dim, tree, fields, ldim=100)[source]
Performs Plurigaussian simulation based on specified dimensions and Gaussian fields, using a decision tree for classification at each point.
- Parameters:
- dim: tuple or list
The dimensions of the output simulation grid, can be 2D or 3D.
- tree: DecisionTree
A decision tree object that makes classification decisions based on Gaussian fields.
- fields: list of ndarray
A list of Gaussian fields, where each field is a numpy array representing a spatial distribution of values. The list should contain 2 fields for 2D simulations and 3 fields for 3D simulations.
- ldim: (int, optional)
The dimensions of the lithotype in each direction used for decision tree classification. Defaults to 100.
- Returns:
- L: ndarray
The lithotype based on the decision tree configuration. An ldim x ldim (or ldim x ldim x ldim for 3D) array where each entry is the decision outcome based on the linearly scaled indices.
- P: ndarray
Plurigaussian realisation. An array of the same dimension as dim where each entry is the decision outcome based on the values from the fields array.
- Notes:
The function scales the indices of the lithotype linearly to map the range [-3, 3] across ldim.
The decision tree is queried with this scaled data to populate the L array.
For generating the P array, the decision tree is queried with actual data points from the fields.