#NEWLINE# @ slow_test #NEWLINE# @ testing . requires_testing_data #NEWLINE# def test_volume_stc( ) : #NEWLINE# #INDENT# 'Test volume STCs\n    ' #NEWLINE# tempdir = _TempDir ( ) #NEWLINE# N = 100 #NEWLINE# data = np . arange ( N ) [ : , np . newaxis ] #NEWLINE# datas = [ data , data , np . arange ( 2 ) [ : , np . newaxis ] ] #NEWLINE# vertno = np . arange ( N ) #NEWLINE# vertnos = [ vertno , vertno [ : , np . newaxis ] , np . arange ( 2 ) [ : , np . newaxis ] ] #NEWLINE# vertno_reads = [ vertno , vertno , np . arange ( 2 ) ] #NEWLINE# for ( data , vertno , vertno_read ) in zip ( datas , vertnos , vertno_reads ) : #NEWLINE# #INDENT# stc = VolSourceEstimate ( data , vertno , 0 , 1 ) #NEWLINE# fname_temp = op . join ( tempdir , 'temp-vl.stc' ) #NEWLINE# stc_new = stc #NEWLINE# for _ in range ( 2 ) : #NEWLINE# #INDENT# stc_new . save ( fname_temp ) #NEWLINE# stc_new = read_source_estimate ( fname_temp ) #NEWLINE# assert_true ( isinstance ( stc_new , VolSourceEstimate ) ) #NEWLINE# assert_array_equal ( vertno_read , stc_new . vertices ) #NEWLINE# assert_array_almost_equal ( stc . data , stc_new . data ) #NEWLINE# #UNINDENT# #UNINDENT# stc = read_source_estimate ( fname_vol , 'sample' ) #NEWLINE# assert_true ( isinstance ( stc , VolSourceEstimate ) ) #NEWLINE# assert_true ( ( 'sample' in repr ( stc ) ) ) #NEWLINE# stc_new = stc #NEWLINE# assert_raises ( ValueError , stc . save , fname_vol , ftype = 'whatever' ) #NEWLINE# for _ in range ( 2 ) : #NEWLINE# #INDENT# fname_temp = op . join ( tempdir , 'temp-vol.w' ) #NEWLINE# stc_new . save ( fname_temp , ftype = 'w' ) #NEWLINE# stc_new = read_source_estimate ( fname_temp ) #NEWLINE# assert_true ( isinstance ( stc_new , VolSourceEstimate ) ) #NEWLINE# assert_array_equal ( stc . vertices , stc_new . vertices ) #NEWLINE# assert_array_almost_equal ( stc . data , stc_new . data ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# import nibabel as nib #NEWLINE# with warnings . catch_warnings ( record = True ) : #NEWLINE# #INDENT# warnings . simplefilter ( 'always' ) #NEWLINE# src = read_source_spaces ( fname_vsrc ) #NEWLINE# #UNINDENT# vol_fname = op . join ( tempdir , 'stc.nii.gz' ) #NEWLINE# stc . save_as_volume ( vol_fname , src , dest = 'surf' , mri_resolution = False ) #NEWLINE# with warnings . catch_warnings ( record = True ) : #NEWLINE# #INDENT# img = nib . load ( vol_fname ) #NEWLINE# #UNINDENT# assert_true ( ( img . shape == ( src [ 0 ] [ 'shape' ] + ( len ( stc . times ) , ) ) ) ) #NEWLINE# with warnings . catch_warnings ( record = True ) : #NEWLINE# #INDENT# t1_img = nib . load ( fname_t1 ) #NEWLINE# #UNINDENT# stc . save_as_volume ( op . join ( tempdir , 'stc.nii.gz' ) , src , dest = 'mri' , mri_resolution = True ) #NEWLINE# with warnings . catch_warnings ( record = True ) : #NEWLINE# #INDENT# img = nib . load ( vol_fname ) #NEWLINE# #UNINDENT# assert_true ( ( img . shape == ( t1_img . shape + ( len ( stc . times ) , ) ) ) ) #NEWLINE# assert_array_almost_equal ( img . get_affine ( ) , t1_img . get_affine ( ) , decimal = 5 ) #NEWLINE# img = stc . as_volume ( src , dest = 'mri' , mri_resolution = True ) #NEWLINE# assert_true ( ( img . shape == ( t1_img . shape + ( len ( stc . times ) , ) ) ) ) #NEWLINE# assert_array_almost_equal ( img . get_affine ( ) , t1_img . get_affine ( ) , decimal = 5 ) #NEWLINE# #UNINDENT# except ImportError : #NEWLINE# #INDENT# print ( 'Save as nifti test skipped, needs NiBabel' )