@@ -108,34 +108,9 @@ def _run_interface(self, runtime):
108
108
if isdefined (self .inputs .cohort ):
109
109
specs ['cohort' ] = self .inputs .cohort
110
110
111
- name = self .inputs .template .strip (':' ).split (':' , 1 )
112
- if len (name ) > 1 :
113
- specs .update (
114
- {
115
- k : v
116
- for modifier in name [1 ].split (':' )
117
- for k , v in [tuple (modifier .split ('-' ))]
118
- if k not in specs
119
- }
120
- )
121
-
122
- if specs ['resolution' ] and not isinstance (specs ['resolution' ], list ):
123
- specs ['resolution' ] = [specs ['resolution' ]]
124
-
125
- available_resolutions = tf .TF_LAYOUT .get_resolutions (template = name [0 ])
126
- if specs ['resolution' ] and not set (specs ['resolution' ]) & set (available_resolutions ):
127
- fallback_res = available_resolutions [0 ] if available_resolutions else None
128
- LOGGER .warning (
129
- f"Template { name [0 ]} does not have resolution(s): { specs ['resolution' ]} ."
130
- f"Falling back to resolution: { fallback_res } ."
131
- )
132
- specs ['resolution' ] = fallback_res
133
-
134
- self ._results ['t1w_file' ] = tf .get (name [0 ], desc = None , suffix = 'T1w' , ** specs )
135
-
136
- self ._results ['brain_mask' ] = tf .get (
137
- name [0 ], desc = 'brain' , suffix = 'mask' , ** specs
138
- ) or tf .get (name [0 ], label = 'brain' , suffix = 'mask' , ** specs )
111
+ files = fetch_template_files (self .inputs .template , specs )
112
+ self ._results ['t1w_file' ] = files ['t1w' ]
113
+ self ._results ['brain_mask' ] = files ['mask' ]
139
114
return runtime
140
115
141
116
@@ -186,3 +161,39 @@ def _run_interface(self, runtime):
186
161
descsplit = desc .split ('-' )
187
162
self ._results ['spec' ][descsplit [0 ]] = descsplit [1 ]
188
163
return runtime
164
+
165
+
166
+ def fetch_template_files (template : str , specs : dict | None = None ) -> dict :
167
+ if specs is None :
168
+ specs = {}
169
+
170
+ name = template .strip (':' ).split (':' , 1 )
171
+ if len (name ) > 1 :
172
+ specs .update (
173
+ {
174
+ k : v
175
+ for modifier in name [1 ].split (':' )
176
+ for k , v in [tuple (modifier .split ('-' ))]
177
+ if k not in specs
178
+ }
179
+ )
180
+
181
+ if specs ['resolution' ] and not isinstance (specs ['resolution' ], list ):
182
+ specs ['resolution' ] = [specs ['resolution' ]]
183
+
184
+ available_resolutions = tf .TF_LAYOUT .get_resolutions (template = name [0 ])
185
+ if specs ['resolution' ] and not set (specs ['resolution' ]) & set (available_resolutions ):
186
+ fallback_res = available_resolutions [0 ] if available_resolutions else None
187
+ LOGGER .warning (
188
+ f"Template { name [0 ]} does not have resolution(s): { specs ['resolution' ]} ."
189
+ f"Falling back to resolution: { fallback_res } ."
190
+ )
191
+ specs ['resolution' ] = fallback_res
192
+
193
+ files = {}
194
+ files ['t1w' ] = tf .get (name [0 ], desc = None , suffix = 'T1w' , ** specs )
195
+ files ['mask' ] = (
196
+ tf .get (name [0 ], desc = 'brain' , suffix = 'mask' , ** specs )
197
+ or tf .get (name [0 ], label = 'brain' , suffix = 'mask' , ** specs )
198
+ )
199
+ return files
0 commit comments