VoxelFeatureField

Note

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

class VoxelFeatureField(subject_id: str, feature_names: Tuple[str, ...], values: ndarray, voxel_index: ndarray, geometry: Geometry, provenance: Provenance)[source]

Bases: object

Per-voxel feature vectors inside one subject’s ROI.

This is where every habitat analysis begins. In v0.1 it existed only as an anonymous DataFrame passed between pipeline steps, which made it impossible for an external tool to supply its own voxel features (for example embeddings from a self-supervised model).

subject_id

Owning subject.

Type:

str

feature_names

Column names in values order.

Type:

Tuple[str, …]

values

Array of shape (n_voxels, n_features).

Type:

numpy.ndarray

voxel_index

Array of shape (n_voxels, 3) giving the (z, y, x) grid position of each row, so the field can be rendered back into image space.

Type:

numpy.ndarray

geometry

Grid the indices refer to.

Type:

habit.contracts.geometry.Geometry

provenance

How this field was produced.

Type:

habit.contracts.provenance.Provenance

__post_init__() → None[source]

Enforce the row/column invariants that make the field renderable.

to_frame() → DataFrame[source]

Return the field as a DataFrame for inspection and interoperability.

feature_frame() → DataFrame[source]

Return the bare unit-by-feature matrix.

The uniform algorithm view shared with Supervoxelization.feature_frame(). Any operation defined on “a matrix whose rows are clustering units” can therefore be written once and applied at either granularity, even though the two contracts store their matrices differently – an array plus column names here, because a subject holds hundreds of thousands of voxels whose row identity is a 3D coordinate; an indexed frame there, because supervoxels are few and identified by a single id.

Unlike to_frame(), no coordinate columns are added: the result contains features and nothing else, so column-wise computations need no exclusion list.

Returns:

Feature matrix with a positional index, in feature_names order.

with_feature_frame(frame: DataFrame, *, produced_by: str, spec_fingerprint: str) → VoxelFeatureField[source]

Return a copy carrying a recomputed feature matrix.

Parameters:
  • frame – Replacement matrix, row-aligned with this field. Columns may be fewer than the current ones (a filtering step) but the row count must match, since voxel_index continues to describe those rows.

  • produced_by – Provenance label of the step that produced frame.

  • spec_fingerprint – Fingerprint of that step’s specification.

Returns:

A new field sharing this field’s geometry and voxel index.

Raises:

HABITAPIError – If frame has a different number of rows.

save(path: str | Path) → Path[source]

Persist the field as a versioned zip (manifest + arrays).

Not a pickle: the archive stays readable across HABIT versions. voxel_batch and device knobs do not belong here; they do not change the numbers.

Parameters:

path – Destination file path.

Returns:

The written path.

classmethod load(path: str | Path) → VoxelFeatureField[source]

Load a field previously written by save().

Parameters:

path – Source file path.

Returns:

The reconstructed field.

Raises:
__init__(subject_id: str, feature_names: Tuple[str, ...], values: ndarray, voxel_index: ndarray, geometry: Geometry, provenance: Provenance) → None

Examples using habit.contracts.VoxelFeatureField

Load from NumPy arrays

Load from NumPy arrays

Voxel features

Voxel features

Custom features

Custom features

Expression voxel features

Expression voxel features

Voxel texture and GPU

Voxel texture and GPU

Supervoxel feature extraction and acceleration

Supervoxel feature extraction and acceleration

Preprocessing voxel texture before clustering

Preprocessing voxel texture before clustering

Extracting voxel intensities

Extracting voxel intensities

Extracting a voxel texture

Extracting a voxel texture

Clustering habitats from a derived map

Clustering habitats from a derived map

Clustering habitats from a texture field

Clustering habitats from a texture field

Preprocessing features before clustering

Preprocessing features before clustering

Partitioning a ROI into supervoxels

Partitioning a ROI into supervoxels

Per-habitat radiomics

Per-habitat radiomics

Matching habitat labels across subjects

Matching habitat labels across subjects

Precise voxel features

Precise voxel features