[18]:
import mne
import numpy as np
from PIL import Image
from matplotlib import pyplot as plt

from matplotlib.offsetbox import TextArea, DrawingArea, OffsetImage, AnnotationBbox
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
[115]:
channels_names = 'Fp1,Fp2,F7,Fz,F8,T3,C3,Cz,C4,T4,T5,Pz,T6,O1,O2,EOG'.split(',')
montage = mne.channels.make_standard_montage('standard_1020')
values = np.random.normal(size=15)


dig = montage.dig[-1]
dig = dig.copy()
dig['r'] = np.array([ -0.1, -0.02397066, -0.06520565])
# dig['ident'] = 999
montage.dig.append(dig)

info = mne.create_info(channels_names, sfreq=1000, ch_types="eeg")
info.set_montage(montage)

fig = plt.figure(figsize=(16, 9), dpi=90)
ax = plt.subplot(111)


for pos in [-0.18, -0.25]:
    imagebox = OffsetImage(mpimg.imread('eye.png'), zoom=0.05, resample=True)
    ab = AnnotationBbox(imagebox, (pos, 0), frameon=False)
    ax.add_artist(ab)



plt.xlim(-0.25, 0.12)
# plt.ylim(-0.5, 0.5)


mne.viz.plot_topomap(values, info, vmin=-1, vmax=1, contours=0, outlines='skirt', names=channels_names, show_names=True, axes=ax)



---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-115-5a8ff58cfa56> in <module>
     11
     12 info = mne.create_info(channels_names, sfreq=1000, ch_types="eeg")
---> 13 info.set_montage(montage)
     14
     15 fig = plt.figure(figsize=(16, 9), dpi=90)

<decorator-gen-23> in set_montage(self, montage, match_case, match_alias, on_missing, verbose)

~/Development/BCI-Framework/venv/lib/python3.9/site-packages/mne/io/meas_info.py in set_montage(self, montage, match_case, match_alias, on_missing, verbose)
    168         from ..channels.montage import _set_montage
    169         info = self if isinstance(self, Info) else self.info
--> 170         _set_montage(info, montage, match_case, match_alias, on_missing)
    171         return self
    172

~/Development/BCI-Framework/venv/lib/python3.9/site-packages/mne/channels/montage.py in _set_montage(***failed resolving arguments***)
    803
    804         # get the channels in the montage in head
--> 805         ch_pos = mnt_head._get_ch_pos()
    806
    807         # only get the eeg, seeg, dbs, ecog channels

~/Development/BCI-Framework/venv/lib/python3.9/site-packages/mne/channels/montage.py in _get_ch_pos(self)
    301     def _get_ch_pos(self):
    302         pos = [d['r'] for d in _get_dig_eeg(self.dig)]
--> 303         assert len(self.ch_names) == len(pos)
    304         return OrderedDict(zip(self.ch_names, pos))
    305

AssertionError:
[88]:
d = montage.dig[0]
[102]:
dig = montage.dig[-1]
dig = dig.copy()
dig['r'] = np.array([ -0.1, -0.02397066, -0.06520565])
dig['ident'] = 999

montage.dig.append(dig)
[101]:
len(channels_names)
[101]:
16
[117]:
montage
[117]:
<DigMontage | 0 extras (headshape), 0 HPIs, 3 fiducials, 95 channels>
[ ]:
info.