nirspipe.qc.figures.hyper.hyper_post_figures#

Figure builders for the hyperscanning post-processing QC report.

Module Contents#

Functions#

build_wtc_channel

WTC map for one channel or ROI pair, as a base64 PNG: time x log-frequency, colour 0-1.

wtc_condition_views

Each condition’s view of one whole-run coherence map, keyed by slug for a page to pick.

build_wtc_map_interactive

build_wtc_channel() as a Plotly figure, for the panels worth zooming into.

flat_colorbar

A colorbar with no black box around it. Every bar in this report goes through it.

build_cross_panel

A cross-brain matrix as two live panels: the heatmap, and the same numbers as a circle.

build_wtc_cross_matrix

Band-mean coherence for every pairing across the two brains, one heatmap per chromophore.

build_isc_panel

The 2-panel ISC summary: ISC matrix | connectogram.

build_isc_roi_matrix

ISC at the ROI level, one heatmap per chromophore on a single correlation scale.

Data#

API#

nirspipe.qc.figures.hyper.hyper_post_figures.logger = 'get_logger(...)'#
nirspipe.qc.figures.hyper.hyper_post_figures.ARROW_MIN_COHERENCE = 0.5#
nirspipe.qc.figures.hyper.hyper_post_figures.build_wtc_channel(wtc_data: dict, freqs: numpy.ndarray, times: numpy.ndarray, pair_label: str, markers_list: list[dict], cond_colors: dict[str, str], site_label: str = '', arrow_min: float = ARROW_MIN_COHERENCE) → str | None#

WTC map for one channel or ROI pair, as a base64 PNG: time x log-frequency, colour 0-1.

wtc_data: {"wtc": ndarray(n_freqs, n_times), "coi": ndarray(n_times),
           "phase": ndarray(n_freqs, n_times), "sig": ndarray(n_freqs) | None}

Frequency runs downward on a log axis labelled at the decades. site_label names the pairing in the title, "S1_D1" for a homologous one and "S1_D1 × S2_D2" for a crossed one, which is what the pair of selectors above the panel picks. Four things are drawn on top of the map:

  • the phase arrows, thinned onto a coarse grid by _phase_arrows(). Right is in phase, left antiphase, up means the first member leads by a quarter cycle. Plotly’s figure_factory.create_quiver lays its arrowheads out in data coordinates, which would skew on a log axis.

  • the region outside the cone of influence, washed out rather than only bounded by the dashed line: those cells are coefficients padded against the record’s edges.

  • the significance contour, where coherence beats the Monte Carlo level, when one was computed.

  • one span bar per block above the axes with a line at each end of it, and one legend entry per condition in the top right. The bar runs the block’s actual length, so the gaps between blocks are visible, and sits outside the axes, where the heatmap cannot cover it.

nirspipe.qc.figures.hyper.hyper_post_figures.PANEL_HEIGHT = 720#
nirspipe.qc.figures.hyper.hyper_post_figures.WTC_FIGSIZE = (15.0, 3.0)#
nirspipe.qc.figures.hyper.hyper_post_figures.WTC_QUIVER_SCALE = 52.0#
nirspipe.qc.figures.hyper.hyper_post_figures.wtc_condition_views(fig, spans, wtc_data: dict, freqs: numpy.ndarray, times: numpy.ndarray, arrow_min: float = ARROW_MIN_COHERENCE) → dict | None#

Each condition’s view of one whole-run coherence map, keyed by slug for a page to pick.

wtc_condition_views(fig, [("video", 300.0, 600.0)], data, freqs, times)
-> {"video": {"x": [300.0, 600.0], "annotations": [...]}}

What the file then serves is the run at its own URL and each condition at …/map.html#video, which is the arrangement the subject report’s time-axis figures use. A condition read out of the whole-run transform and never cut from it is a slice of this one, down to the cone. A run transformed per condition, or one that marks each condition’s own cone, is a different figure and gets its own file. The caller decides, since it is the one that knows which route ran.

Only the arrows are rebuilt. They sit on a grid spread over whatever span they were drawn for, so a narrowed view of the run’s set would show a handful of columns; each condition carries its own set and the caption is left alone.

nirspipe.qc.figures.hyper.hyper_post_figures.build_wtc_map_interactive(wtc_data: dict, freqs: numpy.ndarray, times: numpy.ndarray, pair_label: str, markers_list: list[dict], cond_colors: dict[str, str], site_label: str = '', arrow_min: float = ARROW_MIN_COHERENCE)#

build_wtc_channel() as a Plotly figure, for the panels worth zooming into.

the same wtc_data -> go.Figure, about 3 MB of standalone HTML

Same map, same cone, same arrow rule, same span bars and legend. What it adds is hover (time, frequency and coherence per cell) and zoom. The ROI panel takes this and the channel panels stay PNG, since a crossed dyad has n^2 channel pairings.

Each arrow is an annotation anchored in data with its tail offset in pixels (axref="pixel"), which is what angles="uv" gives the matplotlib panel: the head sits on its grid point and the direction is a screen direction, so a relative phase of a quarter cycle draws a quarter turn however wide the frame ends up. ff.create_quiver lays its arrowheads out in data coordinates, which on axes of seconds against log-Hz shears them. Plotly’s ay grows downward, which is the sign that makes sin point up.

No zsmooth: interpolating the cells would smooth the real fast-band structure away.

nirspipe.qc.figures.hyper.hyper_post_figures.flat_colorbar(fig, mappable, ax, label: str, **kwargs)#

A colorbar with no black box around it. Every bar in this report goes through it.

flat_colorbar(fig, mesh, ax, "WTC", pad=0.015)

The live ROI panel is Plotly and draws an unframed bar; this gives the matplotlib stills the same look, chosen in one place.

nirspipe.qc.figures.hyper.hyper_post_figures.NODE_COLORS = None#
nirspipe.qc.figures.hyper.hyper_post_figures.ARC_FALLBACK_QUANTILE = 0.9#
nirspipe.qc.figures.hyper.hyper_post_figures.build_cross_panel(z: numpy.ndarray, row_labels: list[str], col_labels: list[str], subject_ids: list[str], *, cmap: str, vmin: float, vmax: float, value_label: str, matrix_title: str, suptitle: str, arc_threshold: float | None, arc_level: numpy.ndarray | None = None, arc_quantile: float | None = None, arc_level_name: str = 'its own null', kind: str = '')#

A cross-brain matrix as two live panels: the heatmap, and the same numbers as a circle.

an n x n of ISC values -> [ matrix with every cell printed | connectogram ]

The matrix is the record: every cell drawn carries its value, so a pairing can be looked up. The circle is the shape: the chords say which sites the strong pairings actually land on. A site with no value is left off both (kept_axes()).

The coherence matrices are not drawn by this: build_wtc_cross_matrix() spends both halves of its width on the HbO and HbR heatmaps instead.

Rows are the first member’s sites and columns the second’s, so cell (i, j) is one member’s site i against the other’s site j, and the diagonal is the homologous pairing while neither member lost a site. There is no within-brain cell anywhere in it, which is why every chord on the circle crosses the middle.

Live rather than a still, so hovering a chord or a cell says which pairing it is and what it is worth.

The scale is the caller’s and both panels share it, so there is one colorbar: a correlation takes CORRELATION_SCALE over -1 to 1.

Which pairings get a chord is _arc_rule(). It changes no number, and the subtitle over the circle says which of its rules drew them.

nirspipe.qc.figures.hyper.hyper_post_figures.build_wtc_cross_matrix(band_dfs: dict, labels: list[str], subject_ids: list[str], band_fmin: float, band_fmax: float, kind: str = 'channel')#

Band-mean coherence for every pairing across the two brains, one heatmap per chromophore.

{"HbO": frame, "HbR": frame} -> [ HbO matrix | HbR matrix ], one colour scale

Rows are sub1’s sites, columns sub2’s, so cell (i, j) is sub1’s site i against sub2’s site j and the diagonal is the homologous pairing the rest of the report shows. It draws the crossed pairs --channel-cross writes to the TSV.

The two chromophores share the figure and the scale. HbO and HbR are two parallel passes, never mixed and never averaged. There is no connectogram. build_isc_panel() keeps its circle, having a null to rank the pairings by; the ROI ISC matrices have none and are laid out like this one.

band_dfs maps a display name to that chromophore’s band-mean frame. A frame that is None, carries no label2 column, or has no finite cell is left out rather than drawn empty, so a run of one chromophore gets one panel. labels is the montage rather than whatever the frames happen to carry; the figure leaves off any site with no value.

nirspipe.qc.figures.hyper.hyper_post_figures.build_isc_panel(isc_mat: numpy.ndarray, ch_names: list[str], subject_ids: list[str], ch_type: str = 'hbo', isc_threshold: float | None = None, arc_level: numpy.ndarray | None = None, arc_level_name: str = 'its own null')#

The 2-panel ISC summary: ISC matrix | connectogram.

The panel itself is build_cross_panel(). What stays here is the scale a correlation is read on and the wording of its titles.

Parameters:
  • isc_mat -- n × n ISC matrix from compute_isc_pairs().

  • ch_names -- Channel labels (n,), without type suffix.

  • subject_ids -- [sub1_id, sub2_id, …].

  • ch_type -- “hbo”, “hbr” or “hbt”, shown in titles.

  • isc_threshold -- Absolute |ISC| a pairing must clear for a chord. None, the default, leaves the choice to _arc_rule().

  • arc_level -- Per-cell |r| level out of a null, when one was drawn.

  • arc_level_name -- How the chord subtitle names that null.

nirspipe.qc.figures.hyper.hyper_post_figures.build_isc_roi_matrix(isc_by_chroma: dict, subject_ids: list[str])#

ISC at the ROI level, one heatmap per chromophore on a single correlation scale.

{"HbO": (4 x 4 r, ["L", "R", ...]), "HbR": (...)} -> [ HbO matrix | HbR matrix ]

The ROI counterpart of build_isc_panel(), and it drops the connectogram that one keeps, since the ROI matrices have no phase-scrambled null to rank pairings by. Laid out like build_wtc_cross_matrix().

isc_by_chroma maps a display name to (matrix, roi labels). An entry that is None, has no finite cell, or does not match the axis the first panel set is left out rather than drawn empty, so a run of one chromophore gets one panel.