def test_get_montage_volume_labels(): """Test finding ROI labels near montage channel locations.""" ch_coords = np.array([[-8.7040273, 17.99938754, 10.29604017], [-14.03007764, 19.69978401, 12.07236939], [-21.1130506, 21.98310911, 13.25658887]]) ch_pos = dict(zip(['1', '2', '3'], ch_coords / 1000)) # mm -> m montage = make_dig_montage(ch_pos, coord_frame='mri') labels, colors = get_montage_volume_labels(montage, 'sample', subjects_dir, aseg='aseg', dist=1) assert labels == { '1': ['Unknown'], '2': ['Left-Cerebral-Cortex'], '3': ['Left-Cerebral-Cortex'] } assert 'Unknown' in colors assert 'Left-Cerebral-Cortex' in colors np.testing.assert_almost_equal( colors['Left-Cerebral-Cortex'], (0.803921568627451, 0.24313725490196078, 0.3058823529411765, 1.0)) np.testing.assert_almost_equal(colors['Unknown'], (0.0, 0.0, 0.0, 1.0)) # test inputs with pytest.raises(RuntimeError, match='`aseg` file path must end with "aseg"'): get_montage_volume_labels(montage, 'sample', subjects_dir, aseg='foo') fail_montage = make_dig_montage(ch_pos, coord_frame='head') with pytest.raises(RuntimeError, match='Coordinate frame not supported'): get_montage_volume_labels(fail_montage, 'sample', subjects_dir, aseg='aseg')
fig = mne.viz.plot_alignment(epochs.info, trans, 'fsaverage', subjects_dir=subjects_dir, show_axes=True, surfaces=['pial', 'head'], coord_frame='mri') # %% # Let's also look at which regions of interest are nearby our electrode # contacts. aseg = 'aparc+aseg' # parcellation/anatomical segmentation atlas labels, colors = mne.get_montage_volume_labels(montage, 'fsaverage', subjects_dir=subjects_dir, aseg=aseg) # separate by electrodes which have names like LAMY 1 electrodes = set([ ''.join([lttr for lttr in ch_name if not lttr.isdigit() and lttr != ' ']) for ch_name in montage.ch_names ]) print(f'Electrodes in the dataset: {electrodes}') electrodes = ('LPM', 'LSMA') # choose two for this example for elec in electrodes: picks = [ch_name for ch_name in epochs.ch_names if elec in ch_name] fig = plt.figure(num=None, figsize=(8, 8), facecolor='black') mne.viz.plot_channel_labels_circle(labels, colors, picks=picks, fig=fig) fig.text(0.3, 0.9, 'Anatomical Labels', color='white')