mne-tools / mne-python

MNE: Magnetoencephalography (MEG) and Electroencephalography (EEG) in Python
https://mne.tools
BSD 3-Clause "New" or "Revised" License
2.7k stars 1.31k forks source link

Only the exact match ch is detected by eog, misc and stim_channel of read_raw_edf #10360

Closed rcmdnk closed 2 years ago

rcmdnk commented 2 years ago

Describe the bug

eog, misc, and stim_channel of read_raw_edf are used to assign the channel type for each channel.

Currently, only the exact matched channel can be detected. Nevertheless, some tutorials, such as Sleep stage classification from polysomnography (PSG) data - MNE 0.24.1 documentation, assume partial match and the results may differ from what is expected.

stim_channel is checked by _check_stim_channel.

eog and misc is checked directly in_get_info.

I'm not sure if this is a bug or intentional behavior. The behavior of some programs may change if this is changed to an exact match. (If the EDF file contains a long name channel whose part matches another stim/misc/eog channel...)

If this is intentional behavior, these tutorials should be fixed. Otherwise, these codes should be updated to allow the partial match.

Steps to reproduce

import mne

files = mne.datasets.sleep_physionet.age.fetch_data(subjects=[0], recording=[1])
raw = mne.io.read_raw_edf(files[0][0], eog=['eog'], stim_channel='marker', misc=['rectal'])
for c, t in zip(raw.ch_names, raw.get_channel_types()):
    print(f'{c}: {t}')

Expected results

EEG Fpz-Cz: eeg
EEG Pz-Oz: eeg
EOG horizontal: eog
Resp oro-nasal: eeg
EMG submental: eeg
Temp rectal: misc
Event marker: stim

Actual results

EEG Fpz-Cz: eeg
EEG Pz-Oz: eeg
EOG horizontal: eeg
Resp oro-nasal: eeg
EMG submental: eeg
Temp rectal: eeg
Event marker: eeg

All channels show eeg (default type).

Additional information

mne.sys_info():

Platform:       Linux-5.4.144+-x86_64-with-Ubuntu-18.04-bionic
Python:         3.7.12 (default, Jan 15 2022, 18:48:18)  [GCC 7.5.0]
Executable:     /usr/bin/python3
CPU:            x86_64: 2 cores
Memory:         12.7 GB

mne:            0.24.1
numpy:          1.21.5 {blas=openblas, lapack=openblas}
scipy:          1.4.1
matplotlib:     3.2.2 {backend=module://ipykernel.pylab.backend_inline}

sklearn:        1.0.2
numba:          0.51.2
nibabel:        3.0.2
nilearn:        Not found
dipy:           Not found
cupy:           Not found
pandas:         1.3.5
mayavi:         Not found
pyvista:        Not found
pyvistaqt:      Not found
ipyvtklink:     Not found
vtk:            Not found
PyQt5:          Not found
ipympl:         Not found
mne_qt_browser: Not found
pooch:          v1.6.0
welcome[bot] commented 2 years ago

Hello! 👋 Thanks for opening your first issue here! ❤️ We will try to get back to you soon. 🚴🏽‍♂️

cbrnr commented 2 years ago

I think we should update the tutorial – these parameters are meant to match exact names only. Note that you can always re-assign channels types after reading with mne.rename_channels(), which is more flexible because it also accepts a callable or a dict.

rcmdnk commented 2 years ago

Thanks. It's fine for me the usage is confirmed. Thank you for the rename function, too.

cbrnr commented 2 years ago

Do you have time to update the tutorial?

rcmdnk commented 2 years ago

Yes, I can do at least for the sleep stage classification part and will try to find others if exist.

rcmdnk commented 2 years ago

It seems no other documents have the problem. (some uses read_raw_edf(stim_channel=, but they seem full names of the channels)

agramfort commented 2 years ago

good catch. It's great if you can send a PR.

Message ID: @.***>

rcmdnk commented 2 years ago

Yes. Done: #10362