[Mne_analysis] [merge/add/replace events & save - not?]

Virginie van Wassenhove virginie.van.wassenhove at gmail.com
Wed Aug 1 08:57:30 EDT 2018
Search archives:

        External Email - Use Caution        

Last spam about this for end users, and bottom lines:

- merge_events does the job but does not preserve changes of events in raw
file, so not useful for my purpose;

- add_events  literally add events so when none is there, it is simple to
add a trigger value; when an event is already at the wished for sample, we
cannot easily *replace* without considering already the initial value
(which will be added otherwise). Computing the difference with the existing
value is possible but a pain. The usefulness is that add_events can be kept.

I'll work around today  but it would be nice to have the equivalent of a
"merge_events with replace=True" for the add_events context.

Cheers,




Virginie van Wassenhove





On Wed, Aug 1, 2018 at 2:05 PM Virginie van Wassenhove <
virginie.van.wassenhove at gmail.com> wrote:

>         External Email - Use Caution
>
>
> OK but that solution does not work for this analysis and/or not practical
> because I only need these triggers to crop data (unless I can pass an
> events file in a raw or sss appended data?)
>
> + I want to illustrate  that this is not intuitive for the end user.
>
> - it was pointed out I had code error with overlapping variable names
> (evts, tmpevts) but when this solved, that does not change anything .
>
> - if I do this (case 5)
> tmpevts = mne.merge_events(evts, [1],
> runs_info['evts_list'][r-1][0],replace_events=True)
> tmpevts = mne.merge_events(tmpevts, [2],
> runs_info['evts_list'][r-1][1],replace_events=True)
> print(tmpevts)
> [[ 63196      0    102]
>  [363197      0    202]]
>
> I get what I want (with no real need to preserve prior triggers) but it is
> still does not get saved
> blah = mne.find_events(tmp, stim_channel=stim_channel, output='onset',
>                                  min_duration=0.001, uint_cast=True,
> initial_event=True)
> 2 events found
> Event IDs: [1 2]
>
>
>
>
>
>
> On Wed, Aug 1, 2018 at 1:44 PM Alexandre Gramfort <
> alexandre.gramfort at inria.fr> wrote:
>
>>         External Email - Use Caution
>>
>> hi Virginie,
>>
>> as you have a single stim channel you cannot have 2 events with different
>> values
>> at the same instant. So what you wish is not possible like this.
>>
>> What you can do however is to store the events you want in a distinct
>> file.
>>
>> You can use:
>>
>> https://martinos.org/mne/stable/generated/mne.write_events.html
>>
>> Note that you can pass events to raw.plot to see when are the events you
>> used.
>> It's a good sanity check that they are correct.
>>
>> HTH
>> Ale
>>
>>
>> On Wed, Aug 1, 2018 at 1:38 PM Virginie van Wassenhove
>> <virginie.van.wassenhove at gmail.com> wrote:
>> >
>> >         External Email - Use Caution
>> >
>> > Here are simplified steps + 4 cases used to try and explain what I
>> would think as inconsistencies from the user's viewpoint:
>> >
>> > #__________________________
>> > #load raw, maxfilter, find events
>> > #__________________________
>> > raw = mne.io.Raw(fname, allow_maxshield=True, preload=True)
>> > sss = maxwell_filter(raw, calibration=cal_path, cross_talk=ct_path,
>> >                      verbose=False, destination=refrun_path,
>> >                      bad_condition='warning')
>> > #find events
>> > evts = mne.find_events(sss, stim_channel=stim_channel, output='onset',
>> >                          min_duration=0.001, uint_cast=True,
>> initial_event=True)
>> > print(evts)
>> > 2 events found
>> > Event IDs: [1 2]
>> > [[ 63196      0      1]
>> >  [363197      0      2]]
>> >
>> > _________________________________________________________
>> > (1) Case 1: does "merge" (or here, add) events but does not save
>> > _________________________________________________________
>> > #add events
>> > evts = mne.merge_events(evts, [1],
>> runs_info['evts_list'][r-1][0],replace_events=False)
>> > evts = mne.merge_events(evts, [2],
>> runs_info['evts_list'][r-1][1],replace_events=False)
>> >
>> > print(evts)
>> > [[ 63196      0      1]
>> >  [ 63196      0    102]
>> >  [363197      0      2]
>> >  [363197      0    202]]
>> >
>> > sss.resample(returnResampFreq(), npad="auto", events=evts)
>> > sss.save(sss_fname, overwrite=True, verbose=False)
>> > del raw, evts, sss
>> >
>> > # reload and check after saving
>> > tmp = mne.io.Raw(sss_fname, preload=True)
>> > evts = mne.find_events(tmp, stim_channel=stim_channel, output='onset',
>> >                          min_duration=0.001,
>> >                          uint_cast=True, initial_event=True)
>> > print(evts)
>> > 2 events found
>> > Event IDs: [1 2]
>> > [[15799     0     1]
>> >  [90799     0     2]]
>> >
>> > __________________________________________________
>> > (2) Case 2: does "merge" (or here, add) events but does not save
>> > [same as Case 1 w/o resampling] => resampling not an issue just to check
>> > _________________________________________________________
>> > evts = mne.merge_events(evts, [1],
>> runs_info['evts_list'][r-1][0],replace_events=False)
>> > evts = mne.merge_events(evts, [2],
>> runs_info['evts_list'][r-1][1],replace_events=False)
>> > print(evts)
>> > [[ 63196      0      1]
>> >  [ 63196      0    102]
>> >  [363197      0      2]
>> >  [363197      0    202]]
>> > sss.save(sss_fname, overwrite=True, verbose=False)
>> >
>> > # reload and check after saving
>> > tmp = mne.io.Raw(sss_fname, preload=True)
>> > evts = mne.find_events(tmp, stim_channel=stim_channel, output='onset',
>> >                          min_duration=0.001,
>> >                          uint_cast=True, initial_event=True)
>> > print(evts)
>> > 2 events found
>> > Event IDs: [1 2]
>> > [[ 63196      0      1]
>> >  [363197      0      2]]
>> >
>> > _______________________________________________________
>> > (3) Case 3: does merge events but also add values and save
>> > _________________________________________________________
>> > same as (1) with add_events and no  resampling of sss before saving
>> > sss.add_events(evts,stim_channel)
>> > sss.save(sss_fname, overwrite=True, verbose=False)
>> >
>> > # reload and check after saving
>> > tmp = mne.io.Raw(sss_fname, preload=True)
>> > evts = mne.find_events(tmp, stim_channel=stim_channel, output='onset',
>> >                          min_duration=0.001, uint_cast=True,
>> initial_event=True)
>> > 2 events found
>> > Event IDs: [103 204]
>> > [[ 63196      0    103]
>> >  [363197      0    204]]
>> >
>> > _______________________________________________________
>> > (4) Case 4: file in which there is no trigger to start with but I want
>> to create some
>> > _________________________________________________________
>> > print(evts)
>> > []
>> >
>> > #add evt on 50 consecutive samples (tried with 1 to 100, same outcome)
>> > for si in range(0,50):
>> >     tmpevts += ([[sss.first_samp+si, 0,
>> runs_info['evts_list'][r-1][0]]])
>> > for si in range(0,50):
>> >     tmpevts += ([[sss.last_samp-si, 0, runs_info['evts_list'][r-1][1]]])
>> >
>> > sss.add_events(tmpevts,stim_channel)
>> > sss.save(sss_fname, overwrite=True, verbose=False)
>> >
>> > # reload and check after saving
>> > tmp = mne.io.Raw(sss_fname, preload=True)
>> > evts = mne.find_events(tmp, stim_channel=stim_channel, output='onset',
>> >                          min_duration=0.001, uint_cast=True,
>> initial_event=True)
>> > 2 events found
>> > Event IDs: [101 201]
>> > ____________________________________
>> >
>> > From these, I conclude that adding events with add_events may be saved
>> when the initial event values are 0 and there are no triggers in the file.
>> > If there are triggers at the sample I wish to transform  w/o preserving
>> existing triggers (value adding), it is saved.
>> > If there are triggers at the sample I wish to transform  while
>> preserving existing triggers (duplicating sample and adding new values) it
>> is not saved (*that's what I wish)
>> > So the only option to save changes in events is to do a merge with
>> replacement (aka adding value) but then I lose initial triggers.
>> >
>> >
>> >
>> > Virginie van Wassenhove
>> >
>> >
>> >
>> >
>> >
>> >
>> > On Wed, Aug 1, 2018 at 11:54 AM Alexandre Gramfort <
>> alexandre.gramfort at inria.fr> wrote:
>> >>
>> >>         External Email - Use Caution
>> >>
>> >> hi Virginie,
>> >>
>> >> did you use:
>> >>
>> >>
>> https://martinos.org/mne/dev/generated/mne.io.Raw.html#mne.io.Raw.add_events
>> >>
>> >> ?
>> >>
>> >> if you create events and add them with this method it should then be
>> >> save to disk
>> >> when writing the updated file. If it's not the case we have a bug.
>> >>
>> >> Alex
>> >> On Wed, Aug 1, 2018 at 9:57 AM Virginie van Wassenhove
>> >> <virginie.van.wassenhove at gmail.com> wrote:
>> >> >
>> >> >         External Email - Use Caution
>> >> >
>> >> > Hi everyone,
>> >> >
>> >> > long story short, why saving a raw/sss file to which I either added
>> or merged events do not actually preserve the new events?  (longer story
>> below)
>> >> >
>> >> > Thanks,
>> >> > Virginie
>> >> >
>> >> >
>> >> > Longer story:
>> >> >
>> >> > My goal: mark the initial/final few samples of raw data (not just
>> with annotations but with my own new trigger) or replace existing triggers
>> with new ones. This is so I can crop again preprocessed data (sss
>> post-reject post-ICA raw) as I wish, after I concatenated runs to apply ICA.
>> >> >
>> >> > I tried:
>> >> > - using merge/add operations (all going fine detecting the events I
>> want to replace) but some events are systematically missing after I saved
>> the file and reload it;
>> >> > - tried to catch missing triggers again and redo the same operations
>> before concatenation but the sss file is still not being saved with the
>> added/replaced events
>> >> >
>> >> > What am I missing? Do you consider it no desirable to be able to
>> rewrite a preprocessed sss file with new events?
>> >> > Thanks.
>> >> >
>> >> >
>> >> > Virginie van Wassenhove
>> >> > https://brainthemind.com/
>> >> >
>> >> >
>> >> >
>> >> > _______________________________________________
>> >> > 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.
>> >>
>> >> _______________________________________________
>> >> Mne_analysis mailing list
>> >> Mne_analysis at nmr.mgh.harvard.edu
>> >> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
>> >
>> > _______________________________________________
>> > 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.
>>
>> _______________________________________________
>> Mne_analysis mailing list
>> Mne_analysis at nmr.mgh.harvard.edu
>> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20180801/66f647a0/attachment-0001.html 


More information about the Mne_analysis mailing list