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#

stylesheet

A stylesheet from templates/, read once per process.

guard

Run a report section, and on failure record it instead of losing the whole report.

note

Record something the report leaves out on purpose.

outlier_flags

Which rows of an index table sit apart from the others on one metric.

template_env

The environment the reports render in, the globals every template may call included.

render

page_vars

Variables the shell’s head and nav bar read.

nav_bar

The entries of a report’s top bar, from the sections that report drew.

provenance_rows

One row per output: what it is, what made it, and what that step did.

merge_provenance_rows

Outputs whose step said the same thing with the same settings share one row.

collapse_messages

One line per distinct message, in first-seen order, counted when it repeats.

footer_vars

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.

scope is 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_note is not to be confused with note() above, which collects what a section skipped.

nirspipe.qc.common.report_shell.render(template_name: str, **variables: Any) → str#
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_meta prints as label: <b>value</b> chips in run order; nav_note is the right-aligned line, which is where the parameters a reader needs to judge the numbers belong.

css replaces 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#
nirspipe.qc.common.report_shell.nav_bar(sections, *, key: str = '', rated: bool = True, group: int | None = None, closing=CLOSING_SECTIONS, summary: str = '#Final', siblings=(), index: str = '', index_label: str = '← All runs') → list[dict]#

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; None is a divider between two runs of them. key is appended to every ratable id, so a subject’s runs do not file one verdict between them, and rated=False drops the pills, which is what a page summarising other pages wants. group stamps one run’s entries on a viewer holding several.

siblings are the pages read alongside this one, as {label, href, current}, and index the 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 fc step become one row with twelve names, so the table reads one line per thing that happened. family is the names’ shared first word when more than two merge (relmat for every relmat ...), 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.

nirspipe.qc.common.report_shell.footer_vars(*, scope: str = '', errors: list | None = None, notes: list | None = None, nirs_dir: pathlib.Path | None = None, label: str | None = None, provenance_path: str | None = None, methods: dict | None = None, versions: dict[str, str] | None = None) → dict#

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 errors gets the errors block even when the list is empty, because “no errors” is itself worth printing; passing nirs_dir gets the provenance table, methods the Methods tabs, versions the version table.