44from __future__ import division
55
66import os
7-
87from ....interfaces import fsl as fsl # fsl
98from ....interfaces import utility as util # utility
109from ....pipeline import engine as pe # pypeline engine
@@ -771,7 +770,7 @@ def create_susan_smooth(name="susan_smooth", separate_masks=True):
771770 Inputs::
772771
773772 inputnode.in_files : functional runs (filename or list of filenames)
774- inputnode.fwhm : fwhm for smoothing with SUSAN
773+ inputnode.fwhm : fwhm for smoothing with SUSAN (float or list of floats)
775774 inputnode.mask_file : mask used for estimating SUSAN thresholds (but not for smoothing)
776775
777776 Outputs::
@@ -788,6 +787,19 @@ def create_susan_smooth(name="susan_smooth", separate_masks=True):
788787 >>> smooth.run() # doctest: +SKIP
789788
790789 """
790+ # replaces the functionality of a "for loop"
791+ def cartesian_product (fwhms , in_files , usans , btthresh ):
792+ from nipype .utils .filemanip import filename_to_list
793+ # ensure all inputs are lists
794+ in_files = filename_to_list (in_files )
795+ fwhms = [fwhms ] if isinstance (fwhms , (int , float )) else fwhms
796+ # create cartesian product lists (s_<name> = single element of list)
797+ cart_in_file = [s_in_file for s_in_file in in_files for s_fwhm in fwhms ]
798+ cart_fwhm = [s_fwhm for s_in_file in in_files for s_fwhm in fwhms ]
799+ cart_usans = [s_usans for s_usans in usans for s_fwhm in fwhms ]
800+ cart_btthresh = [s_btthresh for s_btthresh in btthresh for s_fwhm in fwhms ]
801+
802+ return cart_in_file , cart_fwhm , cart_usans , cart_btthresh
791803
792804 susan_smooth = pe .Workflow (name = name )
793805
@@ -807,8 +819,15 @@ def create_susan_smooth(name="susan_smooth", separate_masks=True):
807819 functional
808820 """
809821
822+ multi_inputs = pe .Node (util .Function (function = cartesian_product ,
823+ output_names = ['cart_in_file' ,
824+ 'cart_fwhm' ,
825+ 'cart_usans' ,
826+ 'cart_btthresh' ]),
827+ name = 'multi_inputs' )
828+
810829 smooth = pe .MapNode (interface = fsl .SUSAN (),
811- iterfield = ['in_file' , 'brightness_threshold' , 'usans' ],
830+ iterfield = ['in_file' , 'brightness_threshold' , 'usans' , 'fwhm' ],
812831 name = 'smooth' )
813832
814833 """
@@ -865,10 +884,17 @@ def create_susan_smooth(name="susan_smooth", separate_masks=True):
865884 """
866885 Define a function to get the brightness threshold for SUSAN
867886 """
868- susan_smooth .connect (inputnode , 'fwhm' , smooth , 'fwhm' )
869- susan_smooth .connect (inputnode , 'in_files' , smooth , 'in_file' )
870- susan_smooth .connect (median , ('out_stat' , getbtthresh ), smooth , 'brightness_threshold' )
871- susan_smooth .connect (merge , ('out' , getusans ), smooth , 'usans' )
887+
888+ susan_smooth .connect ([
889+ (inputnode , multi_inputs , [('in_files' , 'in_files' ),
890+ ('fwhm' , 'fwhms' )]),
891+ (median , multi_inputs , [(('out_stat' , getbtthresh ), 'btthresh' )]),
892+ (merge , multi_inputs , [(('out' , getusans ), 'usans' )]),
893+ (multi_inputs , smooth , [('cart_in_file' , 'in_file' ),
894+ ('cart_fwhm' , 'fwhm' ),
895+ ('cart_btthresh' , 'brightness_threshold' ),
896+ ('cart_usans' , 'usans' )]),
897+ ])
872898
873899 outputnode = pe .Node (interface = util .IdentityInterface (fields = ['smoothed_files' ]),
874900 name = 'outputnode' )
0 commit comments