trouble reading the triggers in a .BDF file

Hi,

I have data from a study in which Eprime was used to send triggers
(integer numbers from 0-32) to the eeg system.
When I load the data using 'mne.io.read_raw_edf' and I try to load the the
trigger info 'mne.find_events(mydata)' I see only 5 digit numbers such as
65303, and even when I count the number of triggers of each type it does
not match what is expected.
I also tried to convert these numbers to 2 high and low byte numbers but
again the actual numbers and the amount do not match what is expected. I
have no idea what the problem is but I am sure the trigger info is well
contained in the .bdf file, as a colleague of mine analysed this data for
a different research purpose using Brain Vision Analyser. I am quite keen
on learning mne-python so any advise on how to load this trigger info would
be much appreciated.
In case it is useful a sample of the data can be downloaded here
https://drive.google.com/open?id=0B0PbSnFq24yMc2tKU29zWHZKRU0

thanks!

david
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20160604/8bedc3d1/attachment.html

Hi David,

I just had a look at your edf file that you uploaded, and quick question,
is this the correct file or is there a .BDF that you are trying to analyze?
I had a look at the header of this file, and there isn't a stim channel
listed ($head Anna\ Priming-edf.edf). Here, I see that there are 132 EEG
channels, and two reference channels. Is this the same file your colleague
looked at, if so, what channel did they see the corresponding trigger
channels on?

Quick explanation for what you saw on the supposed trigger channel: the
reader assumes the last channel of the data block is the stimulus channel
(i.e. stim_channel=-1), which is the typical setting. The values you saw
were the software attempt to decode the stim channel values.

You can look to see how the test data for edf and bdf list either triggers
or annotation for the triggering information (cf.
mne-python/mne/io/edf/tests/data/).

Feel free to follow up and I can try to further debug this problem.

Hope this helps,

teon

Hi Teon,

thanks for the message. True I uploaded .edf version of the original .bdf
the original pdf can be found here
https://drive.google.com/open?id=0B0PbSnFq24yMZWxoWGNFNGctQmM
I think the channel info was 'STI 014' as this appears to be the only place
where I get events id

[ 65281 65282 etc]

definitely I am missing something in how to read the triggers from biosemi

Looking at mne.io.read_raw_edf, there appears to be required an annotation
file and annotation map to interprete the stim_channel...but am not clear
what is to be done here

cheers,
david

Hi David,

The BDF file does have the original stimulus channel.

Since your trigger values are represented from 0 to 32 (first six bits) and
we permit trigger values up to 2**17 (some DIO triggering device can permit
up 24bit triggers), you will need to mask the higher bit values of the
trigger channel.

This can be done with the function, mne.find_events(raw=raw, mask=2**17 -
32). This should provide you with your triggers.

I just started a discussion
<https://github.com/mne-tools/mne-python/issues/3284> on github about this
mask argument, and there might be an API change to make it more
user-friendly. As for now, this would be the solution to your problem.

HTH

teon

Hi Teon,

thanks for pointing me to the mask argument, I?ve just tried it and the
integer values and their numbers are not yet closer to what is expected,
however. To be exact the trigger values that were sent to the biosemi were
between 0 and 36 (rather than 0- 32 as noted in my prior email, apologies
for that)
and there could be also 64 trigger values (if there were response errors on
some trials).

I am not too sure the mask parameter as given ' mask=2**17 - 32 ' has to
be changed as 0- 64 is also represented in the first 6 bites, but I may
be missing something. What is the 32 in ' mask=2**17 - 32 ' representing?

thanks again,
david

Hi David,

The 32 refers to the bit mask that you want. I think you would be safe with
using 2**17 - 256. Below is the code snippet of what I did. Do you expect
there to be 2000 events total?

In [1]: raw = mne.io.read_raw_edf('/Users/teon/Downloads/AnnaPriming.bdf',
stim_channel=-1)

Extracting edf Parameters from /Users/teon/Downloads/AnnaPriming.bdf...

Setting channel info structure...

Creating Raw.info structure...

Ready.

In [2]: mne.find_events(raw, mask=2**17 -256)

Removing orphaned offset at the beginning of the file.

2000 events found

Events id: [ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
22 23 24 25

26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 47 63 64]

Out[2]:

array([[ 1550, 0, 25],

       [ 1942, 25, 27],

       [ 2352, 0, 27],

       ...,

       [1100573, 31, 63],

       [1100982, 0, 33],

       [1101254, 0, 34]])

teon

HI Teon, thanks this seems to do the job!
best
david