nirspipe.qc.metrics.hyper#

Dyad-level quality metrics: the shared screening grid, and the scalars a record holds.

Nothing here imports qc.figures. What lives there is figure data rather than a measured number: motion_series builds carpet z-scores, head_geometry projects optodes.

Module Contents#

Functions#

sci_of

The per-channel windowed SCI a dyad page prints, for one member; never the whole-run one.

passing_grid

The screening verdict per long pair per window, for every member, on one clock.

shared_screen_windows

sqm_data with each member’s screen_windows measured again on its aligned recording.

dyad_status

pair x window: 2 passing in every member, 1 in some, 0 in none.

member_rejections

Each member’s rejected S-D pairs: screening, by hand and the recording’s channels.tsv.

without_rejected

grid with every window of a pair a member rejected counted as not passing there.

member_series

One member’s long-channel means per window, on the dyad’s clock.

motion_summary

The dyad’s motion scalars, in the same units the figures are drawn in.

compute_hyper_sqm

The dyad’s pair counts and alignment span; pair_sets adds the counts per channel set.

Data#

API#

nirspipe.qc.metrics.hyper.logger = 'get_logger(...)'#
nirspipe.qc.metrics.hyper.sci_of(sqm_data: dict, sid: str) → dict#

The per-channel windowed SCI a dyad page prints, for one member; never the whole-run one.

nirspipe.qc.metrics.hyper.passing_grid(sqm_data: dict[str, dict], subject_ids: list[str], duration_s: float | None = None) → dict | None#

The screening verdict per long pair per window, for every member, on one clock.

-> {"t": [...], "pairs": ["S1_D1", ..., "S1_D8", ...],
    "long_pairs": ["S1_D1", ...], "ok": {"sub-01": mask, "sub-02": mask}}

with each mask a pair x window boolean, True where that member’s window passed its lines, SCI’s and PSP’s when it has one. The three dyad panels that read it (the usable-time carpet, the two head figures) then cannot disagree about which window was good.

Every pair, with the long ones named separately. The carpet is a long-channel picture because the dyad measures run on long channels, but a head draws the whole montage, short markers included.

The grids are on the dyad’s clock: the dyad raw pass hands over shared_screen_windows(), measured on the aligned recordings, so every member’s windows coincide. Windows past duration_s are dropped rather than drawn past the end of the shared clock.

The first member’s windows are the dyad’s; every other member contributes its window nearest each of them in time (_nearest_windows()), and counts as not passing where it has none. index keeps that choice so member_series() reads the same columns.

None when a member has no grid, or shares no window with the first member.

nirspipe.qc.metrics.hyper.shared_screen_windows(od_raws: dict[str, mne.io.Raw], intensity_raws: dict[str, mne.io.Raw], sqm_data: dict[str, dict], subject_ids: list[str]) → dict[str, dict]#

sqm_data with each member’s screen_windows measured again on its aligned recording.

-> {"sub-01": {..., "screen_windows": {"mask", "centers", "sci", "psp", "cv", "gvtd",
                                       "channel_order"}}, ...}

Each member’s own screening runs on its own clock from its first sample, so two members whose triggers sit at different points of their recordings were screened on windows that never coincide. Measured on the aligned copies, every member’s windows start at 0 on the shared clock and are the same stretches of it, so passing_grid() compares like with like at zero offset. The verdict a member was rejected by is untouched: that stays the one from its own screening, which its own report shows. The lines and the cardiac band are each member’s own, screen_cutoffs and screen_band.

nirspipe.qc.metrics.hyper.dyad_status(grid: dict, subject_ids: list[str]) → numpy.ndarray#

pair x window: 2 passing in every member, 1 in some, 0 in none.

nirspipe.qc.metrics.hyper.member_rejections(sqm_data: dict[str, dict], subject_ids: list[str]) → dict[str, set[str]]#

Each member’s rejected S-D pairs: screening, by hand and the recording’s channels.tsv.

nirspipe.qc.metrics.hyper.without_rejected(grid: dict, rejected: dict[str, set[str]]) → dict#

grid with every window of a pair a member rejected counted as not passing there.

A rejected channel leaves the analysis whatever its windows did, so the dyad’s usable counts read this grid, while the carpet keeps drawing the screening it came from.

nirspipe.qc.metrics.hyper.member_series(sqm_data: dict, sid: str, grid: dict) → dict#

One member’s long-channel means per window, on the dyad’s clock.

-> {"t": (388,), "sci": (388,), "psp": (388,), "cv": (388,), "gvtd": (388,),
    "per_pair_sci": {"S1_D1": (388,), ...}, "per_pair_psp": {"S1_D1": (388,), ...}}

The three series are averaged over the same rows the carpet folds into pairs, off the same matrices its mask came from, so a dip in a line and a hole under it are one measurement and not two. GVTD is absent unless the member’s record carried it; see passing_grid(). A dyad window the member has no window for is NaN.

per_pair_sci and per_pair_psp keep every pair separately, short ones included, because the head figures colour one marker per channel and draw both separations.

A channel undefined in a window (an intensity pinned at the device’s ceiling has no pulse to correlate) is left out of that window’s mean rather than voiding it.

nirspipe.qc.metrics.hyper.motion_summary(motion: dict) → dict#

The dyad’s motion scalars, in the same units the figures are drawn in.

-> {"unit": "x its own before-median", "canonical": "long",
    "long": {"before": {"sub-01": 1.61, "sub-02": 1.51, "together": 0.95},
             "after": {...}, "reduction": 0.33}, "all": {...}, ...}

together is the mean of the pointwise minimum of the members’ traces, which is high only where both were high. A minimum needs no cutoff chosen, and being a mean of the same normalised trace it is comparable between stages. reduction is the share of simultaneous movement the correction removed.

nirspipe.qc.metrics.hyper.compute_hyper_sqm(sqm_data: dict[str, dict], aligned_raws: dict[str, mne.io.Raw], offsets: dict[str, float], subject_ids: list[str], sci_threshold: float, pair_sets: dict[str, set[str]] | None = None) → dict#

The dyad’s pair counts and alignment span; pair_sets adds the counts per channel set.

pair_sets={"long": {"S1_D1", ...}, "short": {...}} -> pairs_by_set holding n_all_good, n_mixed, n_all_bad, n_total for each set.