nirspipe.io.optode_space#
Where a recording’s optodes sit on its head template, decided once per run and recorded beside it.
SNIRF does not say which space its optode coordinates are in, and a dataset’s
_coordsystem.json is often wrong about it. So the placement is decided from the coordinates:
the labelled landmarks (the probe’s, else the _coordsystem.json’s) registered onto the
same points on the template, or, when that leaves
the cap off the scalp, the reading of the coordinates (a head frame, or already on fsaverage)
that puts the optodes on the template’s scalp. Prep writes the result as the run’s channel
table, and every later reader takes the placement from that record instead of deciding again.
Module Contents#
Classes#
How a recording’s optode coordinates reach its template’s surface RAS (fsaverage: MNI305). |
Functions#
Give a SNIRF rewritten through MNE the fields of its source that MNE drops or rewrites. |
|
Decide where a recording’s optodes sit on the template |
|
The channel table recording a run’s placement on |
|
The channel table prep wrote for a run, whichever template it was placed on. |
|
Each source-detector pair’s region in the run’s channel table; empty when it has none. |
|
One row per fNIRS channel at its source-detector midpoint on the template, and the placement. |
|
The JSON beside a channel position table: space, units, columns, and the placement record. |
|
The placement prep recorded for a run, or StageError when the tree predates the record. |
|
Carry a run’s placement record to a file written under another run’s name. |
|
Attach a placement to the Raw, for the life of the object; returns raw. |
|
The placement of a Raw’s optodes: held on it, recorded for its run, or read off its file. |
Data#
API#
- nirspipe.io.optode_space.logger = 'get_logger(...)'#
- nirspipe.io.optode_space.SCALP_FIT_MAX_MM = 5.0#
- nirspipe.io.optode_space.LANDMARK_AGREE_MM = 5.0#
- class nirspipe.io.optode_space.Placement#
How a recording’s optode coordinates reach its template’s surface RAS (fsaverage: MNI305).
methodis"landmarks"(the file’s landmarks registered onto the template’s),"head"(the template’s own head frame),"mni"or"fsaverage_head"(fsaverage’s surface RAS or head frame, which an infant template reaches through the 10-10 system), or"none"(no reading puts the cap on the scalp). On fsaverage the two head frames are one,"head".transformtakes coordinates as MNE holds them, in metres, to the template in millimetres;spacenames the template.- transform: numpy.ndarray | None = None#
- apply(coords_m: numpy.ndarray) numpy.ndarray#
- classmethod from_json(record: dict) nirspipe.io.optode_space.Placement#
- nirspipe.io.optode_space.copy_source_fields(source_path, dest_path) None#
Give a SNIRF rewritten through MNE the fields of its source that MNE drops or rewrites.
source landmarkLabels [Nz, Cz, F3]in mm -> the same three indest, in its own unitsource sourceLabels [F7, F5]->dest sourceLabels [F7, F5], not S1, S2source MeasurementTime 14:19:51+01-> the same string, not 00:00:00ZMNE keeps a landmark’s position but not its name (anything but the three fiducials reads back as EEG001, EEG002, …), MNE 1.13 reads one in mm a million times too large, and mne-nirs writes template fiducials where the source had none, so a cropped or re-marked recording would otherwise be placed by landmarks it never had. A source without landmarks leaves the copy without any.
mne-nirs also names every optode S1, D1, …, and MNE sets a date it cannot parse to 2000-01-01 and drops the text tags it does not know. Those come back verbatim. The units, the subject id and the per-sample device arrays stay as written.
- nirspipe.io.optode_space.place_optodes(snirf_path, space: str = FSAVERAGE) nirspipe.io.optode_space.Placement#
Decide where a recording’s optodes sit on the template
space, from the SNIRF file.The probe’s own landmarks are used; a probe without any takes those of the recording’s BIDS
_coordsystem.json, when that file has them in the optodes’ frame.Landmarks first: every landmark label the file shares with the template’s 10-10 positions (10-5 on fsaverage), the three fiducials included, is registered onto its position there, and the result is kept when the optodes land on the scalp. Otherwise the coordinates are read in each frame they could be in, and the reading that lands on the scalp is kept. A file no reading places, or one whose probe cannot be read, gets
method "none"with the reason.10-10 labelled landmarks, cap on the scalp once registered -> "landmarks" fiducials from another template tilt the cap, raw values fit -> "mni" digitiser coordinates never registered to a head -> "none"
- nirspipe.io.optode_space.channel_coords_path(run_file, space: str = FSAVERAGE) pathlib.Path#
The channel table recording a run’s placement on
space, beside any file of that run..../sub-01_ses-02_task-rest_run-01_desc-preproc_nirs.snirf->
.../sub-01_ses-02_task-rest_run-01_space-fsaverage_channels.tsv
- nirspipe.io.optode_space.recorded_coords_path(run_file) pathlib.Path#
The channel table prep wrote for a run, whichever template it was placed on.
StageError when there is none (a tree from before the record) or more than one.
- nirspipe.io.optode_space.recorded_regions(run_file, atlas: str = 'aparc') dict[str, str]#
Each source-detector pair’s region in the run’s channel table; empty when it has none.
S1_D1 hboandS1_D1 hbrinprecentral-lh->{"S1_D1": "precentral-lh"}; an unplaced pair, writtenn/a, is left out.
- nirspipe.io.optode_space.write_channel_coords(raw: mne.io.Raw, placement: nirspipe.io.optode_space.Placement, out_path: pathlib.Path, sources: list[str | Path] = (), population: str | None = None) pathlib.Path#
One row per fNIRS channel at its source-detector midpoint on the template, and the placement.
S1_D1 hbowith source (0.01, 0.05, 0.06) and detector (0.04, 0.05, 0.06) m->
name x y z=S1_D1 hboand the transformed midpoint in mm; n/a when unplaced
Each atlas the template ships adds a column naming the region of the pial vertex nearest that midpoint.
populationis the run’s--population, which the Methods name the template by.
- nirspipe.io.optode_space.write_coords_sidecar(out_path, sources: list[str | Path], placement: dict, space: str | None, regions: list[str] = ()) None#
The JSON beside a channel position table: space, units, columns, and the placement record.
spaceNone is a table whose rows lie on more than one template, named in its ownspacecolumn.regionsare the table’s atlas columns.
- nirspipe.io.optode_space.read_placement(run_file) nirspipe.io.optode_space.Placement#
The placement prep recorded for a run, or StageError when the tree predates the record.
- nirspipe.io.optode_space.copy_placement(source_file, dest_file) None#
Carry a run’s placement record to a file written under another run’s name.
sub-01_task-rest_desc-preproccut intosub-01_task-early_desc-preproc->
sub-01_task-early_space-fsaverage_channels.tsvand.jsonbeside it
- nirspipe.io.optode_space.hold_placement(raw: mne.io.Raw, placement: nirspipe.io.optode_space.Placement) mne.io.Raw#
Attach a placement to the Raw, for the life of the object; returns raw.
- nirspipe.io.optode_space.placement_of(raw: mne.io.Raw) nirspipe.io.optode_space.Placement#
The placement of a Raw’s optodes: held on it, recorded for its run, or read off its file.
A derivative takes the record prep left beside it, placed from the recording itself, so it is never placed a second time from its own copy. A raw file read here is placed on fsaverage; a run on another template holds its placement on the Raw.