nirspipe.qc.subject.trial_qc#
Score each trial window on its own, so one bad trial is visible before it is averaged in.
The recording-level metrics answer “was this run usable”. They cannot answer “was trial 12 usable”, and a run whose mean SCI is 0.9 can still hold two trials where the cap moved. The raw QC viewer and the subject report both show that per-trial view, and they score it here so the two cannot end up measuring different windows or different metrics.
Nothing is persisted: a trial is not a BIDS entity, so a per-trial record has nowhere to live in the derivatives tree without colliding on filename.
Module Contents#
Functions#
Whether the crop |
|
How many trials are partly scored and how many unscored: |
|
Turn the event list into (label, t0, t1, onset) windows to score one at a time. |
|
SQM scalars for one trial window, scored the way the whole recording was. |
|
Every trial window scored, as |
Data#
API#
- nirspipe.qc.subject.trial_qc.logger = 'get_logger(...)'#
- nirspipe.qc.subject.trial_qc.MIN_TRIAL_S = 'max(...)'#
- nirspipe.qc.subject.trial_qc.MIN_SCI_TRIAL_S = 5.0#
- nirspipe.qc.subject.trial_qc.SHORT_TRIAL_KEYS = ('sci_mean', 'gvtd_filt_mean')#
- nirspipe.qc.subject.trial_qc.trial_fits(sfreq: float, t0: float, t1: float, window_s: float = MIN_TRIAL_S) bool#
Whether the crop
[t0, t1]holds one wholewindow_swindow.Counted the way MNE crops, to the nearest sample at each end:
trial_fits(10.0, 30.0, 40.0) -> True (101 samples, 100 needed) trial_fits(7.8125, 33.408, 34.408) -> False (9 samples, 79 needed)
- nirspipe.qc.subject.trial_qc.short_trial_counts(windows: list[tuple[str, float, float, float]], sfreq: float) tuple[int, int]#
How many trials are partly scored and how many unscored:
1, 5, 8, 10 s at 10 Hz -> (2, 1).
- nirspipe.qc.subject.trial_qc.trial_windows(markers: list[dict], tmin: float | None, tmax: float | None, duration: float) list[tuple[str, float, float, float]]#
Turn the event list into (label, t0, t1, onset) windows to score one at a time.
Two ways to size a window, chosen by whether tmin/tmax were given: fixed, [onset+tmin, onset+tmax], which lets a negative tmin pull in a baseline; or the event’s own duration, [onset, onset+duration], for block designs that record one.
Example: an event at 30.0 s of 8 s with tmin/tmax unset yields
("trial-001_30s_speak", 30.0, 38.0, 30.0).The onset travels beside the bounds because it is what says which condition a trial belongs to, and with a fixed window it is not recoverable from
t0: a negative tmin putst0before the event and a clamp at either edge of the recording moves it again.Events that describe no window are dropped rather than guessed at: a zero duration with no tmin/tmax has no extent, and a window starting past the end of the recording has no data.
- nirspipe.qc.subject.trial_qc.trial_sqm(raw, t0: float, t1: float, sci_threshold: float, cardiac_l_freq: float, cardiac_h_freq: float, psp_threshold: float | None = None, min_good_frac: float | None = None) dict#
SQM scalars for one trial window, scored the way the whole recording was.
The intensity recording is what gets cropped, not the optical density derived from it, so that a trial’s CV, SNR and spike count sit on the same scale as the recording-level numbers in the same report.
A trial shorter than one
MIN_TRIAL_Swindow keeps onlySHORT_TRIAL_KEYS, the rows that read no fixed window: its CV and SNR would be the whole crop’s under a windowed label. One shorter thanMIN_SCI_TRIAL_Sreturns{}, drawn blank: its SCI would be a correlation over a heartbeat or two. No sliding-window series is attached, and a trial shorter than two screening windows gets no passing-window share, so its status row screens nothing rather than rejecting everything.
- nirspipe.qc.subject.trial_qc.score_trials(raw, markers: list[dict], sci_threshold: float, cardiac_l_freq: float, cardiac_h_freq: float, tmin: float | None = None, tmax: float | None = None, psp_threshold: float | None = None, min_good_frac: float | None = None) tuple[list[str], list[dict]]#
Every trial window scored, as
(labels, sqms)ready for the heatmap.Returns two empty lists when no event describes a window that lies inside the recording, which is what a block design marking only condition boundaries looks like. The caller draws nothing in that case rather than an empty figure. A window too short to score (
trial_fits()) keeps its label and comes back as{}.