<p><span style="padding: 3px 10px; border-radius: 5px; color: #ffffff; font-weight: bold; display: inline-block; background-color: #ff0000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;External Email - Use Caution&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p><p></p><div dir="ltr">Dear Alex,<div><br></div><div>this is actually the answer. </div><div>I found out that MNE Python translates the sample info to the real time of the recording,</div><div>which in my case is starting at t = 39 seconds.</div><div>So my code works if I build the events array as follows</div><div><br></div><div><i>events = np.vstack((spevents[0] <b>+ raw.first_samp</b>, np.zeros(60), np.arange(60)+1)).T.astype(<a href="http://np.int">np.int</a>) # array int32 (60,3) Nevents,3<br>epochs = mne.Epochs(raw, events,  tmin = -0.1, tmax = 0.1, proj = False, baseline=None, detrend=0, preload=False)     <br></i></div><div><i><br></i></div><div>where <b>raw.first_samp</b> set the correct offset for MNE Python to understand where I want to point in my continuous data.</div><div><br></div><div>Thanks,</div><div><br></div><div>Best,</div><div>Tommaso</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Nov 27, 2019 at 4:41 PM Alexandre Gramfort &lt;<a href="mailto:alexandre.gramfort@inria.fr">alexandre.gramfort@inria.fr</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><p><span style="padding:3px 10px;border-radius:5px;color:rgb(255,255,255);font-weight:bold;display:inline-block;background-color:rgb(255,0,0)">        External Email - Use Caution        </span></p><p></p><div dir="ltr">hi Tommaso,<div><br></div><div>unfortunately it&#39;s really hard to help without more context and knowledge about the data.</div><div><br></div><div>Best,</div><div>Alex</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Nov 26, 2019 at 3:36 PM Tommaso Fedele &lt;<a href="mailto:fedele.tm@gmail.com" target="_blank">fedele.tm@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><p><span style="padding:3px 10px;border-radius:5px;color:rgb(255,255,255);font-weight:bold;display:inline-block;background-color:rgb(255,0,0)">        External Email - Use Caution        </span></p><p></p><div dir="ltr"><div dir="ltr">Dear MNE people,<div><br></div><div>I got a problem when epoching data in MNE Python using mne.Epochs.</div><div><br></div><div>I am running some analysis with a Matlab code and I would like to transfer the same analysis to MNE Python.</div><div><br></div><div>My problem is that if I compare one epoch from Matlab with the output of mne.Epochs in Python they do not correspond.</div><div><br></div><div>Here below the code and a figure explaining the problem</div><div><br></div><div>My question is: why</div><div><br></div><div>  spike1[295, :]  # epoch from matlab data</div><div> 

data[295, (np.arange(index-100,index+100))]  

 # epoch from data imported in python and manually extracted with a sample reference &#39;index&#39;</div><div><br></div><div>do not correspond with</div><div><br></div><div>  epochs9[0,295,:] # which is the output of mne.Epochs for the very same epoch?<br></div><div><br></div><div>They both should refer to the sample 75650, with a pre- and post-trigger of 100 samples.</div><div><br></div><div>I am not applying any SSP projection or baseline. What am I missing?</div><div> <br></div><div>Thanks in advance for your help,</div><div><br></div><div>Best,</div><div>Tommaso</div><div><br></div><div>%%%%%%%%%%%%%%%%% code</div><div><br></div><div>import numpy as np<br>import mne<br>import xlrd<br>import <a href="http://scipy.io" target="_blank">scipy.io</a> as sio<br>import pandas as pd<br>from mne.viz import plot_evoked_topo<br>import matplotlib.pyplot as plt<br><br>spike = sio.loadmat(<br>        &#39;E:/../spike75650.mat&#39;<br>        )# data imported from Matlab as dict spike. <br>         #The field &#39;spike is an array float64 (404, 201) channels, samples<br> <br> <br>raw = mne.io.read_raw_fif(&#39;E:/.../B1C2_ii_run1_raw_tsss_mc_art_corr.fif&#39;) #data after tsss<br>excel = xlrd.open_workbook(&#39;E:/.../list raw detections B1C2.xlsx&#39;) #trigger info from excel file<br> <br># create an array for mne.Epochs<br>sheet = excel.sheet_by_index(2)<br>sp=list()<br>for i in range(1,61):<br>    sp.append(sheet.cell_value(i,2))<br>spevents     = np.array(sp, ndmin=2, dtype=int)<br>zeros        = np.zeros((1,60), dtype=int)<br>event_id_int = np.ones((1,60), dtype=int)<br>event_id_int[:,:] = np.arange(0,60)<br>event_id_str = list(map(str,np.arange(0,60)))<br>events = np.hstack((spevents.T, zeros.T, event_id_int.T)) # array int32 (60,3) Nevents,3</div><div>                                                                                           # one row is 75650        0        9<br><br># Create epochs including different events<br>event_id = dict(zip(event_id_str, np.arange(0,60)))<br>epochs   = mne.Epochs(raw, events, event_id, tmin = -0.1, tmax = 0.1, proj = False)     <br><br># Generate list of evoked objects from conditions names<br>evokeds = [epochs[name].average() for name in np.arange(0,60)]<br>  <br><br>##################### Figure<br>plt.close(&#39;all&#39;)<br>plt.figure()   <br><br>ep_id = 9<br>index = spevents[0,ep_id] # trigger sample for continuous data, value 75650 <br>  </div><div># spike from matlab  <br>spike1 = spike[&#39;spike&#39;]<br>plt.plot(spike1[295, :], <br>                       label = [&#39;Matlab: spike from raw data - MEG2613&#39;])<br><br></div><div># spike from continuous data  <br>plt.plot(data[295, (np.arange(index-100,index+100))]-5*10**-11,<br>                            label = [&#39;Python: spike from raw data - MEG2613&#39;])<br><br> # spike from MNE epochs  <br>epochs9 = epochs[ep_id].get_data()<br>plt.plot(epochs9[0,295,:]-5*2*10**-11, <br>                        label = [&#39;MNE Python: spike from EPOCHED data - MEG2613&#39;])<br><br># spike from MNE average  <br>evoked9 = epochs[ep_id].average()<br>plt.plot(evoked9.data[295]-5*3*10**-11, <br>                        label = [&#39;MNE Python: spike from averaged data - MEG2613&#39;])<br><br>plt.legend()</div><div><br></div><div># check that the channel labels is the same<br>print(epochs.ch_names[295]), print(raw.ch_names[295]) <br></div><div><br></div><div>%%%%%%%%%%%%%%%%%%%%%% FIGURE</div><div><br></div><div><div><img src="cid:ii_k3dhceki0" alt="image.png" width="345" height="279" style="margin-right: 0px;"><br></div></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div></div>
_______________________________________________<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></blockquote></div>
_______________________________________________<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></blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr">Tommaso Fedele<br>Assistant professor, Institute of Cognitive Neuroscience<br>Higher School of Economics - National Research University<br>101000, Moscow, 18 Myasnitskaya Ulitsa <br>Russian Federation<br></div></div>