32
32
class ComputeDVARSInputSpec (BaseInterfaceInputSpec ):
33
33
in_file = File (exists = True , mandatory = True , desc = 'functional data, after HMC' )
34
34
in_mask = File (exists = True , mandatory = True , desc = 'a brain mask' )
35
- remove_zerovariance = traits .Bool (False , usedefault = True ,
35
+ remove_zerovariance = traits .Bool (True , usedefault = True ,
36
36
desc = 'remove voxels with zero variance' )
37
37
save_std = traits .Bool (True , usedefault = True ,
38
38
desc = 'save standardized DVARS' )
@@ -626,7 +626,7 @@ def compute_dvars(in_file, in_mask, remove_zerovariance=False):
626
626
627
627
if remove_zerovariance :
628
628
# Remove zero-variance voxels across time axis
629
- mask = zero_variance ( func , mask )
629
+ mask = zero_remove ( func_sd , mask )
630
630
631
631
idx = np .where (mask > 0 )
632
632
mfunc = func [idx [0 ], idx [1 ], idx [2 ], :]
@@ -650,35 +650,28 @@ def compute_dvars(in_file, in_mask, remove_zerovariance=False):
650
650
# standardization
651
651
dvars_stdz = dvars_nstd / diff_sd_mean
652
652
653
-
654
- with warnings .catch_warnings (): # catch divide by zero errors
653
+ with warnings .catch_warnings (): # catch, e.g., divide by zero errors
655
654
warnings .filterwarnings ('error' )
656
655
657
656
# voxelwise standardization
658
- diff_vx_stdz = func_diff / np .array ([diff_sdhat ] * func_diff .shape [- 1 ]).T
657
+ diff_vx_stdz = func_diff / np .array ([diff_sdhat ] * func_diff .shape [- 1 ]).T
659
658
dvars_vx_stdz = diff_vx_stdz .std (axis = 0 , ddof = 1 )
660
659
661
660
return (dvars_stdz , dvars_nstd , dvars_vx_stdz )
662
661
663
- def zero_variance ( func , mask ):
662
+ def zero_remove ( data , mask ):
664
663
"""
665
- Mask out voxels with zero variance across t-axis
664
+ Modify inputted mask to also mask out zero values
666
665
667
- :param numpy.ndarray func: input fMRI dataset, after motion correction
668
- :param numpy.ndarray mask: 3D brain mask
669
- :return: the 3D mask of voxels with nonzero variance across :math:`t`.
666
+ :param numpy.ndarray data: e.g. voxelwise stddev of fMRI dataset, after motion correction
667
+ :param numpy.ndarray mask: brain mask (same dimensions as data)
668
+ :return: the mask with any additional zero voxels removed (same dimensions as inputs)
670
669
:rtype: numpy.ndarray
671
670
672
671
"""
673
- idx = np .where (mask > 0 )
674
- func = func [idx [0 ], idx [1 ], idx [2 ], :]
675
- tvariance = func .var (axis = 1 )
676
- tv_mask = np .zeros_like (tvariance , dtype = np .uint8 )
677
- tv_mask [tvariance > 0 ] = 1
678
-
679
- newmask = np .zeros_like (mask , dtype = np .uint8 )
680
- newmask [idx ] = tv_mask
681
- return newmask
672
+ new_mask = mask .copy ()
673
+ new_mask [data == 0 ] = 0
674
+ return new_mask
682
675
683
676
def plot_confound (tseries , figsize , name , units = None ,
684
677
series_tr = None , normalize = False ):
0 commit comments