Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Architecture & Internals

This section is the design reference for contributors and maintainers (and for AI coding assistants working in the repo). It documents how nltools is built and why — the invariants that keep the codebase coherent. For what the public API does, see the API reference; for a visual, interactive walkthrough, see the Design Tour.

Functional core, imperative shell

nltools follows one organizing principle: classes are facades and glue — all real logic lives in pure functions.

LayerRoleWhere
Imperative shellFour data classes that hold state and delegate. Each is a facade over a submodule package (io, modeling, plotting, …).nltools/data/{braindata,adjacency,designmatrix,collection}/
Functional corePure functions — the actual computation. Containers in, containers out. Every user-facing function is importable flat from nltools.algorithms.nltools/algorithms/ (corrections, outliers, signal, similarity, regression, …), utils, cross_validation, mask
Algorithm substrateHeavy numerical machinery with its own backend/parallel story.nltools/algorithms/{alignment,inference,ridge}/

The four facades and their submodules:

Design rules

Canonical API vocabulary

The four facades share one kwarg vocabulary (v0.6.0). The machine-readable source of truth is docs/_data/api-vocabulary.yml, which also carries the enforcement rules scripts/check_api_vocabulary.py checks every public signature against in CI. The table below is rendered from it:

ConceptCanonical kwarg
Algorithm / variant choicemethod
Spatial scalespatial_scale ('whole_brain' | 'roi' | 'searchlight')
Distance / similarity metricmetric
Central tendencysummary ('mean' | 'median')
Cross-validation speccv (int | 'loo' | 'logo' | splitter; sklearn-style names — the grouping lives in groups=)
Subject-level parallelismn_jobs: int = -1
GPU / CPU selectiondevice: str = "cpu" — run-or-raise: explicit 'gpu' never silently degrades to CPU; 'auto' is the one graceful-fallback path
Backend (ridge/alignment internals)parallel: None | 'cpu' | 'gpu' (the inference engine uses device as of v0.6.0)
Progress indicatorprogress_bar: bool = False
Permutation countn_permute
Bootstrap sample countn_samples
Tail of testtail (2 | 'two' | 1 | 'one'; direction fixed by the test, never the data)
Threshold pairlower, upper, binarize (+ threshold where bidirectional)
Diagonal flaginclude_diag: bool
Radius (mm)radius_mm: float

The internals pages