@brainpilot/skills 0.0.12 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,334 @@
1
+ # Output Spaces & TemplateFlow
2
+
3
+ `--output-spaces` controls where fMRIPrep resamples anatomical + BOLD
4
+ derivatives. It accepts a **space-separated list** of tokens. Each token is:
5
+
6
+ ```
7
+ <SPACE>[:cohort-<label>][:res-<idx>][:den-<idx>][:...]
8
+ ```
9
+
10
+ ## Table of Contents
11
+ 1. [Default behavior](#default-behavior)
12
+ 2. [Standard spaces (TemplateFlow)](#standard-spaces-templateflow)
13
+ 3. [Modifiers: `res-`, `cohort-`, `den-`, `atlas-`](#modifiers-res--cohort--den--atlas-)
14
+ 4. [Nonstandard spaces (`T1w`, `anat`, `fsnative`, `func`, ...)](#nonstandard-spaces-t1w-anat-fsnative-func-)
15
+ 5. [Surface spaces](#surface-spaces)
16
+ 6. [Custom templates](#custom-templates)
17
+ 7. [Implicit spaces required by other flags](#implicit-spaces-required-by-other-flags)
18
+ 8. [Pre-fetching templates (offline / HPC)](#pre-fetching-templates-offline--hpc)
19
+ 9. [Common recipes](#common-recipes)
20
+
21
+ ---
22
+
23
+ ## Default behavior
24
+
25
+ If `--output-spaces` is omitted:
26
+
27
+ ```
28
+ --output-spaces MNI152NLin2009cAsym:res-native
29
+ ```
30
+
31
+ - `MNI152NLin2009cAsym` = MNI non-linear 2009c asymmetric — fMRIPrep's
32
+ internal reference.
33
+ - `res-native` = keep the original BOLD grid rather than resample to a
34
+ template resolution.
35
+
36
+ The bare invocation `--output-spaces` (no tokens) is meaningful: it disables
37
+ BOLD resampling entirely. Only anatomical + transforms are written.
38
+
39
+ Whatever you list, fMRIPrep also keeps at least the *internal* reference
40
+ (`MNI152NLin2009cAsym`) even if it's not in the list — but that reference is
41
+ NOT saved to derivatives unless you include it.
42
+
43
+ ---
44
+
45
+ ## Standard spaces (TemplateFlow)
46
+
47
+ Bundled with the container (or fetched on demand). Common IDs:
48
+
49
+ | Space | Description | Notes |
50
+ |-------|-------------|-------|
51
+ | `MNI152NLin2009cAsym` | MNI152 non-linear 2009c asymmetric — **fMRIPrep default** | Res 1 = 1 mm, res 2 = 2 mm |
52
+ | `MNI152NLin6Asym` | FSL's MNI152 non-linear 6-generation asymmetric | Required for CIFTI output |
53
+ | `MNI152NLin6Sym` | Symmetric version | Rare |
54
+ | `MNI152Lin` | Linear MNI152 (SPM) | Legacy |
55
+ | `OASIS30ANTs` | ANTs' Oxford Aging Study 30 | Skull-strip default |
56
+ | `NKI` | Enhanced Nathan Kline Institute template | |
57
+ | `PNC` | Philadelphia Neurodevelopmental Cohort | |
58
+ | `MNIPediatricAsym` | Pediatric MNI, multi-cohort by age | Use `cohort-N` (see below) |
59
+ | `MNIInfant` | Infant template, multi-cohort | Use `cohort-N` |
60
+ | `UNCInfant` | UNC infant | Use `cohort-N` |
61
+ | `fsLR` | HCP-style fsLR mesh (32k or 164k) | Surface only |
62
+ | `fsaverage` | FreeSurfer average | Surface only (default den-10k = fsaverage5) |
63
+ | `fsaverage5` | 10k mesh (legacy alias for `fsaverage:den-10k`) | Surface |
64
+ | `fsaverage6` | 41k mesh (legacy alias for `fsaverage:den-41k`) | Surface |
65
+
66
+ Full template catalog: https://www.templateflow.org
67
+
68
+ Wrapper's built-in whitelist (`TF_TEMPLATES` in `wrapper/src/fmriprep_docker/__main__.py`):
69
+ `MNI152Lin`, `MNI152NLin2009cAsym`, `MNI152NLin6Asym`, `MNI152NLin6Sym`,
70
+ `MNIInfant`, `MNIPediatricAsym`, `NKI`, `OASIS30ANTs`, `PNC`, `UNCInfant`,
71
+ `fsLR`, `fsaverage`, `fsaverage5`, `fsaverage6`.
72
+
73
+ Anything outside this list is treated as a custom template by the wrapper — it
74
+ must live in `$TEMPLATEFLOW_HOME` or be pointed to as a filesystem path (which
75
+ the wrapper bind-mounts).
76
+
77
+ ---
78
+
79
+ ## Modifiers: `res-`, `cohort-`, `den-`, `atlas-`
80
+
81
+ Colon-separated modifiers control which template variant / resolution is used
82
+ for that entry. Modifiers may be combinatorial (multiple `res-`, multiple `cohort-`).
83
+
84
+ ### `res-<idx>`
85
+
86
+ **Resolution INDEX in TemplateFlow — NOT millimeters.** Look up what each
87
+ index means in the template's `template_description.json`.
88
+
89
+ Common:
90
+ - `MNI152NLin2009cAsym:res-1` → 1 mm
91
+ - `MNI152NLin2009cAsym:res-2` → 2 mm
92
+ - `MNI152NLin6Asym:res-2` → 2 mm
93
+ - `MNI152NLin6Asym:res-3` → **0.5 mm** (not 3 mm!) — always verify
94
+
95
+ Aliases:
96
+ - `res-native` — keep the original BOLD grid (no template resampling).
97
+ - `res-*` combined with another (e.g. `MNIPediatricAsym:res-native:res-1`) generates BOTH.
98
+
99
+ ### `cohort-<label>`
100
+
101
+ Used by multi-cohort templates (pediatric, infant). Example:
102
+
103
+ ```
104
+ --output-spaces MNIPediatricAsym:cohort-2:res-1
105
+ ```
106
+
107
+ `cohort-2` for MNIPediatricAsym = prepuberty phase (4.5–8.5 y). See the
108
+ template description JSON at
109
+ https://github.com/templateflow/tpl-MNIPediatricAsym.
110
+
111
+ Combinatorial: `MNIPediatricAsym:cohort-1:cohort-2:res-native:res-1` →
112
+ 4 variants (2 cohorts × 2 resolutions).
113
+
114
+ ### `den-<idx>` (surfaces only)
115
+
116
+ Surface density. Common:
117
+
118
+ - `fsaverage:den-10k` = fsaverage5 (10,242 vertices/hemi)
119
+ - `fsaverage:den-41k` = fsaverage6 (40,962 vertices/hemi)
120
+ - `fsaverage:den-164k` = full fsaverage (163,842 vertices/hemi)
121
+ - `fsLR:den-32k` = HCP 32k mesh (default for CIFTI 91k output)
122
+ - `fsLR:den-164k` = HCP 164k mesh
123
+
124
+ Prefer the `den-` form over the legacy `fsaverageN` names.
125
+
126
+ ### `atlas-<label>` and others
127
+
128
+ Some template variants come with an atlas modifier (e.g., HCP atlas). Rarely
129
+ needed by end users.
130
+
131
+ ---
132
+
133
+ ## Nonstandard spaces (`T1w`, `anat`, `fsnative`, `func`, ...)
134
+
135
+ Non-template outputs; **modifiers are NOT allowed** on these:
136
+
137
+ | Token | Meaning | Output surface/volume? |
138
+ |-------|---------|-----------------------|
139
+ | `T1w` / `anat` | Subject's native anatomical (T1w) reference | Volume |
140
+ | `fsnative` | FreeSurfer's subject-specific cortical mesh | Surface |
141
+ | `func` / `bold` / `run` / `boldref` / `sbref` | Original BOLD grid, after STC/HMC/SDC | Volume (**experimental** — expected to change) |
142
+
143
+ `T1w` and `anat` are aliases in current versions. `func` and friends are for
144
+ downstream tools that want the corrected native-BOLD-grid data.
145
+
146
+ ---
147
+
148
+ ## Surface spaces
149
+
150
+ - **`fsnative`** — subject's original cortical mesh (varies per subject).
151
+ - **`fsaverage[:den-10k|41k|164k]`** — FreeSurfer's standard template.
152
+ - **`fsLR[:den-32k|164k]`** — HCP-style mesh with aligned L/R hemispheres.
153
+
154
+ CIFTI output requires `fsLR:den-32k` (91k) or `fsLR:den-91k`-equivalent (170k)
155
+ internally; it's added automatically when `--cifti-output` is set.
156
+
157
+ ---
158
+
159
+ ## Custom templates
160
+
161
+ ### Via TemplateFlow home
162
+
163
+ Put a directory named `tpl-<Name>/` under `$TEMPLATEFLOW_HOME`:
164
+
165
+ ```
166
+ $TEMPLATEFLOW_HOME/
167
+ tpl-MyCustom/
168
+ template_description.json
169
+ tpl-MyCustom_res-1_T1w.nii.gz
170
+ tpl-MyCustom_res-1_desc-brain_mask.nii.gz
171
+ tpl-MyCustom_res-2_T1w.nii.gz
172
+ tpl-MyCustom_res-2_desc-brain_mask.nii.gz
173
+ ```
174
+
175
+ Then reference it in `--output-spaces MyCustom:res-1`.
176
+
177
+ Minimum required files:
178
+ - `template_description.json` (identifies the template)
179
+ - `tpl-<Name>_res-<idx>_T1w.nii.gz` (one per resolution)
180
+ - `tpl-<Name>_res-<idx>_desc-brain_mask.nii.gz` (one per resolution)
181
+
182
+ Full guide: https://www.templateflow.org/python-client/tutorials.html
183
+
184
+ ### Via filesystem path (wrapper only)
185
+
186
+ ```bash
187
+ fmriprep-docker /data /out participant \
188
+ --output-spaces /home/me/tpl-MyCustom:res-1 \
189
+ -w /work
190
+ ```
191
+
192
+ The wrapper bind-mounts `/home/me/tpl-MyCustom` into
193
+ `/home/fmriprep/.cache/templateflow/tpl-MyCustom` inside the container and
194
+ strips the `tpl-` prefix when passing the flag on.
195
+
196
+ **Restriction**: custom template folders must be prefixed `tpl-` for the
197
+ wrapper to accept them.
198
+
199
+ ---
200
+
201
+ ## Implicit spaces required by other flags
202
+
203
+ Even if you don't list them, fMRIPrep will add these internally when needed:
204
+
205
+ | Flag | Implicit space |
206
+ |------|----------------|
207
+ | Always | `MNI152NLin2009cAsym` (skull-strip fallback + reference frame) |
208
+ | No `--skull-strip-template` override | `OASIS30ANTs` |
209
+ | `--cifti-output` | `MNI152NLin6Asym` (for the CIFTI subcortical grid) |
210
+ | `--use-syn-sdc` / `--force syn-sdc` | `MNI152NLin2009cAsym` (SyN prior) |
211
+
212
+ Templates added implicitly are **not** saved to derivatives — you have to list
213
+ them in `--output-spaces` to get outputs.
214
+
215
+ ---
216
+
217
+ ## Pre-fetching templates (offline / HPC)
218
+
219
+ Compute nodes are often offline. TemplateFlow downloads templates on demand,
220
+ so pre-populate the cache from a login node:
221
+
222
+ ```bash
223
+ # One-time on a network-connected host
224
+ export TEMPLATEFLOW_HOME=$HOME/.cache/templateflow
225
+ python -m pip install --user templateflow
226
+
227
+ python <<'EOF'
228
+ from templateflow.api import get
229
+ for tpl in [
230
+ "MNI152NLin2009cAsym",
231
+ "MNI152NLin6Asym",
232
+ "OASIS30ANTs",
233
+ "MNIPediatricAsym",
234
+ "MNIInfant",
235
+ "fsaverage",
236
+ "fsLR",
237
+ ]:
238
+ get(tpl)
239
+ EOF
240
+ ```
241
+
242
+ Or use the helper script bundled in the fMRIPrep repo:
243
+
244
+ ```bash
245
+ wget https://raw.githubusercontent.com/nipreps/fmriprep/master/scripts/fetch_templates.py
246
+ python fetch_templates.py --tf-dir /shared/templateflow
247
+ ```
248
+
249
+ `fetch_templates.py` pulls:
250
+ - `MNI152NLin2009cAsym` (T1w, T2w, brain mask, carpet dseg, fMRIPrep boldref, brain probseg — res 1 and 2)
251
+ - `MNI152NLin6Asym` (T1w, brain mask, HCP atlas dseg — res 1 and 2)
252
+ - `OASIS30ANTs` (T1w, WM/BS/brain probseg, brain mask, BrainCerebellumExtraction mask)
253
+ - `fsaverage` (164k sphere, midthickness, sulc)
254
+ - `fsLR` (32k density — sphere, midthickness, dparc, etc.)
255
+
256
+ Then bind-mount into the container:
257
+
258
+ ```bash
259
+ # Docker
260
+ -v $HOME/.cache/templateflow:/home/fmriprep/.cache/templateflow
261
+
262
+ # Apptainer
263
+ -B $HOME/.cache/templateflow:/opt/templateflow --env TEMPLATEFLOW_HOME=/opt/templateflow
264
+ ```
265
+
266
+ ---
267
+
268
+ ## Common recipes
269
+
270
+ ### Only MNI, ready for group analysis in SPM/FSL
271
+
272
+ ```
273
+ --output-spaces MNI152NLin2009cAsym:res-2
274
+ ```
275
+
276
+ ### Volumetric MNI + native anat for QC
277
+
278
+ ```
279
+ --output-spaces MNI152NLin2009cAsym:res-2 anat
280
+ ```
281
+
282
+ ### Both MNI152NLin2009c (default) AND MNI152NLin6 (FSL/HCP compatible)
283
+
284
+ ```
285
+ --output-spaces MNI152NLin2009cAsym:res-2 MNI152NLin6Asym:res-2
286
+ ```
287
+
288
+ ### HCP-style: surface + CIFTI
289
+
290
+ ```
291
+ --output-spaces MNI152NLin6Asym:res-2 fsLR fsaverage:den-10k
292
+ --cifti-output 91k
293
+ ```
294
+
295
+ ### Multi-resolution for method comparisons
296
+
297
+ ```
298
+ --output-spaces \
299
+ MNI152NLin2009cAsym:res-1 MNI152NLin2009cAsym:res-2 MNI152NLin2009cAsym:res-native
300
+ ```
301
+
302
+ ### Pediatric study, multiple cohorts
303
+
304
+ ```
305
+ --output-spaces MNIPediatricAsym:cohort-1:res-1 MNIPediatricAsym:cohort-2:res-1
306
+ ```
307
+
308
+ ### Infant study
309
+
310
+ ```
311
+ --output-spaces MNIInfant:cohort-1:res-2 UNCInfant:cohort-1:res-2
312
+ ```
313
+
314
+ ### Surface-only (skip volumetric BOLD)
315
+
316
+ ```
317
+ --output-spaces fsaverage:den-10k fsnative
318
+ ```
319
+
320
+ ### Absolutely no BOLD resampling (transforms and reports only)
321
+
322
+ ```
323
+ --output-spaces
324
+ ```
325
+
326
+ (pass the flag with no arguments — only anatomical outputs and transforms are saved)
327
+
328
+ ### Custom template alongside standard
329
+
330
+ ```
331
+ --output-spaces MNI152NLin2009cAsym:res-2 MyLabTemplate:res-1
332
+ ```
333
+
334
+ (with `MyLabTemplate` prepared under `$TEMPLATEFLOW_HOME/tpl-MyLabTemplate/`)