mne-tools / mne-tools/mne-python
mne.find_event()'s uint_cast needs to be more flexible
@hoechenberger is already working on this.
Since Apr 30, 2020.
- Dominant language
- Python
- Stars
- 3.5k
- Forks
- 1.6k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 100
Description
Describe the bug
I am currently working with Cam-CAN data, which were acquired using a Neuromag MEG system. According to the mne.find_events() docs, there may be issues when reading events created on such a system if STI016 was active. In the data I have, there is no STI016; however, my stimulus channel of interest, STI101, yields spurious events, even when passing the recommended uint_cast=True parameter to mne.find_events. I found that this param causes a type cast to uint16; yet, it seems my data requires to be cast to uint8 instead.
Steps to reproduce
I have prepared a raw FIF file that only contains the STI101 channel:
https://drive.google.com/open?id=1rpgvxNSyWti6_VoAaFaCqsKgYAQ2wWUh
import numpy as np
import mne
infile = '/tmp/STI101_raw.fif'
sti101_raw = mne.io.read_raw_fif(infile, verbose=False)
events = mne.find_events(sti101_raw, verbose=False)
print(np.unique(events[:, 2]))
events_uint_cast = mne.find_events(sti101_raw, verbose=False,
uint_cast=True)
print(np.unique(events_uint_cast[:, 2]))
# Handle the data manually.
data = sti101_raw.get_data().squeeze()
print(np.unique(data))
print(np.unique(data.astype(np.uint8)))
Expected results
[ 1 2 3 4 5 6 7 ]
[ 1 2 3 4 5 6 7 ]
[-3.2768e+04 -3.2764e+04 0.0000e+00 1.0000e+00 2.0000e+00 3.0000e+00
4.0000e+00 5.0000e+00 6.0000e+00 7.0000e+00]
[0 1 2 3 4 5 6 7]
Actual results
[ 1 2 3 4 5 6 7 32768]
[ 1 2 3 4 5 6 7 32768 32772]
[-3.2768e+04 -3.2764e+04 0.0000e+00 1.0000e+00 2.0000e+00 3.0000e+00
4.0000e+00 5.0000e+00 6.0000e+00 7.0000e+00]
[0 1 2 3 4 5 6 7]
As you can see, only when casting to uint8, I get the correct results (last line)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.