roi_confirmation
tit.roi_confirmation ¶
Resolve a job's target to the files that describe it, and write its ROI scene.
Why this exists¶
A number about an ROI is only as good as the ROI. An MNI ROI is not the ROI
that runs — every runner transforms it into the subject with the m2m_
registration first (mni2subject / :func:tit.opt.masks.prepare_mask), and a
transform that put the putamen in the wrong hemisphere, or 15 mm anterior, or
half outside the head, is the one error in this pipeline that no later number can
reveal: the optimisation converges, the focality ratio is finite, the analyzer's
table is full — and all of it is self-consistently about the wrong voxels.
A subject-space ROI has the same failure modes with none of the transform: an atlas label with detached islands, a hand-drawn mask off by a slice, a sphere whose centre was typed in guide coordinates. So the check is for every target, in every space, written before the expensive work starts.
This module is the thin place in the middle. It turns a target — an atlas file
and a label, a hemisphere's .annot, a mask, a sphere — into
- the layers a scene needs (which file, which label values, what colour),
- the cursor and zoom (:func:
tit.figures.roi_plate.plan_framing), and - the numbers (voxels, centroid, grey-matter overlap),
and hands them to :func:tit.figures.roi_plate.write_roi_scene, which writes one
small roi.tetravox.json that points at files that already exist.
Nothing is rasterised or duplicated to do it, with exactly one exception: an
MNI target's transformed mask is the ROI that runs and exists nowhere else,
so it is written once as a compressed uint8 roi_mask.nii.gz on the
atlas's voxel grid — about 100 KB, not the 125 MB a 0.5 mm T1 grid costs.
Two rules, each with the failure it prevents:
- An artefact never fails a job. Everything here is wrapped. A failure is one log line.
- It reports the mask that will actually be used, not a second computation of
it — the same :func:
tit.opt.masks.prepare_maskcall the runner makes, on the same label. A confirmation derived independently could agree with the user and disagree with the run.
confirm_roi ¶
confirm_roi(*, atlas_path: str | list[str], space: str | list[str], m2m: str, out_dir: str, label: int | None | list[int | None] = None, name: str | list[str] = '', sphere: tuple | None = None) -> dict | None
Write the ROI scene for one target and return its meta block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atlas_path
|
str | list[str]
|
the ROI's source — an atlas, a mask, or a |
required |
space
|
str | list[str]
|
|
required |
m2m
|
str
|
the subject's |
required |
out_dir
|
str
|
where the scene goes. |
required |
label
|
int | None | list[int | None]
|
one label of atlas_path, or |
None
|
name
|
str | list[str]
|
what to call this ROI. |
''
|
sphere
|
tuple | None
|
|
None
|
Returns:
| Type | Description |
|---|---|
dict | None
|
The |
dict | None
|
or could not be written — never raises, because a job must not fail |
dict | None
|
because an artefact did. |
Source code in tit/roi_confirmation.py
confirm_rois ¶
Write one scene for a search's targets, however many regions it has.
A search treats several regions as one union target, so the confirmation is
one scene too — never a directory per region. Each region keeps its own
colour in the scene and its own voxel count in meta.
Source code in tit/roi_confirmation.py
cortical_entries ¶
.annot path and label index for each named cortical region.
The analyzer names a cortical target by atlas and region (DK40 /
lh.superiorfrontal); the scene needs the file and the integer. Discovery
goes through :class:tit.atlas.MeshAtlasManager, the same one
GET /api/catalog/atlases uses, so the scene sees exactly the atlases the
subject has. A name that resolves to neither hemisphere is skipped with one
log line -- an artefact never fails a job.