21
21
# https://www.nipreps.org/community/licensing/
22
22
#
23
23
"""Interfaces to get templates from TemplateFlow."""
24
+ import logging
24
25
from templateflow import api as tf
25
26
from nipype .interfaces .base import (
26
27
SimpleInterface ,
32
33
InputMultiObject ,
33
34
)
34
35
36
+ LOGGER = logging .getLogger ("nipype.interface" )
37
+
35
38
36
39
class _TemplateFlowSelectInputSpec (BaseInterfaceInputSpec ):
37
40
template = traits .Str ("MNI152NLin2009cAsym" , mandatory = True , desc = "Template ID" )
@@ -87,8 +90,11 @@ class TemplateFlowSelect(SimpleInterface):
87
90
'.../tpl-MNIPediatricAsym_cohort-5_res-1_T1w.nii.gz'
88
91
89
92
>>> select = TemplateFlowSelect()
90
- >>> select.inputs.template = 'UNCInfant:cohort-1'
91
- >>> result = select.run() # doctest: +SKIP
93
+ >>> select.inputs.template = 'MNI305'
94
+ >>> select.inputs.template_spec = {'resolution': 1}
95
+ >>> result = select.run()
96
+ >>> result.outputs.t1w_file # doctest: +ELLIPSIS
97
+ '.../tpl-MNI305_T1w.nii.gz'
92
98
93
99
"""
94
100
@@ -115,6 +121,18 @@ def _run_interface(self, runtime):
115
121
}
116
122
)
117
123
124
+ if specs ['resolution' ] and not isinstance (specs ['resolution' ], list ):
125
+ specs ['resolution' ] = [specs ['resolution' ]]
126
+
127
+ available_resolutions = tf .TF_LAYOUT .get_resolutions (template = name [0 ])
128
+ if specs ['resolution' ] and not set (specs ["resolution" ]) & set (available_resolutions ):
129
+ fallback_res = available_resolutions [0 ] if available_resolutions else None
130
+ LOGGER .warning (
131
+ f"Template { name [0 ]} does not have resolution(s): { specs ['resolution' ]} ."
132
+ f"Falling back to resolution: { fallback_res } ."
133
+ )
134
+ specs ["resolution" ] = fallback_res
135
+
118
136
self ._results ["t1w_file" ] = tf .get (name [0 ], desc = None , suffix = "T1w" , ** specs )
119
137
120
138
self ._results ["brain_mask" ] = (
0 commit comments