<div dir="ltr">I think the code works properly if the eeg_loc is set to the correct 3x2 matrix: I reran the forward solution for the old data using MNE python and I get basically the same answer as MNE C (differences on the order of 10^-3, when the lead field matrix entries are on the order of 100). So MNE python is loading the data properly and using it properly.<div><br></div><div>The problem is that I can&#39;t create a Raw object using *only* MNE python that has the supposedly correct 3x2 eeg_loc parameters. I think the solution would involve adding the reference electrode to the Montage or the DigMontage, since that&#39;s where the information is (at least in my data). In case it matters, I&#39;m getting my Montage from a hpts file that labels the reference as eeg electrode 0. Since that electrode doesn&#39;t exist in the recordings, it isn&#39;t used by set_montage. That&#39;s why I thought it might work to add the reference electrode using add_reference_channels before running set_montage.</div><div><br></div><div>Emily</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Dec 11, 2015 at 10:22 AM, Emily Stephen <span dir="ltr">&lt;<a href="mailto:emilyps14@gmail.com" target="_blank">emilyps14@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">In line 141, _bem_specify_els loops over the columns of el_r, which is a transformed version of els[...][rmag].<div><br></div><div>els comes from the coils variable in _prep_field_computation, which come from fwd_data from _compute_forwards, yada yada yada...</div><div><br></div><div>If you trace it all the way to its source, the field rmag is set through make_forward_solution &gt; _prep_channels &gt; _create_coils &gt; _create_eeg_el, which sets it to a (potentially transformed) version of ch[eeg_loc].</div><div><br></div><div>The reason it matters is that in _bem_specify_els, the sol variable is constructed as a weighted sum of the bem solution at tri vertices near the locations in the columns of rmag. The weight w on the second column (from elw, also set in _create_eeg_el) is -1. So the bem is subtracting off the influence of the reference electrode.</div><div><br></div><div>Apologies if this is vague -- I&#39;m still familiarizing myself with the theory. At this point I have a better grasp on the code, since I&#39;ve been stepping through it debugging.</div><div><br></div><div>Thanks,<br>Emily</div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Dec 11, 2015 at 2:32 AM, Marijn van Vliet <span dir="ltr">&lt;<a href="mailto:w.m.vanvliet@gmail.com" target="_blank">w.m.vanvliet@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Dear Emily,<br>
<br>
the `set_eeg_reference` and `add_reference_channels` are functions that transform the EEG data. They allow you to specify different referencing schemes, which is useful for sensor level analysis. They also set the `custom_ref_applied` flag in the info structure to explicitly override the average reference projector. Since you are doing source localisation and therefore want the average reference, don’t use these functions, they don’t do what you wanted them to do.<br>
<br>
Let’s move on to your problem:<br>
<br>
I was always wondering why `eeg_loc` was a 3x2 matrix… thank you for tracking it down. I think many of our data import routines only set the first row of `eeg_loc`; this should be fixed. However, where in `_bem_specify_els` does it loop over the `eeg_loc` matrix exactly? I can’t find it...<br>
<br>
regards,<br>
Marijn.<br>
--<br>
Marijn van Vliet<br>
<a href="mailto:w.m.vanvliet@gmail.com" target="_blank">w.m.vanvliet@gmail.com</a><br>
<div><div><br>
<br>
<br>
<br>
<br>
&gt; On 11 Dec 2015, at 00:25, Emily Stephen &lt;<a href="mailto:emilyps14@gmail.com" target="_blank">emilyps14@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt; Hi Again,<br>
&gt;<br>
&gt; I&#39;ve been debugging my code by comparing an EEG forward model that I constructed using MNE python to one constructed by a former labmate using MNE C. The lead field matrices are different, even when I use identical source space, BEM solution, and transformation file.<br>
&gt;<br>
&gt; I&#39;ve narrowed down the problem to info[&#39;chs&#39;][...][&#39;eeg_loc&#39;], which in the old data is 3x2, with the second column having the location of the reference electrode. In my data, eeg_loc is 3x1, with no information about the location of the reference electrode. The information in this second column appears to be used by _bem_specify_els, which loops over the columns of the electrode location matrix.<br>
&gt;<br>
&gt; I&#39;ve played around a bit with add_reference_channels and set_eeg_reference, but neither of them changes the second column in eeg_loc for the non-reference electrodes. The location of the reference electrode is specified in my montage file (hpts), but there doesn&#39;t seem to be a way to apply it to the eeg_loc of all of the other electrodes.<br>
&gt;<br>
&gt; This is what I thought might have worked, but it seems to just add another electrode, without influencing the chs of the other electrodes:<br>
&gt; montage = mne.channels.read_montage(montage_hpts, transform=True, unit=&#39;mm&#39;)<br>
&gt; raw = mne.io.read_raw_fif(rawfile,preload=True)<br>
&gt; mne.io.add_reference_channels(raw,&#39;EEG000&#39;,copy=False)<br>
&gt; raw.set_montage(montage)<br>
&gt; mne.io.set_eeg_reference(raw,[&#39;EEG000&#39;],copy=False)<br>
&gt;<br>
&gt; Thoughts?<br>
&gt;<br>
&gt; Thanks,<br>
&gt; Emily<br>
&gt;<br>
&gt;<br>
</div></div><div><div>&gt; _______________________________________________<br>
&gt; Mne_analysis mailing list<br>
&gt; <a href="mailto:Mne_analysis@nmr.mgh.harvard.edu" target="_blank">Mne_analysis@nmr.mgh.harvard.edu</a><br>
&gt; <a href="https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis" rel="noreferrer" target="_blank">https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis</a><br>
&gt;<br>
&gt;<br>
&gt; The information in this e-mail is intended only for the person to whom it is<br>
&gt; addressed. If you believe this e-mail was sent to you in error and the e-mail<br>
&gt; contains patient information, please contact the Partners Compliance HelpLine at<br>
&gt; <a href="http://www.partners.org/complianceline" rel="noreferrer" target="_blank">http://www.partners.org/complianceline</a> . If the e-mail was sent to you in error<br>
&gt; but does not contain patient information, please contact the sender and properly<br>
&gt; dispose of the e-mail.<br>
<br>
<br>
_______________________________________________<br>
Mne_analysis mailing list<br>
<a href="mailto:Mne_analysis@nmr.mgh.harvard.edu" target="_blank">Mne_analysis@nmr.mgh.harvard.edu</a><br>
<a href="https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis" rel="noreferrer" target="_blank">https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis</a></div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>