Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to read events from a file #8

Open
teekuningas opened this issue May 3, 2019 · 11 comments
Open

Add possibility to read events from a file #8

teekuningas opened this issue May 3, 2019 · 11 comments
Labels
enhancement New feature or request

Comments

@teekuningas
Copy link
Collaborator

Should make it possible to read events from a file. Can either implement on epochs and spectrum creation, or globally for subject.

@teekuningas teekuningas added the enhancement New feature or request label May 3, 2019
@r-lamarque
Copy link

Hello,

Does that mean that it is not possible at the moment to read event info from a STIM channel in a file? I am using .bdf files that include a STIM channel called "Status" with all event info. However, the "Event info" section of the "Preprocessing" part of Meggie remains empty. Then I am not sure how I could proceed towards epochs.

Best regards,
Rémi Lamarque

@teekuningas
Copy link
Collaborator Author

Hello,

Normally mne is able to gather the event information from the raw files automatically, with different loaders trying their best to understand the different formats.

@teekuningas
Copy link
Collaborator Author

teekuningas commented Apr 4, 2023

Sorry, misclicked the close button..

So this issue is really meant for a different scenario where the raw data really does not contain the events and the events have to be loaded in a different way.

For your case, we have to figure out why the events do not appear. If you plot the data with raw plot, can you there see the stimulus channel? Just to make sure, the events have not become annotations (that is there is no big colored rectangles overlayed on the plot)?

It might be that we need to allow you to specify the name of the stimulus channel if it does not work otherwise. It shouldn't take more than a day to have a new release with that.

Hope we can find a solution!
Erkka

@r-lamarque
Copy link

Hello,

I see, it is a different scenario indeed.

I do see the "Status" channel on the raw plot, as seen on the picture below. It does look like proper triggers there. I thought it may be a matter of Meggie not finding which channel has the event info indeed.

Let me know if there is anything else I could try.

Best regards,
Rémi Lamarque

image

@r-lamarque
Copy link

I forgot to mention, I do not know what the "STI101" channel is. When opening the same file on mne, it says I only have one STIM channel, which is "Status". And STI101 seems perfectly flat all the way through.

@teekuningas
Copy link
Collaborator Author

teekuningas commented Apr 5, 2023

With the meggie conda environment activated, can you start python shell:

> conda activate meggie-env
> python

And then run following commands:

>>> import mne
>>> raw = mne.io.read_raw('/path/to/the/raw-file.bdf')
>>> mne.find_events(raw)
>>> mne.find_events(raw, stim_channel="Status")

And then paste all the output here..

It might be that it's trying to synthetize the Status channel to STI101, but is failing for some reason.. or it might be that the api is designed so that we need to specify the "Status" channel and the STI101 is there for some other reason..

@teekuningas
Copy link
Collaborator Author

There is some legacy code in meggie that is heuristically specifying STI014 or STI101 as the source of events if it's found. It might be that nowadays mne handles things so well that I should not specify anything and we would get a better result. If both of those, mne.find_events(raw) and mne.find_events(raw, stim_channel="Status") seem to return all the events, I think I'm gonna patch meggie to just use mne.find_events(raw). At some point have to add it as a option that the user can specify.

I'll test a few cases myself to see if it works.

@r-lamarque
Copy link

Sure, here is the result:

(base) C:\Users\Lamarque>conda activate meggie-env

(meggie-env) C:\Users\Lamarque>python
Python 3.10.9 | packaged by conda-forge | (main, Feb 2 2023, 20:14:58) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

import mne

raw = mne.io.read_raw('D:\Documents\LAB MANAGER\BDF files\Greek BDF Files (new)_BDFdata_GK01-English-v2r-lm.bdf')
Extracting EDF parameters from D:\Documents\LAB MANAGER\BDF files\Greek BDF Files (new)_BDFdata_GK01-English-v2r-lm.bdf...
BDF file detected
Setting channel info structure...
Creating raw.info structure...

mne.find_events(raw)
Trigger channel has a non-zero initial value of 65536 (consider using initial_event=True to detect this event)
Removing orphaned offset at the beginning of the file.
2321 events found
Event IDs: [ 1 2 5 6 7 9 11 12 13 14 15 21 22 23 24 25 31 32
41 42 200 255]
array([[ 215949, 0, 6],
[ 221176, 0, 7],
[ 224797, 0, 6],
...,
[2656181, 0, 200],
[2656366, 0, 2],
[2662051, 0, 6]], dtype=int64)

mne.find_events(raw, stim_channel="Status")
Trigger channel has a non-zero initial value of 65536 (consider using initial_event=True to detect this event)
Removing orphaned offset at the beginning of the file.
2321 events found
Event IDs: [ 1 2 5 6 7 9 11 12 13 14 15 21 22 23 24 25 31 32
41 42 200 255]
array([[ 215949, 0, 6],
[ 221176, 0, 7],
[ 224797, 0, 6],
...,
[2656181, 0, 200],
[2656366, 0, 2],
[2662051, 0, 6]], dtype=int64)

@teekuningas
Copy link
Collaborator Author

Ok, it seems to do fine. I'll fix meggie quickly and let you know when to update. In the anomaly that mne would not work fine with a different dataset, one can (in the future) still set the environment variable MNE_STIM_CHANNEL.

Thanks!
Erkka

@teekuningas
Copy link
Collaborator Author

teekuningas commented Apr 5, 2023

v1.5.1 with a fix should now be in conda. Can you try to update?

EDIT: It seems it's not immediately available as it has to run tests.

-- Erkka

@r-lamarque
Copy link

I just tried it and it works perfectly now.

Thank you very much for your quick and efficient answer.

Best,
Rémi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants