nirspipe.qc.hyper.hyper_report#
Generate hyperscanning group-level raw QC HTML report.
Module Contents#
Functions#
Each member’s own |
|
One value when the members agree, else each member’s: |
|
One entry per metric the members carry a value for, with a cell per member. |
|
One block of the quality table per channel set, laid out by |
|
The blocks of |
|
The members’ IMU summaries as registry rows, for |
|
The dyad raw page’s own member rows, for |
|
The dyad’s own numbers, a column per channel set. |
|
|
|
Per member and pair: the run’s verdict, and each condition’s own result beside it. |
|
The grid’s pair columns, long block first, and the index the short block starts at. |
|
|
|
Methods prose for a dyad: what made the files read, the clock, then the group’s steps. |
|
The dyad’s channel table: one entry per pair, carrying every member’s cells. |
|
Each |
|
The wavelengths the channel table’s header names: the members’, when they agree. |
|
Build hyperscanning post-QC report. |
Data#
API#
- nirspipe.qc.hyper.hyper_report.logger = 'get_logger(...)'#
- nirspipe.qc.hyper.hyper_report.member_sci_lines(sqm_data: dict, subject_ids: list[str]) dict[str, float | None]#
Each member’s own
--sci-threshold, as its screening recorded it; None where none was.{"sub-01": {"screen_cutoffs": {"sci": 0.8}}, "sub-02": {}} -> {"sub-01": 0.8, "sub-02": None}
- nirspipe.qc.hyper.hyper_report.sci_lines_text(lines: dict[str, float | None]) str#
One value when the members agree, else each member’s:
0.80orsub-01 0.80, sub-02 0.70.
- nirspipe.qc.hyper.hyper_report.subject_metric_rows(sqm_data: dict[str, dict], subject_ids: list[str], sci_lines: dict[str, float | None], condition: bool = False, grid_window: float | None = None, colour: bool = True) list[dict]#
One entry per metric the members carry a value for, with a cell per member.
colourFalse leaves every cell’s verdict off, for a set the cutoffs were not drawn for.-> [{"key": "sci_win_mean", "label": "SCI (10 s windows)", "summary": "...", "key_metric": True, "cells": [{"text": "0.91", "cls": "qm-ok"}, ...]}]
Metric-major, the way the page prints it: a metric per row and a member per column, the arrangement the subject report’s own metrics section uses.
No direction arrow. The subject report does not carry one either: which end is better is the registry’s and reaches the reader through the label’s hover text, so a table cannot say one thing and a tooltip another.
- nirspipe.qc.hyper.hyper_report.subject_metric_tables(by_set: dict[str, dict[str, dict]], subject_ids: list[str], sci_lines: dict[str, float | None], condition: bool = False, grid_window: float | None = None) list[dict]#
One block of the quality table per channel set, laid out by
member_metric_table().-> [{"set": "Long", "members": ["sub-01", "sub-02"], "metrics": [{"key", "group", "label", "summary", "key_metric", "cells": [{"text", "cls"}, ...]}, ...]}]
by_setis{set_name: {subject_id: scalars}}.A set is a separate measurement and not a grouping of the same one: GVTD is an RMS across the channels of its set, and a long and a short retention rate are fractions of different montages. So each set is measured and kept on its own, and the page prints it under its own heading.
A montage with no short channel measures one set, and
allandlongare then the same numbers printed twice; it gets a single unheaded block instead. That is also what a caller with no split at all passes, underall. Where the montage splits, only the Long block carries verdicts, as the member’s own table: the cutoffs are drawn for long channels.
- nirspipe.qc.hyper.hyper_report.member_metric_table(tables: list[dict], extra: dict[str, list[dict]] | None = None) dict#
The blocks of
subject_metric_tables()as one table, a channel set over each member.[{"set": "All", "members": ["sub-01", "sub-02"], ...}, {"set": "Long", ...}] -> {"sets": ["All", "Long"], "members": ["sub-01", "sub-02"], "groups": [{"title": "Optical density", "rows": [{"key", "label", "summary", "key_metric", "cells": [All sub-01, All sub-02, Long sub-01, Long sub-02]}]}]}
A metric one set lacks prints a dash in that set’s columns.
extraappends a page’s own rows, cells in the same order, to the group of that title; “Recording” comes first. A single unheaded block gives an emptysets.
- nirspipe.qc.hyper.hyper_report.imu_member_rows(values: dict[str, dict], subject_ids: list[str], n_sets: int, condition: bool = False) list[dict]#
The members’ IMU summaries as registry rows, for
member_metric_table()’sextra.{"sub-01": {"gyro_speed_mean": 1.25}, "sub-02": {}}, n_sets 2 -> [{"key": "gyro_speed_mean", ..., "cells": ["1.25", "—", "", ""]}]
The sensor belongs to no channel set, so each value sits under the first set’s columns and the rest stay blank, as on the subject report. A sensor no member has gets no row.
- nirspipe.qc.hyper.hyper_report.raw_member_rows(member_info: list[dict], motion: dict, subject_ids: list[str], sets: list[str], imu: dict[str, dict] | None = None) dict[str, list[dict]]#
The dyad raw page’s own member rows, for
member_metric_table()’sextra.setsare the table’s set headings; an empty list is an unsplit montage, whose one column group reads every pair and the motion pass’s only set.imuis each member’s scalars, of which the IMU summaries are printed.
- nirspipe.qc.hyper.hyper_report.dyad_metric_table(sqm: dict, sets: list[str]) dict#
The dyad’s own numbers, a column per channel set.
-> {"columns": ["All", "Long", "Short"], "rows": [{"label": "Pairs good in every member", "cells": [{"text": "14 / 26", "cls": ""}, ...]}, ...]}
The pair counts and the motion figures’ numbers. Colour sits on the long set, as in the subject report; an unsplit montage has one column and colours it.
- nirspipe.qc.hyper.hyper_report.member_condition_entries(subject_sqm: dict, subject_ids: list[str], windows: list[tuple[str, float, float]], offsets: dict[str, float] | None = None, sfreq: float | None = None, refused: dict | None = None) dict[str, dict[str, dict]]#
{sid: {label: by_condition entry}}for every dyad window a member’s record holds.windows [("ca", 30.0, 190.0)], sub-02 offset 37.0, its record's ca at [67.0, 227.0] -> {"sub-01": {"ca": {...}}, "sub-02": {"ca": {...}}}
A member whose record has no
by_conditionsection is absent.refused, when given, gains{label: {sid: (start, end)}}, the record’s window on the aligned clock, for each window that holds the label at bounds other than the dyad’s.
- nirspipe.qc.hyper.hyper_report.condition_channel_status(subject_sqm: dict, subject_ids: list[str], entries: dict[str, dict[str, dict]], bad_channels: dict[str, list[str]] | None) dict[str, dict]#
Per member and pair: the run’s verdict, and each condition’s own result beside it.
-> {"sub-01": {"run": {"S5_D5"}, "line": 0.7, "conditions": {"cb": {"S3_D3": (0.5, True), "S1_D1": (1.0, False)}}}}
A condition’s tuple is
(passing share, failing), folded from the two wavelengths of a pair: the lower share, and failing when either is in the entry’sbad_channels. That assessment rejects nothing;runis the set every coherence was computed on.
- nirspipe.qc.hyper.hyper_report.condition_status_axis(aligned_raws: dict[str, mne.io.Raw], subject_ids: list[str], sep_bands=None) tuple[list[str], int | None]#
The grid’s pair columns, long block first, and the index the short block starts at.
sub-01 long S1..S5 short S6, sub-02 the same -> (["S1_D1", ..., "S6_D6"], 5)
- nirspipe.qc.hyper.hyper_report.condition_subject_metrics(subject_sqm: dict, subject_ids: list[str], windows: list[tuple[str, float, float]], sci_lines: dict[str, float | None], offsets: dict[str, float] | None = None, sfreq: float | None = None) dict#
{condition: tables}for the per-subject quality table, one entry per window.Each value is what
subject_metric_tables()returns, one table per channel set.Every number is read out of each member’s
by_conditionrecord section, whichcondition_sections()wrote once after that member’s pipeline finished. Nothing is measured here and nothing is sliced a second time, so a channel’s SCI under one condition cannot differ between a subject page and a dyad page.It reports, it does not re-decide. The coherence on a condition’s page was computed on the channel set the whole recording was screened into, so these rows say how the channels held up over this stretch, and the set they were drawn from is the run’s.
A member whose record predates the section contributes nothing and its column reads as absent, which is the honest answer: the values cannot be recovered from the whole-run scalars.
- nirspipe.qc.hyper.hyper_report.MIN_BAND_CYCLES = 4.0#
- nirspipe.qc.hyper.hyper_report.group_methods(read: list[str], group_nirs: pathlib.Path, label: str, align_info: dict, desc: str | None, versions: dict[str, str], notes: list, scope: str) dict[str, str]#
Methods prose for a dyad: what made the files read, the clock, then the group’s steps.
readis the member files the inter-brain measures were computed on. Each is followed up its ownSources, so a run that readdesc-preprocis not described as filtered because a later stage of the same recording was. The paragraph describes one chain: members processed differently get a note naming the one it describes, and a chain that cannot be read is named by its stage rather than guessed.
- nirspipe.qc.hyper.hyper_report.decision_rows(sqm_data: dict, subject_ids: list[str]) list[dict]#
The dyad’s channel table: one entry per pair, carrying every member’s cells.
-> [{"pair": "S1_D1", "separation": "long", "by_sub": {"sub-01": {"sci": "0.956", "sci_cls": "", ...}, "sub-02": {...}}}]
Grouped by channel rather than by member, because that is the comparison the page is for: a pair’s two members sit side by side in one row. Every string and every cell class is built here by the functions the subject report and the raw viewer use, so the dyad’s cells and the member’s own report cannot disagree; the page’s script only lays them out.
A member with no per-channel section contributes no cells rather than a row of dashes, and the pair order is the first member that has one.
- nirspipe.qc.hyper.hyper_report.dyad_region_table(sqm_data: dict, subject_ids: list[str], roi_map: dict | None) dict#
Each
--roi-mappingregion’s long channels kept, a column per member:{"rows", "notes"}.-> {"rows": [{"region": "r_tpj", "cells": [{"text": "5 of 5", "cls": "", "rejected": ""}, {"text": "0 of 5", "cls": "bad", "rejected": "S10_D10, ..."}]}], "notes": ["sub-201: listed but not counted ... S5_D5 (short)."]}
Read from each member’s raw QC record, under the verdicts its own channel table shows.
- nirspipe.qc.hyper.hyper_report.decision_wavelengths(sqm_data: dict, subject_ids: list[str]) list[str]#
The wavelengths the channel table’s header names: the members’, when they agree.
- nirspipe.qc.hyper.hyper_report.build_hyper_report(group_id: str, task: str, group: list[nirspipe.io.groups.GroupEntry], sqm_data: dict[str, dict], aligned_raws: dict[str, mne.io.Raw], offsets: dict[str, float], output_dir: pathlib.Path, raw_raws: dict[str, mne.io.Raw] | None = None, od_raws: dict[str, mne.io.Raw] | None = None, intensity_raws: dict[str, mne.io.Raw] | None = None, after_raws: dict[str, mne.io.Raw] | None = None, imu: dict[str, dict[str, tuple]] | None = None, full_raws: dict[str, mne.io.Raw] | None = None, full_after: dict[str, mne.io.Raw] | None = None, session: str | None = None, sep_bands=None, roi_map: dict | None = None) pathlib.Path#
- nirspipe.qc.hyper.hyper_report.build_hyper_post_report(group_id: str, task: str, group: list[nirspipe.io.groups.GroupEntry], aligned_raws: dict[str, mne.io.Raw], offsets: dict[str, float], output_dir: pathlib.Path, roi_map: dict[str, list[str]] | None = None, roi_map_name: str = 'custom', bad_channels: dict[str, list[str]] | None = None, subject_sqm: dict[str, dict] | None = None, wtc_fmin: float = 0.004, wtc_fmax: float = 0.2, wtc_band_fmin: float | None = None, wtc_band_fmax: float | None = None, wtc_significance: bool = False, wtc_seed: int | None = None, wtc_mc_count: int = 300, wtc_channel_cross: bool = False, wtc_by_condition: bool = False, wtc_window_s: float | None = None, wtc_cond_pad_s: float | None = None, wtc_cond_cone: bool = True, cond_margins: dict | None = None, wtc_limit_scales: bool = True, wtc_save_maps: bool = False, wtc_mask_coi: bool = True, wtc_roi_min_channels: int = ROI_MIN_CHANNELS, wtc_arrow_min: float | None = None, wtc_chroma: tuple[str, ...] | list[str] = ('hbo', 'hbr'), wtc_whiten_s: float = 0.0, wtc_nulls: dict | None = None, wtc_phase_null: int = 0, wtc_phase_null_cross: bool = False, isc_threshold: float | None = None, isc_whiten_s: float = 0.0, isc_max_lag_s: float = 0.0, isc_band: tuple[float | None, float | None] | None = None, isc_phase_null: int = 0, phase_null_shared: bool = False, sep_bands=None, cond_windows: list[tuple[str, float, float]] | None = None, analysis_window: tuple[float, float] | None = None, no_report: bool = False, result: HyperPostResult | None = None, desc: str | None = None, bads_scope: str | None = None, bads_scope_tasks: list[str] | None = None, session: str | None = None, wtc_device=None, unread_flags: list[tuple[str, str]] | None = None) Path | None#
Build hyperscanning post-QC report.
- Sections:
Per-channel WTC: Morlet wavelet coherence, one heatmap per channel
Per-ROI WTC: the member channels’ maps averaged cell by cell (when roi_map given)
- Cross matrices: band-mean coherence per channel pair and per ROI pair, HbO
beside HbR on one scale (when wtc_channel_cross)
- ISC: inter-brain Pearson r, a ROI × ROI heatmap (when roi_map
given) and then per chromophore a channel heatmap beside its connectogram, whose arcs are chosen by _arc_rule
Each WTC map is also collapsed to one number per channel over [wtc_band_fmin, wtc_band_fmax] and written as a TSV under the group’s nirs/, so a group analysis reads the same values the figures were drawn from.
wtc_channel_crosscrosses every long channel with every other, n channels giving n^2 rows instat-wtc_relmat.tsvinstead of n. The extra pairs reach the TSV, the crossed matrix and the map selectors, whose second selector picks the partner’s channel. Crossing is also what produces the ROI × ROI matrix, since the ROI numbers are grouped from the channel ones.wtc_by_conditionrepeats the whole coherence analysis inside each task annotation’s own window, on top of the whole-run pass, which stays as it was. The band means of every window land instat-wtc_relmat.tsvbeside the whole run’s, told apart by aconditioncolumn (n/aon the whole run’s rows), and each window gets its own figures. Seecondition_windows()for how a window is decided, and note that the runtime is roughly doubled: the windows together are about one more pass over the recording.cond_windowssupplies those windows instead of resolving them here. The caller passes the same list to the phase-scrambled null, and the two tables can only be subtracted row by row if they describe the same windows. Left at None the windows are resolved here, which is what a caller that writes no null wants.analysis_windowis--tstart/--tend: the stretch the whole-run pass reports on. It is taken out of the transform of the whole recording, the way a condition window is, so a run restricted to a window carries the recording’s cone of influence rather than two edges of its own. The recordings themselves are never cut.wtc_cond_pad_stransforms each condition on its own instead of reading it out of the whole-run transform, over a cut padded by that many seconds on each side. Left at None, which is the default, conditions are windowed out of the whole-run transform. See_transform_condition(): with adequate padding the two give the same number, so this exists for a caller who wants per-condition transforms, and 0 gives the unpadded cut. Costs one transform per condition per chromophore.wtc_cond_coneadds each condition’s own cone at its start and end, read offcond_marginsfor windows cut out of a condition; seecondition_cone().wtc_mask_coileaves the cone of influence out of each band mean. On by default; the share outside the cone is reported either way asn_valid_frac.wtc_chromais the chromophores to run, some of("hbo", "hbr", "hbt"); HbO and HbR are the default. Each costs a full pass, since they are the same computation run once each: a member’s HbO pairs only with the other member’s HbO, and they are never mixed and never averaged. HbT has to be onaligned_rawsalready. Every band-mean table gains achromophorecolumn rather than splitting per chromophore, the tables being long-format. The figures are keyed by chromophore instead and the page carries all of them, switched together by one control;wtc_chroma[0]is only what the page opens on.wtc_save_mapswrites the full time-frequency maps beside the tables as.npz, one per chromophore, so a different band can be averaged later without a second wavelet transform. Seenirspipe.pipeline.hyper.wtc_store.wtc_limit_scalescomputes only the scales inside[wtc_fmin, wtc_fmax]plus margin, which is most of the runtime and, given that the scales land on pycwt’s own grid and the margin exceeds the scale-smoothing window, reproduces the unrestricted coherences bit for bit.resultis an already-computedHyperPostResult. Passed one, this draws it and runs no transform, which is how a page is rebuilt after a figure or a caption changes without paying for the wavelet pass again. Left at None the analysis is run here from thewtc_*arguments, which is what the CLI does. The arguments that only describe the analysis are then ignored, since the result already carries what they resolved to.wtc_arrow_minis the coherence a cell has to reach before its phase arrow is drawn when no Monte Carlo level was computed. Display only: no table or figure value changes with it.NonetakesARROW_MIN_COHERENCE.wtc_nullsis whatrun_wtc_null()drew, withwtc_phase_nullandwtc_phase_null_crossthe iteration count and crossing it was drawn with. Its table is written here, once the real tables it is ranked against exist and before the provenance diagram is drawn, so the diagram lists it on the first run.