#NEWLINE# @ testing . requires_testing_data #NEWLINE# @ requires_freesurfer #NEWLINE# @ requires_nibabel ( ) #NEWLINE# def test_source_space_from_label( ) : #NEWLINE# #INDENT# 'Test generating a source space from volume label\n    ' #NEWLINE# tempdir = _TempDir ( ) #NEWLINE# aseg_fname = op . join ( subjects_dir , 'sample' , 'mri' , 'aseg.mgz' ) #NEWLINE# label_names = get_volume_labels_from_aseg ( aseg_fname ) #NEWLINE# volume_label = src [ int ( ( np . random . rand ( ) * len ( label_names ) ) ) ] #NEWLINE# pos = dict ( ) #NEWLINE# assert_raises ( ValueError , setup_volume_source_space , 'sample' , pos = pos , volume_label = volume_label , mri = aseg_fname ) #NEWLINE# assert_raises ( RuntimeError , setup_volume_source_space , 'sample' , mri = None , volume_label = volume_label ) #NEWLINE# assert_raises ( ValueError , setup_volume_source_space , 'sample' , volume_label = 'Hello World!' , mri = aseg_fname ) #NEWLINE# src = setup_volume_source_space ( 'sample' , subjects_dir = subjects_dir , volume_label = volume_label , mri = aseg_fname , add_interpolator = False ) #NEWLINE# assert_equal ( volume_label , src [ 0 ] [ 'seg_name' ] ) #NEWLINE# out_name = op . join ( tempdir , 'temp-src.fif' ) #NEWLINE# write_source_spaces ( out_name , src ) #NEWLINE# src_from_file = read_source_spaces ( out_name ) #NEWLINE# _compare_source_spaces ( src , src_from_file , mode = 'approx' )