nirspipe.qc.subject.group_writer#

Cohort-level QC aggregation: glob per-subject (or per-group) SQM JSONs into TSV + an HTML viewer with heatmap / boxplots / sortable table / outlier panel.

Module Contents#

Functions#

condition_rows

One row per condition of a run, its values under the cohort table’s column names.

unfinished_subjects

Runs whose last invocation failed or never wrote its outcome, one per run record, raw QC’s too.

channels_kept

How many subjects kept each source-detector pair, per task: {"tasks", "rows"}, empty without a channel table.

swapped_label_tasks

Each task whose runs mostly read as if the two wavelength labels were swapped.

optode_losses

Each optode’s long channels rejected over the runs of each task, pooled: {"tasks", "rows"}, empty without a channel table.

region_losses

The runs of each task in which an --roi-mapping region kept no long channel: {"tasks", "rows"}, empty without a map or a channel table.

fc_distributions

Each run’s channel-pair r over its kept long channels, before and after the regression, per task.

fc_against_movement

Each connection’s r, across the runs of a task, between a run’s head movement and its FC.

rows_to_dataframe

Scalar-only table from full SQM records, one row per run, columns sorted.

dyad_page

The dyad cohort page’s name when the tree holds dyad records, which build that page next.

build_group_raw_report

Aggregate all sub-XX/nirs/…desc-sqm_qc.json into desc-subjects_{qc.tsv,report.html}.

Data#

API#

nirspipe.qc.subject.group_writer.logger = 'get_logger(...)'#
nirspipe.qc.subject.group_writer.SMALL_COHORT_N = 5#
nirspipe.qc.subject.group_writer.condition_rows(row: dict) → list[dict]#

One row per condition of a run, its values under the cohort table’s column names.

nirspipe.qc.subject.group_writer.unfinished_subjects(output_dir: pathlib.Path) → list[dict]#

Runs whose last invocation failed or never wrote its outcome, one per run record, raw QC’s too.

sub-01/logs/sub-01.toml        [outcome] status = "failed"   ->  listed, with its error
sub-02/logs/sub-02.toml        [outcome] status = "success"  ->  left out
sub-03/logs/sub-03_ses-2.toml  no [outcome] (killed)         ->  listed as sub-03_ses-2
nirspipe.qc.subject.group_writer.channels_kept(output_dir: pathlib.Path) → dict#

How many subjects kept each source-detector pair, per task: {"tasks", "rows"}, empty without a channel table.

sub-01 keeps S1_D1 in run 1 only, sub-02 rejects it  ->  S1_D1  task-rest  1/2

A subject keeps a pair when any of its runs of the task did, sessions included; the count is over the subjects whose runs of the task list the pair.

nirspipe.qc.subject.group_writer.swapped_label_tasks(full_rows: list[dict]) → list[dict]#

Each task whose runs mostly read as if the two wavelength labels were swapped.

[{"task": "task-rest", "runs": [names], "n": runs with a verdict}], a task listed when more than half of its runs with a verdict read swapped (labels_look_swapped()). A label error belongs to a device or a converter, so it shows in most runs; one run alone can read swapped by chance.

nirspipe.qc.subject.group_writer.optode_losses(output_dir: pathlib.Path) → dict#

Each optode’s long channels rejected over the runs of each task, pooled: {"tasks", "rows"}, empty without a channel table.

run 1 rejects S1_D1 and S1_D2, run 2 rejects neither  ->  S1  task-rest  50% (2/4)

Short channels are left out, as on each run’s optode map.

nirspipe.qc.subject.group_writer.region_losses(output_dir: pathlib.Path, roi_map: dict[str, list[str]] | None) → dict#

The runs of each task in which an --roi-mapping region kept no long channel: {"tasks", "rows"}, empty without a map or a channel table.

run 1 keeps 0 of L's 2 long channels, run 2 keeps 1  ->  L  task-rest  1/2

A run whose recording has none of the region’s long channels counts as keeping none, since the region drops out of its region outputs either way. Each cell carries the runs it counts under runs.

nirspipe.qc.subject.group_writer.fc_distributions(output_dir: pathlib.Path) → dict#

Each run’s channel-pair r over its kept long channels, before and after the regression, per task.

{task: {"runs": [label, ...], "values": {(chromophore, "before"|"after"): [r per run]}}}, read from the residual’s channel matrix and the one written beside it on the series the regression started from (_desc-<stage>_relmat.tsv); a run without the second ran no regression and is left out. Long and kept are read off the run’s channel table.

nirspipe.qc.subject.group_writer.FC_MOVEMENT_MIN_RUNS = 5#
nirspipe.qc.subject.group_writer.FC_MOVEMENT_COLUMNS = None#
nirspipe.qc.subject.group_writer.fc_against_movement(output_dir: pathlib.Path, full_rows: list[dict]) → pandas.DataFrame#

Each connection’s r, across the runs of a task, between a run’s head movement and its FC.

One row per task, chromophore and pair of kept long channels that at least FC_MOVEMENT_MIN_RUNS runs share; the columns are FC_MOVEMENT_COLUMNS. Movement is each record’s gvtd_filt_mean on its long set, FC the run’s channel matrix after the regression. Runs pool by task, connections match by channel name.

3 runs keep S1_D1 and S2_D2, movement 1, 2, 3, FC z 0.1, 0.2, 0.3  ->  r 1.0
nirspipe.qc.subject.group_writer.rows_to_dataframe(full_rows: list[dict]) → pandas.DataFrame#

Scalar-only table from full SQM records, one row per run, columns sorted.

nirspipe.qc.subject.group_writer.dyad_page(output_dir: pathlib.Path) → str | None#

The dyad cohort page’s name when the tree holds dyad records, which build that page next.

nirspipe.qc.subject.group_writer.build_group_raw_report(output_dir: pathlib.Path, roi_map: dict[str, list[str]] | None = None) → pathlib.Path | None#

Aggregate all sub-XX/nirs/…desc-sqm_qc.json into desc-subjects_{qc.tsv,report.html}.