ValueError: Could not find any of the events you specified.

I am trying to deal with my EEG data by this documentation:
https://mne.tools/stable/auto_examples/decoding/decoding_csp_eeg.html
when I switch the data sort to my EEG data through this:

#LOAD DATA
subj = 'S1'
f_name = f'{subj}_mi1.cnt'
data_path = os.path.join('../data/eeg/S1/')
raw = mne.io.read_raw_cnt(os.path.join(data_path, f_name), preload=True)
# drop bad channels
raw.drop_channels(['left chn', 'rigth chn', 'M1', 'M2', 'CB1', 'CB2'])
print(raw.info['ch_names'])
raw.plot()
plt.show()
#raw_fnames = eegbci.load_data(subject, runs)
#raw = concatenate_raws([read_raw_edf(f, preload=True) for f in raw_fnames])
eegbci.standardize(raw)  # set channel names
montage = make_standard_montage('standard_1005')
raw.set_montage(montage)

# strip channel names of "." characters
raw.rename_channels(lambda x: x.strip('.'))

# Apply band-pass filter
raw.filter(7., 30., fir_design='firwin', skip_by_annotation='edge')

events, _ = events_from_annotations(raw, event_id=dict(T1=2, T2=3))

picks = pick_types(raw.info, meg=False, eeg=True, stim=False, eog=False,
                   exclude='bads')

# Read epochs (train will be done only between 1 and 2s)
# Testing will be done with a running classifier
epochs = Epochs(raw, events, event_id, tmin, tmax, proj=True, picks=picks,
                baseline=None, preload=True)
epochs_train = epochs.copy().crop(tmin=1., tmax=2.)
labels = epochs.events[:, -1] - 2

it comes with the error:

ValueError: Could not find any of the events you specified.

dont know where goes wrong and how to fix this?

Apparently there are no annotations with descriptions T1 and T2 in raw.annotations.

You can check raw.annotations, or simply not pass event_id to events_from_annotations().

Best wishes,
Richard

when I switch to:

events, _ = events_from_annotations(raw, event_id='auto')

and

events, _ = events_from_annotations(raw, event_id=None)

it comes with:

ValueError: No matching events found for feet (event id 3)
Used Annotations descriptions: ['1', '2']

the code is:

events, _ = events_from_annotations(raw, event_id='auto')

picks = pick_types(raw.info, meg=False, eeg=True, stim=False, eog=False,
                   exclude='bads')

# Read epochs (train will be done only between 1 and 2s)
# Testing will be done with a running classifier
epochs = Epochs(raw, events, event_id, tmin, tmax, proj=True, picks=picks,
                baseline=None, preload=True)
epochs_train = epochs.copy().crop(tmin=1., tmax=2.)
labels = epochs.events[:, -1] - 2

I don’t know where the error you’re reporting occurs. You need to provide the full traceback (the entire stack of error message)

my code:

# strip channel names of "." characters
raw.rename_channels(lambda x: x.strip('.'))

# Apply band-pass filter
raw.filter(7., 30., fir_design='firwin', skip_by_annotation='edge')

events, _ = events_from_annotations(raw, event_id='auto')

picks = pick_types(raw.info, meg=False, eeg=True, stim=False, eog=False,
                   exclude='bads')

# Read epochs (train will be done only between 1 and 2s)
# Testing will be done with a running classifier
print(str(event_id)+'test')
epochs = Epochs(raw, events, event_id, tmin, tmax, proj=True, picks=picks,
                baseline=None, preload=True)
epochs_train = epochs.copy().crop(tmin=1., tmax=2.)
labels = epochs.events[:, -1] - 2

error text:

Used Annotations descriptions: ['1', '2']
{'hands': 2, 'feet': 3}test
Traceback (most recent call last):
  File "C:\Users\22100\Desktop\SCNS3\code\decoding_csp_eeg.py", line 54, in <module>
    epochs = Epochs(raw, events, event_id, tmin, tmax, proj=True, picks=picks,
  File "<decorator-gen-206>", line 24, in __init__
  File "C:\Users\22100\PycharmProjects\pythonProject\venv\lib\site-packages\mne\epochs.py", line 2196, in __init__
    super(Epochs, self).__init__(
  File "<decorator-gen-196>", line 24, in __init__
  File "C:\Users\22100\PycharmProjects\pythonProject\venv\lib\site-packages\mne\epochs.py", line 423, in __init__
    _on_missing(on_missing, msg)
  File "C:\Users\22100\PycharmProjects\pythonProject\venv\lib\site-packages\mne\utils\check.py", line 732, in _on_missing
    raise ValueError(msg)
ValueError: No matching events found for feet (event id 3)

You should use the event_id returned from events_from_annotations() (currently you’re ignoring it by assigning it to _) instead of creating and passing your own. It doesn’t match your events array.

and when I change T1,T2(event_id) to 1 and 2,like this:


events, _ = events_from_annotations(raw, event_id=dict(T1=1,T2=2))

picks = pick_types(raw.info, meg=False, eeg=True, stim=False, eog=False,
                   exclude='bads')

# Read epochs (train will be done only between 1 and 2s)
# Testing will be done with a running classifier
print(str(event_id)+'test')
epochs = Epochs(raw, events, event_id, tmin, tmax, proj=True, picks=picks,
                baseline=None, preload=True)
epochs_train = epochs.copy().crop(tmin=1., tmax=2.)
labels = epochs.events[:, -1] - 2

it comes with:


Traceback (most recent call last):
  File "C:\Users\22100\Desktop\SCNS3\code\decoding_csp_eeg.py", line 46, in <module>
    events, _ = events_from_annotations(raw, event_id=dict(T1=1,T2=2))
  File "<decorator-gen-50>", line 24, in events_from_annotations
  File "C:\Users\22100\PycharmProjects\pythonProject\venv\lib\site-packages\mne\annotations.py", line 1021, in events_from_annotations
    event_sel, event_id_ = _select_annotations_based_on_description(
  File "C:\Users\22100\PycharmProjects\pythonProject\venv\lib\site-packages\mne\annotations.py", line 875, in _select_annotations_based_on_description
    raise ValueError('Could not find any of the events you specified.')
ValueError: Could not find any of the events you specified.

What you need to do is something like

events, event_id = events_from_annotations(raw)
epochs = Epochs(raw, events=events, event_id=event_id)

in my data,it should be: {‘hands’: 2, ‘feet’: 3}
when I changed the code as:

events, _ = events_from_annotations(raw)

picks = pick_types(raw.info, meg=False, eeg=True, stim=False, eog=False,
                   exclude='bads')

# Read epochs (train will be done only between 1 and 2s)
# Testing will be done with a running classifier
print(str(event_id)+'test')
epochs = Epochs(raw, events=events, event_id=event_id, tmin=-1, tmax=4, proj=True, picks=picks,
                baseline=None, preload=True)
epochs_train = epochs.copy().crop(tmin=1., tmax=2.)
labels = epochs.events[:, -1] - 2


it comes with


Traceback (most recent call last):
  File "C:\Users\22100\Desktop\SCNS3\code\decoding_csp_eeg.py", line 54, in <module>
    epochs = Epochs(raw, events=events, event_id=event_id, tmin=-1, tmax=4, proj=True, picks=picks,
  File "<decorator-gen-206>", line 24, in __init__
  File "C:\Users\22100\PycharmProjects\pythonProject\venv\lib\site-packages\mne\epochs.py", line 2196, in __init__
    super(Epochs, self).__init__(
  File "<decorator-gen-196>", line 24, in __init__
  File "C:\Users\22100\PycharmProjects\pythonProject\venv\lib\site-packages\mne\epochs.py", line 423, in __init__
    _on_missing(on_missing, msg)
  File "C:\Users\22100\PycharmProjects\pythonProject\venv\lib\site-packages\mne\utils\check.py", line 732, in _on_missing
    raise ValueError(msg)
ValueError: No matching events found for feet (event id 3)
Used Annotations descriptions: ['1', '2']
{'hands': 2, 'feet': 3}test

how to use annotations as [‘2’,‘3’]

oh I solved, there is a label at the front of the code, after changed it worked