@@ -757,7 +757,7 @@ def create_featreg_preproc(name='featpreproc', highpass=True, whichvol='middle',
757
757
return featpreproc
758
758
759
759
760
- def create_susan_smooth (name = "susan_smooth" , separate_masks = True ):
760
+ def create_susan_smooth (name = "susan_smooth" , separate_masks = True , list_fwhms = False ):
761
761
"""Create a SUSAN smoothing workflow
762
762
763
763
Parameters
@@ -767,11 +767,12 @@ def create_susan_smooth(name="susan_smooth", separate_masks=True):
767
767
768
768
name : name of workflow (default: susan_smooth)
769
769
separate_masks : separate masks for each run
770
+ list_fwhms : multiple full wide half maximum smoothing kernels
770
771
771
772
Inputs::
772
773
773
774
inputnode.in_files : functional runs (filename or list of filenames)
774
- inputnode.fwhm : fwhm for smoothing with SUSAN
775
+ inputnode.fwhm : fwhm for smoothing with SUSAN (float or list of floats)
775
776
inputnode.mask_file : mask used for estimating SUSAN thresholds (but not for smoothing)
776
777
777
778
Outputs::
@@ -788,6 +789,18 @@ def create_susan_smooth(name="susan_smooth", separate_masks=True):
788
789
>>> smooth.run() # doctest: +SKIP
789
790
790
791
"""
792
+ def cartesian_product (fwhms , in_files , mask_files , merge_out , median_out ):
793
+ if type (in_files ) == str :
794
+ in_files = [in_files ]
795
+ if type (mask_files ) == str :
796
+ mask_files = [mask_files ]
797
+ multi_in_files = [in_file for in_file in in_files for fwhm in fwhms ]
798
+ multi_mask_files = [mask_file for mask_file in mask_files for fwhm in fwhms ]
799
+ multi_fwhms = [fwhm for fwhm in fwhms for in_file in in_files ]
800
+ multi_merge_out = [merge for merge in merge_out for fwhm in fwhms ]
801
+ multi_median_out = [median for median in median_out for fwhm in fwhms ]
802
+
803
+ return multi_in_files , multi_mask_files , multi_fwhms , multi_merge_out , multi_median_out
791
804
792
805
susan_smooth = pe .Workflow (name = name )
793
806
@@ -806,10 +819,27 @@ def create_susan_smooth(name="susan_smooth", separate_masks=True):
806
819
of the median value for each run and a mask consituting the mean
807
820
functional
808
821
"""
809
-
810
- smooth = pe .MapNode (interface = fsl .SUSAN (),
811
- iterfield = ['in_file' , 'brightness_threshold' , 'usans' ],
812
- name = 'smooth' )
822
+ if list_fwhms :
823
+ multi_inputs = pe .Node (util .Function (input_names = ['fwhms' ,
824
+ 'in_files' ,
825
+ 'mask_files' ,
826
+ 'merge_out' ,
827
+ 'median_out' ],
828
+ output_names = ['multi_in_files' ,
829
+ 'multi_mask_files' ,
830
+ 'multi_fwhms' ,
831
+ 'multi_merge_out' ,
832
+ 'multi_median_out' ],
833
+ function = cartesian_product ),
834
+ name = 'multi_inputs' )
835
+
836
+ smooth = pe .MapNode (interface = fsl .SUSAN (),
837
+ iterfield = ['in_file' , 'brightness_threshold' , 'usans' , 'fwhm' ],
838
+ name = 'smooth' )
839
+ else :
840
+ smooth = pe .MapNode (interface = fsl .SUSAN (),
841
+ iterfield = ['in_file' , 'brightness_threshold' , 'usans' ],
842
+ name = 'smooth' )
813
843
814
844
"""
815
845
Determine the median value of the functional runs using the mask
@@ -865,10 +895,24 @@ def create_susan_smooth(name="susan_smooth", separate_masks=True):
865
895
"""
866
896
Define a function to get the brightness threshold for SUSAN
867
897
"""
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' )
898
+ # if you are going to iterate over multiple values of fwhm
899
+ if list_fwhms :
900
+ susan_smooth .connect ([
901
+ (inputnode , multi_inputs , [('in_files' , 'in_files' ),
902
+ ('fwhm' , 'fwhms' ),
903
+ ('mask_file' , 'mask_files' )]),
904
+ ])
905
+ susan_smooth .connect (median , ('out_stat' , getbtthresh ), multi_inputs , 'median_out' )
906
+ susan_smooth .connect (merge , ('out' , getusans ), multi_inputs , 'merge_out' )
907
+ susan_smooth .connect (multi_inputs , 'multi_fwhms' , smooth , 'fwhm' )
908
+ susan_smooth .connect (multi_inputs , 'multi_in_files' , smooth , 'in_file' )
909
+ susan_smooth .connect (multi_inputs , 'multi_median_out' , smooth , 'brightness_threshold' )
910
+ susan_smooth .connect (multi_inputs , 'multi_merge_out' , smooth , 'usans' )
911
+ else :
912
+ susan_smooth .connect (inputnode , 'in_files' , smooth , 'in_file' )
913
+ susan_smooth .connect (inputnode , 'fwhm' , smooth , 'fwhm' )
914
+ susan_smooth .connect (median , ('out_stat' , getbtthresh ), smooth , 'brightness_threshold' )
915
+ susan_smooth .connect (merge , ('out' , getusans ), smooth , 'usans' )
872
916
873
917
outputnode = pe .Node (interface = util .IdentityInterface (fields = ['smoothed_files' ]),
874
918
name = 'outputnode' )
0 commit comments