spatial_interaction_matrix

Note

This page is a reference documentation. It only explains the function signature, and not how to use it. Please refer to the Habitat Guide and Python API guide (v2.0) for usage.

spatial_interaction_matrix(label_array: ndarray, n_classes: int) → ndarray[source]

Count face-connected neighbour pairs between habitat classes (MSI matrix).

Entry [i, j] is the number of directed face-neighbour pairs with the centre voxel labelled i and the neighbour labelled j. The array is cropped to the bounding box of non-zero labels and padded with one zero layer first, so boundary voxels record an interaction with background – the exact semantics of the v0.1 calculate_MSI_matrix.

Implementation (definition unchanged): count each unordered face once along +z/+y/+x, then M + M.T restores the six directed pairs. A numba kernel is used when numba is installed; otherwise a numpy bincount histogram of the same pairs.

Parameters:
  • label_array – Integer habitat labels, 0 denoting background.

  • n_classes – Number of classes including background; sets the matrix size to (n_classes, n_classes).

Returns:

Symmetric int64 matrix of shape (n_classes, n_classes); all zeros when the array contains no non-zero label.

Examples using habit.kernels.spatial_interaction_matrix

Quickstart: Python API

Quickstart: Python API