Skip to content

Commit e7b3a97

Browse files
committed
FIX: Add truth table logic to determine which derivatives should be used
1 parent b32b7ab commit e7b3a97

File tree

1 file changed

+35
-6
lines changed
  • nibabies/workflows/anatomical

1 file changed

+35
-6
lines changed

nibabies/workflows/anatomical/base.py

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,41 @@ def init_infant_anat_wf(
199199
cifti_output=cifti_output,
200200
)
201201

202-
# Multiple anatomical files -> generate average reference
202+
# Derivatives used based on the following truth table:
203+
# |--------|--------|---------------------------------|------------------|
204+
# | Has T1 | Has T2 | M-CRIB-S surface reconstruction | Derivatives Used |
205+
# |--------|--------|---------------------------------|------------------|
206+
# | Yes | No | No | T1 |
207+
# | Yes | Yes | No | T1 |
208+
# | No | Yes | No | T2 |
209+
# | Yes | Yes | Yes | T2 |
210+
211+
recon_method = config.workflow.surface_recon_method
203212
t1w_mask = bool(derivatives.t1w_mask)
204213
t1w_aseg = bool(derivatives.t1w_aseg)
205214
t2w_mask = bool(derivatives.t2w_mask)
206215
t2w_aseg = bool(derivatives.t2w_aseg)
207216

217+
# The T2 derivatives are only prioritized first if MCRIBS reconstruction is to be used.
218+
if recon_method == "mcribs":
219+
if t2w_aseg:
220+
t1w_aseg = False
221+
if t2w_mask:
222+
t1w_mask = False
223+
224+
if t1w_mask:
225+
t2w_mask = False
226+
if t1w_aseg:
227+
t2w_aseg = False
228+
229+
config.loggers.workflow.debug(
230+
"Derivatives used:\n<T1 mask %s>\n<T1 aseg %s>\n<T2 mask %s>\n<T2 aseg %s>",
231+
t1w_mask,
232+
t1w_aseg,
233+
t2w_mask,
234+
t2w_aseg,
235+
)
236+
208237
t1w_template_wf = init_anat_template_wf(
209238
contrast="T1w",
210239
num_files=num_t1w,
@@ -425,11 +454,11 @@ def init_infant_anat_wf(
425454
if not freesurfer:
426455
return wf
427456

428-
if config.workflow.surface_recon_method == 'freesurfer':
457+
if recon_method == 'freesurfer':
429458
from smriprep.workflows.surfaces import init_surface_recon_wf
430459

431460
surface_recon_wf = init_surface_recon_wf(omp_nthreads=omp_nthreads, hires=hires)
432-
elif config.workflow.surface_recon_method == 'infantfs':
461+
elif recon_method == 'infantfs':
433462
from .surfaces import init_infantfs_surface_recon_wf
434463

435464
# if running with precomputed aseg, or JLF, pass the aseg along to FreeSurfer
@@ -439,7 +468,7 @@ def init_infant_anat_wf(
439468
use_aseg=use_aseg,
440469
)
441470

442-
elif config.workflow.surface_recon_method == 'mcribs':
471+
elif recon_method == 'mcribs':
443472
from nipype.interfaces.ants import DenoiseImage
444473

445474
from .surfaces import init_mcribs_sphere_reg_wf, init_mcribs_surface_recon_wf
@@ -471,7 +500,7 @@ def init_infant_anat_wf(
471500
else:
472501
raise NotImplementedError
473502

474-
if config.workflow.surface_recon_method in ('freesurfer', 'infantfs'):
503+
if recon_method in ('freesurfer', 'infantfs'):
475504
from smriprep.workflows.surfaces import init_sphere_reg_wf
476505

477506
# fsaverage to fsLR
@@ -553,7 +582,7 @@ def init_infant_anat_wf(
553582
init_anat_fsLR_resampling_wf,
554583
)
555584

556-
is_mcribs = config.workflow.surface_recon_method == "mcribs"
585+
is_mcribs = recon_method == "mcribs"
557586
# handles morph_grayords_wf
558587
anat_fsLR_resampling_wf = init_anat_fsLR_resampling_wf(cifti_output, mcribs=is_mcribs)
559588
anat_derivatives_wf.get_node('inputnode').inputs.cifti_density = cifti_output

0 commit comments

Comments
 (0)