nifreeze.viz.corrections module¶
How each volume of a DWI dataset is corrected, as an animated SVG.
For each volume, animate_corrections() plays, on three axial, three coronal and
three sagittal cuts:
the volume as found, labelled original;
where the eddy-current field sends its voxels, as a quiver, where the volume was acquired;
the data travelling there, labelled eddy-corrected on arrival: the field undone in place;
where head motion sends them next, as a second quiver;
the data travelling into the reference, labelled realigned.
Each volume’s mapping \(W = E M\) (get_transform())
is split into head motion \(M_z\) and a field \(E_z\) that moves nothing at a
point \(z\) (the centre of the field of view, GEM’s default), so that the shift the
field makes there counts as head motion.
Realignment reads the volume at \(E_z M_z y\) for each point \(y\) of the
reference: head motion takes the point into the volume as acquired, and the field moves
it along phase encoding there.
In image terms, the field is undone first, in place, and head motion after it, which is
the order the animation plays.
The third step’s frame is the volume read through \(E_z\) alone, and the fifth’s is the volume read once through \(W\), the volume the command line writes. Every frame of the first, third and fifth steps is an exact resampling. In between, the browser moves the data continuously along the cut, with the 2D mapping each step induces on it, while the part of the motion across the cut dissolves from one frame into the next.
Drawn throughout:
the brain mask at the reference position (dashed), and the mask moved by head motion and the eddy currents (solid), which travels with the data into the reference;
in each cut’s corner, the b-vector projected onto the cut, which turns with the head during the realignment, as the b-vectors the command line writes do;
across a cut,
⊙points toward the viewer and⊗away from them.
The quivers are drawn magnify times their size (by default, ×30 for the eddy
currents and ×10 for the larger head motion); the data travel at true scale.
The SVG plays on its own (as an <img>, it loops the first volume).
Opened as a document (a browser tab, <object> or <iframe>), it plays every
volume, with controls for speed (keys - and +), pause (space), the previous and
next volume (arrow keys), and a progress bar that jumps to a volume.
- nifreeze.viz.corrections.COLORS = {'bvec': '#81c784', 'eddy': '#f06292', 'motion': '#ffd54f', 'moved': '#4fc3f7', 'muted': '#8f8d88', 'reference': '#eb6834', 'text': '#f0efec'}¶
Colours of the text and of each overlay.
- nifreeze.viz.corrections.COMPASS = 7.0¶
Radius of the b-vector’s compass (mm).
- nifreeze.viz.corrections.GAP = 4.0¶
Space between cuts (mm).
- nifreeze.viz.corrections.LEFT = 34.0¶
Room for the row labels and the header (mm).
- nifreeze.viz.corrections.MARGIN = 3¶
Voxels kept around the brain.
- nifreeze.viz.corrections.ORIENTATIONS = ('axial', 'coronal', 'sagittal')¶
The rows of the panel, top to bottom.
- nifreeze.viz.corrections.SMALLEST = 0.8¶
Arrows and marks smaller than this (mm, as drawn) are left out.
- nifreeze.viz.corrections.SPACING = 20.0¶
Space between the quiver’s arrows (mm).
- nifreeze.viz.corrections.SPEEDS = (0.25, 0.5, 1, 2, 4)¶
The playback speeds the controls offer.
- nifreeze.viz.corrections.TOP = 30.0¶
Room for the row labels and the header (mm).
- class nifreeze.viz.corrections.Timing(self, original: 'float' = 1.0, eddy: 'float' = 1.5, correct: 'float' = 2.0, motion: 'float' = 2.0, realign: 'float' = 2.0, hold: 'float' = 1.0, fade: 'float' = 0.25) None[source]¶
Bases:
objectHow long each step of a volume’s sequence lasts (s).
>>> marks = Timing().marks(eddy=True) >>> marks["correct"], marks["corrected"], marks["realign"], marks["end"] (2.75, 4.75, 7.0, 10.0) >>> Timing().marks(eddy=False)["realign"], Timing().marks(eddy=False)["end"] (3.25, 6.25)
Method generated by attrs for class Timing.
- nifreeze.viz.corrections.animate_corrections(dataset: DWI, out: str | Path | None = None, *, volumes: Sequence[int] | None = None, cuts: int = 3, magnify: float | tuple[float, float] = (10.0, 30.0), zero_point: Any = None, timing: Timing | None = None, quality: int = 75) str[source]¶
Animate how each volume of a DWI dataset is corrected, as an SVG.
- Parameters:
dataset (
DWI) – The dataset with its estimates (motionand, if set,eddy), such as the command line’s--write-hdf5output.out (
os.PathLike, optional) – Where to write the SVG.volumes (sequence of
int, optional) – The volumes to play, in this order (all of them by default).cuts (
int, optional) – Cuts per orientation, spread evenly across the brain.magnify (
floator pair offloat, optional) – How many times larger the quivers are drawn than the displacements: one factor for both, or one for head motion, then one for the eddy currents.zero_point (array-like, optional) – The point (RAS+, mm) where the eddy-current field moves nothing; its shift there counts as head motion. By default, the centre of the field of view (as GEM’s).
timing (
Timing, optional) – How long each step lasts.quality (
int, optional) – The frames’ JPEG quality.
- Returns:
The SVG document.
- Return type: