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.

Every fake dataset, checked against its own ground truth

Two independent bugs just silently misplaced every MRSI overlay this fixture pipeline produced — a shift-math error in the affine build, and an array reorder that decoupled data from its own header. Both were caught by chasing one dataset (brain_mrs_mrsi_exam) by hand. What about the other four?

mnutils.testing.build_fake_exam() backs every docs page and test in this repo (see the dev-diary entry for why it’s fake and how its content is made real). That reach is exactly the risk: a silent regression in the generator doesn’t fail loudly in one place, it quietly drifts every page that reads from it. This page is the single place that loads all five fixtures and checks each one against ground truth computed independently of the code path being tested — not by eyeballing a plot, by comparing to a position or ordering derived a different way.

FunctionWhat it does here
MRISeriesloads the anatomical NIfTI for each exam
MRSISeriesloads the spectroscopic grid; .RAW_exp is the blocky display NIfTI checked below
overlay_nifti_data_on_T1()the visual half of each geometric check
get_mat_data_from_series()series-ID lookup checked on the missing-series fixture
load_mat_file()loads the legacy-format fixture

The MRSI grid’s per-voxel signal comes from the real T1 template, downsampled by template_grid_intensity(). That gives an independent way to check RAW_exp’s affine: pick a grid index, work out where template_grid_intensity()'s downsampling actually placed it by going back to the full-resolution template directly (not through any of the code under test), and compare to what RAW_exp.nii.affine says that index’s world position is.

Overlay of RAW_exp on the T1 shows the grid correctly placed on the anatomy.

Loading...

Overlay of the interpolated MRSI grid

Loading...
max ground-truth error across sampled indices (mm): 0.0002469226121917245

mrsi_brain.nii (the interpolated pseudo image plotted above, not RAW_exp) carries its own affine straight from the fixture -- RAW_exp’s check above never exercises it. The interpolated grid’s index j corresponds to native template index (j + 0.5) * (native/interp) - 0.5, the same grid_mode=True mapping as RAW_exp, just at the interpolated resolution instead of the blocky one.

max ground-truth error, interpolated affine (mm): 3.4440308809280396e-06

The NIST phantom places its spheres analytically — SphereRing.spheres() returns each sphere’s exact world-mm center and intensity, strictly increasing around the ring. That’s ground truth with no downsampling involved at all: every bright RAW_exp voxel should sit inside its sphere’s 10 mm radius, and brightness should rank in the same order as the assigned intensities.

Loading...
Loading...
n bright voxels: 8 n spheres: 8
max sphere-to-voxel distance (mm): 9.462138612358062 / sphere radius: 12.0
brightness order matches intensity order: True

brain_extraction_exam, mrsi_missing_series_exam, and legacy_matlab73_example don’t carry MRSI geometry to check — they exist to exercise a loading code path, not a spatial one. Their actual teaching pages are Loading a series and an exam, Finding files in a data folder, and Loading a .mat reconstruction; this section only confirms each one still produces the shape those pages (and tests/test_brain_extract.py, for the HD-BET path) expect.

brain_extraction_exam T1 body shape: (188, 256, 186)
mrsi_missing_series_exam Series7 .mat: ScanArchive_Series7.mat
legacy_matlab73_example keys: ['pyr']