-
Notifications
You must be signed in to change notification settings - Fork 52
/
fetch_templates.py
executable file
·121 lines (93 loc) · 4 KB
/
fetch_templates.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env python
"""
Standalone script to facilitate caching of required TemplateFlow templates.
To download and view how to use this script, run the following commands inside a terminal:
1. wget https://raw.githubusercontent.com/nipreps/fmriprep/master/scripts/fetch_templates.py
2. python fetch_templates.py -h
"""
import argparse
import os
def fetch_MNI2009():
"""
Expected templates:
tpl-MNI152NLin2009cAsym/tpl-MNI152NLin2009cAsym_res-02_desc-brain_mask.nii.gz
tpl-MNI152NLin2009cAsym/tpl-MNI152NLin2009cAsym_res-02_desc-fMRIPrep_boldref.nii.gz
tpl-MNI152NLin2009cAsym/tpl-MNI152NLin2009cAsym_res-01_label-brain_probseg.nii.gz
"""
template = "MNI152NLin2009cAsym"
tf.get(template, resolution=2, desc="brain", suffix="mask")
tf.get(template, resolution=2, desc="fMRIPrep", suffix="boldref")
tf.get(template, resolution=1, label="brain", suffix="probseg")
def fetch_MNI152Lin():
"""
Expected templates:
tpl-MNI152Lin/tpl-MNI152Lin_res-02_T1w.nii.gz
tpl-MNI152Lin/tpl-MNI152Lin_res-02_desc-brain_mask.nii.gz
"""
template = "MNI152Lin"
tf.get(template, resolution=2, desc=None, suffix="T1w")
tf.get(template, resolution=2, desc="brain", suffix="mask")
def fetch_OASIS():
"""
Expected templates:
tpl-OASIS30ANTs/tpl-OASIS30ANTs_res-01_T1w.nii.gz
tpl-OASIS30ANTs/tpl-OASIS30ANTs_res-01_label-WM_probseg.nii.gz
tpl-OASIS30ANTs/tpl-OASIS30ANTs_res-01_label-BS_probseg.nii.gz
tpl-OASIS30ANTs/tpl-OASIS30ANTs_res-01_label-brain_probseg.nii.gz
tpl-OASIS30ANTs/tpl-OASIS30ANTs_res-01_desc-brain_mask.nii.gz
tpl-OASIS30ANTs/tpl-OASIS30ANTs_res-01_desc-BrainCerebellumExtraction_mask.nii.gz
"""
template = "OASIS30ANTs"
tf.get(template, resolution=1, desc="4", suffix="dseg")
tf.get(template, resolution=1, desc=None, suffix="T1w")
tf.get(template, resolution=1, label="brain", suffix="mask")
tf.get(template, resolution=1, desc="BrainCerebellumExtraction", suffix="mask")
tf.get(template, resolution=1, label="brain", suffix="probseg")
def fetch_fsaverage():
"""
Expected templates:
tpl-fsaverage/tpl-fsaverage_hemi-L_den-164k_desc-std_sphere.surf.gii
tpl-fsaverage/tpl-fsaverage_hemi-R_den-164k_desc-std_sphere.surf.gii
tpl-fsaverage/tpl-fsaverage_hemi-L_den-164k_desc-vaavg_midthickness.shape.gii
tpl-fsaverage/tpl-fsaverage_hemi-R_den-164k_desc-vaavg_midthickness.shape.gii
tpl-fsaverage/tpl-fsaverage_hemi-L_den-164k_midthickness.surf.gii
tpl-fsaverage/tpl-fsaverage_hemi-R_den-164k_midthickness.surf.gii
"""
template = "fsaverage"
tf.get(template, density="164k", desc="std", suffix="sphere")
tf.get(template, density="164k", suffix="midthickness")
def fetch_fsLR():
"""
Expected templates:
tpl-fsLR/tpl-fsLR_hemi-L_den-32k_desc-nomedialwall_dparc.label.gii
tpl-fsLR/tpl-fsLR_hemi-L_den-32k_desc-vaavg_midthickness.shape.gii
tpl-fsLR/tpl-fsLR_hemi-L_den-32k_sphere.surf.gii
tpl-fsLR/tpl-fsLR_hemi-R_den-32k_desc-nomedialwall_dparc.label.gii
tpl-fsLR/tpl-fsLR_hemi-R_den-32k_desc-vaavg_midthickness.shape.gii
tpl-fsLR/tpl-fsLR_hemi-R_den-32k_sphere.surf.gii
tpl-fsLR/tpl-fsLR_space-fsaverage_hemi-L_den-32k_sphere.surf.gii
tpl-fsLR/tpl-fsLR_space-fsaverage_hemi-R_den-32k_sphere.surf.gii
"""
tf.get("fsLR", density="32k")
def fetch_all():
fetch_MNI2009()
fetch_MNI152Lin()
fetch_OASIS()
fetch_fsaverage()
fetch_fsLR()
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Helper script for pre-caching required templates to run fMRIPrep",
)
parser.add_argument(
"--tf-dir",
type=os.path.abspath,
help="Directory to save templates in. If not provided, templates will be saved to"
" `${HOME}/.cache/templateflow`.",
)
opts = parser.parse_args()
# set envvar (if necessary) prior to templateflow import
if opts.tf_dir is not None:
os.environ["TEMPLATEFLOW_HOME"] = opts.tf_dir
import templateflow.api as tf
fetch_all()