Subject: mne.viz.plot_alignment not displaying electrodes

  • MNE version 1.2.2
  • operating system: Windows 10 Pro

Dear MNE experts,

I am trying to use the mne.viz.plot_alignment function to plot the sensor locations of my EEG data. However, I have noticed that the function does not display the electrodes on the scalp plot.

fig = mne.viz.plot_alignment(epoched.info, trans=trans, subject=subject, subjects_dir=subjects_dir, surfaces=['head', 'outer_skull', 'white'], coord_frame='mri', meg=False, eeg=['original', 'projected'], dig=False, ecog=False, src=src, mri_fiducials=False, bem=bem, seeg=False, show_axes=False, fig=None, interaction='terrain', verbose=True)

In case you want to inspect the eeg-epoched file you can find that here:

Is there a way to modify the function to show the electrodes, or is there an alternative function that I can use?

Thank you for your help.

Best regards,

D

Hi @Davi1990,

Did you set up the EEG montage correctly? Can you provide the output of epochs.info?

Here is the simple plot arguments that work with MNE example data:

mne.viz.plot_alignment(epochs.info, src=src, eeg=['original', 'projected'], trans=trans, show_axes=True, mri_fiducials=True, dig='fiducials')

best,
Dip

Hello,

Maybe dig=True?

Mathieu

Quick update:

When I create the enter position I only updated the epochs.info[‘dig’] locations. So I run the code below for setup a montage

pos_ordered = dict()
for idx, i in enumerate(epochs.ch_names):
    pos_ordered[i]= epochs.info['dig'][idx+3]['r']

montage = mne.channels.make_dig_montage(pos_ordered, nasion, lpa, rpa, coord_frame='mri')
epochs.set_montage(montage)

And then plot. But it doesn’t seems correct:

Can you check the following thread to see if its a channel re-scaling issue?

I am willing to have a look only if you can provide me the details, similar to the marked solution from the above thread.

best,
Dip

Thanks @dasdiptyajit,

I played all morning with it but it doesn’t seem a scaling problem. I would be grateful if you want to take a look at it. Please find all the data in this folder:

https://drive.google.com/drive/folders/1PCUagJHkHdnYi43h4WBjIBVWXxHO4C_n?usp=sharing

I uploaded the mri, bem, src as well as the epoched.fif file.

Please note that the dataset comes also with a x,y,z coordinates tsv file and fiducial.json that I also uploaded.

I hope it is clear

Thanks

D

@Davi1990 Thanks for sharing. I had a quick look. It seems like a re-scaling issue to me. DigPoint values look 1000 times higher. They should be as it is in x,y,z coordinates tsv file.

Test output:

In [74]: mne.viz.plot_montage(dig_mont, sphere='auto')
<ipython-input-74-73f4a0fefcd4>:1: RuntimeWarning: Estimated head radius (9509.3 cm) is above the 99th percentile for adult head size.
  mne.viz.plot_montage(dig_mont, sphere='auto')
<ipython-input-74-73f4a0fefcd4>:1: RuntimeWarning: (X, Y) fit (-5834.7, -4635.4) more than 20 mm from head frame origin
  mne.viz.plot_montage(dig_mont, sphere='auto')
Out[74]: <Figure size 640x640 with 1 Axes>

In [75]: epo.get_montage().dig
Out[75]: 
[<DigPoint |        LPA : (-71606.0, -2699.0, 1785.0) mm : head frame>,
 <DigPoint |     Nasion : (-10649.0, 93094.0, 17156.0) mm : head frame>,
 <DigPoint |        RPA : (57778.0, -569.0, -4316.0) mm : head frame>,
 <DigPoint |     EEG #1 : (60310.0, 54730.0, 19850.0) mm : head frame>,
 <DigPoint |     EEG #2 : (56820.0, 66800.0, 44930.0) mm : head frame>,
 <DigPoint |     EEG #3 : (52740.0, 71640.0, 63210.0) mm : head frame>,
 <DigPoint |     EEG #4 : (36210.0, 78970.0, 82400.0) mm : head frame>,
 <DigPoint |     EEG #5 : (24080.0, 74380.0, 98910.0) mm : head frame>,
 <DigPoint |     EEG #6 : (14080.0, 65340.0, 111560.0) mm : head frame>,
 <DigPoint |     EEG #7 : (2090.0, 50680.0, 124150.0) mm : head frame>,
 <DigPoint |     EEG #8 : (-6030.0, 36550.0, 131010.0) mm : head frame>,
 <DigPoint |     EEG #9 : (-18920.0, 12460.0, 136990.0) mm : head frame>,
 <DigPoint |    EEG #10 : (51200.0, 77360.0, 27200.0) mm : head frame>,
 <DigPoint |    EEG #11 : (44460.0, 84980.0, 45090.0) mm : head frame>,
 <DigPoint |    EEG #12 : (31750.0, 90700.0, 69940.0) mm : head frame>,
 <DigPoint |    EEG #13 : (16160.0, 87610.0, 86830.0) mm : head frame>,
 <DigPoint |    EEG #14 : (2140.0, 80660.0, 102120.0) mm : head frame>,
 <DigPoint |    EEG #15 : (-8460.0, 67050.0, 115380.0) mm : head frame>,
 <DigPoint |    EEG #16 : (-20850.0, 52720.0, 122600.0) mm : head frame>,
 <DigPoint |    EEG #17 : (-29500.0, 30610.0, 130330.0) mm : head frame>,
 <DigPoint |    EEG #18 : (30940.0, 94510.0, 32740.0) mm : head frame>,
 <DigPoint |    EEG #19 : (23170.0, 98890.0, 51760.0) mm : head frame>,
 <DigPoint |    EEG #20 : (7740.0, 97370.0, 72680.0) mm : head frame>,
 <DigPoint |    EEG #21 : (-8650.0, 90030.0, 90410.0) mm : head frame>,
 <DigPoint |    EEG #22 : (-22010.0, 77870.0, 103100.0) mm : head frame>,
 <DigPoint |    EEG #23 : (-32080.0, 64470.0, 110920.0) mm : head frame>,
 <DigPoint |    EEG #24 : (-40640.0, 42040.0, 120580.0) mm : head frame>,
 <DigPoint |    EEG #25 : (7890.0, 102820.0, 37020.0) mm : head frame>,
 <DigPoint |    EEG #26 : (-4550.0, 103570.0, 55560.0) mm : head frame>,
 <DigPoint |    EEG #27 : (-18400.0, 97330.0, 73800.0) mm : head frame>,
 <DigPoint |    EEG #28 : (-32390.0, 85680.0, 87110.0) mm : head frame>,
 <DigPoint |    EEG #29 : (-41950.0, 72480.0, 98680.0) mm : head frame>,
 <DigPoint |    EEG #30 : (-50820.0, 53590.0, 108200.0) mm : head frame>,
 <DigPoint |    EEG #31 : (-8950.0, 100410.0, 22290.0) mm : head frame>,
 <DigPoint |    EEG #32 : (-20180.0, 105880.0, 40140.0) mm : head frame>,
 <DigPoint |    EEG #33 : (-36720.0, 99030.0, 56620.0) mm : head frame>,
 <DigPoint |    EEG #34 : (-45820.0, 93200.0, 69220.0) mm : head frame>,
 <DigPoint |    EEG #35 : (-53570.0, 77850.0, 80470.0) mm : head frame>,
 <DigPoint |    EEG #36 : (-60240.0, 63590.0, 89520.0) mm : head frame>,
 <DigPoint |    EEG #37 : (-45750.0, 93520.0, 32780.0) mm : head frame>,
 <DigPoint |    EEG #38 : (-57950.0, 84060.0, 45680.0) mm : head frame>,
 <DigPoint |    EEG #39 : (-65470.0, 73570.0, 58330.0) mm : head frame>,
 <DigPoint |    EEG #40 : (-71240.0, 57800.0, 73580.0) mm : head frame>,
 <DigPoint |    EEG #41 : (-68150.0, 43300.0, 98780.0) mm : head frame>,
 <DigPoint |    EEG #42 : (-63220.0, 36330.0, 107430.0) mm : head frame>,
 <DigPoint |    EEG #43 : (-54220.0, 21310.0, 121950.0) mm : head frame>,
 <DigPoint |    EEG #44 : (-40050.0, 10420.0, 132980.0) mm : head frame>,
 <DigPoint |    EEG #45 : (-24490.0, -7900.0, 140530.0) mm : head frame>,
 <DigPoint |    EEG #46 : (-65780.0, 74270.0, 28190.0) mm : head frame>,
 <DigPoint |    EEG #47 : (-74310.0, 60920.0, 39200.0) mm : head frame>,
 <DigPoint |    EEG #48 : (-78450.0, 49350.0, 57540.0) mm : head frame>,
 <DigPoint |    EEG #49 : (-79370.0, 37160.0, 74330.0) mm : head frame>,
 <DigPoint |    EEG #50 : (-81220.0, 31560.0, 83290.0) mm : head frame>,
 <DigPoint |    EEG #51 : (-76310.0, 23900.0, 100290.0) mm : head frame>,
 <DigPoint |    EEG #52 : (-69870.0, 12040.0, 111290.0) mm : head frame>,
 <DigPoint |    EEG #53 : (-45350.0, -12230.0, 132100.0) mm : head frame>,
 <DigPoint |    EEG #54 : (-75940.0, 48540.0, 15060.0) mm : head frame>,
 <DigPoint |    EEG #55 : (-85010.0, 45730.0, 23020.0) mm : head frame>,
 <DigPoint |    EEG #56 : (-84720.0, 29080.0, 54240.0) mm : head frame>,
 <DigPoint |    EEG #57 : (-85540.0, 16410.0, 72060.0) mm : head frame>,
 <DigPoint |    EEG #58 : (-83480.0, 9990.0, 91600.0) mm : head frame>,
 <DigPoint |    EEG #59 : (-72940.0, -5380.0, 109990.0) mm : head frame>,
 <DigPoint |    EEG #60 : (-61350.0, -20040.0, 122110.0) mm : head frame>,
 <DigPoint |    EEG #61 : (-81480.0, 26110.0, 15930.0) mm : head frame>,
 <DigPoint |    EEG #62 : (-85370.0, 19390.0, 32010.0) mm : head frame>,
 <DigPoint |    EEG #63 : (-88920.0, -750.0, 73870.0) mm : head frame>,
 <DigPoint |    EEG #64 : (-85520.0, -10550.0, 87770.0) mm : head frame>,
 <DigPoint |    EEG #65 : (-77260.0, -25560.0, 105450.0) mm : head frame>,
 <DigPoint |    EEG #66 : (-80950.0, 12620.0, 290.0) mm : head frame>,
 <DigPoint |    EEG #67 : (-81680.0, 12210.0, 1770.0) mm : head frame>,
 <DigPoint |    EEG #68 : (-83630.0, 6860.0, 15390.0) mm : head frame>,
 <DigPoint |    EEG #69 : (-87080.0, -4580.0, 35380.0) mm : head frame>,
 <DigPoint |    EEG #70 : (-89370.0, -8560.0, 54080.0) mm : head frame>,
 <DigPoint |    EEG #71 : (-88980.0, -22210.0, 68180.0) mm : head frame>,
 <DigPoint |    EEG #72 : (-82240.0, -29510.0, 83480.0) mm : head frame>,
 <DigPoint |    EEG #73 : (-85600.0, -25750.0, 33080.0) mm : head frame>,
 <DigPoint |    EEG #74 : (-84780.0, -34340.0, 49610.0) mm : head frame>,
 <DigPoint |    EEG #75 : (-83640.0, -40380.0, 70330.0) mm : head frame>,
 <DigPoint |    EEG #76 : (-77490.0, -43290.0, 92300.0) mm : head frame>,
 <DigPoint |    EEG #77 : (-64970.0, -44280.0, 110880.0) mm : head frame>,
 <DigPoint |    EEG #78 : (-48470.0, -37720.0, 127220.0) mm : head frame>,
 <DigPoint |    EEG #79 : (-27230.0, -29930.0, 137260.0) mm : head frame>,
 <DigPoint |    EEG #80 : (-12460.0, -25520.0, 146570.0) mm : head frame>,
 <DigPoint |    EEG #81 : (-78830.0, -42720.0, 22240.0) mm : head frame>,
 <DigPoint |    EEG #82 : (-81210.0, -46020.0, 41860.0) mm : head frame>,
 <DigPoint |    EEG #83 : (-79580.0, -55160.0, 58180.0) mm : head frame>,
 <DigPoint |    EEG #84 : (-74800.0, -58260.0, 80740.0) mm : head frame>,
 <DigPoint |    EEG #85 : (-63660.0, -60330.0, 101030.0) mm : head frame>,
 <DigPoint |    EEG #86 : (-45840.0, -55140.0, 121930.0) mm : head frame>,
 <DigPoint |    EEG #87 : (-27520.0, -50920.0, 132940.0) mm : head frame>,
 <DigPoint |    EEG #88 : (-2170.0, -39740.0, 138200.0) mm : head frame>,
 <DigPoint |    EEG #89 : (-75770.0, -47810.0, 6350.0) mm : head frame>,
 <DigPoint |    EEG #90 : (-77360.0, -57140.0, 28850.0) mm : head frame>,
 <DigPoint |    EEG #91 : (-74180.0, -66280.0, 40940.0) mm : head frame>,
 <DigPoint |    EEG #92 : (-69310.0, -75340.0, 65850.0) mm : head frame>,
 <DigPoint |    EEG #93 : (-58140.0, -79460.0, 90340.0) mm : head frame>,
 <DigPoint |    EEG #94 : (-43940.0, -75500.0, 109890.0) mm : head frame>,
 <DigPoint |    EEG #95 : (-36100.0, -77830.0, 121980.0) mm : head frame>,
 <DigPoint |    EEG #96 : (-8020.0, -78000.0, 117640.0) mm : head frame>,
 <DigPoint |    EEG #97 : (-66600.0, -64480.0, 8070.0) mm : head frame>,
 <DigPoint |    EEG #98 : (-66390.0, -73830.0, 29660.0) mm : head frame>,
 <DigPoint |    EEG #99 : (-60170.0, -84530.0, 44680.0) mm : head frame>,
 <DigPoint |   EEG #100 : (-49370.0, -90860.0, 68340.0) mm : head frame>,
 <DigPoint |   EEG #101 : (-37780.0, -89690.0, 87850.0) mm : head frame>,
 <DigPoint |   EEG #102 : (-24940.0, -83580.0, 106380.0) mm : head frame>,
 <DigPoint |   EEG #103 : (-51320.0, -86300.0, 18040.0) mm : head frame>,
 <DigPoint |   EEG #104 : (-44730.0, -94340.0, 35290.0) mm : head frame>,
 <DigPoint |   EEG #105 : (-36420.0, -98580.0, 52080.0) mm : head frame>,
 <DigPoint |   EEG #106 : (-24920.0, -100360.0, 75470.0) mm : head frame>,
 <DigPoint |   EEG #107 : (-15840.0, -96060.0, 92020.0) mm : head frame>,
 <DigPoint |   EEG #108 : (-6050.0, -87690.0, 106080.0) mm : head frame>,
 <DigPoint |   EEG #109 : (-30240.0, -100360.0, 21370.0) mm : head frame>,
 <DigPoint |   EEG #110 : (-19780.0, -104600.0, 36320.0) mm : head frame>,
 <DigPoint |   EEG #111 : (-13580.0, -102590.0, 53240.0) mm : head frame>,
 <DigPoint |   EEG #112 : (-2930.0, -101330.0, 79580.0) mm : head frame>,
 <DigPoint |   EEG #113 : (9650.0, -94740.0, 92400.0) mm : head frame>,
 <DigPoint |   EEG #114 : (12620.0, -83840.0, 107100.0) mm : head frame>,
 <DigPoint |   EEG #115 : (15250.0, -65960.0, 122130.0) mm : head frame>,
 <DigPoint |   EEG #116 : (19250.0, -46740.0, 132960.0) mm : head frame>,
 <DigPoint |   EEG #117 : (17650.0, -25680.0, 137890.0) mm : head frame>,
 <DigPoint |   EEG #118 : (11260.0, -3240.0, 141080.0) mm : head frame>,
 <DigPoint |   EEG #119 : (-5610.0, -110590.0, 27200.0) mm : head frame>,
 <DigPoint |   EEG #120 : (-2390.0, -109480.0, 36650.0) mm : head frame>,
 <DigPoint |   EEG #121 : (5480.0, -106690.0, 57020.0) mm : head frame>,
 <DigPoint |   EEG #122 : (16190.0, -106440.0, 76720.0) mm : head frame>,
 <DigPoint |   EEG #123 : (31660.0, -95960.0, 102590.0) mm : head frame>,
 <DigPoint |   EEG #124 : (33720.0, -77660.0, 108070.0) mm : head frame>,
 <DigPoint |   EEG #125 : (35970.0, -58680.0, 119150.0) mm : head frame>,
 <DigPoint |   EEG #126 : (34680.0, -35270.0, 130820.0) mm : head frame>,
 <DigPoint |   EEG #127 : (31680.0, -10240.0, 134050.0) mm : head frame>,
 <DigPoint |   EEG #128 : (11580.0, -106540.0, 22740.0) mm : head frame>,
 <DigPoint |   EEG #129 : (19740.0, -106600.0, 35460.0) mm : head frame>,
 <DigPoint |   EEG #130 : (29920.0, -98810.0, 57170.0) mm : head frame>,
 <DigPoint |   EEG #131 : (40340.0, -89770.0, 72800.0) mm : head frame>,
 <DigPoint |   EEG #132 : (47710.0, -77720.0, 89360.0) mm : head frame>,
 <DigPoint |   EEG #133 : (50940.0, -62820.0, 103420.0) mm : head frame>,
 <DigPoint |   EEG #134 : (51050.0, -41880.0, 116240.0) mm : head frame>,
 <DigPoint |   EEG #135 : (47680.0, -17410.0, 124330.0) mm : head frame>,
 <DigPoint |   EEG #136 : (42960.0, -91780.0, 20420.0) mm : head frame>,
 <DigPoint |   EEG #137 : (44330.0, -87350.0, 37810.0) mm : head frame>,
 <DigPoint |   EEG #138 : (52600.0, -80480.0, 56210.0) mm : head frame>,
 <DigPoint |   EEG #139 : (56220.0, -71680.0, 66490.0) mm : head frame>,
 <DigPoint |   EEG #140 : (62980.0, -55910.0, 82750.0) mm : head frame>,
 <DigPoint |   EEG #141 : (62260.0, -44570.0, 98430.0) mm : head frame>,
 <DigPoint |   EEG #142 : (63420.0, -22750.0, 107050.0) mm : head frame>,
 <DigPoint |   EEG #143 : (43750.0, -84470.0, 12480.0) mm : head frame>,
 <DigPoint |   EEG #144 : (59700.0, -74750.0, 35740.0) mm : head frame>,
 <DigPoint |   EEG #145 : (65670.0, -63680.0, 45120.0) mm : head frame>,
 <DigPoint |   EEG #146 : (67650.0, -50760.0, 68050.0) mm : head frame>,
 <DigPoint |   EEG #147 : (70680.0, -36730.0, 78140.0) mm : head frame>,
 <DigPoint |   EEG #148 : (70380.0, -23520.0, 90740.0) mm : head frame>,
 <DigPoint |   EEG #149 : (56870.0, -64280.0, 14400.0) mm : head frame>,
 <DigPoint |   EEG #150 : (64610.0, -58000.0, 26730.0) mm : head frame>,
 <DigPoint |   EEG #151 : (69960.0, -45360.0, 41960.0) mm : head frame>,
 <DigPoint |   EEG #152 : (72380.0, -33840.0, 55810.0) mm : head frame>,
 <DigPoint |   EEG #153 : (74970.0, -17330.0, 74490.0) mm : head frame>,
 <DigPoint |   EEG #154 : (71170.0, -5910.0, 92630.0) mm : head frame>,
 <DigPoint |   EEG #155 : (60840.0, 1550.0, 109330.0) mm : head frame>,
 <DigPoint |   EEG #156 : (46640.0, 5880.0, 121360.0) mm : head frame>,
 <DigPoint |   EEG #157 : (30230.0, 13890.0, 131040.0) mm : head frame>,
 <DigPoint |   EEG #158 : (3980.0, 20250.0, 139020.0) mm : head frame>,
 <DigPoint |   EEG #159 : (65040.0, -47450.0, 12600.0) mm : head frame>,
 <DigPoint |   EEG #160 : (70040.0, -42110.0, 23140.0) mm : head frame>,
 <DigPoint |   EEG #161 : (76120.0, -22330.0, 39660.0) mm : head frame>,
 <DigPoint |   EEG #162 : (77280.0, -9330.0, 52080.0) mm : head frame>,
 <DigPoint |   EEG #163 : (76040.0, 1450.0, 69540.0) mm : head frame>,
 <DigPoint |   EEG #164 : (69640.0, 11640.0, 90720.0) mm : head frame>,
 <DigPoint |   EEG #165 : (56200.0, 19960.0, 109160.0) mm : head frame>,
 <DigPoint |   EEG #166 : (36090.0, 27630.0, 121320.0) mm : head frame>,
 <DigPoint |   EEG #167 : (12880.0, 29530.0, 132090.0) mm : head frame>,
 <DigPoint |   EEG #168 : (75440.0, -2600.0, 30260.0) mm : head frame>,
 <DigPoint |   EEG #169 : (76540.0, 16300.0, 53030.0) mm : head frame>,
 <DigPoint |   EEG #170 : (73940.0, 27480.0, 69740.0) mm : head frame>,
 <DigPoint |   EEG #171 : (65440.0, 33740.0, 87440.0) mm : head frame>,
 <DigPoint |   EEG #172 : (49960.0, 44960.0, 104270.0) mm : head frame>,
 <DigPoint |   EEG #173 : (29380.0, 47190.0, 121270.0) mm : head frame>,
 <DigPoint |   EEG #174 : (72590.0, 10850.0, 13150.0) mm : head frame>,
 <DigPoint |   EEG #175 : (73440.0, 21850.0, 31110.0) mm : head frame>,
 <DigPoint |   EEG #176 : (71450.0, 32640.0, 46540.0) mm : head frame>,
 <DigPoint |   EEG #177 : (66710.0, 42900.0, 73220.0) mm : head frame>,
 <DigPoint |   EEG #178 : (56960.0, 48450.0, 88880.0) mm : head frame>,
 <DigPoint |   EEG #179 : (36110.0, 56870.0, 108430.0) mm : head frame>,
 <DigPoint |   EEG #180 : (71790.0, 17390.0, 1160.0) mm : head frame>,
 <DigPoint |   EEG #181 : (69410.0, 29970.0, 14870.0) mm : head frame>,
 <DigPoint |   EEG #182 : (66620.0, 41940.0, 32950.0) mm : head frame>,
 <DigPoint |   EEG #183 : (63810.0, 54990.0, 53140.0) mm : head frame>,
 <DigPoint |   EEG #184 : (56310.0, 61310.0, 74960.0) mm : head frame>,
 <DigPoint |   EEG #185 : (43060.0, 65300.0, 92660.0) mm : head frame>]

Yes,

I forgot to mention that I rescale but things hasn’t changed. I mean I was able to visualize the electrodes but they are not in the right place

Thanks

May I ask, whats the purpose of re-scale? This values are sensitive. Does it looks good without the re-scale?

These are physical locations of the sensors position in x,y,z coordinates. If you re-scale, it will make a distance shift from the head frame.

I simply divided that by 1000 to obtain the correct scale.

Was I wrong?

@Davi1990 I would recommend you not to modify the actual coordinate vales if its not required. All you need to check what values MNE expect (millimeters/meters) while setting up the montage. If its a must to re-scale the coordinates then (only) perform the re-scale and create montage afterwards.

Here is the code for your solution:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@author: diptyajit das <bmedasdiptyajit@gmail.com>
Created on Apr 25, 2023

Task: current electrode positions look wrong, require re-scaling?

"""
print(__doc__)

# import necessary modules
import mne
from mne import read_epochs
from mne.channels import make_dig_montage
# ---------------------------------
# test code:

# epoch file
fname = '/home/dip_meg/Downloads/sub-02-epoched.fif'
epo = read_epochs(fname)

# re-scale factor (current electrode positions are wrong, needs re-scaling )
scale_factor = 1000

# fiducial points  # re-scale
lpa = epo.info['dig'][0].get('r')/scale_factor
nasion = epo.info['dig'][1].get('r')/scale_factor
rpa = epo.info['dig'][2].get('r')/scale_factor
fid_points = [lpa, nasion, rpa]

# get the cardinal points
digi = epo.info['dig']

# extract eeg sensors positions from info directory and rescaling
eeg_dig_pos = []
for i in range(len(fid_points), len(epo.info['dig'])):
    loc = epo.info['dig'][i].get('r')/scale_factor   # rescaling
    eeg_dig_pos.append(loc)

# zip the eeg sensors position (x,y,z coordinates) along with their names
eeg_chs = epo.info['ch_names'][-len(epo.info['dig']):]
eeg_ch_pos = dict(zip(eeg_chs, eeg_dig_pos))

# create the EEG montage
montage = make_dig_montage(ch_pos=eeg_ch_pos, nasion=nasion, lpa=lpa, rpa=rpa, coord_frame='head')

# set the montage
epochs = epo.set_montage(montage=montage)
print(epochs.info['dig'])

# visualize the montage
mne.viz.plot_montage(montage, sphere='auto')

# Check that the locations of EEG electrodes is correct with respect to MRI (fsaverage surface)

bem = '/media/dip_meg/sub-02/bem/sub-02-bem.fif'
src = '/media/dip_meg/sub-02/sub-02-src.fif'
trans = '/media/dip_meg/sub-02/bem/sub-02-fsaverage-trans.fif'

# I have created a trans file on fsaverge surface for testing,
# use your real subject's trans file (for accurate fitting)

# Check that the locations of EEG electrodes is correct with respect to MRI
mne.viz.plot_alignment(
    epochs.info, src=src, eeg=['original', 'projected'], trans=trans,
    show_axes=True, mri_fiducials=True, dig='fiducials')

Test results:



# After re-scaling. 

In [93]: epochs.info['dig']
Out[93]: 
[<DigPoint |        LPA : (-71.6, -2.7, 1.8) mm     : head frame>,
 <DigPoint |     Nasion : (-10.6, 93.1, 17.2) mm    : head frame>,
 <DigPoint |        RPA : (57.8, -0.6, -4.3) mm     : head frame>,
 <DigPoint |     EEG #1 : (60.3, 54.7, 19.9) mm     : head frame>,
 <DigPoint |     EEG #2 : (56.8, 66.8, 44.9) mm     : head frame>,
 <DigPoint |     EEG #3 : (52.7, 71.6, 63.2) mm     : head frame>,
 <DigPoint |     EEG #4 : (36.2, 79.0, 82.4) mm     : head frame>,
 <DigPoint |     EEG #5 : (24.1, 74.4, 98.9) mm     : head frame>,
 <DigPoint |     EEG #6 : (14.1, 65.3, 111.6) mm    : head frame>,
 <DigPoint |     EEG #7 : (2.1, 50.7, 124.2) mm     : head frame>,
 <DigPoint |     EEG #8 : (-6.0, 36.6, 131.0) mm    : head frame>,
 <DigPoint |     EEG #9 : (-18.9, 12.5, 137.0) mm   : head frame>,
 <DigPoint |    EEG #10 : (51.2, 77.4, 27.2) mm     : head frame>,
 <DigPoint |    EEG #11 : (44.5, 85.0, 45.1) mm     : head frame>,
 <DigPoint |    EEG #12 : (31.8, 90.7, 69.9) mm     : head frame>,
 <DigPoint |    EEG #13 : (16.2, 87.6, 86.8) mm     : head frame>,
 <DigPoint |    EEG #14 : (2.1, 80.7, 102.1) mm     : head frame>,
 <DigPoint |    EEG #15 : (-8.5, 67.1, 115.4) mm    : head frame>,
 <DigPoint |    EEG #16 : (-20.9, 52.7, 122.6) mm   : head frame>,
 <DigPoint |    EEG #17 : (-29.5, 30.6, 130.3) mm   : head frame>,
 <DigPoint |    EEG #18 : (30.9, 94.5, 32.7) mm     : head frame>,
 <DigPoint |    EEG #19 : (23.2, 98.9, 51.8) mm     : head frame>,
 <DigPoint |    EEG #20 : (7.7, 97.4, 72.7) mm      : head frame>,
 <DigPoint |    EEG #21 : (-8.6, 90.0, 90.4) mm     : head frame>,
 <DigPoint |    EEG #22 : (-22.0, 77.9, 103.1) mm   : head frame>,
 <DigPoint |    EEG #23 : (-32.1, 64.5, 110.9) mm   : head frame>,
 <DigPoint |    EEG #24 : (-40.6, 42.0, 120.6) mm   : head frame>,
 <DigPoint |    EEG #25 : (7.9, 102.8, 37.0) mm     : head frame>,
 <DigPoint |    EEG #26 : (-4.6, 103.6, 55.6) mm    : head frame>,
 <DigPoint |    EEG #27 : (-18.4, 97.3, 73.8) mm    : head frame>,
 <DigPoint |    EEG #28 : (-32.4, 85.7, 87.1) mm    : head frame>,
 <DigPoint |    EEG #29 : (-42.0, 72.5, 98.7) mm    : head frame>,
 <DigPoint |    EEG #30 : (-50.8, 53.6, 108.2) mm   : head frame>,
 <DigPoint |    EEG #31 : (-8.9, 100.4, 22.3) mm    : head frame>,
 <DigPoint |    EEG #32 : (-20.2, 105.9, 40.1) mm   : head frame>,
 <DigPoint |    EEG #33 : (-36.7, 99.0, 56.6) mm    : head frame>,
 <DigPoint |    EEG #34 : (-45.8, 93.2, 69.2) mm    : head frame>,
 <DigPoint |    EEG #35 : (-53.6, 77.8, 80.5) mm    : head frame>,
 <DigPoint |    EEG #36 : (-60.2, 63.6, 89.5) mm    : head frame>,
 <DigPoint |    EEG #37 : (-45.7, 93.5, 32.8) mm    : head frame>,
 <DigPoint |    EEG #38 : (-58.0, 84.1, 45.7) mm    : head frame>,
 <DigPoint |    EEG #39 : (-65.5, 73.6, 58.3) mm    : head frame>,
 <DigPoint |    EEG #40 : (-71.2, 57.8, 73.6) mm    : head frame>,
 <DigPoint |    EEG #41 : (-68.1, 43.3, 98.8) mm    : head frame>,
 <DigPoint |    EEG #42 : (-63.2, 36.3, 107.4) mm   : head frame>,
 <DigPoint |    EEG #43 : (-54.2, 21.3, 122.0) mm   : head frame>,
 <DigPoint |    EEG #44 : (-40.0, 10.4, 133.0) mm   : head frame>,
 <DigPoint |    EEG #45 : (-24.5, -7.9, 140.5) mm   : head frame>,
 <DigPoint |    EEG #46 : (-65.8, 74.3, 28.2) mm    : head frame>,
 <DigPoint |    EEG #47 : (-74.3, 60.9, 39.2) mm    : head frame>,
 <DigPoint |    EEG #48 : (-78.4, 49.3, 57.5) mm    : head frame>,
 <DigPoint |    EEG #49 : (-79.4, 37.2, 74.3) mm    : head frame>,
 <DigPoint |    EEG #50 : (-81.2, 31.6, 83.3) mm    : head frame>,
 <DigPoint |    EEG #51 : (-76.3, 23.9, 100.3) mm   : head frame>,
 <DigPoint |    EEG #52 : (-69.9, 12.0, 111.3) mm   : head frame>,
 <DigPoint |    EEG #53 : (-45.4, -12.2, 132.1) mm  : head frame>,
 <DigPoint |    EEG #54 : (-75.9, 48.5, 15.1) mm    : head frame>,
 <DigPoint |    EEG #55 : (-85.0, 45.7, 23.0) mm    : head frame>,
 <DigPoint |    EEG #56 : (-84.7, 29.1, 54.2) mm    : head frame>,
 <DigPoint |    EEG #57 : (-85.5, 16.4, 72.1) mm    : head frame>,
 <DigPoint |    EEG #58 : (-83.5, 10.0, 91.6) mm    : head frame>,
 <DigPoint |    EEG #59 : (-72.9, -5.4, 110.0) mm   : head frame>,
 <DigPoint |    EEG #60 : (-61.3, -20.0, 122.1) mm  : head frame>,
 <DigPoint |    EEG #61 : (-81.5, 26.1, 15.9) mm    : head frame>,
 <DigPoint |    EEG #62 : (-85.4, 19.4, 32.0) mm    : head frame>,
 <DigPoint |    EEG #63 : (-88.9, -0.8, 73.9) mm    : head frame>,
 <DigPoint |    EEG #64 : (-85.5, -10.5, 87.8) mm   : head frame>,
 <DigPoint |    EEG #65 : (-77.3, -25.6, 105.4) mm  : head frame>,
 <DigPoint |    EEG #66 : (-80.9, 12.6, 0.3) mm     : head frame>,
 <DigPoint |    EEG #67 : (-81.7, 12.2, 1.8) mm     : head frame>,
 <DigPoint |    EEG #68 : (-83.6, 6.9, 15.4) mm     : head frame>,
 <DigPoint |    EEG #69 : (-87.1, -4.6, 35.4) mm    : head frame>,
 <DigPoint |    EEG #70 : (-89.4, -8.6, 54.1) mm    : head frame>,
 <DigPoint |    EEG #71 : (-89.0, -22.2, 68.2) mm   : head frame>,
 <DigPoint |    EEG #72 : (-82.2, -29.5, 83.5) mm   : head frame>,
 <DigPoint |    EEG #73 : (-85.6, -25.8, 33.1) mm   : head frame>,
 <DigPoint |    EEG #74 : (-84.8, -34.3, 49.6) mm   : head frame>,
 <DigPoint |    EEG #75 : (-83.6, -40.4, 70.3) mm   : head frame>,
 <DigPoint |    EEG #76 : (-77.5, -43.3, 92.3) mm   : head frame>,
 <DigPoint |    EEG #77 : (-65.0, -44.3, 110.9) mm  : head frame>,
 <DigPoint |    EEG #78 : (-48.5, -37.7, 127.2) mm  : head frame>,
 <DigPoint |    EEG #79 : (-27.2, -29.9, 137.3) mm  : head frame>,
 <DigPoint |    EEG #80 : (-12.5, -25.5, 146.6) mm  : head frame>,
 <DigPoint |    EEG #81 : (-78.8, -42.7, 22.2) mm   : head frame>,
 <DigPoint |    EEG #82 : (-81.2, -46.0, 41.9) mm   : head frame>,
 <DigPoint |    EEG #83 : (-79.6, -55.2, 58.2) mm   : head frame>,
 <DigPoint |    EEG #84 : (-74.8, -58.3, 80.7) mm   : head frame>,
 <DigPoint |    EEG #85 : (-63.7, -60.3, 101.0) mm  : head frame>,
 <DigPoint |    EEG #86 : (-45.8, -55.1, 121.9) mm  : head frame>,
 <DigPoint |    EEG #87 : (-27.5, -50.9, 132.9) mm  : head frame>,
 <DigPoint |    EEG #88 : (-2.2, -39.7, 138.2) mm   : head frame>,
 <DigPoint |    EEG #89 : (-75.8, -47.8, 6.3) mm    : head frame>,
 <DigPoint |    EEG #90 : (-77.4, -57.1, 28.9) mm   : head frame>,
 <DigPoint |    EEG #91 : (-74.2, -66.3, 40.9) mm   : head frame>,
 <DigPoint |    EEG #92 : (-69.3, -75.3, 65.8) mm   : head frame>,
 <DigPoint |    EEG #93 : (-58.1, -79.5, 90.3) mm   : head frame>,
 <DigPoint |    EEG #94 : (-43.9, -75.5, 109.9) mm  : head frame>,
 <DigPoint |    EEG #95 : (-36.1, -77.8, 122.0) mm  : head frame>,
 <DigPoint |    EEG #96 : (-8.0, -78.0, 117.6) mm   : head frame>,
 <DigPoint |    EEG #97 : (-66.6, -64.5, 8.1) mm    : head frame>,
 <DigPoint |    EEG #98 : (-66.4, -73.8, 29.7) mm   : head frame>,
 <DigPoint |    EEG #99 : (-60.2, -84.5, 44.7) mm   : head frame>,
 <DigPoint |   EEG #100 : (-49.4, -90.9, 68.3) mm   : head frame>,
 <DigPoint |   EEG #101 : (-37.8, -89.7, 87.8) mm   : head frame>,
 <DigPoint |   EEG #102 : (-24.9, -83.6, 106.4) mm  : head frame>,
 <DigPoint |   EEG #103 : (-51.3, -86.3, 18.0) mm   : head frame>,
 <DigPoint |   EEG #104 : (-44.7, -94.3, 35.3) mm   : head frame>,
 <DigPoint |   EEG #105 : (-36.4, -98.6, 52.1) mm   : head frame>,
 <DigPoint |   EEG #106 : (-24.9, -100.4, 75.5) mm  : head frame>,
 <DigPoint |   EEG #107 : (-15.8, -96.1, 92.0) mm   : head frame>,
 <DigPoint |   EEG #108 : (-6.0, -87.7, 106.1) mm   : head frame>,
 <DigPoint |   EEG #109 : (-30.2, -100.4, 21.4) mm  : head frame>,
 <DigPoint |   EEG #110 : (-19.8, -104.6, 36.3) mm  : head frame>,
 <DigPoint |   EEG #111 : (-13.6, -102.6, 53.2) mm  : head frame>,
 <DigPoint |   EEG #112 : (-2.9, -101.3, 79.6) mm   : head frame>,
 <DigPoint |   EEG #113 : (9.6, -94.7, 92.4) mm     : head frame>,
 <DigPoint |   EEG #114 : (12.6, -83.8, 107.1) mm   : head frame>,
 <DigPoint |   EEG #115 : (15.3, -66.0, 122.1) mm   : head frame>,
 <DigPoint |   EEG #116 : (19.2, -46.7, 133.0) mm   : head frame>,
 <DigPoint |   EEG #117 : (17.6, -25.7, 137.9) mm   : head frame>,
 <DigPoint |   EEG #118 : (11.3, -3.2, 141.1) mm    : head frame>,
 <DigPoint |   EEG #119 : (-5.6, -110.6, 27.2) mm   : head frame>,
 <DigPoint |   EEG #120 : (-2.4, -109.5, 36.7) mm   : head frame>,
 <DigPoint |   EEG #121 : (5.5, -106.7, 57.0) mm    : head frame>,
 <DigPoint |   EEG #122 : (16.2, -106.4, 76.7) mm   : head frame>,
 <DigPoint |   EEG #123 : (31.7, -96.0, 102.6) mm   : head frame>,
 <DigPoint |   EEG #124 : (33.7, -77.7, 108.1) mm   : head frame>,
 <DigPoint |   EEG #125 : (36.0, -58.7, 119.1) mm   : head frame>,
 <DigPoint |   EEG #126 : (34.7, -35.3, 130.8) mm   : head frame>,
 <DigPoint |   EEG #127 : (31.7, -10.2, 134.0) mm   : head frame>,
 <DigPoint |   EEG #128 : (11.6, -106.5, 22.7) mm   : head frame>,
 <DigPoint |   EEG #129 : (19.7, -106.6, 35.5) mm   : head frame>,
 <DigPoint |   EEG #130 : (29.9, -98.8, 57.2) mm    : head frame>,
 <DigPoint |   EEG #131 : (40.3, -89.8, 72.8) mm    : head frame>,
 <DigPoint |   EEG #132 : (47.7, -77.7, 89.4) mm    : head frame>,
 <DigPoint |   EEG #133 : (50.9, -62.8, 103.4) mm   : head frame>,
 <DigPoint |   EEG #134 : (51.0, -41.9, 116.2) mm   : head frame>,
 <DigPoint |   EEG #135 : (47.7, -17.4, 124.3) mm   : head frame>,
 <DigPoint |   EEG #136 : (43.0, -91.8, 20.4) mm    : head frame>,
 <DigPoint |   EEG #137 : (44.3, -87.3, 37.8) mm    : head frame>,
 <DigPoint |   EEG #138 : (52.6, -80.5, 56.2) mm    : head frame>,
 <DigPoint |   EEG #139 : (56.2, -71.7, 66.5) mm    : head frame>,
 <DigPoint |   EEG #140 : (63.0, -55.9, 82.8) mm    : head frame>,
 <DigPoint |   EEG #141 : (62.3, -44.6, 98.4) mm    : head frame>,
 <DigPoint |   EEG #142 : (63.4, -22.7, 107.1) mm   : head frame>,
 <DigPoint |   EEG #143 : (43.7, -84.5, 12.5) mm    : head frame>,
 <DigPoint |   EEG #144 : (59.7, -74.7, 35.7) mm    : head frame>,
 <DigPoint |   EEG #145 : (65.7, -63.7, 45.1) mm    : head frame>,
 <DigPoint |   EEG #146 : (67.7, -50.8, 68.1) mm    : head frame>,
 <DigPoint |   EEG #147 : (70.7, -36.7, 78.1) mm    : head frame>,
 <DigPoint |   EEG #148 : (70.4, -23.5, 90.7) mm    : head frame>,
 <DigPoint |   EEG #149 : (56.9, -64.3, 14.4) mm    : head frame>,
 <DigPoint |   EEG #150 : (64.6, -58.0, 26.7) mm    : head frame>,
 <DigPoint |   EEG #151 : (70.0, -45.4, 42.0) mm    : head frame>,
 <DigPoint |   EEG #152 : (72.4, -33.8, 55.8) mm    : head frame>,
 <DigPoint |   EEG #153 : (75.0, -17.3, 74.5) mm    : head frame>,
 <DigPoint |   EEG #154 : (71.2, -5.9, 92.6) mm     : head frame>,
 <DigPoint |   EEG #155 : (60.8, 1.5, 109.3) mm     : head frame>,
 <DigPoint |   EEG #156 : (46.6, 5.9, 121.4) mm     : head frame>,
 <DigPoint |   EEG #157 : (30.2, 13.9, 131.0) mm    : head frame>,
 <DigPoint |   EEG #158 : (4.0, 20.3, 139.0) mm     : head frame>,
 <DigPoint |   EEG #159 : (65.0, -47.5, 12.6) mm    : head frame>,
 <DigPoint |   EEG #160 : (70.0, -42.1, 23.1) mm    : head frame>,
 <DigPoint |   EEG #161 : (76.1, -22.3, 39.7) mm    : head frame>,
 <DigPoint |   EEG #162 : (77.3, -9.3, 52.1) mm     : head frame>,
 <DigPoint |   EEG #163 : (76.0, 1.5, 69.5) mm      : head frame>,
 <DigPoint |   EEG #164 : (69.6, 11.6, 90.7) mm     : head frame>,
 <DigPoint |   EEG #165 : (56.2, 20.0, 109.2) mm    : head frame>,
 <DigPoint |   EEG #166 : (36.1, 27.6, 121.3) mm    : head frame>,
 <DigPoint |   EEG #167 : (12.9, 29.5, 132.1) mm    : head frame>,
 <DigPoint |   EEG #168 : (75.4, -2.6, 30.3) mm     : head frame>,
 <DigPoint |   EEG #169 : (76.5, 16.3, 53.0) mm     : head frame>,
 <DigPoint |   EEG #170 : (73.9, 27.5, 69.7) mm     : head frame>,
 <DigPoint |   EEG #171 : (65.4, 33.7, 87.4) mm     : head frame>,
 <DigPoint |   EEG #172 : (50.0, 45.0, 104.3) mm    : head frame>,
 <DigPoint |   EEG #173 : (29.4, 47.2, 121.3) mm    : head frame>,
 <DigPoint |   EEG #174 : (72.6, 10.9, 13.2) mm     : head frame>,
 <DigPoint |   EEG #175 : (73.4, 21.9, 31.1) mm     : head frame>,
 <DigPoint |   EEG #176 : (71.4, 32.6, 46.5) mm     : head frame>,
 <DigPoint |   EEG #177 : (66.7, 42.9, 73.2) mm     : head frame>,
 <DigPoint |   EEG #178 : (57.0, 48.5, 88.9) mm     : head frame>,
 <DigPoint |   EEG #179 : (36.1, 56.9, 108.4) mm    : head frame>,
 <DigPoint |   EEG #180 : (71.8, 17.4, 1.2) mm      : head frame>,
 <DigPoint |   EEG #181 : (69.4, 30.0, 14.9) mm     : head frame>,
 <DigPoint |   EEG #182 : (66.6, 41.9, 32.9) mm     : head frame>,
 <DigPoint |   EEG #183 : (63.8, 55.0, 53.1) mm     : head frame>,
 <DigPoint |   EEG #184 : (56.3, 61.3, 75.0) mm     : head frame>,
 <DigPoint |   EEG #185 : (43.1, 65.3, 92.7) mm     : head frame>]

Note, you have to create a -trans file to plot head, sensor, and source space alignment in 3D. Currently, I have created one with a fsaverage head surface for testing. It looks good to me. I would also recommend you to stick to MNE’s naming convention while saving data in different file extensions.

I hope this solves your issue. If you are happy with the solution, mark it as the solution so that others can find it easily.

best,
Dip

1 Like

@dasdiptyajit thanks! That’s exactly what I meant with rescaling (dividing the previous coords 1000). The problem in my case was a mistake in my code before:

I changed the coord_frame from mri to head in the mne.channels.make_dig_montage

function.

I apologize for the confusion and thanks again for the help

D

@Davi1990 No problem. I am glad that you have resolved the issue.

One thing is still not clear to me, how did you end with these values at the first place? x,y,z coordinates tsv file values seem to be correct. Are you getting these values directly from EEG electrode digitizer? If this is the case, you may like to adjust the measuring units in your electrode digitizer program. Perhaps this would be a permanent fix?

How did you setup up your montage in the beginning? Did you set it up at the raw object?

In [75]: epo.get_montage().dig
Out[75]: 
[<DigPoint |        LPA : (-71606.0, -2699.0, 1785.0) mm : head frame>,
 <DigPoint |     Nasion : (-10649.0, 93094.0, 17156.0) mm : head frame>,
 <DigPoint |        RPA : (57778.0, -569.0, -4316.0) mm : head frame>,
 <DigPoint |     EEG #1 : (60310.0, 54730.0, 19850.0) mm : head frame>,
 <DigPoint |     EEG #2 : (56820.0, 66800.0, 44930.0) mm : head frame>,
 <DigPoint |     EEG #3 : (52740.0, 71640.0, 63210.0) mm : head frame>,
 <DigPoint |     EEG #4 : (36210.0, 78970.0, 82400.0) mm : head frame>,

Sorry, are you saying: This is the main reason?
I changed the `coord_frame` from `mri` to `head` in the mne.channels.make_dig_montage function.