4
4
from __future__ import division
5
5
6
6
import os
7
-
8
7
from ....interfaces import fsl as fsl # fsl
9
8
from ....interfaces import utility as util # utility
10
9
from ....pipeline import engine as pe # pypeline engine
@@ -771,7 +770,7 @@ def create_susan_smooth(name="susan_smooth", separate_masks=True):
771
770
Inputs::
772
771
773
772
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)
775
774
inputnode.mask_file : mask used for estimating SUSAN thresholds (but not for smoothing)
776
775
777
776
Outputs::
@@ -788,6 +787,19 @@ def create_susan_smooth(name="susan_smooth", separate_masks=True):
788
787
>>> smooth.run() # doctest: +SKIP
789
788
790
789
"""
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
791
803
792
804
susan_smooth = pe .Workflow (name = name )
793
805
@@ -807,8 +819,15 @@ def create_susan_smooth(name="susan_smooth", separate_masks=True):
807
819
functional
808
820
"""
809
821
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
+
810
829
smooth = pe .MapNode (interface = fsl .SUSAN (),
811
- iterfield = ['in_file' , 'brightness_threshold' , 'usans' ],
830
+ iterfield = ['in_file' , 'brightness_threshold' , 'usans' , 'fwhm' ],
812
831
name = 'smooth' )
813
832
814
833
"""
@@ -865,10 +884,17 @@ def create_susan_smooth(name="susan_smooth", separate_masks=True):
865
884
"""
866
885
Define a function to get the brightness threshold for SUSAN
867
886
"""
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
+ ])
872
898
873
899
outputnode = pe .Node (interface = util .IdentityInterface (fields = ['smoothed_files' ]),
874
900
name = 'outputnode' )
0 commit comments