morphogen.models.lattice_field

Microstructures defined cell by cell on a regular lattice.

Cellular automata and lattice growth processes (nucleation and growth, aggregation) produce a phase per cell, and sometimes a label per cell (grains). Such a realization is resolution-independent like the other microstructures:

  • on its own lattice, it voxelizes to its cells exactly;

  • elsewhere, the indicator of phase 1 (or a continuous field, such as a concentration, when the process has one) is interpolated trilinearly, after an optional Gaussian smoothing of smoothing cells, and thresholded; labels are taken from the nearest cell;

  • its level set is smooth across the interface, so that conforming meshes (MMG) follow the cells’ boundaries, rounded at the corners.

class morphogen.models.lattice_field.LatticeField(domain: Domain, phases, *, labels=None, orientations=None, smoothing: float = 0.0, field=None, threshold: float = 0.0, attributes: dict | None = None, **kwargs)[source]

Bases: Microstructure

A phase (and optionally a label) per cell of a regular lattice of the domain.

Parameters:
  • phases – uint8 array (nx, ny, nz) (nz = 1 for 2D structures, extruded through the thickness of the domain).

  • labels – Optional int32 array of the same shape: grain index per cell (-1: none, e.g. untransformed matrix).

  • orientations – Optional crystal orientations of the labels (Bunge Euler angles, degrees).

  • smoothing – Gaussian smoothing, in cells, of the indicator of phase 1 before interpolation (0: plain trilinear interpolation, which keeps one-cell features).

  • field – Optional continuous field per cell (e.g. a concentration) whose excursion field > threshold is phase 1: it is interpolated instead of the indicator, which gives smoother interfaces.

  • threshold – Optional continuous field per cell (e.g. a concentration) whose excursion field > threshold is phase 1: it is interpolated instead of the indicator, which gives smoother interfaces.

  • attributes – Per-label arrays (e.g. nucleation times) and other JSON-able data.

property shape: tuple[int, int, int]
property lattice: Grid
property cell_size: ndarray
property binary: bool
property has_labels: bool

Whether labels(...) gives an image of cell indices (cells, grains).

property lipschitz: float

The largest slope of the trilinear interpolant of the lattice values.

level_set_at(points, reach: float = inf) → ndarray[source]

level_at(): the level set of the lattice interpolated at the points.

level_at(points) → ndarray[source]

Interpolated level set at points (negative in phase 1).

voxelize(shape=None, *, voxel_size=None, grid: Grid | None = None, supersampling=1)[source]

Phase image (uint8), or partial volume fractions of phase 1 (float32) when supersampling > 1 (supersampling**3 sub-samples per voxel).

level_set(shape=None, *, voxel_size=None, grid: Grid | None = None) → VoxelImage[source]

Interpolated level set, negative in phase 1: threshold - field for structures with a continuous field, otherwise (1/2 - indicator) * scale, about the signed distance to the interface near it (scale is the cell size, times sqrt(2 pi) times the smoothing when it exceeds one cell).

contains(points) → ndarray[source]

Whether points lie in phase 1.

labels(shape=None, *, voxel_size=None, grid: Grid | None = None) → VoxelImage[source]

Image of the cell labels (int32 grain indices; -1: no grain), sampled from the nearest cell.

summary() → dict[source]

Counts and sizes describing the realization.

morphogen.models.lattice_field.lattice_shape(domain: Domain, cell_size: float, dimension: int = 3) → tuple[int, int, int][source]

Number of cells of edge about cell_size along each axis of the domain (one cell through the thickness for 2D structures).