nirspipe.qc.figures.subject.raw_figures#

Plotly figure builders for the interactive raw fNIRS QC viewer.

Module Contents#

Functions#

psd_layout

Layout for a single-panel PSD to fmax, with the physiological bands shaded.

sci_color

Red if the channel was rejected; otherwise green above the run’s SCI line, amber near it.

share_color

An optode’s fill for the share of its long channels rejected, linear in RGB along SHARE_RAMP.

sci_legend

Caption for sci_color(), from the same two numbers it colours by.

condition_colors

build_ts_figure

build_channel_figure

One channel pair as up to three panels: HbO/HbR over time, its PSD, its epoch average.

build_psd_mean_figure

Channel spectra in optical density, one mean per separation group, channels behind.

build_trial_image_views

One HbO channel’s trial images as views keyed by condition: the pooled trials, then that condition, in one figure. Rows = trials, x = time from onset, colour = baseline-corrected HbO, smoothed across neighbouring trials in long runs.

build_trial_image_by_condition

One HbO channel’s trial image, split by condition window rather than by event name.

build_roi_trial_image_by_condition

The ROI trial image split by condition window. Channels averaged first, as the run’s is.

build_roi_trial_image_figure

ROI trial image: average the ROI’s HbO channels first (higher SNR), then stack trials.

build_epoch_preview_figure

Grand mean per condition: every good long channel averaged, the good short ones dotted.

build_trigger_timeline_single

build_evoked_topo_figure

Per-channel evoked HbO/HbR laid out at the channel’s position on the head.

Data#

API#

nirspipe.qc.figures.subject.raw_figures.logger = 'get_logger(...)'#
nirspipe.qc.figures.subject.raw_figures.EPOCH_MIN_TRIALS = 2#
nirspipe.qc.figures.subject.raw_figures.WAVELENGTH_COLORS = ('#f28e2b', '#4e79a7', '#4d9221')#
nirspipe.qc.figures.subject.raw_figures.psd_layout(height: int = 220, cardiac=None, resp=None, fmax: float = PSD_FMAX) → dict#

Layout for a single-panel PSD to fmax, with the physiological bands shaded.

cardiac and resp are the run’s own (l_freq, h_freq), not constant edges. Passing None omits that band, and the colours and frequencies both come from the same place the multi-stage PSD figure reads them from.

nirspipe.qc.figures.subject.raw_figures.SCI_WARN_RATIO = 0.625#
nirspipe.qc.figures.subject.raw_figures.sci_color(sci: float | None, threshold: float, rejected: bool | None = None) → str#

Red if the channel was rejected; otherwise green above the run’s SCI line, amber near it.

sci_color(0.96, 0.80)                  -> green
sci_color(0.96, 0.80, rejected=True)   -> red

rejected outranks SCI because the two are not the same question. Screening counts how many windows a channel passed in, so a channel whose whole-run SCI is 0.96 can still be loose through most of a condition and be dropped.

Passing None keeps the SCI-only ladder, for the callers that have no verdict to hand.

nirspipe.qc.figures.subject.raw_figures.SHARE_RAMP = ('#ffffff', '#e74c3c')#
nirspipe.qc.figures.subject.raw_figures.NO_SHARE_COLOR = '#cfd6dc'#
nirspipe.qc.figures.subject.raw_figures.share_color(share: float) → str#

An optode’s fill for the share of its long channels rejected, linear in RGB along SHARE_RAMP.

share_color(0.0) -> “#ffffff”, share_color(1.0) -> “#e74c3c”

nirspipe.qc.figures.subject.raw_figures.sci_legend(threshold: float) → str#

Caption for sci_color(), from the same two numbers it colours by.

nirspipe.qc.figures.subject.raw_figures.condition_colors(markers: list[dict]) → dict[str, str]#
nirspipe.qc.figures.subject.raw_figures.build_ts_figure(raw: mne.io.Raw, markers: list[dict], bad_channels: set[str], max_ts_pts: int, sep_bands: Bands | None = None) → tuple[plotly.graph_objects.Figure, list[dict], dict[str, str], list[dict], float, float]#
nirspipe.qc.figures.subject.raw_figures.build_channel_figure(raw_haemo: mne.io.Raw, markers: list[dict], ch_pair: str, max_ts_pts: int, epoch_tmin: float = -5.0, epoch_tmax: float = 25.0, cardiac: tuple[float, float] | None = None, resp: tuple[float, float] | None = None, epoch: bool = True) → tuple[plotly.graph_objects.Figure, plotly.graph_objects.Figure | None, plotly.graph_objects.Figure | None]#

One channel pair as up to three panels: HbO/HbR over time, its PSD, its epoch average.

cardiac and resp are the run’s own band edges, taken from the CLI, and shade the PSD panel the way the multi-stage PSD figure shades its rows; passing None omits that band rather than guessing a default.

epoch=False returns None for the third panel, for a caller with a denoised view of the same channel elsewhere.

nirspipe.qc.figures.subject.raw_figures.build_psd_mean_figure(raw: mne.io.Raw, cardiac=None, resp=None, sep_bands=None, heart_rate=None) → plotly.graph_objects.Figure | None#

Channel spectra in optical density, one mean per separation group, channels behind.

Nothing here is a quality verdict: the panel shows what the spectrum looks like, and the screening result is the quality heatmap’s and the per-channel table’s job. The run’s heart_rate is marked, so a pulse outside the shaded cardiac band shows.

nirspipe.qc.figures.subject.raw_figures.build_trial_image_views(raw_haemo: mne.io.Raw, ch_name: str, epoch_tmin: float = -5.0, epoch_tmax: float = 25.0, trial_smooth: int | None = None) → dict[str, go.Figure] | None#

One HbO channel’s trial images as views keyed by condition: the pooled trials, then that condition, in one figure. Rows = trials, x = time from onset, colour = baseline-corrected HbO, smoothed across neighbouring trials in long runs.

The key "" holds the pooled trials alone, for a condition with no panel of its own (one trial, a row of the pooled image). One colour scale across every view, so switching the condition does not recolour the pooled trials. A run with one condition has no pooled panel and every view is that condition. None if no (non-BAD) events / channel absent.

e.g. conditions “a” and “b” -> {“a”: pooled + a, “b”: pooled + b, “”: pooled}.

nirspipe.qc.figures.subject.raw_figures.build_trial_image_by_condition(raw_haemo: mne.io.Raw, ch_name: str, spans: list[tuple[str, float, float]], epoch_tmin: float = -5.0, epoch_tmax: float = 25.0, trial_smooth: int | None = None, min_trials: int = 2) → dict[str, list[go.Figure]] | None#

One HbO channel’s trial image, split by condition window rather than by event name.

min_trials is why a block design gets nothing: its condition window holds the one annotation that defines it, and a one-row heatmap is a colour strip above a copy of its own average.

nirspipe.qc.figures.subject.raw_figures.build_roi_trial_image_by_condition(raw_haemo: mne.io.Raw, roi_name: str, channels: list[str], spans: list[tuple[str, float, float]], epoch_tmin: float = -5.0, epoch_tmax: float = 25.0, trial_smooth: int | None = None, min_trials: int = 2) → dict[str, list[go.Figure]] | None#

The ROI trial image split by condition window. Channels averaged first, as the run’s is.

nirspipe.qc.figures.subject.raw_figures.build_roi_trial_image_figure(raw_haemo: mne.io.Raw, roi_name: str, channels: list[str], epoch_tmin: float = -5.0, epoch_tmax: float = 25.0, trial_smooth: int | None = None) → list[go.Figure] | None#

ROI trial image: average the ROI’s HbO channels first (higher SNR), then stack trials.

channels are channel names or S-D pair labels; matched to their HbO channels. One figure per condition, pooled panel first.

nirspipe.qc.figures.subject.raw_figures.build_epoch_preview_figure(raw_haemo: mne.io.Raw, epoch_tmin: float = -5.0, epoch_tmax: float = 25.0, sep_bands=None) → plotly.graph_objects.Figure | None#

Grand mean per condition: every good long channel averaged, the good short ones dotted.

The short channels are drawn rather than dropped, as the scalp reference for the long-channel mean.

sep_bands is this run’s separations from separation_bands(); None takes the package defaults.

nirspipe.qc.figures.subject.raw_figures.build_trigger_timeline_single(markers: list[dict], cond_colors: dict[str, str]) → plotly.graph_objects.Figure | None#
nirspipe.qc.figures.subject.raw_figures.build_evoked_topo_figure(raw_haemo: mne.io.Raw, markers: list[dict], max_ts_pts: int = 2000, epoch_tmin: float = -5.0, epoch_tmax: float = 25.0) → plotly.graph_objects.Figure | None#

Per-channel evoked HbO/HbR laid out at the channel’s position on the head.

One cell per S-D pair, one trace pair per condition. Without usable events the cells show the continuous signal instead, so a resting-state run still gets the layout view.