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

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