Skip to content

[ENH]: add list_fwhm option to create_susan_smooth #2233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 13, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions nipype/workflows/fmri/fsl/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from __future__ import division

import os

from ....interfaces import fsl as fsl # fsl
from ....interfaces import utility as util # utility
from ....pipeline import engine as pe # pypeline engine
Expand Down Expand Up @@ -771,7 +770,7 @@ def create_susan_smooth(name="susan_smooth", separate_masks=True):
Inputs::

inputnode.in_files : functional runs (filename or list of filenames)
inputnode.fwhm : fwhm for smoothing with SUSAN
inputnode.fwhm : fwhm for smoothing with SUSAN (float or list of floats)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doc update is good, though. Let's keep that.

inputnode.mask_file : mask used for estimating SUSAN thresholds (but not for smoothing)

Outputs::
Expand All @@ -788,6 +787,19 @@ def create_susan_smooth(name="susan_smooth", separate_masks=True):
>>> smooth.run() # doctest: +SKIP

"""
# replaces the functionality of a "for loop"
def cartesian_product(fwhms, in_files, usans, btthresh):
from nipype.utils.filemanip import filename_to_list
# ensure all inputs are lists
in_files = filename_to_list(in_files)
fwhms = [fwhms] if isinstance(fwhms, (int, float)) else fwhms
# create cartesian product lists (s_<name> = single element of list)
cart_in_file = [s_in_file for s_in_file in in_files for s_fwhm in fwhms]
cart_fwhm = [s_fwhm for s_in_file in in_files for s_fwhm in fwhms]
cart_usans = [s_usans for s_usans in usans for s_fwhm in fwhms]
cart_btthresh = [s_btthresh for s_btthresh in btthresh for s_fwhm in fwhms]

return cart_in_file, cart_fwhm, cart_usans, cart_btthresh

susan_smooth = pe.Workflow(name=name)

Expand All @@ -807,8 +819,15 @@ def create_susan_smooth(name="susan_smooth", separate_masks=True):
functional
"""

multi_inputs = pe.Node(util.Function(function=cartesian_product,
output_names=['cart_in_file',
'cart_fwhm',
'cart_usans',
'cart_btthresh']),
name='multi_inputs')

smooth = pe.MapNode(interface=fsl.SUSAN(),
iterfield=['in_file', 'brightness_threshold', 'usans'],
iterfield=['in_file', 'brightness_threshold', 'usans', 'fwhm'],
name='smooth')

"""
Expand Down Expand Up @@ -865,10 +884,17 @@ def create_susan_smooth(name="susan_smooth", separate_masks=True):
"""
Define a function to get the brightness threshold for SUSAN
"""
susan_smooth.connect(inputnode, 'fwhm', smooth, 'fwhm')
susan_smooth.connect(inputnode, 'in_files', smooth, 'in_file')
susan_smooth.connect(median, ('out_stat', getbtthresh), smooth, 'brightness_threshold')
susan_smooth.connect(merge, ('out', getusans), smooth, 'usans')

susan_smooth.connect([
(inputnode, multi_inputs, [('in_files', 'in_files'),
('fwhm', 'fwhms')]),
(median, multi_inputs, [(('out_stat', getbtthresh), 'btthresh')]),
(merge, multi_inputs, [(('out', getusans), 'usans')]),
(multi_inputs, smooth, [('cart_in_file', 'in_file'),
('cart_fwhm', 'fwhm'),
('cart_btthresh', 'brightness_threshold'),
('cart_usans', 'usans')]),
])

outputnode = pe.Node(interface=util.IdentityInterface(fields=['smoothed_files']),
name='outputnode')
Expand Down