Skip to content

Commit

Permalink
FIX: Add truth table logic to determine which derivatives should be used
Browse files Browse the repository at this point in the history
  • Loading branch information
mgxd committed Aug 14, 2023
1 parent b32b7ab commit e7b3a97
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions nibabies/workflows/anatomical/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,41 @@ def init_infant_anat_wf(
cifti_output=cifti_output,
)

# Multiple anatomical files -> generate average reference
# Derivatives used based on the following truth table:
# |--------|--------|---------------------------------|------------------|
# | Has T1 | Has T2 | M-CRIB-S surface reconstruction | Derivatives Used |
# |--------|--------|---------------------------------|------------------|
# | Yes | No | No | T1 |
# | Yes | Yes | No | T1 |
# | No | Yes | No | T2 |
# | Yes | Yes | Yes | T2 |

recon_method = config.workflow.surface_recon_method
t1w_mask = bool(derivatives.t1w_mask)
t1w_aseg = bool(derivatives.t1w_aseg)
t2w_mask = bool(derivatives.t2w_mask)
t2w_aseg = bool(derivatives.t2w_aseg)

Check warning on line 215 in nibabies/workflows/anatomical/base.py

View check run for this annotation

Codecov / codecov/patch

nibabies/workflows/anatomical/base.py#L211-L215

Added lines #L211 - L215 were not covered by tests

# The T2 derivatives are only prioritized first if MCRIBS reconstruction is to be used.
if recon_method == "mcribs":
if t2w_aseg:
t1w_aseg = False
if t2w_mask:
t1w_mask = False

Check warning on line 222 in nibabies/workflows/anatomical/base.py

View check run for this annotation

Codecov / codecov/patch

nibabies/workflows/anatomical/base.py#L218-L222

Added lines #L218 - L222 were not covered by tests

if t1w_mask:
t2w_mask = False
if t1w_aseg:
t2w_aseg = False

Check warning on line 227 in nibabies/workflows/anatomical/base.py

View check run for this annotation

Codecov / codecov/patch

nibabies/workflows/anatomical/base.py#L224-L227

Added lines #L224 - L227 were not covered by tests

config.loggers.workflow.debug(

Check warning on line 229 in nibabies/workflows/anatomical/base.py

View check run for this annotation

Codecov / codecov/patch

nibabies/workflows/anatomical/base.py#L229

Added line #L229 was not covered by tests
"Derivatives used:\n<T1 mask %s>\n<T1 aseg %s>\n<T2 mask %s>\n<T2 aseg %s>",
t1w_mask,
t1w_aseg,
t2w_mask,
t2w_aseg,
)

t1w_template_wf = init_anat_template_wf(
contrast="T1w",
num_files=num_t1w,
Expand Down Expand Up @@ -425,11 +454,11 @@ def init_infant_anat_wf(
if not freesurfer:
return wf

if config.workflow.surface_recon_method == 'freesurfer':
if recon_method == 'freesurfer':

Check warning on line 457 in nibabies/workflows/anatomical/base.py

View check run for this annotation

Codecov / codecov/patch

nibabies/workflows/anatomical/base.py#L457

Added line #L457 was not covered by tests
from smriprep.workflows.surfaces import init_surface_recon_wf

surface_recon_wf = init_surface_recon_wf(omp_nthreads=omp_nthreads, hires=hires)
elif config.workflow.surface_recon_method == 'infantfs':
elif recon_method == 'infantfs':

Check warning on line 461 in nibabies/workflows/anatomical/base.py

View check run for this annotation

Codecov / codecov/patch

nibabies/workflows/anatomical/base.py#L461

Added line #L461 was not covered by tests
from .surfaces import init_infantfs_surface_recon_wf

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

elif config.workflow.surface_recon_method == 'mcribs':
elif recon_method == 'mcribs':

Check warning on line 471 in nibabies/workflows/anatomical/base.py

View check run for this annotation

Codecov / codecov/patch

nibabies/workflows/anatomical/base.py#L471

Added line #L471 was not covered by tests
from nipype.interfaces.ants import DenoiseImage

from .surfaces import init_mcribs_sphere_reg_wf, init_mcribs_surface_recon_wf
Expand Down Expand Up @@ -471,7 +500,7 @@ def init_infant_anat_wf(
else:
raise NotImplementedError

if config.workflow.surface_recon_method in ('freesurfer', 'infantfs'):
if recon_method in ('freesurfer', 'infantfs'):

Check warning on line 503 in nibabies/workflows/anatomical/base.py

View check run for this annotation

Codecov / codecov/patch

nibabies/workflows/anatomical/base.py#L503

Added line #L503 was not covered by tests
from smriprep.workflows.surfaces import init_sphere_reg_wf

# fsaverage to fsLR
Expand Down Expand Up @@ -553,7 +582,7 @@ def init_infant_anat_wf(
init_anat_fsLR_resampling_wf,
)

is_mcribs = config.workflow.surface_recon_method == "mcribs"
is_mcribs = recon_method == "mcribs"

Check warning on line 585 in nibabies/workflows/anatomical/base.py

View check run for this annotation

Codecov / codecov/patch

nibabies/workflows/anatomical/base.py#L585

Added line #L585 was not covered by tests
# handles morph_grayords_wf
anat_fsLR_resampling_wf = init_anat_fsLR_resampling_wf(cifti_output, mcribs=is_mcribs)
anat_derivatives_wf.get_node('inputnode').inputs.cifti_density = cifti_output
Expand Down

0 comments on commit e7b3a97

Please sign in to comment.