nifreeze.estimator module

Orchestrates model and registration in volume-to-volume artifact estimation.

nifreeze.estimator.ALIGN_CONFIGS = {'eddy': PosixPath('/home/runner/work/nifreeze/nifreeze/src/nifreeze/registration/config/affine.yaml'), 'motion': None}

Default registration settings by field of estimates. None takes the run’s align_config, or the backend’s default (RIGID): a default of the estimator’s own would override the run’s.

class nifreeze.estimator.Estimator(self, model: 'BaseModel | str', strategy: 'str' = 'random', prev: 'Estimator | Filter | None' = None, model_kwargs: 'dict | None' = None, single_fit: 'bool' = False, start_index: 'int' = 0, stop_index: 'int | None' = None, registration: 'Registration | str | None' = None, estimates: 'str' = 'motion', **kwargs)[source]

Bases: object

Orchestrates components for a single estimation step.

The estimator traverses the 4D sequence with a Leave-One-Volume-Out (LOVO) strategy: for each target volume it fits the model on the remaining volumes, predicts the held-out volume, and registers the observed volume to that prediction. Held-out independence is what makes the estimated transform valid (see fit_predict()).

Parameters:
  • model (BaseModel or str) – The model (or model name) used to generate the registration target.

  • strategy (str, optional) – Name of the iterator used to traverse the 4D sequence.

  • prev (Estimator, Filter, optional) – A previous estimator/filter whose output initializes this one (cascade).

  • model_kwargs (dict, optional) – Extra keyword arguments passed through to the model at construction.

  • single_fit (bool, optional) – Run the model in single-fit mode: fit once on all volumes up front (via model.fit_predict(None)) and lock that fit instead of refitting per held-out volume. Prediction is no longer unbiased.

  • start_index (int, optional) – First volume index to process.

  • stop_index (int, optional) – One-past-last volume index to process (None = to the end).

  • registration (Registration or str, optional) – The registration backend, or the name of one (BACKENDS), built for each run from the registration settings (default: elastix where itk-elastix is installed, ANTs otherwise; see default_backend()).

  • estimates (str, optional) – The field of the dataset this estimator’s estimates go to, one of its ESTIMATES: "motion" (default), or "eddy" for the eddy currents of a DWI (as --eddy does), registered with AFFINE unless align_config is given (see ALIGN_CONFIGS). Each volume is registered from its mapping, every estimate composed (get_transform()), and the other fields’ estimates are factored out of the result (set_transform()). A backend that estimates head motion and the field together (split(), such as ITK restricted to phase encoding) stores both instead: the head motion it refined, and the field.

  • **kwargs – Registration settings of this estimator, which take precedence over the run’s align_kwargs: align_config (a mapping, or a file with a section per backend, such as RIGID, the default, and AFFINE), and the options of Registration.

run(dataset: DatasetT, **kwargs) → Self[source]

Trigger execution of the workflow this estimator belongs.

Parameters:
  • dataset (BaseDataset) – The input dataset this estimator operates on.

  • align_kwargs (dict, optional) – Registration settings for every estimator of the chain (e.g., {"align_config": <the file of --align-config>}). The settings given to an estimator at construction take precedence.

  • clip (str, optional) – Clip the intensity of "sample", "predicted", "both" (default) or "none" of the images to the sample’s window before registration.

  • debug_dir (os.pathlike, optional) – Keep, in a folder of debug_dir per estimator of the chain, the images each volume was registered with and an aligned_<index>.nii trace: the sample with its affine corrected by the estimate, which a viewer shows on top of predicted_<index>.nii.

  • instant_update (bool, optional) – Whether models train on the realigned view of the dataset (default): right after a volume is registered, the model sees it resampled once, from the original volume, with the estimate (and, for DWI, its rotated b-vector). The dataset itself is never modified; registration and export keep using the original volumes. It applies to models given by name and to model instances built on this dataset (see set_dataset()), except the trivial model, whose reference never moves.

  • num_threads (int, optional) – Threads of each registration (default: omp_nthreads).

  • realigned (dict, optional) – Realigned views by dataset, shared by the estimators of a chain.

Returns:

The estimator, after fitting.

Return type:

Estimator

class nifreeze.estimator.Filter(self, /, *args, **kwargs)[source]

Bases: object

Alters an input data object (e.g., downsampling).

run(dataset: DatasetT, **kwargs) → DatasetT[source]

Trigger execution of the designated filter.

Parameters:

dataset (BaseDataset) – The input dataset this estimator operates on.

Returns:

dataset – The dataset, after filtering.

Return type:

BaseDataset