nirspipe.qc.figures.common._utils#
Shared color constants and helpers used across QC figure modules.
Module Contents#
Functions#
One row of an event timeline: a bar per timed block, a tick per instant event. |
|
Alternating row backgrounds for an event timeline, as layout shapes. |
|
The length printed on each block wide enough to hold it, as layout annotations. |
|
The x and y axis dicts both event timelines share. |
|
Thin one trace to at most |
|
Scatter x/y kwargs for a long trace, sized for the file it is written to. |
|
PSD annotation bands as (name, f_lo, f_hi). Single source so every PSD figure agrees. |
|
Where a spectrum’s x axis ends: 2 Hz, or 0.2 Hz past the highest of |
|
A dotted line at the run’s heart rate on every panel of a PSD figure, labelled on the first. |
|
Shade and label the physiological bands on a PSD figure. |
|
Draw the head circle, ears and nose around a set of optode x/y, and set the limits. |
|
A copy of |
Data#
API#
- nirspipe.qc.figures.common._utils.logger = 'get_logger(...)'#
- nirspipe.qc.figures.common._utils.HBO_COLOR = '#e74c3c'#
- nirspipe.qc.figures.common._utils.HBR_COLOR = '#3498db'#
- nirspipe.qc.figures.common._utils.HBT_COLOR = '#27ae60'#
- nirspipe.qc.figures.common._utils.HBO_MEAN_COLOR = '#c0392b'#
- nirspipe.qc.figures.common._utils.HBR_MEAN_COLOR = '#11629e'#
- nirspipe.qc.figures.common._utils.CHROMA_STYLE = None#
- nirspipe.qc.figures.common._utils.LONG_COLOR = '#f37d7d'#
- nirspipe.qc.figures.common._utils.SHORT_COLOR = '#78b1f2'#
- nirspipe.qc.figures.common._utils.UNCLASSIFIED_COLOR = '#95a5a6'#
- nirspipe.qc.figures.common._utils.SPAN_KIND_COLOR = None#
- nirspipe.qc.figures.common._utils.SPAN_KIND_LABEL = None#
- nirspipe.qc.figures.common._utils.AXIS_TEXT_COLOR = '#2a3f5f'#
- nirspipe.qc.figures.common._utils.PSD_NFFT = 256#
- nirspipe.qc.figures.common._utils.CONDITION_PALETTE = ['#e74c3c', '#3498db', '#2ecc71', '#f39c12', '#9b59b6', '#1abc9c', '#e67e22', '#34495e']#
- nirspipe.qc.figures.common._utils.MEMBER_COLORS = ('#8e44ad', '#e67e22', '#16a085', '#2c3e50', '#1abc9c', '#34495e')#
- nirspipe.qc.figures.common._utils.SCALE_MIN_TRIALS = 3#
- nirspipe.qc.figures.common._utils.timeline_row_traces(events, y, color, name, showlegend, hover_tail='')#
One row of an event timeline: a bar per timed block, a tick per instant event.
timeline_row_traces([{"onset": 10, "duration": 30}], 1, "#e74c3c", "video", True) -> [Bar spanning 10-40 s at y=1]
Both shapes can appear on one row, since a run can mix a timed block with an instant cue, so each event picks its own by its duration and the two traces share a legend entry.
- nirspipe.qc.figures.common._utils.TIMELINE_BAND_COLOR = '#f7f8fa'#
- nirspipe.qc.figures.common._utils.TIMELINE_ROW_PX = 36#
- nirspipe.qc.figures.common._utils.timeline_row_bands(n_rows: int) list#
Alternating row backgrounds for an event timeline, as layout shapes.
- nirspipe.qc.figures.common._utils.block_duration_labels(events, y, span: float) list#
The length printed on each block wide enough to hold it, as layout annotations.
block_duration_labels([{"onset": 10, "duration": 300}], 1, 3900) -> [annotation "300 s" centred on the block at y=1]
- nirspipe.qc.figures.common._utils.timeline_axes(row_labels: list[str] | None)#
The x and y axis dicts both event timelines share.
- nirspipe.qc.figures.common._utils.minmax_xy(times: numpy.ndarray, values: numpy.ndarray, max_pts: int)#
Thin one trace to at most
max_ptsby keeping each bin’s lowest and highest sample.A stride keeps one arbitrary sample per bin, so a rhythm faster than the drawn rate, the cardiac pulse on a long recording, folds into a slow wave the data does not have. The two extremes keep the envelope instead, each at the time it was recorded:
minmax_xy([0, 1, 2, 3, 4, 5], [0, 3, 1, 2, -1, 0], 4) -> ([0, 1, 3, 4], [0, 3, 2, -1])
- nirspipe.qc.figures.common._utils.line_xy(times: numpy.ndarray, values: numpy.ndarray) dict#
Scatter x/y kwargs for a long trace, sized for the file it is written to.
Two things, both invisible on screen:
line_xy([0, .5, 1], [3, 4, 5]) -> {"x0": 0.0, "dx": 0.5, "y": array([3., 4., 5.])} line_xy([0, .5, 9], [3, 4, 5]) -> {"x": array([0., .5, 9.]), "y": array([3., 4., 5.])}
Plotly writes a numpy array as base64 and a Python list as one full-precision decimal per element, so the arrays have to reach it as arrays:
0.6881280000000001is eighteen characters for a number that occupies eight bytes. A uniformly sampled x is then not sent at all,x0/dxsaying the same thing in two numbers.The uniformity test is what keeps this honest.
minmax_xyand_maxpool_xykeep the timestamp each kept sample was recorded at, so a peak sits where it happened rather than on a bin edge, and those fail the test and keep their x.Values go out as float32, which is a display cast and not a measurement one. Timestamps stay float64, since those are what the uniformity test and the peak positions are read off.
- nirspipe.qc.figures.common._utils.physio_bands(cardiac=None, resp=None)#
PSD annotation bands as (name, f_lo, f_hi). Single source so every PSD figure agrees.
Mayer is a fixed visual reference (no metric counterpart).
cardiac/resptake the CLI(l_freq, h_freq)so the shading matches the bands the metrics integrate over; pass None to omit that band entirely rather than guess a default (e.g. a dyad whose members were given different bands).
- nirspipe.qc.figures.common._utils.BAND_COLORS = None#
- nirspipe.qc.figures.common._utils.HEART_RATE_COLOR = '#a93226'#
- nirspipe.qc.figures.common._utils.PSD_FMAX = 2.0#
- nirspipe.qc.figures.common._utils.spectrum_fmax(sfreq: float, *freqs: float | None) float#
Where a spectrum’s x axis ends: 2 Hz, or 0.2 Hz past the highest of
freqsbeyond it, at most Nyquist.spectrum_fmax(10.0, 1.8, 1.38) -> 2.0 spectrum_fmax(10.0, 3.1, 2.4) -> 3.3
- nirspipe.qc.figures.common._utils.add_heart_rate_line(fig, heart_rate: float | None, fmax: float, rows: int | None = None, cols: int = 1) None#
A dotted line at the run’s heart rate on every panel of a PSD figure, labelled on the first.
rowsandcolsas inadd_band_shading(). Nothing is drawn without a heart rate or pastfmax.
- nirspipe.qc.figures.common._utils.add_band_shading(fig, fmax: float, bands: list, rows: int | None = None, cols: int = 1) None#
Shade and label the physiological bands on a PSD figure.
One definition so the multi-stage PSD panel and the per-channel PSD mark the same bands the same way.
rowsis the subplot row count for a figure made with make_subplots, or None for a plain single-axis figure, which is the only difference between the two:add_band_shading(fig, 2.0, physio_bands(cardiac=(0.7, 1.5))) # plain add_band_shading(fig, 2.0, physio_bands((0.7, 1.5), (0.2, 0.4)), 2) # 2 subplots
Bands starting past
fmaxare dropped rather than clamped: a stripe pinned to the right edge would claim the band is in view when it is off the plot.colsshades a grid of that many columns, row by row.
- nirspipe.qc.figures.common._utils.head_outline(ax, xs, ys)#
Draw the head circle, ears and nose around a set of optode x/y, and set the limits.
One definition so every flat map in the report has the same head. The circle is centred on the optode bounding box, not on the origin, because montage coordinates are in head space and a frontal-only cap sits well off centre:
xs = [-0.05, 0.05], ys = [0.0, 0.08] -> centre (0, 0.04), radius 0.047
Returns
(cx, cy, r)so the caller can place anything else relative to the head.
- nirspipe.qc.figures.common._utils.chunk_annotations(raw, chunk_duration: float | None)#
A copy of
rawwith each long annotation cut intochunk_duration-long trials.MNE’s Epochs is a 3-D array, so every trial has to be the same length, and a block design marks one long annotation per block. Cutting the annotations rather than the events means every figure, the event timeline and the per-trial scoring all see the same trials.
A 240 s block chunked at 25 s -> 9 annotations of 25 s, and the 15 s that do not fill a chunk are dropped, which is the rule MNE applies. Annotations already shorter than a chunk are left alone, and
BAD_marks are censoring spans rather than stimuli and are never cut.Nonereturnsrawitself, so a caller can pass the option straight through.