nirspipe.qc.subject.subject_index#

Subject-level landing page: one row per run, linking to that run’s QC report.

Every QC figure is per run, so the subject report is an index rather than a report. What it adds on top of the links is the three things no single run can show: which run stands apart from the subject’s others on each metric, which channels were rejected in which run (the set --bads-scope subject unions), and, for a run driven with --by-condition, its conditions side by side.

The rows are read back off disk from the records the run already wrote, so this needs nothing held in memory and can be rebuilt for a past output tree.

The Conditions section covers per-condition views only, the by_condition block a whole-run pass leaves in its record. A tree cropped per condition first is already listed above, one run per condition, and belongs there rather than here: its numbers are not comparable with a view’s, so the two must not share a table. See nirspipe.qc.subject.condition_views.

Module Contents#

Functions#

collect_bad_channels

Which source-detector pair each run rejected, over all of the subject’s runs.

collect_runs

One row per run under sub_dir, newest BIDS entity order, for the index table.

run_headings

Each run’s short name: its task, plus whichever other entities tell the runs apart.

collect_conditions

One group per run carrying per-condition views, each a whole-run row and its windows.

write_condition_figures

Write the Conditions figures and return what the template needs to embed them.

collect_combined

Each --combine-runs series of the subject: its label, the runs it joined, its FC tables.

combined_run_rows

One row per joined run: its duration, the seconds kept outside BAD_ spans, its rejected pairs.

write_combined_figures

The joined series’ run table, carpet, channel FC panel and ROI matrix, drawn as a run report draws them.

write_subject_index

Render sub-<subject>_desc-index_report.html as the index over the subject’s per-run reports.

Data#

API#

nirspipe.qc.subject.subject_index.logger = 'get_logger(...)'#
nirspipe.qc.subject.subject_index.collect_bad_channels(sub_dir: pathlib.Path, labels: list[str]) → dict#

Which source-detector pair each run rejected, over all of the subject’s runs.

Read from each run’s channel table, which carries one is_bad per channel: the pipeline’s _desc-channel_qc.tsv, else raw QC’s _desc-rawchannel_qc.tsv. The two wavelengths of a pair are collapsed into the pair: rejecting one rejects the optode.

Returns {"rejected": [{"pair", "bad_in", "n_bad"}], "clean", "n_pairs", "n_clean"}. Only the rejected pairs get a row, ordered by how many runs rejected them and then by the montage order the CSV is written in; the pairs that survived are listed in clean. An empty dict when no run wrote the file.

nirspipe.qc.subject.subject_index.collect_runs(sub_dir: pathlib.Path) → list[dict]#

One row per run under sub_dir, newest BIDS entity order, for the index table.

nirspipe.qc.subject.subject_index.run_headings(entities: list[dict]) → list[str]#

Each run’s short name: its task, plus whichever other entities tell the runs apart.

[{task: rest, acq: a}, {task: rest, acq: b}]  ->  ["rest acq-a", "rest acq-b"]
nirspipe.qc.subject.subject_index.collect_conditions(sub_dir: pathlib.Path) → list[dict]#

One group per run carrying per-condition views, each a whole-run row and its windows.

A group is {"label", "task", "windows", "by_condition", "record", "rows", "columns"}, rows open with the run itself so a condition is read against the whole it was cut from. Runs without a by_condition block contribute nothing, which is what a tree produced without --by-condition, or cropped per condition first, looks like.

nirspipe.qc.subject.subject_index.write_condition_figures(sub_dir: pathlib.Path, subject: str, groups: list[dict]) → dict#

Write the Conditions figures and return what the template needs to embed them.

Three pictures, all of them builders the group report already owns: the profile over every run at once, and then per run a channel-by-condition matrix and a timeline. The profile takes the runs together because that is the comparison it is for; the other two are of one run’s channels and one run’s clock and cannot be pooled.

nirspipe.qc.subject.subject_index.collect_combined(sub_dir: pathlib.Path) → list[dict]#

Each --combine-runs series of the subject: its label, the runs it joined, its FC tables.

sub-01_task-rest_desc-errts_nirs.snirf joined from run-01 and run-02

-> {"label": "sub-01_task-rest", "runs": [...], "channel": {"hbo": path, ...}}

nirspipe.qc.subject.subject_index.combined_run_rows(series: pathlib.Path, raw) → list[dict]#

One row per joined run: its duration, the seconds kept outside BAD_ spans, its rejected pairs.

run-02 starting at 300 s of a 10 Hz joined series 500 s long

-> {"run": "run-02", "onset_s": 300.0, "duration_s": 200.0, "kept_s": 180.0, "rejected": ["S1_D2"]}

nirspipe.qc.subject.subject_index.write_combined_figures(sub_dir: pathlib.Path, item: dict, roi_map: dict | None = None) → dict#

The joined series’ run table, carpet, channel FC panel and ROI matrix, drawn as a run report draws them.

nirspipe.qc.subject.subject_index.write_subject_index(subject: str, sub_dir: pathlib.Path, run_command: str, mode: str | None = None, roi_map: dict | None = None) → pathlib.Path | None#

Render sub-<subject>_desc-index_report.html as the index over the subject’s per-run reports.