nirspipe.qc.common.report_shell#
The page shell every QC report is rendered into, and the variables that fill it.
templates/_report_base.html.j2 owns the document: head, nav bar, rating bar, the four
closing sections and the tab script. A report template extends it and fills
{% block content %}. This module builds what that shell reads, so what a report header
shows and what its footer carries is decided once instead of once per builder.
Three groups of helpers:
guard()/note()collect what a section failed at and what it skipped on purpose, both of which the footer prints.page_vars()fills the head and the nav bar.footer_vars()fills the footer: errors, the provenance table, the Methods prose and the version table.
Module Contents#
Functions#
A stylesheet from |
|
Run a report section, and on failure record it instead of losing the whole report. |
|
Record something the report leaves out on purpose. |
|
Which rows of an index table sit apart from the others on one metric. |
|
The environment the reports render in, the globals every template may call included. |
|
Variables the shell’s head and nav bar read. |
|
The entries of a report’s top bar, from the sections that report drew. |
|
One row per output: what it is, what made it, and what that step did. |
|
Outputs whose step said the same thing with the same settings share one row. |
|
One line per distinct message, in first-seen order, counted when it repeats. |
|
Variables the shell’s four closing sections read. |
Data#
API#
- nirspipe.qc.common.report_shell.logger = 'get_logger(...)'#
- nirspipe.qc.common.report_shell.TEMPLATE_DIR = None#
- nirspipe.qc.common.report_shell.stylesheet(name: str) str#
A stylesheet from
templates/, read once per process.
- nirspipe.qc.common.report_shell.TOKENS_CSS = 'stylesheet(...)'#
- nirspipe.qc.common.report_shell.LOOK_CSS = 'stylesheet(...)'#
- nirspipe.qc.common.report_shell.FOOTER_CSS = 'stylesheet(...)'#
- nirspipe.qc.common.report_shell.guard(label: str, errors: list, scope: str)#
Run a report section, and on failure record it instead of losing the whole report.
scopeis what the run is called in the log:sub-01,group-G01_task-main.
- nirspipe.qc.common.report_shell.note(notes: list, scope: str, message: str) None#
Record something the report leaves out on purpose.
Kept apart from the errors list: a section skipped because the run does not carry what it needs is a property of the data, not a failure, and it reads as one in the report and in the run log. The caller decides what is worth a note; nothing here is fatal.
- nirspipe.qc.common.report_shell.OUTLIER_Z = 3.5#
- nirspipe.qc.common.report_shell.outlier_flags(values: list[float | None], z: float = OUTLIER_Z) list[bool]#
Which rows of an index table sit apart from the others on one metric.
[0.96, 0.95, 0.96, 0.40, 0.97] -> [False, False, False, True, False]
Scaled by the median absolute deviation, so the row being looked for cannot widen the scale that is meant to catch it. Under four rows there is nothing to compare against, which is why a two-condition design gets no flags at all.
A column whose rows agree exactly has a zero MAD, which would divide by nothing. The mean deviation takes over there: it is zero only when every row agrees, and otherwise still marks the single row standing away from a set that agrees with itself.
- nirspipe.qc.common.report_shell.template_env(**options: Any)#
The environment the reports render in, the globals every template may call included.
Globals rather than variables each builder passes, so a template can use a paragraph or a nav bar that another already has without being wired for it.
section_noteis not to be confused withnote()above, which collects what a section skipped.
- nirspipe.qc.common.report_shell.page_vars(*, title: str, heading: str, nav_meta: list[tuple[str, str]] | None = None, nav_note: str = '', css: str | None = None) dict#
Variables the shell’s head and nav bar read.
- page_vars(title=”nirspipe Hyper Raw Report - G01 / main”,
heading=”nirspipe Hyper Raw Report”, nav_meta=[(“group”, “G01”), (“task”, “main”)], nav_note=”SCI thr: 0.80”)
nav_metaprints aslabel: <b>value</b>chips in run order;nav_noteis the right-aligned line, which is where the parameters a reader needs to judge the numbers belong.cssreplaces the look, for a report that needs one of its own; the shared tokens come before it and the footer’s own sheet after, either way, because neither belongs to a look. Every report in the package leaves it alone, there being one look.
- nirspipe.qc.common.report_shell.CLOSING_SECTIONS = (('Provenance', 'Provenance'), ('Methods', 'Methods'))#
- nirspipe.qc.common.report_shell.NAV_SHORT = None#
The entries of a report’s top bar, from the sections that report drew.
nav_bar([("Motion", "Motion"), ("GLM", "GLM")], key="__sub-01_task-main", index="sub-01_desc-index_report.html") -> Summary | Motion GLM | Provenance Methods | <- All runs
A section is
(id, name), anchored at#id, or(id, name, href)where the anchor is spelled differently from the id a verdict is filed under;Noneis a divider between two runs of them.keyis appended to every ratable id, so a subject’s runs do not file one verdict between them, andrated=Falsedrops the pills, which is what a page summarising other pages wants.groupstamps one run’s entries on a viewer holding several.siblingsare the pages read alongside this one, as{label, href, current}, andindexthe page above it.summary=""drops the leading entry, for an index page whose first section is its summary. The skeleton lives here rather than in each template.
- nirspipe.qc.common.report_shell.provenance_rows(nirs_dir: pathlib.Path, *, scope: str = '', errors: list | None = None, label: str | None = None) list[dict]#
One row per output: what it is, what made it, and what that step did.
The diagram carries the topology; this carries the narrative, which does not fit in a node box. Both come from the same sidecars, so this works on a subject’s
nirs/and on a group’s alike.
- nirspipe.qc.common.report_shell.merge_provenance_rows(rows: list[dict]) list[dict]#
Outputs whose step said the same thing with the same settings share one row.
Twelve FC matrices from one
fcstep become one row with twelve names, so the table reads one line per thing that happened.familyis the names’ shared first word when more than two merge (relmatfor everyrelmat ...), else empty.
- nirspipe.qc.common.report_shell.collapse_messages(messages: list[str]) list[str]#
One line per distinct message, in first-seen order, counted when it repeats.
[“Channel S1_D1: no data”, “Channel S1_D2: no data”] stays two lines; the same message twice becomes one line ending in “ (x2)”, so a per-channel section that fails the same way on every channel prints one line rather than one per channel.
Public because the raw viewer prints its own lists: it renders in JavaScript and can never share the footer’s markup, but the strings it renders come from here.
Variables the shell’s four closing sections read.
Only the keys a report has something to say about are returned, and the shell skips a section whose key is absent. Passing
errorsgets the errors block even when the list is empty, because “no errors” is itself worth printing; passingnirs_dirgets the provenance table,methodsthe Methods tabs,versionsthe version table.