Skip to content

Commit f30c2fd

Browse files
mgxdeffigies
authored andcommitted
FIX: Ensure templates are pulled on workflow construction
1 parent 4b6d38d commit f30c2fd

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

smriprep/utils/misc.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
# https://www.nipreps.org/community/licensing/
2222
#
2323
"""Self-contained utilities to be used within Function nodes."""
24+
from pathlib import Path
25+
import typing as ty
26+
27+
if ty.TYPE_CHECKING:
28+
from niworkflows.utils.spaces import Reference
2429

2530

2631
def apply_lut(in_dseg, lut, newpath=None):
@@ -95,3 +100,25 @@ def fs_isRunning(subjects_dir, subject_id, mtime_tol=86400, logger=None):
95100
if logger:
96101
logger.warn(f'Removed "IsRunning*" files found under {subj_dir}')
97102
return subjects_dir
103+
104+
105+
def get_template_t1w(template: str, sloppy: bool = False) -> Path:
106+
"""Query templateflow for the T1w to ensure it is present on the filesystem."""
107+
import templateflow.api as tf
108+
109+
spec = {}
110+
_space = template.split(':', 1)
111+
if len(_space) > 1:
112+
spec['cohort'] = _space[1].replace('cohort-', '')
113+
space = _space[0]
114+
115+
available_res = tf.TF_LAYOUT.get_resolutions(template=space)
116+
if sloppy and 2 in available_res:
117+
res = 2
118+
elif 1 in available_res:
119+
res = 1
120+
else:
121+
res = None
122+
spec['resolution'] = res
123+
124+
return tf.get(space, desc=None, suffix='T1w', **spec)

smriprep/workflows/anatomical.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,9 @@ def init_anat_fit_wf(
973973
templates = []
974974
found_xfms = {}
975975
for template in spaces.get_spaces(nonstandard=False, dim=(3,)):
976+
from ..utils.misc import get_template_t1w
977+
978+
get_template_t1w(template, sloppy)
976979
xfms = precomputed.get('transforms', {}).get(template, {})
977980
if set(xfms) != {'forward', 'reverse'}:
978981
templates.append(template)

0 commit comments

Comments
 (0)