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.
Nonetakes the run’salign_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:
objectOrchestrates 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 (
BaseModelorstr) – 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 (viamodel.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 (
Registrationorstr, optional) – The registration backend, or the name of one (BACKENDS), built for each run from the registration settings (default: elastix whereitk-elastixis installed, ANTs otherwise; seedefault_backend()).estimates (
str, optional) – The field of the dataset this estimator’s estimates go to, one of itsESTIMATES:"motion"(default), or"eddy"for the eddy currents of a DWI (as--eddydoes), registered withAFFINEunlessalign_configis given (seeALIGN_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 asITKrestricted 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 asRIGID, the default, andAFFINE), and the options ofRegistration.
- 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 ofdebug_dirper estimator of the chain, the images each volume was registered with and analigned_<index>.niitrace: the sample with its affine corrected by the estimate, which a viewer shows on top ofpredicted_<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 (seeset_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:
- class nifreeze.estimator.Filter(self, /, *args, **kwargs)[source]¶
Bases:
objectAlters 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: