[Mne_analysis] concatenation raws and events

J.A. Entakli jae40 at cam.ac.uk
Tue Sep 16 05:33:13 EDT 2014
Search archives:

Hello Mainak,

Yes you definitely right, the events used for the epochs are usually a 
numpy array. I tried what you said (in different way) and it works 
perfectly. What I did exactly :

I concatenated raw1 and raw2 such as raws = mne.io.Raw([raw1,raw2].

For the events I created manually a "big" empty numpy array (3D, in my 
case) of the length events1+events2. I copied and pasted the events1 in 
the big numpy array and and before to copy and paste events2 I added, 
for each sample of time, the difference between the last sample of the 
"Old" events (coming from raws) and the last sample of events2:

events_Old = mne.find_events(raws,stim_channel='...')
load events2 and events1(from my file)
Last_Old = events_Old[-1,0]
Last_events2 = events2[-1,0]
Diff = Last_Old - Last_events2

for i in range(0,events2.shape[0]):
events2[i,0] = events2[i,0] + Diff

big_events = np.zeros(shape = (len(events1+2[:,1]),3))
big_events = [0:len(events1)] = events1
big_events = [len(events2)::] = events2

I think there is easier but for the moment it works :)

Thank you everybody for your help.

John.



On 12/09/2014 13:45, Mainak Jas wrote:
> Hi Jonathan,
> 
> On Fri, Sep 12, 2014 at 3:36 PM, J.A. Entakli <jae40 at cam.ac.uk> wrote:
> 
>> Hi,
>> 
>> 1) Mainak : I've already try your idea, the concatenation works but
>> the
>> samples are not added, so I can't use events concatenated in the
>> big raw
>> file.
> 
> What I was suggesting was the following: concatenate the raws as you
> do right now
> 
> raw_conc= concatenate_raws([raw1,raw2], events_list=events_list)
> 
> but when computing the epochs, you need to use
> 
> epochs = mne.Epochs(raw,  np.concatenate((events1, events2)),
> event_id, tmin, tmax, picks=picks, baseline= baseline, reject=reject)
> 
> because events is usually a numpy array when computing epochs. How
> were these events computed? Maybe you need to do:
> 
> events2[0, :] += raw1.last_samp
> 
> or something of that sort before you do np.concatenate((events1,
> events2))?
> 
> Mainak
> 
>> 2) dgw : Actually I like all the 3 options. I tried the option 2. It
>> seems very long to do but it seems the most coherent for me. And
>> above
>> all it works perfectly :)
>> 
>> Thank you very much,
>> Cheers,
>> 
>> John
>> 
>> On 11/09/2014 18:35, Mainak Jas wrote:
>>> Hi Jonathan,
>>> 
>>> I spotted a bug in your script here:
>>> 
>>> On Thu, Sep 11, 2014 at 5:44 PM, J.A. Entakli <jae40 at cam.ac.uk>
>> wrote:
>>> 
>>>> Hello Everybody,
>>>> During my experiment I recorded 2 blocs per subject. I am just
>>>> started
>>>> with mne_python.
>>>> 
>>>> I have two questions in one ::
>>>> 1) I would like to know how can I concatenate the blocs and
>> above
>>>> all
>>>> the events (corresponding to each bloc) to have just one bloc.
>>>> In brief, for each subject I have one bloc with its events and
>>>> another
>>>> bloc with its events also.
>>>> 
>>>> raw_fname1= '...'
>>>> raw_fname2= '...'
>>>> event_fname1= '...'
>>>> event_fname2= '...'
>>>> 
>>>> raw1 = io.Raw(raw_fname1)
>>>> raw2 = io.Raw(raw_fname2)
>>>> 
>>>> events1 = mne.read_events(event_fname1)
>>>> events2 = mne.read_events(event_fname2)
>>>> events_list = [events1,events2]
>>> 
>>> events is a numpy array, not a list. So, you need to use
>>> np.concatenate() to stitch the events together. Something like:
>>> 
>>> import numpy as np
>>> events = np.concatenate((events1, events2))
>>> 
>>> Does this solve your problem?
>>> 
>>> Mainak
>>> 
>>>> raw_conc= concatenate_raws([raw1,raw2], events_list=events_list)
>>>> 
>>>> Until here I think these several code lines work correctly...
>>>> 
>>>> 2) But when I try to extract the epochs from raw_conc I have
>> some
>>>> error
>>>> messages (concerning I think the events_list)
>>>> 
>>>> picks =
>>>> mne.pick_types(raw1.info [1]
>>>> [1],meg='mag',eeg=False,ecg=False,eog=False,stim=False,
>>>> exclude='bads')
>>>> epochs = mne.Epochs(raw, events_list, event_id, tmin, tmax,
>>>> picks=picks,
>>>> baseline= baseline, reject=reject)
>>>> 
>>>> The aim of both questions is to use the tfr_morlet function
>> which
>>>> asks
>>>> in input the epochs.
>>>> 
>>>> power, itc = tfr_morlet(epochs, freqs=freqs, n_cycles=n_cycles,
>>>> use_fft=False, return_itc=True, decim=3,n_jobs=1)
>>>> 
>>>> Someone has an idea about this?
>>>> 
>>>> Bests,
>>>> 
>>>> Jonathan
>>>> --
>>>> Dr Jonathan Entakli - Research Associate Post doctoral position
>>>> 
>>>> Department of Psychology
>>>> University of Cambridge, Downing St
>>>> Cambridge CB2 3EB
>>>> 
>>>> Sir William Hardy Building
>>>> Office : 314
>>>> Mobile : 07778 692 458
>>>> 
>>>> http://www.viscog.psychol.cam.ac.uk/ [2] [2]
>>>> _______________________________________________
>>>> Mne_analysis mailing list
>>>> Mne_analysis at nmr.mgh.harvard.edu
>>>> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
>> [3] [3]
>>>> 
>>>> The information in this e-mail is intended only for the person
>> to
>>>> whom it is
>>>> addressed. If you believe this e-mail was sent to you in error
>> and
>>>> the e-mail
>>>> contains patient information, please contact the Partners
>>>> Compliance HelpLine at
>>>> http://www.partners.org/complianceline [4] [4] . If the e-mail
>> was sent
>>>> to you in error
>>>> but does not contain patient information, please contact the
>> sender
>>>> and properly
>>>> dispose of the e-mail.
>>> 
>>> 
>>> 
>>> Links:
>>> ------
>>> [1] http://raw1.info [1]
>>> [2] http://www.viscog.psychol.cam.ac.uk/ [2]
>>> [3]
>> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis [3]
>>> [4] http://www.partners.org/complianceline [4]
>>> 
>>> _______________________________________________
>>> Mne_analysis mailing list
>>> Mne_analysis at nmr.mgh.harvard.edu
>>> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
>> [3]
>>> 
>>> 
>>> The information in this e-mail is intended only for the person to
>> whom
>>> it is
>>> addressed. If you believe this e-mail was sent to you in error
>> and the
>>> e-mail
>>> contains patient information, please contact the Partners
>> Compliance
>>> HelpLine at
>>> http://www.partners.org/complianceline [4] . If the e-mail was
>> sent to you
>>> in error
>>> but does not contain patient information, please contact the
>> sender and
>>> properly
>>> dispose of the e-mail.
>> 
>> --
>> Dr Jonathan Entakli - Research Associate
>> 
>> Department of Psychology
>> University of Cambridge, Downing St
>> Cambridge CB2 3EB
>> 
>> Sir William Hardy Building
>> Office : 314
>> Mobile : 07778 692 458
>> 
>> http://www.viscog.psychol.cam.ac.uk/ [2]
>> _______________________________________________
>> Mne_analysis mailing list
>> Mne_analysis at nmr.mgh.harvard.edu
>> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis [3]
> 
> 
> 
> Links:
> ------
> [1] http://raw1.info
> [2] http://www.viscog.psychol.cam.ac.uk/
> [3] https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
> [4] http://www.partners.org/complianceline
> 
> _______________________________________________
> Mne_analysis mailing list
> Mne_analysis at nmr.mgh.harvard.edu
> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
> 
> 
> The information in this e-mail is intended only for the person to whom 
> it is
> addressed. If you believe this e-mail was sent to you in error and the 
> e-mail
> contains patient information, please contact the Partners Compliance 
> HelpLine at
> http://www.partners.org/complianceline . If the e-mail was sent to you 
> in error
> but does not contain patient information, please contact the sender and 
> properly
> dispose of the e-mail.

-- 
Dr Jonathan Entakli - Research Associate

Department of Psychology
University of Cambridge, Downing St
Cambridge CB2 3EB

Sir William Hardy Building
Office : 314
Mobile : 07778 692 458

http://www.viscog.psychol.cam.ac.uk/



More information about the Mne_analysis mailing list