33
33
from niworkflows .interfaces .utility import KeySelect
34
34
35
35
from ..interfaces import DerivativesDataSink
36
- from ..interfaces .templateflow import TemplateFlowSelect
36
+ from ..interfaces .templateflow import TemplateFlowSelect , fetch_template_files
37
+
38
+ if ty .TYPE_CHECKING :
39
+ from niworkflows .utils .spaces import SpatialReferences
37
40
38
41
BIDS_TISSUE_ORDER = ('GM' , 'WM' , 'CSF' )
39
42
40
43
41
- def init_anat_reports_wf (* , spaces , freesurfer , output_dir , name = 'anat_reports_wf' ):
44
+ def init_anat_reports_wf (* , spaces , freesurfer , output_dir , sloppy = False , name = 'anat_reports_wf' ):
42
45
"""
43
46
Set up a battery of datasinks to store reports in the right location.
44
47
@@ -131,7 +134,7 @@ def init_anat_reports_wf(*, spaces, freesurfer, output_dir, name='anat_reports_w
131
134
# fmt:on
132
135
133
136
if spaces ._cached is not None and spaces .cached .references :
134
- template_iterator_wf = init_template_iterator_wf (spaces = spaces )
137
+ template_iterator_wf = init_template_iterator_wf (spaces = spaces , sloppy = sloppy )
135
138
t1w_std = pe .Node (
136
139
ApplyTransforms (
137
140
dimension = 3 ,
@@ -1112,7 +1115,9 @@ def init_anat_second_derivatives_wf(
1112
1115
return workflow
1113
1116
1114
1117
1115
- def init_template_iterator_wf (* , spaces , name = 'template_iterator_wf' ):
1118
+ def init_template_iterator_wf (
1119
+ * , spaces : 'SpatialReferences' , sloppy : bool = False , name = 'template_iterator_wf'
1120
+ ):
1116
1121
"""Prepare the necessary components to resample an image to a template space
1117
1122
1118
1123
This produces a workflow with an unjoined iterable named "spacesource".
@@ -1122,6 +1127,9 @@ def init_template_iterator_wf(*, spaces, name='template_iterator_wf'):
1122
1127
1123
1128
The fields in `outputnode` can be used as if they come from a single template.
1124
1129
"""
1130
+ for template in spaces .get_spaces (nonstandard = False , dim = (3 ,)):
1131
+ fetch_template_files (template , specs = None , sloppy = sloppy )
1132
+
1125
1133
workflow = pe .Workflow (name = name )
1126
1134
1127
1135
inputnode = pe .Node (
@@ -1159,9 +1167,7 @@ def init_template_iterator_wf(*, spaces, name='template_iterator_wf'):
1159
1167
name = 'select_xfm' ,
1160
1168
run_without_submitting = True ,
1161
1169
)
1162
- select_tpl = pe .Node (
1163
- TemplateFlowSelect (resolution = 1 ), name = 'select_tpl' , run_without_submitting = True
1164
- )
1170
+ select_tpl = pe .Node (TemplateFlowSelect (), name = 'select_tpl' , run_without_submitting = True )
1165
1171
1166
1172
# fmt:off
1167
1173
workflow .connect ([
@@ -1177,7 +1183,7 @@ def init_template_iterator_wf(*, spaces, name='template_iterator_wf'):
1177
1183
(spacesource , select_tpl , [
1178
1184
('space' , 'template' ),
1179
1185
('cohort' , 'cohort' ),
1180
- (('resolution' , _no_native ), 'resolution' ),
1186
+ (('resolution' , _no_native , sloppy ), 'resolution' ),
1181
1187
]),
1182
1188
(spacesource , outputnode , [
1183
1189
('space' , 'space' ),
@@ -1243,10 +1249,6 @@ def _pick_cohort(in_template):
1243
1249
return [_pick_cohort (v ) for v in in_template ]
1244
1250
1245
1251
1246
- def _fmt (in_template ):
1247
- return in_template .replace (':' , '_' )
1248
-
1249
-
1250
1252
def _empty_report (in_file = None ):
1251
1253
from pathlib import Path
1252
1254
@@ -1268,11 +1270,11 @@ def _is_native(value):
1268
1270
return value == 'native'
1269
1271
1270
1272
1271
- def _no_native (value ):
1273
+ def _no_native (value , sloppy = False ):
1272
1274
try :
1273
1275
return int (value )
1274
1276
except (TypeError , ValueError ):
1275
- return 1
1277
+ return 2 if sloppy else 1
1276
1278
1277
1279
1278
1280
def _drop_path (in_path ):
0 commit comments