nirspipe.qc.figures.subject.group_figures#

Plotly figure builders for cohort-level QC reports (individual and hyper).

Module Contents#

Functions#

check_only

Recorded to be checked against, not shown: imu_gyro_speed_gvtd_rho -> True.

group_metrics

Split metric_cols into (groups, ordered_flat) following _METRIC_GROUPS; leftovers -> ‘Other’.

metric_family

The quantity a column measures, which the outlier score counts once.

deviation_scores

Per run, the mean over metric families of each family’s mean |z|.

detect_outliers

{bids_name: [worst metrics]} for runs whose deviation_scores() is past the threshold.

build_deviation_strip

One row per metric, one dot per run at its robust z, colour = channel set.

build_window_grid

Metric x channel-set grid over time: every run pale, the cohort’s band and median over.

condition_colours

One colour per condition, by the rule the run report’s markers already follow.

build_condition_timeline

One run’s windowed metrics over time, the conditions shaded behind them.

condition_names

Conditions the cohort has, in the order the first run that carries them wrote them.

build_condition_panels

One panel per metric: x is the condition, one line per run, the median over them.

build_condition_matrix

run x condition, one panel per metric, colour = robust z inside that condition.

build_channel_condition_matrix

channel x condition for one run, the panels and order of build_condition_panels.

build_grouped_boxes

Flow of small real-value charts, one per scale-homogeneous group.

fc_density

(bin centres, density) of values over -1 to 1, binned at FC_BIN and smoothed by a Gaussian of FC_SMOOTH.

build_fc_distributions

Each run’s channel-pair r before and after the regression, pale, with the cohort median; a row per task and chromophore.

no_relation_density

The density r takes across n_runs runs when the two measures are unrelated (Fisher: arctanh r ~ N(0, 1/(n - 3))).

build_fc_movement

Each connection’s r with movement: counted by r beside the spread with no relation, and against the channels’ distance; a row per task.

Data#

API#

nirspipe.qc.figures.subject.group_figures.check_only(col: str) → bool#

Recorded to be checked against, not shown: imu_gyro_speed_gvtd_rho -> True.

nirspipe.qc.figures.subject.group_figures.group_metrics(metric_cols: list[str]) → tuple[list[tuple[str, list[str]]], list[str]]#

Split metric_cols into (groups, ordered_flat) following _METRIC_GROUPS; leftovers -> ‘Other’.

Matching ignores the section prefix, so raw_sci_mean and raw_long_sci_mean both land in the coupling group while staying separate columns. Settings are dropped rather than grouped, so neither the ordering nor the charts carry them, and so are the metrics recorded only to be checked against.

nirspipe.qc.figures.subject.group_figures.SCORE_THRESHOLD = 2.0#
nirspipe.qc.figures.subject.group_figures.metric_family(col: str) → str#

The quantity a column measures, which the outlier score counts once.

"raw_long_gvtd_filt_p95"            ->  "GVTD amplitude"
"motion_post_gvtd_num_above_thresh" ->  "Motion & spike fraction"
"raw_heart_rate"                    ->  "heart_rate"
nirspipe.qc.figures.subject.group_figures.deviation_scores(df: pandas.DataFrame, metric_cols: list[str]) → numpy.ndarray#

Per run, the mean over metric families of each family’s mean |z|.

A quantity the record holds under several stages and channel sets counts once, so a run is not called out for one quantity written down twelve times.

nirspipe.qc.figures.subject.group_figures.detect_outliers(df: pandas.DataFrame, metric_cols: list[str], threshold: float = SCORE_THRESHOLD) → dict[str, list[str]]#

{bids_name: [worst metrics]} for runs whose deviation_scores() is past the threshold.

The metric list is what put the run there, worst first and one column per family, so the reader gets the reason beside the verdict rather than one quantity under six names.

nirspipe.qc.figures.subject.group_figures.build_deviation_strip(df: pandas.DataFrame, metric_cols: list[str]) → tuple[go.Figure | None, list[str]]#

One row per metric, one dot per run at its robust z, colour = channel set.

This is the report’s overview. The metric names are horizontal, the cohort’s spread is the width of its dot cloud, and a run sitting apart is apart on the axis rather than a shade darker.

Returns (figure, dropped): a metric every run agreed on has no z to plot and is named in the report’s notes instead.

nirspipe.qc.figures.subject.group_figures.SMOOTH_S = 60.0#
nirspipe.qc.figures.subject.group_figures.build_window_grid(rows: list[dict], highlight: list[str] | None = None, metrics: tuple = ('sci', 'cv', 'gvtd')) → plotly.graph_objects.Figure | None#

Metric x channel-set grid over time: every run pale, the cohort’s band and median over.

Rows are metrics and columns are channel sets, sharing the y axis along a row so the three sets are read against each other.

highlight names runs that keep a line of their own, one colour each, the same colour in every cell.

nirspipe.qc.figures.subject.group_figures.condition_colours(conditions: list[str]) → dict[str, str]#

One colour per condition, by the rule the run report’s markers already follow.

raw_figures.condition_colors cycles CONDITION_PALETTE over the descriptions in the order they first appear, and a condition keeps the colour it wears there, so a band on this page and a marker on the run report are the same colour for the same block.

nirspipe.qc.figures.subject.group_figures.build_condition_timeline(row: dict, windows: list[tuple[str, float, float]], metrics: tuple = ('sci', 'cv', 'gvtd')) → plotly.graph_objects.Figure | None#

One run’s windowed metrics over time, the conditions shaded behind them.

The channel sets share a panel, where the cohort’s build_window_grid() gives each a column. Long and short only: all is a blend of the two and lands between them.

Smoothed over SMOOTH_S and sampled at that step.

Colours come from the run report rather than from _SET_COLOURS, whose long-channel blue is the one _utils.HBR_COLOR uses; LONG_COLOR and SHORT_COLOR are the separation split every raw-level view already wears.

nirspipe.qc.figures.subject.group_figures.condition_names(rows: list[dict]) → list[str]#

Conditions the cohort has, in the order the first run that carries them wrote them.

nirspipe.qc.figures.subject.group_figures.build_condition_panels(rows: list[dict], highlight: list[str] | None = None) → plotly.graph_objects.Figure | None#

One panel per metric: x is the condition, one line per run, the median over them.

The windows collapsed into the blocks the run was designed around.

nirspipe.qc.figures.subject.group_figures.build_condition_matrix(rows: list[dict], order: list[str] | None = None) → plotly.graph_objects.Figure | None#

run x condition, one panel per metric, colour = robust z inside that condition.

Sorted worst-first when an order is given, so the runs a reader is looking for are at the top.

nirspipe.qc.figures.subject.group_figures.build_channel_condition_matrix(by_condition: dict, window_s: float | None = None) → plotly.graph_objects.Figure | None#

channel x condition for one run, the panels and order of build_condition_panels.

The cohort’s matrix asks which run moved in a condition; a subject has one run per page, so the same question there is which channel moved. The panel list is derived from _CONDITION_METRICS rather than written again, so the two cannot name different metrics under the same heading.

Channels are ordered by how far they move across conditions on the first panel, worst first, and every panel keeps that order so one row reads across all of them.

nirspipe.qc.figures.subject.group_figures.build_grouped_boxes(df: pandas.DataFrame, metric_cols: list[str]) → list[tuple[str, plotly.graph_objects.Figure]]#

Flow of small real-value charts, one per scale-homogeneous group.

Each point carries its bids_name (customdata) so the report can link to it.

nirspipe.qc.figures.subject.group_figures.FC_BIN = 0.02#
nirspipe.qc.figures.subject.group_figures.FC_SMOOTH = 0.04#
nirspipe.qc.figures.subject.group_figures.fc_density(values: numpy.ndarray) → tuple[np.ndarray, np.ndarray]#

(bin centres, density) of values over -1 to 1, binned at FC_BIN and smoothed by a Gaussian of FC_SMOOTH.

nirspipe.qc.figures.subject.group_figures.build_fc_distributions(by_task: dict) → plotly.graph_objects.Figure | None#

Each run’s channel-pair r before and after the regression, pale, with the cohort median; a row per task and chromophore.

by_task is fc_distributions(). None when no task has a run with both matrices.

nirspipe.qc.figures.subject.group_figures.FC_MOVEMENT_BIN = 0.05#
nirspipe.qc.figures.subject.group_figures.no_relation_density(r: numpy.ndarray, n_runs: int) → numpy.ndarray#

The density r takes across n_runs runs when the two measures are unrelated (Fisher: arctanh r ~ N(0, 1/(n - 3))).

nirspipe.qc.figures.subject.group_figures.build_fc_movement(table: pandas.DataFrame) → plotly.graph_objects.Figure | None#

Each connection’s r with movement: counted by r beside the spread with no relation, and against the channels’ distance; a row per task.

table is fc_against_movement(). None when it is empty.