webapps / hmc /reference /README.md
gdevenyi's picture
hmc: NiFreeze 3bcfb00 and QSIPrep 26.1.1 SHORELine reference runs on ds005577 sub-107
f72ea88 verified
|
Raw History Blame Contribute Delete
40.4 kB
# hmc reference: NiFreeze and QSIPrep SHORELine head-motion runs on ds005577 sub-107 (M0)
Reference runs for the head-motion correction (HMC) port, milestone M0 of
`docs/architecture/dwi-hmc-plan.md`. Each folder keeps what M1-M5 need for deterministic
replay tests: the input, the brain mask, the per-volume ITK transforms, the motion tables,
the rotated b-vectors, the antsRegistration command lines and, for one run of each method,
the per-volume registration inputs (sample/moving and prediction/fixed images).
Status: complete. NiFreeze: six runs. QSIPrep: three repeats on one host (`qsiprep-e1`,
`qsiprep-e2`, `qsiprep-e3`, host epic) for the repeat spread, and one run on the local host
(`qsiprep-r1`) for a cross-host comparison and the kept intermediates. A fourth local run
(r2) was stopped at about 55 % and is not used or included. The registration rules are
decided for both methods: NiFreeze GP against its seed spread (Q53) and SHORELine against
the e1-e3 repeat spread (2026-10-19).
## Input
OpenNeuro ds005577 v1.0.0 ("Functional and structural differences in adults with dyslexia",
doi:10.18112/openneuro.ds005577.v1.0.0), sub-107, `dwi/sub-107_dir-AP_dwi.*`.
Licence: CC0, read from the dataset's `dataset_description.json` (copied to `input/`).
<https://openneuro.org/datasets/ds005577/versions/1.0.0>
The NIfTI, bval and bvec are copied unchanged, because CC0 allows it and M3 (end to end) and
the QSIPrep conform step start from them. The JSON sidecar omits AcquisitionTime,
DeviceSerialNumber, InstitutionAddress, InstitutionName, InstitutionalDepartmentName and
StationName; every other field and byte is as published (the same rule as
`noddi/examples/`). All runs read the original sidecar. None of the six fields affects HMC.
QSIPrep copies these fields into its output sidecar
`qsiprep-{r1,e1,e2,e3}/out/sub-107_dir-AP_space-ACPC_desc-preproc_dwi.json`, twice: at the
top level and in `SourceMetadata/sub-107_dir-AP_dwi.nii.gz`. The four packed copies omit
all 12 entries. Only those 12 lines are removed; every other byte is as QSIPrep wrote it
(`scripts/redact_sidecars.py`, the same rule in `scripts/pack_hmc.py`). `index.json` gives,
for each of the five edited sidecars, the removed fields and their JSON paths
(`removed_fields`, `removed_paths`), the original SHA-256 (`source_sha256`) and size
(`source_bytes`), and the note `site_fields_removed` lists the original and the new
SHA-256.
The NIfTI header `descrip` of `input/sub-107_dir-AP_dwi.nii.gz` still holds the
acquisition time (its `Time=` item). This file is the public CC0 original, copied
unchanged, so the item stays. `mask/sub-107_dir-AP_desc-meanb0_dwiref.nii.gz` has the same
`descrip`, because its header comes from the input. No other file holds the values of the
six fields (this README, `index.json` and two scripts name the fields only).
| File | Bytes | SHA-256 |
| --- | --- | --- |
| `input/sub-107_dir-AP_dwi.nii.gz` | 86729879 | `06d5a733005a9e463f1ca6b581d0a8725378b60967c23dd63d49cc04362e83b9` |
| `input/sub-107_dir-AP_dwi.bval` | 472 | `da890b74d0a531fda05d164ad12600aec9507cf42854bc04303b0f29b62f70f1` |
| `input/sub-107_dir-AP_dwi.bvec` | 2630 | `6f8270c6568dd1b6e781bfb746ec221a2e4e484be0950a4a7c4deaed35303794` |
| `input/sub-107_dir-AP_dwi.json` (this copy) | 3631 | `e3cde00b2a2b4813ae7ba2c1a681f47de06c91f5e2db586e47888bc76c20739c` |
| original OpenNeuro `sub-107_dir-AP_dwi.json` (not included) | 3890 | `7e2d013f1a40cffa3f480574f9998334ae5fffe2d3aacf1d641731ecd4b71d59` |
| `qsiprep-*/out/sub-107_dir-AP_space-ACPC_desc-preproc_dwi.json` (these copies, all four equal) | 8887 | `bdd0ee838f6fca0bfc32f5655febfa865691ce266a5764587b54a009901641c5` |
| original QSIPrep output sidecar (not included, all four runs equal) | 9453 | `24e79de07704797f5e6690c6e8b4913226a16f446b73761682537ace53613347` |
Facts (`input/input-facts.json`):
- 120 × 120 × 75 × 101, 2 mm, TR 3.2 s, Siemens Prisma, int16 on disk.
- `scl_slope` and `scl_inter` are NaN, so no scaling applies.
- b-values 0, 1000 and 3000. The b0 volumes are 0, 10, …, 100 (11 volumes) under both the NiFreeze rule (b ≤ 50) and the QSIPrep rule (b < 100). 30 × b1000 and 60 × b3000 volumes alternate in time.
- The sform and qform codes are 1. The voxel axes are LAS with a 10.6° tilt.
## Brain mask (`mask/`)
MindGrab, model `mindgrab`, of the mean of the 11 raw b0 volumes. It was made with
`@neurodesk/node-drivers/mindgrab` (`loadMindgrabCpu`) and `@brainchop/mindgrab`
0.1.20260925 (`scripts/mindgrab-mask.mjs`, `scripts/mean_b0.py`).
| File | Content |
| --- | --- |
| `sub-107_dir-AP_desc-mindgrab_mask.nii.gz` | uint8 mask, same grid and affine as the DWI. SHA-256 `8b50fc5c298680d58be8353c2ad3e53138fa39f8389e4e33964e5e6228e01249` |
| `sub-107_dir-AP_desc-meanb0_dwiref.nii.gz` | the float32 mean b0 given to MindGrab (gzip of the exact file) |
| `mask-facts.json`, `mask-overlay.png` | 161679 voxels, 1293.4 mL, bounding box 126 × 168 × 136 mm, does not touch the grid edge |
QSIPrep does not accept an external mask for HMC. Each run made its own SynthStrip mask of
its own b0 template (`qsiprep-*/images/b0-template-mask.nii.gz`). Dice of the r1 mask
against the MindGrab mask: 0.947 (`qsiprep-r1/collected/mask-dice-vs-mindgrab.json`).
The four SynthStrip masks are not equal: against r1, e1 and e2 differ in 30 voxels and e3
in 25 (Dice 0.9999). Voxels: r1 163264, e1 163270, e2 163260, e3 163265. Each mask agrees with the SHA-256 in
its run's `manifest-host-paths.json`.
## Software and hosts
- NiFreeze `main` 3bcfb00df1e008b4dfeb59c0d63717c335ba0d1e (version string 26.0.0.dev259), Python 3.12.13. Apache-2.0 (the wheel's `LICENSE`).
- nipype 1.12.0, nitransforms 25.1.0, numpy 2.3.5, scipy 1.18.1, scikit-learn 1.9.1 (patched, see below), dipy 1.13.0.dev0 (git 2ecd365). Full lists: `env/nifreeze-pip-freeze.txt`, `env/analysis-pip-freeze.txt`.
- ANTs 2.6.2 at 52bc0ab (the commit of the repository's ANTs WebAssembly build), Apache-2.0 (the source tree's `COPYING.txt`). Native build: CMake `-G Ninja`, Release, static, no VTK, no MINC (`scripts/build-ants.sh`). GCC 16 needed three build-only changes: `-include stdint.h` for C++, `-std=gnu17` for C and `CMAKE_POLICY_VERSION_MINIMUM=3.5`. They do not change numerics.
- QSIPrep 26.1.1 container, `pennlinc/qsiprep:26.1.1`, registry digest `sha256:b7d91d9755fd97647632a1f900238425239cd834c97e9866b20af39e224d383a`, pulled on each host by that digest. BSD-3-Clause (the package metadata in the container). It contains nipype 1.11.0, dipy 1.12.1 and its own ANTs build (2.6.0.dev1-gb775a15).
- Apptainer SIF SHA-256, local host (r1): `b9064a6d727aff499ce1c2c1b5a309c0d0074be29921732332cd6d0b0d125506` (`env/qsiprep-26.1.1.sif.sha256`).
- Apptainer SIF SHA-256, host epic (e1-e3): `c26848b25c3d8223dfbf68ed305f20becec12180435cefbdb257cad1c18fd1bd` (`env/qsiprep-26.1.1-epic.sif.sha256`).
- Both images report QSIPrep v26.1.1 and the same ANTs version.
- Hosts: all NiFreeze runs and QSIPrep r1 ran on the local Linux x86-64 host. QSIPrep e1, e2 and e3 ran on the Linux x86-64 host epic, at the same time.
- One thread for each computation: `ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS=1`, `OMP_NUM_THREADS=1`, `OPENBLAS_NUM_THREADS=1`, `MKL_NUM_THREADS=1`. NiFreeze and QSIPrep r1 used `--nthreads 1`. QSIPrep e1-e3 used `--nthreads 10`, so nipype ran up to 10 independent nodes in parallel, each on one thread (`--omp-nthreads 1`).
### Patches (`patches/`)
1. `nifreeze-keepdir-float.diff`, NiFreeze:
- `NIFREEZE_KEEP_DIR` makes NiFreeze work in a fixed directory instead of a temporary one, so `sample_*`, `predicted_*`, `cmd-*.sh` and the transforms stay. It also writes the visit order to `order.txt`.
- `NIFREEZE_ANTS_FLOAT=1` adds `--float 1` to antsRegistration (Q53 runs only).
- Neither one changes a result when it is not set.
2. `sklearn-1.9.1-gpr-gradient-memory.diff`, scikit-learn `GaussianProcessRegressor.log_marginal_likelihood`:
- The original builds an (n, n, targets) float64 array for the gradient: (89, 89, 161668), 10.2 GB. It killed a 10 GB run.
- The patch sums over the targets before the trace, so it needs O(n²) memory. Only the summation order changes.
- Against the original formula at 3 theta values, the largest relative difference of the gradient is 3.3e-15.
- All GP runs here used the patch. Peak memory with the patch: 1.35-1.38 GB.
QSIPrep ran unpatched.
### Licences
Each file of this folder is in exactly one row. `scripts/check_licence_rows.py` holds the
rows as path patterns and fails when a file is in no row or in more than one; on this
folder it gives 5 / 1 / 2006 / 1298 / 1 / 1 / 201 files (3513 in all).
| Row | Files | Licence |
| --- | --- | --- |
| 1 | `input/` except `input/input-facts.json`: the ds005577 NIfTI, bval and bvec, the JSON sidecar (six fields removed) and `dataset_description.json` | CC0 (the dataset's `dataset_description.json`) |
| 2 | `mask/sub-107_dir-AP_desc-mindgrab_mask.nii.gz`, the MindGrab output. It is a derived image of the CC0 input: MindGrab segmented the mean b0 of `input/sub-107_dir-AP_dwi.nii.gz` | MIT, the licence of MindGrab (`@brainchop/mindgrab`) |
| 3 | QSIPrep outputs: `qsiprep/input/split_dwis/`; in each `qsiprep-{r1,e1,e2,e3}/`: `qsiprep.log.gz`, `images/`, `out/`, and `collected/` except `collected/manifest-host-paths.json` and `collected/mask-dice-vs-mindgrab.json` (transforms, registration command lines, predictions, motion CSVs, rotated b-vectors, confounds, `config.toml`). The folder holds no separate QSIPrep citation text | BSD-3-Clause, the licence of QSIPrep 26.1.1 |
| 4 | NiFreeze and ANTs outputs: in each `nifreeze-*/`: `work/`, `out/` and `nifreeze.log`; and `nifreeze-gp/bzero.nii.gz` | Apache-2.0, the licence of NiFreeze and of ANTs |
| 5 | `patches/nifreeze-keepdir-float.diff` (a patch to NiFreeze) | Apache-2.0, the licence of NiFreeze |
| 6 | `patches/sklearn-1.9.1-gpr-gradient-memory.diff` (a patch to scikit-learn) | BSD-3-Clause, the licence of scikit-learn |
| 7 | The scripts and the files that the scripts wrote: `scripts/`, `compare/`, `qc/`, `q53-b0/`, `env/` (environment records), `qsiprep/spread-*.json`, `input/input-facts.json`, `mask/mask-facts.json`, `mask/mask-overlay.png`, `mask/sub-107_dir-AP_desc-meanb0_dwiref.nii.gz` (`scripts/mean_b0.py`; a derived image of the CC0 input); in each `nifreeze-*/`: `command.txt`, `timing.txt`, `motion.tsv`, `motion_affines.tsv`, `motion-check.json`, `clip-facts.json`; in each `qsiprep-*/`: `command.txt`, `timing.txt`, `collected/manifest-host-paths.json`, `collected/mask-dice-vs-mindgrab.json` (written by the run and collector scripts); and `README.md`, `SHA256SUMS`, `index.json` | Apache-2.0, the licence of `exes/dwi` in neurodesk/webapps (the HMC port that these files serve; the user's choice, 2026-10-19). The repository has no single licence for all of its parts (`LICENSES.md`) |
The folder holds no third-party template or model file.
## NiFreeze runs (`nifreeze-*/`)
Command (`command.txt` in each folder; mask = the MindGrab mask, `--seed 1234` unless stated):
```sh
ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS=1 OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 MKL_NUM_THREADS=1 \
NIFREEZE_KEEP_DIR=work nifreeze sub-107_dir-AP_dwi.nii.gz \
--gradient-file sub-107_dir-AP_dwi.bvec sub-107_dir-AP_dwi.bval \
--brainmask mask.nii.gz --models <trivial|gp> --seed 1234 --nthreads 1 \
--write-hdf5 --output-dir out
```
| Folder | Model | antsRegistration | Seed | Wall time | Peak memory |
| --- | --- | --- | --- | --- | --- |
| `nifreeze-trivial-a1` | trivial | double | 1234 | 407 s | 0.97 GB |
| `nifreeze-trivial-a2` | trivial | double | 1234 | 412 s | 0.83 GB |
| `nifreeze-trivial-float` | trivial | `--float 1` | 1234 | 421 s | 0.88 GB |
| `nifreeze-gp` | gp | double | 1234 | 682 s | 1.35 GB |
| `nifreeze-gp-float` | gp | `--float 1` | 1234 | 707 s | 1.38 GB |
| `nifreeze-gp-seed1235` | gp | double | 1235 | 647 s | 1.35 GB |
Peak memory is the cgroup `memory.peak` of the run's scope.
Each folder contains:
| File | Content |
| --- | --- |
| `work/cmd-NNNNN.sh` | the antsRegistration command line that NiFreeze ran for DWI index NNNNN (0-89, b0 volumes removed). The paths point at the original host directory; the file names are the same as in this folder |
| `work/ants-NNNNN0GenericAffine.mat` | its ITK transform (LPS, fixed = prediction, moving = sample) |
| `work/order.txt` | visit order of the DWI indices (random, from the seed) |
| `work/brainmask.nii.gz` | the mask file that the command lines read (see "In-place changes") |
| `motion_affines.tsv` | `motion_affines` from the HDF5 output, 90 rows × 16 values (row-major 4 × 4, RAS, reference to scan), `repr` precision. It equals the `.mat` files converted to RAS (max difference 0, `motion-check.json`) |
| `motion.tsv` | translation (mm), rotation vector (rad), framewise displacement (50 mm) and scale per volume. See "Motion table convention" |
| `out/*.bvec`, `out/*.bval` | NiFreeze's rotated gradients: 90 columns (b0 dropped), `%.6f` |
| `out/*.x5` | NiFreeze's X5 transform file |
| `nifreeze.log`, `command.txt`, `timing.txt` | log, exact command and versions, wall time and cgroup memory |
Intermediates (for registration replay):
- `nifreeze-gp/work/sample_NNNNN.nii.gz`: the moving images, the files that NiFreeze wrote (int16, equal to the raw input volumes). All six runs wrote byte-identical samples, so only this set is kept.
- `nifreeze-gp/work/predicted_NNNNN.nii.gz`: the 90 GP predictions (fixed images), stored as float32. NiFreeze wrote float64. All values are integers in 0-255 after the clip, so the cast is exact (max error 0). The 90 source files are byte-identical in `nifreeze-gp`, `nifreeze-gp-float` and `nifreeze-gp-seed1235` (`compare/q53-seed-rule.json`), so this one set serves all three runs.
- `nifreeze-trivial-a1/work/predicted_00000.nii.gz`: the trivial prediction, float32, exact. All 90 files of the run had one SHA-256 (`e7a37cc9…`), so only one is kept.
- `nifreeze-gp/bzero.nii.gz`: float64, the median of the 11 raw b0 volumes before any clip (from the GP run's HDF5). It is the trivial model's input.
- `nifreeze-trivial-a1/clip-facts.json`: facts about the clip and the visit order.
### In-place changes that the port must copy (Q55)
1. **The clip writes into `bzero`.** `_to_nifti` calls `advanced_clip(data, inplace=True)` on the prediction. The data is int16, so the clip does not change the data. But the trivial model returns `dataset.bzero` itself, which is float64. Thus the first clip writes the clipped map into `dataset.bzero`, and each later visit clips the clipped map again.
- On this input the second clip changes nothing: the 35th percentile of the filtered map is 0 and the 99.98th is 255. Thus all 90 predictions are identical and the visit order has no effect.
- The trivial run's HDF5 `bzero` is the clipped map (equal to `predicted_00000`), not the median of the b0 volumes.
- On other data the second clip can change the map, and then the visit order changes the result.
2. **The DWI model removes mask voxels.** `_compute_data_mask` (`model/dmri.py`) writes `False` into `dataset.brainmask` where `bzero < 1e-5`. The GP model does this at construction, before NiFreeze writes `brainmask.nii.gz`.
- The GP runs therefore used a mask of 161668 voxels: the MindGrab mask minus 11 voxels where the b0 median is 0. The registrations used this mask as `--masks`, and it is the GP's voxel set.
- The trivial runs used all 161679 voxels.
### Motion table convention
- `motion.tsv` uses QSIPrep's `get_ras_motion_params` word for word. It moves the point `A[:3,:3]·c`, with `c = (shape − 1)/2`. This is the grid centre minus the origin, not the world grid centre `A·c`. Thus the translation depends on the grid `A` used for the decomposition:
| Reference | Grid | Pivot `A[:3,:3]·c` (mm) | Voxel origin from world origin |
| --- | --- | --- | --- |
| NiFreeze `motion.tsv` (this folder) | raw DWI, LAS, 120 × 120 × 75 | (-119.0, 103.4, 94.6) | 184.4 mm |
| QSIPrep `motion_params_*.csv` and confounds | conformed `b0_mean`, LPS, 120 × 120 × 75 (`qsiprep-r1/images/b0_mean.nii.gz`) | (-119.0, -130.6, 50.8) | 187.9 mm |
- Both grids have the same world centre (0.89, 3.46, -3.53) mm. The QSIPrep-formula translation differs from the world-centre translation by `(A − I)·(−origin)`, where `A` is the full 3 × 3 linear part of the transform. For a rigid transform (NiFreeze) `A = R`, so the difference is about |θ| × 184.4 mm on the raw grid. For SHORELine's affine transforms, scale and shear also contribute.
- A port matches these tables to 1e-6 only on the grid of the tool that made the reference: the raw DWI grid for NiFreeze, the conformed `b0_mean` grid for QSIPrep.
- **Framewise displacement:** `motion.tsv` has 90 rows (NiFreeze drops the b0 volumes). Thus its FD is between consecutive DWI volumes, and row 1 is 0. QSIPrep's confounds have 101 rows, and row 1 is `n/a`. The app keeps the b0 volumes (Q51) and writes 101 rows, so its FD differs from this table.
- The `compare/compare-world-*.json` files give the translation in both conventions.
### Registration settings that NiFreeze ran
- NiFreeze 3bcfb00 uses `b0-to-b0_level0.json` for every volume. No code path selects `dwi-to-b0_level0.json`.
- Stage 1: GC, `Rigid[12.0]`, Random 0.4, 20 iterations, shrink 3, smoothing 2.71 vox.
- Stage 2: GC, `Rigid[1.96]`, Random 0.18, 10 iterations, shrink 2, smoothing 0.
- Histogram matching on, winsorize [0.063, 0.991], `--masks [ brainmask, NULL ]` on each stage.
- Double precision (no `--float`), `ANTS_RANDOM_SEED` from `--seed`.
- Each stage stops at its iteration limit, not by convergence: 4 volumes were checked (`qc/converge/`).
### Results
**Determinism.**
- `trivial-a1` and `trivial-a2` are equal bit for bit: transforms, order and motion (`compare/compare-trivial-a1-vs-a2.json`).
- 4 kept `cmd-*.sh` files, run again with `ANTS_RANDOM_SEED=1234`, gave the same `.mat` byte for byte.
- The GP fit and prediction are deterministic and do not depend on the visit order or the registration precision: the 90 predictions are byte-identical in `gp`, `gp-float` and `gp-seed1235`.
- Only a same-seed repeat of the GP registrations is not tested.
**Trivial model fails on b3000.**
- The target is the b0 map, and a b3000 volume does not correlate with it (r ≈ 0.00).
- After its transform, every one of the 90 volumes moves away from the mean of its raw shell:
- b1000: median r 0.895 → 0.807.
- b3000: median r 0.627 → 0.363.
- Median displacement of the mask voxels: 1.5 mm (b1000) and 7.4 mm (b3000), maximum 42 mm.
- The "motion" follows the b-value, not the time, so it is not subject motion.
- The b0→b0 registrations show 0.0-0.3 mm and up to 0.35°.
- Files: `qc/nifreeze-trivial-*-qc.tsv`, `qc/*-qc-summary.json`, PNG overlays.
**GP succeeds.**
- No volume gets worse. Median r: b1000 0.895 → 0.910, b3000 0.627 → 0.674.
- Median mask displacement: 0.34 mm (b1000) and 0.42 mm (b3000).
- Maximum motion: 1.84 mm and 0.71° (QSIPrep formula).
**GP hyperparameters.**
- In all 90 fits, `beta_a` stopped at its lower bound 0.1 and `beta_l` at its lower bound 0.001. The fitted kernel is `SphericalKriging(a=0.1, λ=0.001) + WhiteKernel(0.999)`.
- Evidence: `nifreeze-gp/nifreeze.log` holds 180 scikit-learn `ConvergenceWarning`s "The optimal value found for … is close to the specified lower bound" (one for `beta_a` and one for `beta_l` in each fit). The dry-run fit (`compare/gp-dryrun-fit.log`) gives exactly a = 0.1 and λ = 0.001 (printed as `0.10000000000000002` and `0.0010000000000000002`).
- The prediction is therefore almost the voxel mean of the other 89 volumes from both shells: r = 0.993 (volumes 0, 1 and 7).
### Q53: antsRegistration `--float 1` against double
Measured against the fixed gate of 0.2 mm and 0.2° on each axis:
| Comparison | Over gate (world centre) | Over gate (QSIPrep formula) | Max \|Δt\| | Max \|Δrot\| |
| --- | --- | --- | --- | --- |
| trivial, float vs double | 55/90 | 66/90 | 42 mm | 6.1° |
| b0→b0, 11 pairs, float vs double | 0/11 | 0/11 | 0.018 mm (QSIPrep 0.178) | 0.052° |
| b0→b0, double, seed 1234 vs 1235 | 0/11 | 4/11 | 0.109 mm (QSIPrep 0.337) | 0.127° |
| GP, float vs double | 7/90 | 30/90 | 0.29 mm (QSIPrep 1.08) | 0.35° |
| GP, double, seed 1234 vs 1235 | 68/90 | 85/90 | 0.71 mm (mask displacement up to 1.7 mm) | 0.79° |
- Trivial: double itself fails on this data, so this row does not measure precision.
- b0→b0 (a well-posed registration): float is within the gate. The b0 test registers each raw b0 volume to the trivial prediction with the command line of `nifreeze-trivial-a1/work/cmd-00000.sh` (`q53-b0/`, `scripts/q53_b0.py`). The b0 volumes it used are slices of the input and are not copied.
- GP (the app default): float is not within the fixed gate (7/90 volumes over it). But a change of seed in double moves the result more than float does.
**Decision (user, 2026-10-19).** The WASM registration (`--float 1`) is not held to the fixed
gate. It is compared against the seed-to-seed spread of native double NiFreeze. No 3DDouble
build is needed. The rule (`scripts/q53_seed_rule.py`, `compare/q53-seed-rule.json`):
- `d_seed[v, k] = |gp − gp-seed1235|` for DWI volume `v` and axis `k`: translation x, y, z in mm about the world grid centre, and the rotation vector x, y, z in degrees, from `motion_affines`.
- The limit for shell `s` and axis `k` is `L[s, k]` = the maximum of `d_seed[v, k]` over the volumes `v` of shell `s`.
- A WASM volume passes when `|wasm(seed 1234) − gp(seed 1234)| ≤ L[s, k]` on each of its six axes. The run passes when all 90 volumes pass.
| Limit `L[s, k]` | trans x / y / z (mm), world centre | rot x / y / z (°) | trans x / y / z (mm), QSIPrep formula |
| --- | --- | --- | --- |
| b1000 | 0.117 / 0.248 / 0.219 | 0.291 / 0.228 / 0.195 | 0.254 / 0.459 / 0.670 |
| b3000 | 0.426 / 0.709 / 0.402 | 0.550 / 0.591 / 0.788 | 2.596 / 1.747 / 1.718 |
| largest \|gp-float − gp\|, all 90 volumes | 0.151 / 0.289 / 0.175 | 0.347 / 0.312 / 0.162 | 0.648 / 0.763 / 1.079 |
- Native `--float 1` passes on 90/90 volumes in both conventions. Its largest ratio to its limit is 0.72.
- Medians, world centre: |gp-float − gp| 0.013 / 0.019 / 0.020 mm and 0.032 / 0.029 / 0.018°; `d_seed` 0.078 / 0.125 / 0.123 mm and 0.149 / 0.123 / 0.147°.
- A per-cell reading (`|float − double| ≤ d_seed[v, k]` of the same volume and axis) fails native float on 40/90 volumes (58/540 cells), because one seed pair gives some cells a spread near 0. Thus the rule uses the shell maximum.
- The limits rest on one seed pair (1234, 1235) and on the GP model only.
- The fixed tolerances stay for the deterministic parts: motion decomposition (1e-6), bvec rotation (printed precision), SHORE prediction (1e-5 relative) and GP prediction.
## QSIPrep SHORELine (`qsiprep/`, `qsiprep-r1/`, `qsiprep-e1/`, `qsiprep-e2/`, `qsiprep-e3/`)
Command (`command.txt` in each run folder; BIDS input = the four original `input/` files
plus a `participants.tsv`, checksums of the local copy in `env/qsiprep-bids-input-sha256.txt`):
```sh
apptainer run --cleanenv --containall \
--env OMP_NUM_THREADS=1,OPENBLAS_NUM_THREADS=1,MKL_NUM_THREADS=1,ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS=1 \
qsiprep-26.1.1.sif /data /out participant --participant-label 107 --output-resolution 2 \
--anat-modality none --hmc-method shoreline --denoise-method none --unringing-method none \
--dwi-biascorrect none --ignore sdc --nthreads <1|10> --omp-nthreads 1 -w /work \
--skip-bids-validation --notrack --stop-on-first-crash
```
- `--anat-modality none` is the DWI-only flag. QSIPrep then registers the b0 template to MNI152NLin2009cAsym for its ACPC output space (`qsiprep-r1/collected/acpc_reg_command.txt`). This does not change the HMC transforms.
- `--denoise-method none`, `--unringing-method none`, `--dwi-biascorrect none` and `--ignore sdc`: only head motion correction affects the motion.
- Settings from `config.toml`: hmc_transform Affine, shoreline_model 3dshore, shoreline_iters 2, b0_threshold 100.
- No FreeSurfer licence was used: the run is DWI-only.
| Run | Host | `--nthreads` | Seeds (master / ants / numpy) | Wall time | CPU time | cgroup peak memory |
| --- | --- | --- | --- | --- | --- | --- |
| `qsiprep-r1` | local | 1 | 53847 / 57526 / 18755 | 17954 s (5.0 h) | 16987 s | 7.54 GB (cap 10G) |
| `qsiprep-e1` | epic | 10 | 124 / 36413 / 752 | 3551 s | 28666 s | 18.11 GB (cap 28G) |
| `qsiprep-e2` | epic | 10 | 21516 / 20495 / 16163 | 3761 s | 30481 s | 18.03 GB (cap 28G) |
| `qsiprep-e3` | epic | 10 | 23156 / 45524 / 14593 | 3785 s | 30508 s | 18.08 GB (cap 28G) |
- QSIPrep has no seed option. `config.toml` records the seeds that each run drew. The ants seed reaches antsRegistration through the environment, not the command line: the nipype `report.rst` of e1 shows `ANTS_RANDOM_SEED : 36413`. Thus the repeats differ by seed, and no same-seed repeat exists.
- e1-e3 ran at the same time on epic. Each one used 1.7-1.8 times the CPU seconds of r1. The memory peak includes the page cache.
- A b>0 registration (model stage) uses `--float 1`, Mattes 48 bins, Random sampling 0.15 (Rigid) and 0.2 (Affine), Rigid[0.2] at 1000x1000 with shrink 2x1 and smoothing 8x2 mm, then Affine[0.15] at 1000 with shrink 1 and smoothing 2 mm, BSpline interpolation, winsorize 0.002/0.998 and the run's own SynthStrip b0 template mask. The b0 stage is Rigid.
- The SHORELine iterations are `initial_model_iteration` (tensor) and `shoreline_iteration001` (3dSHORE).
Files:
| Path | Content |
| --- | --- |
| `qsiprep/input/split_dwis/vol.NNNN.nii.gz` | the 101 volumes after QSIPrep's conform step (LPS, float32), from r1: the moving images of every registration. Gzip of the exact files. The e1-e3 volumes have the same voxel data and the same NIfTI header block. In the AFNI extension only two attributes differ, the random `IDCODE_STRING` and its creation time `IDCODE_DATE`, so the files are not byte-identical (`index.json` note `qsiprep_split_dwis_vs_r1`) |
| `qsiprep/spread-e123.json`, `qsiprep/spread-e123.summary.json` | the Q54 repeat spread over e1, e2 and e3 (rows for each volume, the decomposition check, the NiFreeze comparison) |
| `qsiprep/spread-r1e123.json`, `qsiprep/spread-r1e123.summary.json` | the same with r1 added (cross-host, for information) |
| `qsiprep/spread-e123-rule.json` | the SHORELine spread rule: the limits `L[s, k]` from e1-e3, and the check of r1 against them (`scripts/shoreline_spread_rule.py`) |
| `qsiprep/spread-r1-e1.json`, `qsiprep/spread-r1-e2.json`, `qsiprep/spread-r1-e3.json` | the spread of each pair (r1, e*), same format as `spread-e123.json` (`scripts/shoreline-pairs.sh`) |
| `qsiprep-*/collected/b0/iterative_alignment_00{0,1}/NNN/` | b0 stage: `command.txt` (antsRegistration, Rigid) and `transform0GenericAffine.mat` for the 11 b0 volumes. See the note on folder names below |
| `qsiprep-*/collected/model/<iteration>/NNN/` | model stage: `command.txt` and `transform0GenericAffine.mat` for the 90 DWI volumes. In `qsiprep-r1` only, also `predicted.nii.gz` (the fixed image) |
| `qsiprep-*/collected/motion_params_*.csv` | QSIPrep's 12-parameter motion per iteration |
| `qsiprep-*/collected/rotated_*.bvec` | rotated b-vectors per iteration, `%.8f` |
| `qsiprep-*/collected/config.toml`, `manifest-host-paths.json` | run configuration (with the seeds); the collector's manifest: the SHA-256 of every source image and the host paths under `/var/tmp/dwi-hmc/runs/qsiprep-<run>/work/`. For e2 and e3 the epic paths were rewritten to these local paths after each SHA-256 was checked (`scripts/localize_manifest.py`) |
| `qsiprep-*/images/b0-template-mask.nii.gz` | the SynthStrip mask on the conformed LPS grid (in world space the same voxel grid as the raw LAS DWI grid): the `--masks` file of the model stage |
| `qsiprep-r1/images/` | also: b0 initial template, both b0 template iterations (`average`, `average_trans`), `b0_mean`, the masked template and `SHORELine_CNR` |
| `qsiprep-*/out/` | QSIPrep text outputs: confounds, `hmcOptimization.csv`, image QC, ACPC bvec/bval/b-table, coreg transforms |
| `qsiprep-*/qsiprep.log.gz`, `command.txt`, `timing.txt` | log, exact command (host, SIF SHA-256, digest, memory cap), time and memory |
- **Folder names `NNN` are not volume numbers.** Get the volume of a folder only from the moving image (`split_dwis/vol.VVVV.nii`, the second path of `--metric`) in its `command.txt`, as `scripts/spread_qsiprep.py` does. `scripts/folder_volume_map.py` prints the map; it is the same in all four runs:
- `b0/iterative_alignment_000/`: `000`-`010` are the b0 order 0-10, so volumes 0, 10, …, 100.
- `b0/iterative_alignment_001/`: `010`-`019` and `110`. These names come from the nipype node names `_reg_0010` … `_reg_00110` (the prefix `1` and the b0 order 0-10), not from the b0 index. `010` is volume 0, `011` is volume 10, `110` is volume 100.
- `model/<iteration>/`: `000`-`089` are the DWI order 0-89, so volumes 1-9, 11-19, …, 91-99 (`000` is volume 1, `089` is volume 99).
- The manifest field `index` holds the same values as the folder names.
- The predictions are stored as float32. QSIPrep wrote float64. The largest cast error is 4.9e-8 of the volume maximum. antsRegistration runs with `--float 1` and reads them as float, so the registration input does not change.
- The `.mat` files of every run decompose to its `motion_params_shoreline_iteration001.csv` with a largest difference of 1.5e-14 mm, about 1e-16 rad and about 2e-16 in scale and shear.
- Motion of the DWI volumes, world centre, each run: maximum |t| 0.55-0.60 mm, median |t| about 0.12 / 0.25 / 0.09 mm (x / y / z), maximum rotation 0.86-0.90°, maximum |scale − 1| 0.026, maximum |shear| 0.013.
### Q54: repeat spread over e1, e2 and e3 (one host)
For each volume, the largest difference over the 3 pairs, for each axis
(`qsiprep/spread-e123.summary.json`):
| Group | Max \|Δt\|, world centre (mm, x / y / z) | Max \|Δt\|, QSIPrep formula (mm) | Max \|Δrot\|, `decompose44` (°) | Max mask displacement, MindGrab mask (mm) | Over 0.2 mm / 0.2°, world centre | Over 0.2 mm / 0.2°, QSIPrep formula |
| --- | --- | --- | --- | --- | --- | --- |
| b0 (11 volumes) | 0.007 / 0.018 / 0.022 | 0.037 / 0.040 / 0.089 | 0.037 / 0.030 / 0.015 | 0.075 | 0 | 0 |
| b1000 (30) | 0.026 / 0.031 / 0.029 | 0.170 / 0.152 / 0.188 | 0.051 / 0.043 / 0.061 | 0.128 | 0 | 0 |
| b3000 (60) | 0.046 / 0.055 / 0.141 | 0.350 / 0.637 / 0.461 | 0.208 / 0.096 / 0.183 | 0.484 | 1 | 32 |
- **The spread is above the fixed gate for b3000.** At the world centre, 1 of 101 volumes is over it: volume 53 (b3000), Δrot x 0.208°, mask displacement 0.48 mm. By QSIPrep's formula, 32 of 101 volumes are over it, all b3000, because of the lever arm (a rotation of 0.2° over about 188 mm is about 0.66 mm).
- b0 and b1000 are within the gate in both conventions.
- **The rotation is not unique.** The SHORELine transform is affine (|scale − 1| up to 0.026, shear up to 0.013), so its rotation depends on the decomposition. The rotation columns and the over-gate counts use QSIPrep's `decompose44` (transforms3d), because the port must match QSIPrep's `motion_params_*.csv` to 1e-6. The polar factor of the same affine gives a b3000 maximum of 0.073 / 0.081 / 0.094° and 0/101 volumes over 0.2° (also 0/101 with r1 added). The fixed gate also ignores scale and shear.
- **The mask displacement does not depend on a convention:** the largest displacement of the mask voxels between two runs. For b3000 it is 0.48-0.50 mm, above 0.2 mm, with either mask and either set of runs:
| Mask | e1-e3 | r1 and e1-e3 |
| --- | --- | --- |
| MindGrab, `mask/sub-107_dir-AP_desc-mindgrab_mask.nii.gz` (161679 voxels; `scripts/spread_qsiprep.py`, the table above) | 0.484 mm | 0.488 mm |
| SynthStrip, `qsiprep-e1/images/b0-template-mask.nii.gz` (163270 voxels) | 0.497 mm | 0.500 mm |
- **The spread has more than one cause.** The runs differ in the ANTs seed (see the seeds above). Each run also made its own SynthStrip mask (25-30 voxels different, Dice 0.9999, see "Brain mask") from its own b0 template, and the model stage registers with that mask. Thus the e1-e3 spread includes the change of mask and template, not only the seed.
- With r1 added (another host, `--nthreads 1`): 1/101 over the gate at the world centre, 39/101 by QSIPrep's formula (1 b1000 and 38 b3000 volumes). The maximum values change very little (world-centre b3000 x 0.046 → 0.083 mm, mask displacement 0.484 → 0.488 mm). But for each volume and axis, r1 is not always within the e1-e3 limits (see the rule below).
### SHORELine registration rule (decided, 2026-10-19)
**Decision (user, 2026-10-19; it extends Q53).** The WASM registration of SHORELine is not
held to the fixed 0.2 mm / 0.2° gate. As for NiFreeze GP, it is held to the spread of
native runs: the QSIPrep 26.1.1 repeat spread of e1, e2 and e3 (host epic), for each shell
and axis. The rule (`scripts/shoreline_spread_rule.py`, `qsiprep/spread-e123-rule.json`)
has the same form as the GP rule:
- `d[v, k]` = the maximum over the pairs (e1, e2), (e1, e3) and (e2, e3) of `|run_a − run_b|` for volume `v` and axis `k`: translation x, y, z in mm about the world grid centre, and the rotation vector x, y, z in degrees of QSIPrep's `decompose44` rotation, from the final `.mat` of each run. These are the rows of `qsiprep/spread-e123.json`.
- The limit for shell `s` (b0, b1000, b3000) and axis `k` is `L[s, k]` = the maximum of `d[v, k]` over the volumes `v` of shell `s`, that is the maximum over the volumes and the pairs.
- A WASM volume passes when `|wasm − ref| ≤ L[s, k]` on each of its six axes. The run passes when all 101 volumes pass. `ref` is the QSIPrep run whose inputs the WASM run replays. Only `qsiprep-r1` keeps the fixed images (the predictions), so the M2 replay runs the argv of r1's `command.txt` files with r1's ANTs seed (57526, given as `ANTS_RANDOM_SEED`) against r1's images, and compares with r1's `.mat` files.
- **The spread includes the per-run seed and the per-run SynthStrip mask.** Each run drew its own ANTs seed, and each run also made its own b0 template and its own SynthStrip mask (the model-stage `--masks`; 25-30 voxels different, see "Brain mask"). Thus the limits are not seed noise only.
| Limit `L[s, k]` | trans x / y / z (mm), world centre | rot x / y / z (°), `decompose44` | trans x / y / z (mm), QSIPrep formula |
| --- | --- | --- | --- |
| b0 (11 volumes) | 0.007 / 0.018 / 0.022 | 0.037 / 0.030 / 0.015 | 0.037 / 0.040 / 0.089 |
| b1000 (30) | 0.026 / 0.031 / 0.029 | 0.051 / 0.043 / 0.061 | 0.170 / 0.152 / 0.188 |
| b3000 (60) | 0.046 / 0.055 / 0.141 | 0.208 / 0.096 / 0.183 | 0.350 / 0.637 / 0.461 |
- The limits are the shell maxima of the Q54 table above. The rule uses the world-centre translation. The QSIPrep-formula column is for a check in QSIPrep's own convention.
- **Cross-host check (information only, `qsiprep/spread-r1-e{1,2,3}.json`).** r1 (local host, `--nthreads 1`) is not always within these limits. At the world centre 4, 10 and 9 of 101 volumes of r1 are over a limit against e1, e2 and e3 (largest ratio to the limit 1.38, 1.48 and 1.80). By QSIPrep's formula: 4, 8 and 3 volumes (1.39, 1.58 and 1.54). The limits rest on three runs on one host. A replay that keeps the inputs of one run (M2) does not have the template and mask change; an end-to-end comparison against one QSIPrep run can be over the limits by about this much.
- The fixed tolerances stay for the deterministic parts: motion decomposition (1e-6), bvec rotation (printed precision) and SHORE prediction (1e-5 relative).
### QSIPrep against NiFreeze (information only)
Different methods (Rigid against Affine, other metric, mask and target). The median
difference for each axis was removed first.
- GP: correlation with QSIPrep 0.46-0.67 for translation and 0.29-0.70 for rotation. Median |Δt| 0.03-0.09 mm (b1000) and 0.09-0.15 mm (b3000), maximum 0.66 mm. Over the fixed gate: 10-12 of 30 b1000 and 55 of 60 b3000 volumes. Median offset about (−0.08, 0.25, −0.15) mm.
- trivial: correlation 0.35 or less, b3000 residual up to 43 mm, all 90 volumes over the gate.
- The results are almost the same against r1, e1, e2 and e3.
### Transfer of the epic runs
- e1: the full run except `tmp/` and `home/` was copied. The collector, run again locally, gave the same `collected/` as on epic (`diff -rq` returned 0).
- e2 and e3: only the files the epic manifest names, plus `collected/`, `out/`, `command.txt`, `timing.txt`, `qsiprep.log` and `config.toml` (742 files each). All 742 match the epic SHA-256 lists. 12 b0-stage registration inputs of each run were fetched later and match epic too.
- That is why `qsiprep-e2/` and `qsiprep-e3/` cannot hold the b0 template iterations or `SHORELine_CNR`; e1 has them, but only r1 keeps the intermediates here.
## Dropped (not in this folder)
| Item | Reason |
| --- | --- |
| NiFreeze `out/*.nii.h5` (204 MB each) | 194 MB of it is `dataobj`, a copy of the input. `motion_affines` is in `motion_affines.tsv`, and `bzero` is in `nifreeze-gp/bzero.nii.gz` |
| NiFreeze `out/*.nii.nii.gz` (resampled DWI, 75 MB each) | not needed for the replay tests. Rerun NiFreeze with the commands above to get it |
| NiFreeze `dbg_*.nii.gz` | NiFreeze's debug resampling of each volume |
| `sample_*` of five runs, `predicted_*` of five runs | byte-identical to the kept set (samples: all six runs; GP predictions: the three GP runs; trivial: one file for all 90) |
| `q53-b0/b0_*.nii.gz` | slices of the input |
| `qc/*-warped/` (2 GB) | resampled volumes for the QC numbers. `scripts/qc_registration.py` makes them again |
| `split_dwis` of e1-e3 | the same voxel data and header block as r1's (in the AFNI extension only `IDCODE_STRING` and `IDCODE_DATE` differ) |
| predictions, b0 templates, `b0_mean`, masked template and `SHORELine_CNR` of e1-e3 | one run of each method keeps its intermediates (r1). The b0 initial template is byte-identical in all four runs. The SHA-256 of each source image is in each `manifest-host-paths.json` |
| QSIPrep work directories (6.4 GB each), ACPC DWI, HTML reports | everything the replay needs is listed above |
| local QSIPrep run r2 | stopped by the user at about 55 %; not used |
| original JSON sidecar | six site and time fields; see "Input" |
| original QSIPrep output sidecars (`qsiprep-*/out/*_desc-preproc_dwi.json`) | the same six fields, at the top level and in `SourceMetadata`; see "Input" |
## Other files
- `index.json`: every packed file with its source path, the source SHA-256 and, for cast images, the cast error; for the five edited sidecars, the removed fields; for the seven files written without a source file (the six `motion_affines.tsv` and `env/qsiprep-26.1.1-epic.sif.sha256`), their own SHA-256 (`sha256`). It has an entry for every file except `README.md`, `SHA256SUMS` and itself. Its `notes` hold the sample, prediction, split-volume and template checks, and the sidecar edits (`site_fields_removed`).
- `compare/q53-seed-rule.json`: the Q53 seed-spread limits, the float check, the GP prediction identity and the two grid pivots.
- `scripts/`: the scripts that made these files (runs, mask, QC, comparisons, packing). They use the host paths of the original runs. `scripts/redact_sidecars.py` removed the site fields from the packed QSIPrep sidecars after packing (`scripts/pack_hmc.py` now does the same). `scripts/folder_volume_map.py` checks the folder-to-volume map of the QSIPrep registrations. `scripts/shoreline-pairs.sh` and `scripts/shoreline_spread_rule.py` wrote the SHORELine rule files. `scripts/check_licence_rows.py` checks the licence rows. `scripts/add_shoreline_rule.py` added the rule files, the new scripts and the `sha256` of the files that `pack_hmc.py` writes without a source file (the six `motion_affines.tsv` and `env/qsiprep-26.1.1-epic.sif.sha256`) to the packed folder and its `index.json`; `pack_hmc.py` now does the same. `scripts/epic/` holds the four scripts used on epic (`run-qsiprep.sh`, `launch.sh`, `pull-qsiprep.sh`, `file_list.py`).
- `env/`: package lists, the ANTs build options, the container tag record and the SIF SHA-256 of both hosts.
## Checksums
`SHA256SUMS` lists every file in this directory except itself. Upload under
`hmc/reference/` and pin the commit in the HMC manifest.