nirspipe.io.naming#
Every derivative name this package writes, built from and parsed against one table.
The table is nirspipe/data/nirspipe_bids_config.json: the entities this package adds
to the ones pybids already knows, and the path patterns each kind of output follows.
Two functions, and they are inverses:
derivative_path(out, "relmat", ".tsv", group="G1", task="rest", statistic="wtc")
-> out/group-G1/nirs/group-G1_task-rest_stat-wtc_relmat.tsv
parse_path(that)
-> {"group": "G1", "task": "rest", "statistic": "wtc", ...}
derivative_path() does not create directories. The caller decides when a name becomes
a file, which is what lets a dry run print names without leaving a tree behind.
Module Contents#
Functions#
The merged pybids |
|
Anything a user typed, reduced to what BIDS allows in an entity value. |
|
Letters and digits only, ASCII ones: what a file name’s entity can carry and be read back by. |
|
The |
|
What to hand |
|
Where one output goes, given what it is and which entities distinguish it. |
|
One figure’s filename. |
|
One report page’s filename, from the run label the QC code passes around. |
|
One table a quality record keeps beside its JSON. |
|
Where the human ratings of one report page are kept. |
|
Where the raw QC page keeps a run’s per-channel keep/drop decisions. |
|
Where the raw QC page keeps the stretches a reviewer marked bad, per run. |
|
Read the entities back out of a name |
API#
- nirspipe.io.naming.config()#
The merged pybids
Config: its own entities, its derivatives ones, then ours.Ours go last so a name we declare would win, though none currently collides: pybids already knows
seg-,label-anddesc-, and itsdatatypepattern already matchesnirs/. Redeclaring one is not merely redundant, it breaks BIDSLayout, whose entity table refuses two rows of the same name.
- nirspipe.io.naming.bids_label(text: str, fallback: str = 'custom') str#
Anything a user typed, reduced to what BIDS allows in an entity value.
"left PFC (dorsal)"->"leftPFCdorsal";"__"->"custom"A label is alphanumeric by definition, so a name carrying a space, a hyphen or an underscore would either be rejected or, worse, read as a second entity. ASCII only, the rule
entity_ofreads a label back by.
- nirspipe.io.naming.is_bids_label(text: str) bool#
Letters and digits only, ASCII ones: what a file name’s entity can carry and be read back by.
- nirspipe.io.naming.roi_map_name(mapping) str#
The
seg-entity every ROI output carries, taken from the map file’s own stem."/studies/frontal_rois.json"->"frontalrois";None->"custom"A name rather than a fixed string, so one output tree can hold two ROI definitions instead of the second silently replacing the first.
- nirspipe.io.naming.layout_config() list[str]#
What to hand
BIDSLayout(config=...)so it can index a tree this package wrote.Names rather than the merged
Configabove: BIDSLayout stores its configuration in sqlite, so it takes config names or paths and refuses an object. It also refuses two entities of one name, which is why this package’s file redeclares none of the builtins.
- nirspipe.io.naming.derivative_path(output_dir, suffix: str, extension: str, **entities) pathlib.Path#
Where one output goes, given what it is and which entities distinguish it.
(out, "qc", ".json", subject="01", task="rest", desc="preproc")->
out/sub-01/nirs/sub-01_task-rest_desc-preproc_qc.json
Entities whose value is None are dropped, so a caller can pass
session=Nonewithout branching. Raises ValueError when no pattern fits, rather than returning a name outside the scheme.
- nirspipe.io.naming.figure_name(stem: str, desc: str, *, suffix: str = 'nirs', extension: str = '.html', **entities) str#
One figure’s filename.
descnames the panel,suffixnames what it draws.("sub-01_task-rest", "carpet") -> "sub-01_task-rest_desc-carpet_nirs.html" ("sub-01_task-rest", "detail", channel="S1D1") -> "sub-01_task-rest_chan-S1D1_desc-detail_nirs.html"
The run stem is in the name because a subject’s runs share one
figures/folder. It isstemand notlabelbecauselabel-is itself an entity a caller passes through here.
- nirspipe.io.naming.report_name(label: str, *, desc: str | None = None, condition: str | None = None, pairing: str | None = None) str#
One report page’s filename, from the run label the QC code passes around.
("sub-01_task-rest") -> "sub-01_task-rest_report.html" ("sub-01_task-rest", desc="raw") -> "sub-01_task-rest_desc-raw_report.html" ("group-G1_task-rest", condition="game1") -> "group-G1_task-rest_cond-game1_report.html"
The QC code carries a label rather than a set of entities, so the entities are read back out of it.
- nirspipe.io.naming.record_table_name(label: str, desc: str, suffix: str, statistic: str | None = None) str#
One table a quality record keeps beside its JSON.
("sub-01_task-rest", "sqm", "timeseries", statistic="sci")->
"sub-01_task-rest_stat-sci_desc-sqm_timeseries.tsv"
- nirspipe.io.naming.rating_path(output_dir, report_stem: str, rater: str | None = None)#
Where the human ratings of one report page are kept.
(out, "sub-01_task-rest_desc-raw_report")->
out/sub-01/nirs/sub-01_task-rest_desc-rawrating_qc.json(out, "sub-01_task-rest_cond-game1_report")->
out/sub-01/nirs/sub-01_task-rest_cond-game1_desc-rating_qc.json(out, "sub-01_task-rest_desc-raw_report", rater="qy")->
out/sub-01/nirs/sub-01_task-rest_rater-qy_desc-rawrating_qc.json
One file per rated page, because a run and each of its condition pages are separate reports rated separately, and one per rater, so a second rater never overwrites the first. The raw viewer’s ratings take
rawratingfor the reason its figures take arawprefix: the two viewers rate the same run at different stages and would otherwise ask for one name.
- nirspipe.io.naming.channel_decisions_path(output_dir, subject: str, task: str | None = None, session: str | None = None, rater: str | None = None)#
Where the raw QC page keeps a run’s per-channel keep/drop decisions.
(out, "01", task="rest") -> out/sub-01/nirs/sub-01_task-rest_desc-rawdecision_qc.json (out, "01", task="rest", rater="qy") -> out/sub-01/nirs/sub-01_task-rest_rater-qy_desc-rawdecision_qc.json
One function for the run’s rating server and the dyad’s, which write the same file.
- nirspipe.io.naming.bad_spans_path(output_dir, subject: str, task: str | None = None, session: str | None = None, rater: str | None = None)#
Where the raw QC page keeps the stretches a reviewer marked bad, per run.
(out, "01", task="rest")->out/sub-01/nirs/sub-01_task-rest_desc-rawspans_qc.json
- nirspipe.io.naming.parse_path(path) dict#
Read the entities back out of a name
derivative_path()built."group-G1/nirs/group-G1_task-rest_stat-wtc_relmat.tsv"->
{"group": "G1", "task": "rest", "statistic": "wtc", "suffix": "relmat", ...}
Give it a path relative to the output directory. An absolute one still parses, but any entity-looking fragment in the leading directories is read as an entity too.