Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changes/devel/13007.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Correct :func:`mne.io.read_raw_cnt` to read responses and fix exceptions by `Jacob Woessner`_.
22 changes: 19 additions & 3 deletions mne/io/cnt/cnt.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from ..._fiff.utils import _create_chs, _find_channels, _mult_cal_one, read_str
from ...annotations import Annotations
from ...channels.layout import _topo_to_sphere
from ...utils import _check_option, _validate_type, fill_doc, warn
from ...utils import _check_option, _explain_exception, _validate_type, fill_doc, warn
from ..base import BaseRaw
from ._utils import (
CNTEventType3,
Expand Down Expand Up @@ -150,7 +150,22 @@ def _update_bad_span_onset(accept_reject, onset, duration, description):
np.array([e.KeyPad_Accept for e in my_events])
)

description = np.array([str(e.StimType) for e in my_events])
# Check to see if there are any button presses
description = []
for event in my_events:
# Extract the 4-bit fields
# Upper nibble (4 bits) currently not used
# accept = (event.KeyPad_Accept[0] & 0xF0) >> 4
# Lower nibble (4 bits) keypad button press
keypad = event.KeyPad_Accept[0] & 0x0F
if str(keypad) != "0":
description.append(f"KeyPad Response {keypad}")
elif event.KeyBoard != 0:
description.append(f"Keyboard Response {event.KeyBoard}")
else:
description.append(str(event.StimType))

description = np.array(description)

onset, duration, description = _update_bad_span_onset(
accept_reject, onset / sfreq, duration, description
Expand Down Expand Up @@ -532,7 +547,8 @@ def __init__(
)
except Exception:
raise RuntimeError(
"Could not read header from *.cnt file. mne.io.read_raw_cnt "
f"{_explain_exception()}\n"
"WARNING: mne.io.read_raw_cnt "
"supports Neuroscan CNT files only. If this file is an ANT Neuro CNT, "
"please use mne.io.read_raw_ant instead."
)
Expand Down
3 changes: 2 additions & 1 deletion mne/io/cnt/tests/test_cnt.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def test_auto_data():
third = pytest.warns(RuntimeWarning, match="Omitted 6 annot")
with first, second, third:
raw = read_raw_cnt(input_fname=fname_bad_spans)

# Test that responses are read properly
assert "KeyPad Response 1" in raw.annotations.description
assert raw.info["bads"] == ["F8"]

with _no_parse, pytest.warns(RuntimeWarning, match="number of bytes"):
Expand Down
Loading