morphogen.automata.lattice

Lattices of cellular automata: neighbourhoods and neighbour sums.

An automaton lives on the cells (i, j, k) of a regular grid, with the conventions of voxel images (arrays indexed along x, y, z). Two-dimensional automata use arrays of shape (nx, ny, 1) and planar neighbourhoods (dims=2).

Boundaries are periodic (the lattice is a torus) or fixed: cells outside the lattice then hold a constant boundary value.

morphogen.automata.lattice.NEIGHBOURHOODS = ('von_neumann', 'moore', 'edges', 'euclidean')

|d| is the L1 norm (von Neumann), the max norm (Moore), both (edges: faces and edges of the unit cube), or the Euclidean norm.

Type:

Neighbourhood shapes

morphogen.automata.lattice.offsets(neighbourhood: str = 'moore', radius: float = 1, *, dims: int = 3, include_center: bool = False) → ndarray[source]

Integer offsets (k, 3) of the cells of a neighbourhood.

von_neumann: |dx| + |dy| + |dz| <= r (6 cells for r = 1); moore: max |d| <= r (26 cells); edges: Moore cells with |dx| + |dy| + |dz| <= 2r (18 cells for r = 1); euclidean: dx^2 + dy^2 + dz^2 <= r^2 (a digital ball). dims=2 keeps dz = 0.

morphogen.automata.lattice.neighbour_counts(state: ndarray, offs: ndarray, *, periodic: bool = True, boundary: int = 0) → ndarray[source]

Number of cells in state 1 among the neighbours offs of every cell.

morphogen.automata.lattice.kernel_sum(field: ndarray, offs: ndarray, weights=None, *, periodic: bool = True, boundary: float = 0.0) → ndarray[source]

Weighted sum of field over the neighbourhood offs of every cell (float).

Computed by FFT (circular convolution), which is efficient for large neighbourhoods; fixed boundaries pad the field with the boundary value.

morphogen.automata.lattice.sublattices(neighbourhood: str, shape, dims: int = 3) → list[ndarray][source]

Partition of the cells into sublattices whose cells are not neighbours (radius 1).

Used by sequential updates: von Neumann neighbourhoods need two colours (parity of i + j + k), Moore and edges neighbourhoods eight (parities of i, j, k; four in 2D). On periodic lattices with an odd number of cells along an axis, the cells on both sides of the seam share a colour.