nifreeze.model.dmri module

class nifreeze.model.dmri.AverageDWIModel(self, dataset: nifreeze.data.dmri.base.DWI, stat: str = 'median', atol_low: float = 100.0, atol_high: float = 100.0, detrend: bool = False, **kwargs)[source]

Bases: ExpectationModel

A trivial model that returns an average DWI volume.

Implement object initialization.

Parameters:
  • dataset (DWI) – Reference to a DWI object.

  • stat (str, optional) – Whether the summary statistic to apply is "mean" or "median".

  • atol_low (float, optional) – A lower bound for the b-value corresponding to the diffusion weighted images that will be averaged.

  • atol_low (float, optional) – An upper bound for the b-value corresponding to the diffusion weighted images that will be averaged.

  • detrend (bool, optional) – Whether the overall distribution of each diffusion weighted image will be standardized and centered around the src.nifreeze.model.base.DEFAULT_CLIP_PERCENTILE percentile.

fit_predict(index: int | None = None, *_, **kwargs) → ndarray[source]

Return the average map.

class nifreeze.model.dmri.BaseDWIModel(self, dataset: nifreeze.data.dmri.base.DWI, max_b: float | int | None = None, **kwargs)[source]

Bases: BaseModel

Interface and default methods for DWI models.

Initialization.

Parameters:

dataset (DWI) – Reference to a DWI object.

applicable_schemes: frozenset[str] = frozenset({'DSI', 'multi-shell', 'single-shell'})

Acquisition schemes (as labelled by find_shelling_scheme()) the model supports.

excludes_b0: bool = False

Whether b=0 volumes are excluded from fitting/prediction.

fit_predict(index: int | None = None, **kwargs) → ndarray | None[source]

Predict asynchronously chunk-by-chunk the diffusion signal.

Parameters:

index (int) – The volume index that is left-out in fitting, and then predicted.

requires_multishell: bool = False

Whether the model requires more than one non-zero shell.

nifreeze.model.dmri.DEFAULT_S0_CLIP_PERCENTILE = 98

Upper percentile threshold for non-diffusion-weighted signal estimation.

class nifreeze.model.dmri.DKIModel(self, dataset: nifreeze.data.dmri.base.DWI, max_b: float | int | None = None, **kwargs)[source]

Bases: BaseDWIModel

A wrapper of DiffusionKurtosisModel.

Initialization.

Parameters:

dataset (DWI) – Reference to a DWI object.

applicable_schemes: frozenset[str] = frozenset({'multi-shell'})

Acquisition schemes (as labelled by find_shelling_scheme()) the model supports.

requires_multishell: bool = True

Whether the model requires more than one non-zero shell.

class nifreeze.model.dmri.DTIModel(self, dataset: nifreeze.data.dmri.base.DWI, max_b: float | int | None = None, **kwargs)[source]

Bases: BaseDWIModel

A wrapper of dipy.reconst.dti.TensorModel.

Initialization.

Parameters:

dataset (DWI) – Reference to a DWI object.

applicable_schemes: frozenset[str] = frozenset({'multi-shell', 'single-shell'})

Acquisition schemes (as labelled by find_shelling_scheme()) the model supports.

nifreeze.model.dmri.DWI_DKI_SHELL_ERROR_MSG = 'DKI requires at least 3 b-values (which can include b=0).'

dMRI dataset DKI model insufficient shells error message.

nifreeze.model.dmri.DWI_GTAB_ERROR_MSG = 'Dataset MUST have a gradient table.'

dMRI gradient table error message.

nifreeze.model.dmri.DWI_OBJECT_ERROR_MSG = 'Dataset MUST be a DWI object.'

dMRI object error message.

nifreeze.model.dmri.DWI_SIZE_ERROR_MSG = 'DWI dataset is too small ({directions} directions).'

dMRI dataset size error message.

class nifreeze.model.dmri.GPLOOModel(self, dataset: nifreeze.data.dmri.base.DWI, hyperparameters: str | pathlib._local.Path | Mapping[str, Any] | NoneType = None, **kwargs)[source]

Bases: ClosedFormLOVOMixin, GPModel

A Gaussian process with exact, closed-form leave-one-volume-out prediction.

With hyperparameters held fixed across folds, the GP posterior mean is a linear smoother of the other volumes (see nifreeze.model.lovo), so all LOVO predictions come from one matrix instead of one GP fit per volume. Hyperparameters are either loaded (hyperparameters), e.g., pooled across the subjects of an acquisition protocol, or fitted once on a random voxel subsample of all volumes.

Initialization.

Parameters:
  • dataset (DWI) – Reference to a DWI object.

  • hyperparameters (os.pathlike or Mapping, optional) – A hyperparameter record (see save_hyperparameters()). When given, no hyperparameter is fitted at run time.

  • nvox_prefit (int, optional) – Number of voxels used to fit the hyperparameters (all if None).

  • random_state (int, optional) – Seed for the voxel subsample.

class nifreeze.model.dmri.GPModel(self, dataset: nifreeze.data.dmri.base.DWI, max_b: float | int | None = None, **kwargs)[source]

Bases: BaseDWIModel

A wrapper of GaussianProcessModel.

The Gaussian process does not follow the DIPY Model(gtab).fit(data) convention that BaseDWIModel implements: it is constructed from a kernel_model and receives the gradient table at fit time, fitting all voxels at once (vectorized across GP targets). _fit/fit_predict are therefore overridden here rather than reusing the chunked DIPY path.

Initialization.

Parameters:

dataset (DWI) – Reference to a DWI object.

applicable_schemes: frozenset[str] = frozenset({'multi-shell', 'single-shell'})

Acquisition schemes (as labelled by find_shelling_scheme()) the model supports.

fit_predict(index: int | None = None, **kwargs) → ndarray | None[source]

Fit the GP (LOVO or single-fit) and predict the held-out orientation.

single_fit_is_canary: bool = True

Whether single-fit only makes sense as a self-consistency canary (see _warn_single_fit_canary()).

class nifreeze.model.dmri.GQIKRRModel(self, dataset: nifreeze.data.dmri.base.DWI, krr_lambda: float | None = 0.3, krr_lambda_grid: Sequence[float] = (np.float64(0.0001), np.float64(0.00031622776601683794), np.float64(0.001), np.float64(0.0031622776601683794), np.float64(0.01), np.float64(0.03162277660168379), np.float64(0.1), np.float64(0.31622776601683794), np.float64(1.0), np.float64(3.1622776601683795), np.float64(10.0), np.float64(31.622776601683793), np.float64(100.0)), **kwargs)[source]

Bases: ClosedFormLOVOMixin, GQIModel

GQI with closed-form leave-one-volume-out prediction.

The prediction of GQIModel is kernel ridge regression on the GQI basis, around a mean per shell (see predict()). With the same ridge \(\lambda\), the predictions of all volumes come from one matrix, built from \(\mathbf{A} = \mathbf{G} + \lambda \mathbf{I}\), instead of one fit per volume. Both models share their default ridge.

Initialization.

Parameters:
  • dataset (DWI) – Reference to a DWI object.

  • krr_lambda (float, optional) – Ridge \(\lambda\), the ridge of GQIModel (which takes precedence when given). Defaults to DEFAULT_RIDGE. If None, it is chosen from krr_lambda_grid by closed-form LOVO error on a random voxel subsample, on the dataset the model is built on; the ridge chosen then changes with the motion in the data.

  • krr_lambda_grid (Sequence of float, optional) – Candidate ridge strengths.

  • nvox_prefit (int, optional) – Number of voxels used to choose the ridge strength, when krr_lambda is None (all if None).

  • random_state (int, optional) – Seed for the voxel subsample.

class nifreeze.model.dmri.GQIModel(self, dataset: nifreeze.data.dmri.base.DWI, max_b: float | int | None = None, **kwargs)[source]

Bases: BaseDWIModel

A wrapper of nifreeze.model.gqi.GeneralizedQSamplingModel.

Initialization.

Parameters:

dataset (DWI) – Reference to a DWI object.

excludes_b0: bool = True

Whether b=0 volumes are excluded from fitting/prediction.

single_fit_is_canary: bool = True

Whether single-fit only makes sense as a self-consistency canary (see _warn_single_fit_canary()).