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 labellediand the neighbour labelledj. 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.1calculate_MSI_matrix.Implementation (definition unchanged): count each unordered face once along
+z/+y/+x, thenM + M.Trestores the six directed pairs. A numba kernel is used when numba is installed; otherwise a numpybincounthistogram of the same pairs.- Parameters:
label_array – Integer habitat labels,
0denoting 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.