nirspipe.pipeline.hyper.group_quality#
What a group’s members are worth: rejected channels, screening, and the dyad’s record.
Reads group_io; nothing reads this. Everything that reduces two
members to one answer applies the same rule: a dyad’s channel is usable only while it is
passing in both of them.
Module Contents#
Functions#
Write the rejected channels the inter-brain metrics actually excluded, one row each. |
|
Every member’s channel positions on their own template in one table, with subject_id and space columns. |
|
Mark each subject’s rejected channels bad on their Raw, in place. |
|
The member’s raw QC record for the recording |
|
Each member’s raw QC record in the dyad page’s shape, and the dyad’s two quality tables. |
|
Load per-subject SQM scalars and channel metrics from derivatives. |
|
The separation bands a dyad’s inter-brain metrics run on, read off the members’ records. |
Data#
API#
- nirspipe.pipeline.hyper.group_quality.logger = 'get_logger(...)'#
- nirspipe.pipeline.hyper.group_quality.write_group_bads(output_dir: pathlib.Path, group: list[nirspipe.io.groups.GroupEntry], sqm_by_subject: dict[str, dict], bads_scope: str, session: str | None = None) pathlib.Path#
Write the rejected channels the inter-brain metrics actually excluded, one row each.
The channel set is a decision that changes every coherence value, so it is written here rather than only logged. Columns: group_id, task, subject_id, channel, bads_scope, rejected_in.
rejected_inlists the runs whose quality metrics rejected the channel, which under--bads-scope subjectis how a condition that was clean on its own comes to lose a channel.
- nirspipe.pipeline.hyper.group_quality.write_group_channel_coords(derivatives_dir: pathlib.Path, output_dir: pathlib.Path, group: list[nirspipe.io.groups.GroupEntry], desc: str, session: str | None = None) pathlib.Path#
Every member’s channel positions on their own template in one table, with subject_id and space columns.
Kept per member, since two caps need not sit alike and two members need not share a head (a parent and an infant); a figure wanting one position per channel averages members on one template. Each member’s rows are prep’s record for the run this group reads, and a member whose tree predates that record is refused. The name carries the space when every member shares it, and none otherwise.
sub-A rows S1_D1 hbo ... + sub-B rows S1_D1 hbo ... -> group-G1_task-rest_space-fsaverage_channels.tsv: subject_id space name x y z aparc ...
- nirspipe.pipeline.hyper.group_quality.apply_group_bads(raws: dict[str, mne.io.Raw], sqm_by_subject: dict[str, dict]) None#
Mark each subject’s rejected channels bad on their Raw, in place.
Not because the file lacks the marks: every derivative’s sidecar carries
bad_channelsandread_snirfrestores them. It is--bads-scopethat needs this. A per-file sidecar can only name what that run rejected, whilesubjectscope is the union over every run the subject has, which no single file knows. Marking the union here is what makes WTC, ISC and the report rest on the one channel set the scope chose, sincelong_channel_picksdrops bads.The record names channels by wavelength (“S6_D5 760”), a haemoglobin Raw by chromophore (“S6_D5 hbo”). Both reduce to the S-D label, which is the key every inter-brain metric already matches on, so a pair rejected at either wavelength is marked at both chromophores.
{"sub-A": raw} + {"sub-A": {"bad_channels": ["S6_D5 760", "S6_D5 850"]}} -> raw.info["bads"] == ["S6_D5 hbo", "S6_D5 hbr"]
- nirspipe.pipeline.hyper.group_quality.member_raw_record(output_dir: pathlib.Path, entry: nirspipe.io.groups.GroupEntry, raw: mne.io.Raw) tuple[Path, dict]#
The member’s raw QC record for the recording
rawholds, as(path, record).Matched by the recording its Sources name rather than by label, so a member with several runs of a task gets the record of the run the pairs table chose. Refused when there is none, or when it predates records that carry the respiration band among their parameters.
- nirspipe.pipeline.hyper.group_quality.load_group_sqm_raw(output_dir: pathlib.Path, group: list[nirspipe.io.groups.GroupEntry], raws: dict[str, mne.io.Raw], records: dict[str, tuple[Path, dict]], session: str | None = None) dict[str, dict]#
Each member’s raw QC record in the dyad page’s shape, and the dyad’s two quality tables.
The verdict, the screening lines and the cardiac band are each member’s own, as the participant level recorded them, so nothing is screened here and a parent-child dyad keeps two bands.
recordsismember_raw_record()per member.- Writes two TSVs under group-{gid}/nirs/, where a subject’s own tables sit:
group-{gid}_task-{task}_desc-subject_qc.tsv: one row per subject (scalars) group-{gid}_task-{task}_desc-channel_qc.tsv: one row per subject × channel
Returns {subject_id: sqm_dict} for the HTML report, with
screen_cutoffs,screen_bandandparametersbeside the record’s own numbers.
- nirspipe.pipeline.hyper.group_quality.load_group_sqm(output_dir: pathlib.Path, group: list[nirspipe.io.groups.GroupEntry], bads_scope: str = 'run', scope_tasks: list[str] | None = None) dict[str, dict]#
Load per-subject SQM scalars and channel metrics from derivatives.
A subject has one record and one channel-metrics CSV per run, and every entry names the task it belongs to, so the run’s own files are the ones read. Reading all of them and letting the last win would analyse every task with the last task’s rejected channels.
bads_scopedecides what counts as a bad channel:"run": this task’s own rejections, matching the rest of the metrics returned here."subject": the union over the subject’s runs, so a channel rejected in any condition is rejected in all of them. Conditions then rest on the same channel set, at the cost of losing a channel everywhere because one segment was bad.
scope_tasksbounds that union to the tasks the analysis covers, normally the ones the pairs table names. Without it the union is everydesc-scisidecar in the folder, so a subject who also sat a resting run, or a second experiment, loses channels here for a recording nobody asked about.A recording preprocessed whole is screened once, so the subject has one run per task and the union over it is itself:
subjectandrunthen name the same set, and a line in the log says so. They differ when the conditions were cropped to separate tasks before prep.Returns {subject_id: sqm_dict}. Alongside the flattened scalars each dict carries
windowed(the record’s channel-by-window matrices, their row names beside them),per_channel(the whole per-channel section, which the dyad’s channel table prints),screen_cutoffs(the lines that run screened by) andby_condition(the record’s per-condition entries), which is what a per-condition view of the dyad pages is built from.
- nirspipe.pipeline.hyper.group_quality.resolve_group_bands(group: list[nirspipe.io.groups.GroupEntry], group_sqm: dict[str, dict], override: dict | None = None) tuple[float, float, float | None]#
The separation bands a dyad’s inter-brain metrics run on, read off the members’ records.
nirspipe-hyperworks on derivatives that prep has already split into long and short channels and stamped with the bands it split them by, so the bands are read back rather than taken again from the command line.nirspipe-qc’s group level is not a caller: it takes each member’s bands from that member’s raw QC record.Two members are two prep runs, so they can disagree. That is refused, not reconciled: the bands also chose what short-channel regression removed from each member upstream, so a band derived from both would describe neither.
overrideis the three flags as{"short_max_dist": ..., "long_min_dist": ..., "long_max_dist": ...}in metres, None for one left off. A value given wins and is logged as forced; one left off falls back to the records, not to the package default, so capping the long band does not silently re-assert the other two. An upper bound the records carry therefore cannot be switched off from the command line, which needs a re-run of prep.A member whose record carries no stamp reads back as the defaults. That is a guess rather than a fact, so it is warned about and does not count towards agreement.