this is the error that i;m getting: 2 from event_id is not present in events.

this is my code:

annotation_desc_2_event_id = {'Sleep stage W': 1,
                              'Sleep stage 1': 2,
                              'Sleep stage 2': 3,
                              'Sleep stage 3': 4,
                              'Sleep stage 4': 4,
                              'Sleep stage R': 5}
# keep last 30-min wake events before sleep and first 30-min wake events after
# sleep and redefine annotations on raw data
annot_train.crop(annot_train[1]['onset'] - 30 * 60,
                 annot_train[-2]['onset'] + 30 * 60)
raw_train.set_annotations(annot_train, emit_warning=False)

events_train, _ = mne.events_from_annotations(
    raw_train, event_id=annotation_desc_2_event_id, chunk_duration=30.)

# create a new event_id that unifies stages 3 and 4
event_id = {'Sleep stage W': 1,
            'Sleep stage 1': 2,
            'Sleep stage 2': 3,
            'Sleep stage 3/4': 4,
            'Sleep stage R': 5}
# plot events
fig = mne.viz.plot_events(events_train, event_id=event_id,
                          sfreq=raw_train.info['sfreq'],
                          first_samp=events_train[0, 0], on_missing='warn')

# keep the color-code for further plotting
stage_colors = plt.rcParams['axes.prop_cycle'].by_key()['color']

this is the error:

Used Annotations descriptions: ['Sleep stage R', 'Sleep stage W']
<ipython-input-25-b27e40780e33>:25: RuntimeWarning: 2 from event_id is not present in events.

  first_samp=events_train[0, 0], on_missing='warn')
<ipython-input-25-b27e40780e33>:25: RuntimeWarning: 3 from event_id is not present in events.

  first_samp=events_train[0, 0], on_missing='warn')
<ipython-input-25-b27e40780e33>:25: RuntimeWarning: 4 from event_id is not present in events.

  first_samp=events_train[0, 0], on_missing='warn')

you haven’t provided the events_train array so it’s hard to debug this remotely. But it looks like maybe when you call events_from_annotations it’s not finding any annotations that say ‘Sleep stage 1’ or ‘Sleep stage 2’ or ‘Sleep stage 3’ or ‘Sleep stage 4’.

I don’t think this is relevant but just in case FYI there is a mne.merge_events() function. If you provide the events_train array it will be easier to help.