ExpressionVoxelFeatures

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 ExpressionVoxelFeatures(features: Mapping[str, str] | None = None, expressions: Sequence[str] | None = None, feature_names: Sequence[str] | None = None, modalities: Sequence[str] = (), roi: str | None = None, eps: float = 1e-08)[source]

Bases: object

Per-voxel features defined by restricted arithmetic expressions.

Each formula may reference modality keys on the subject (e.g. T1, T2), the injected constant eps (override via the constructor), and the whitelisted functions abs, sqrt, square, log, log10, exp, minimum, maximum, clip. Power may be written as ** or ^.

Example:

Spec("expression", {
    "features": {
        "t1_over_t2_sq": "square(T1 / (T2 ** 3 + eps))",
    },
})
Parameters:
  • features – Mapping of feature name to formula. Mutually exclusive with expressions.

  • expressions – Ordered formulas when names are not provided up front.

  • feature_names – Names aligned with expressions; defaults to expr_0, expr_1, …

  • modalities – Optional explicit modality list. When empty, modality names are inferred from identifiers used in the formulas (excluding builtins and function names).

  • roi – Mask key; None uses the subject’s single mask.

  • eps – Value bound to the name eps inside every formula.

__init__(features: Mapping[str, str] | None = None, expressions: Sequence[str] | None = None, feature_names: Sequence[str] | None = None, modalities: Sequence[str] = (), roi: str | None = None, eps: float = 1e-08) → None[source]
property spec: Spec

Return the algorithm specification used for provenance.

__call__(subject: Subject) → VoxelFeatureField[source]

Evaluate every formula on the ROI voxels of subject.

Parameters:

subject – Subject providing the referenced modalities and mask.

Returns:

One column per formula, one row per ROI voxel.

Raises:
  • KeyError – If a referenced modality or the ROI is absent.

  • GeometryError – If a modality and the mask do not share a grid.

  • HABITAPIError – If a formula uses unsupported syntax or names.

Examples using habit.voxel_features.ExpressionVoxelFeatures

Expression voxel features

Expression voxel features

Clustering habitats from a derived map

Clustering habitats from a derived map

Why habitat ids must be matched

Why habitat ids must be matched

Matching maps of the same voxels by overlap

Matching maps of the same voxels by overlap

Prototype matching step by step

Prototype matching step by step

Naming a new cohort with frozen prototypes

Naming a new cohort with frozen prototypes

What matching changes in a cohort feature table

What matching changes in a cohort feature table

Matching habitat labels across subjects

Matching habitat labels across subjects