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