mne.find_event()'s uint_cast needs to be more flexible
See original GitHub issueDescribe 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)
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (11 by maintainers)
Top Results From Across the Web
How to Be More Flexible: 30 Tips, Stretches, Exercises, and ...
Read on for our beginner's guide to becoming more flexible, ... Flexibility is also needed to release muscle tension and soreness as well...
Read more >Developing Personal Flexibility - Wright State University
We can all expect less stability and more change in our careers. To survive and thrive, we will need to be flexible. The...
Read more >7 Expert Tips For Improving Flexibility – Forbes Health
Experts provide seven tips on how you can improve your flexibility, plus how being flexible can improve your overall health and well-being.
Read more >Improving Flexibility at Any Age - Tri-City Medical Center
There is no one-size-fits-all flexibility regime, but experts say you should focus on stretching major muscle groups two or more times a week....
Read more >6 Simple Ways to Increase Your Flexibility - HSS
Your muscles will be warm and more pliable after a workout — so this is the perfect time to hold a stretch. Extend...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

go for it. Indeed it’s a frequent pb.
Not that this impacts the solution, but you might be interested in where these spurious events are coming from. It may be an issue with set-ups which have devices (e.g. button boxes) share channels with software triggers – which impacts the calculation of STI101. I think this is done to preserve parallel port compatibility for different presentation software. For instance the Cambridge Neuromag setup has this quirk detailed here: https://imaging.mrc-cbu.cam.ac.uk/meg/Triggers .