Rule Syntax Reference¶
Rules select which specs and converter hooks apply to a scan. They are evaluated against Bruker Paravision parameter values and only select behavior (they do not modify metadata).
Evaluation¶
- Rule files are loaded from the config root, in filename order
- Within a file, entries are evaluated top → bottom
- Rules are grouped by category:
info_spec,metadata_spec,converter_hook - If multiple entries match a category, the last matching entry wins
File shape (YAML)¶
A rules file is a YAML mapping. Any of these top-level keys may appear:
info_spec: selects which info spec powersbrkraw infometadata_spec: selects which metadata spec drives sidecarsconverter_hook: selects which conversion hook runs
Each key maps to a list of rule entries:
metadata_spec:
- name: "epi-metadata"
when:
Method:
sources:
- file: method
key: Method
if:
regex: ["$Method", "^EPI"]
use: "bids_bold_metadata"
Interpretation:
- When the Paravision parameter
method:Methodis mapped to the variable$Method, if$Methodmatches^EPI, select the metadata specbids_bold_metadata.
Rule entry fields¶
Minimal schema:
- name: "<id>"
description: "<optional text>"
when: { <var>: <binding>, ... } # optional
if: <condition> # required if `when` exists
use: "<spec-or-hook>" # required
version: "<optional version>" # optional (specs only)
name(required): identifier for logging/debuggingdescription(optional): human-readable noteuse(required): target to select- for
info_spec/metadata_spec: spec name (recommended) or a spec path under the config root - for
converter_hook: a hook name registered underbrkraw.converter_hook
- for
version(optional, specs only): pin a spec version; if omitted, the latest version is selectedwhen(optional): variable bindings (see next section)if(required whenwhenexists): match condition (operators below)
Variables (when)¶
when binds variables from Paravision parameter files using the same “remapper”
binding shape as specs (i.e., sources and optional transform). The name
when is intended to read as “when these variables (bindings) are available,
evaluate the condition”.
when:
Method:
sources:
- file: method
key: Method
Interpretation:
-
When the parameter key
Methodis read from themethodfile, bind its value to$Methodfor use inif. -
Each key under
whendefines a variable name. - Variables are referenced in conditions as
$<name>(e.g.,$Method). - If you use
transform, it is resolved from the spec selected byusevia__meta__.transforms_source(see Spec syntax reference).
For the full binding syntax, reuse the spec “Sources/Transforms” rules in Spec syntax reference.
Conditions (if)¶
if is a single operator mapping. Operands can be literals or variables like
"$Method".
Boolean¶
if: { always: true }
Interpretation:
- If evaluated, always match (no variable needed).
Equality / ordering¶
if: { eq: ["$Method", "EPI"] }
if: { ne: ["$Method", "RARE"] }
if: { gt: ["$SomeNumber", 0] }
if: { ge: ["$SomeNumber", 0] }
if: { lt: ["$SomeNumber", 10] }
if: { le: ["$SomeNumber", 10] }
Interpretation:
- If
$MethodequalsEPI, match. - If
$Methodis notRARE, match. - If
$SomeNumberis greater/greater-or-equal/less/less-or-equal than the given value, match.
Membership¶
if: { in: ["$Method", ["EPI", "BOLD", "FMRI"]] }
Interpretation:
- If
$Methodis one ofEPI,BOLD,FMRI, match.
Strings¶
if: { regex: ["$Method", "^EPI"] }
if: { startswith: ["$Method", "EPI"] }
if: { contains: ["$Method", "EPI"] }
Interpretation:
- If
$Methodmatches a regex / starts with / contains the given string, match.
Composition¶
if:
any:
- eq: ["$Method", "EPI"]
- regex: ["$Method", "^RARE"]
if:
all:
- eq: ["$A", 1]
- ne: ["$B", 2]
if:
not:
eq: ["$Method", "EPI"]
Interpretation:
any: match if any sub-condition matches (OR).all: match only if every sub-condition matches (AND).not: match if the nested condition does not match.
Defaults / fallback¶
An entry without when/if always matches:
info_spec:
- name: "default-info"
use: "default"
Interpretation:
- If no explicit
when/ifis provided, the entry always matches and selectsdefaultforinfo_spec(unless later rules override it).
Recommendation: put a default entry first, and more specific overrides after it (because the last matching entry wins).
Category constraints (specs)¶
Rules selecting specs must match the spec’s __meta__.category:
info_specrules → specs with__meta__.category: info_specmetadata_specrules → specs with__meta__.category: metadata_spec