nirspipe.qc.metrics.screening#
Which channels get rejected, and on what grounds.
One table, CRITERIA, lists every per-channel number the reports carry. A channel is
rejected if it fails any criterion whose screens is set, so the screening half of the
table is a union and its entries are independent: dropping a criterion is deleting its line,
adding one is adding a line plus a scorer. Everything that prunes goes through
screen_channels(), so the prep pipeline, the raw QC report, the per-trial scoring and
the dyad path cannot end up screening on different things.
SCI and PSP are measured and reported but do not decide. good_frac counts the short
windows in which a channel’s SCI clears its line, and its PSP too when the run gives PSP a
line; the two whole-run numbers stay in the table because every report prints them.
The scores themselves are measured in nirspipe.qc.metrics.coupling; this module
only decides. Cutoffs live in nirspipe.qc.metrics._helpers beside the other
per-channel lines.
Module Contents#
Classes#
One screening criterion: what it measures, where its line is, and how to score it. |
Functions#
Each criterion’s line for this run: its default, overridden from |
|
|
|
Every criterion’s per-channel scores, measured on optical density. |
|
The labels of the screening criteria that came back empty. |
|
Refuse a recording whose screening criteria came back unmeasured. |
|
Why screening cannot judge a recording, or None when it can. |
|
The rejected channels, and which criteria each one failed. |
Data#
API#
- nirspipe.qc.metrics.screening.logger = 'get_logger(...)'#
- class nirspipe.qc.metrics.screening.Criterion#
One screening criterion: what it measures, where its line is, and how to score it.
scorertakes optical density and the cardiac band and returns{channel: score}.cutoffNone is a criterion with no line unless a run gives one.config_fieldnames the PrepConfig / CLI field a run may overridecutoffwith, or None for a criterion with no flag. Every criterion so far fails low, which is whatfails_belowrecords; a criterion that fails high would set it False.screensis whether failing this criterion rejects the channel. False means measured and reported only.needs_contextmarks a scorer that is handed a fourth argument, the run’s screening context: the resolved cutoffs undercutoffsand the stretches of the recording that count underscope. That is how a criterion built out of other criteria’s lines gets them without reaching for a global.
- nirspipe.qc.metrics.screening.CRITERIA: tuple[nirspipe.qc.metrics.screening.Criterion, ...] = ()#
- nirspipe.qc.metrics.screening.criterion_cutoffs(config: object | None = None) dict[str, float | None]#
Each criterion’s line for this run: its default, overridden from
config.criterion_cutoffs(config_with_sci_threshold_0_9) -> {“sci”: 0.9, “psp”: None, …}
A criterion with no
config_field, or a config that does not carry it, keeps the default. Passing None gives the defaults, which is what a caller with no run config has.
- nirspipe.qc.metrics.screening.resolve_cutoffs(config: object | None = None, **overrides) dict[str, float | None]#
criterion_cutoffs()with loose per-criterion overrides laid on top.resolve_cutoffs(sci=0.9, psp=None) -> {“sci”: 0.9, “psp”: None, …}
For a caller holding the lines as separate floats rather than as a config object, which is every CLI command and every report builder. A None override is not a value, so it keeps whatever the config or the default gave; an unknown criterion name is a typo the screening would silently ignore, so it raises.
- nirspipe.qc.metrics.screening.screening_scores(raw_od: mne.io.Raw, cardiac_l_freq: float, cardiac_h_freq: float, have: dict[str, dict[str, float]] | None = None, cutoffs: dict[str, float] | None = None, scope: list[tuple[str, float, float]] | None = None) dict[str, dict[str, float]]#
Every criterion’s per-channel scores, measured on optical density.
haveis whatever the caller measured already, keyed by criterion name; those are passed through rather than recomputed, which is what keeps a caller that needs SCI for its own reasons from paying for it twice.cutoffsis only read by criteria built out of other criteria’s lines, and defaults to the table’s own. Pass the same dict here and toscreen_channels(), or a run would count windows against one SCI line and colour its report against another.scopeis the stretches of the recording that count,[(label, tstart, tstop)], and None counts all of it. It reaches the window-counting criterion only; nothing else in the table has a time axis to restrict.
- nirspipe.qc.metrics.screening.unmeasured(scores: dict[str, dict[str, float]]) list[str]#
The labels of the screening criteria that came back empty.
- nirspipe.qc.metrics.screening.require_screened(scores: dict[str, dict[str, float]], name: str) None#
Refuse a recording whose screening criteria came back unmeasured.
screening_scores()leaves a criterion it cannot measure empty, which rejects nothing; a caller screening a whole recording must not read that as every channel passing. Per-trial scoring tolerates it on purpose and does not call this.
- nirspipe.qc.metrics.screening.screening_gap(raw_od: mne.io.Raw | None, scores: dict[str, dict[str, float]], scope=None) str | None#
Why screening cannot judge a recording, or None when it can.
The two conditions preprocessing refuses on: fewer than two counted windows, or a criterion that came back unmeasured. The raw QC reports print the reason and reject nothing on screening instead of stopping.
- nirspipe.qc.metrics.screening.screen_channels(scores: dict[str, dict[str, float]], cutoffs: dict[str, float] | None = None) tuple[list[str], dict[str, list[str]]]#
The rejected channels, and which criteria each one failed.
screen_channels({“good_frac”: {“S1_D1 760”: 0.4}}) -> ([“S1_D1 760”], {“S1_D1 760”: [“passing windows”]})
The union over the criteria that screen: one failed is enough. Criteria with
screensunset are scored and reported but reject nothing, so a channel with a poor whole-run SCI that still passes enough windows is kept. The second half is what lets a report say why a channel went rather than only that it did.