'Add events to stim channel.
Parameters
events : ndarray, shape (n_events, 3)
Events to add. The first column specifies the sample number of
each event, the second column is ignored, and the third column
provides the event value. If events already exist in the Raw
instance at the given sample numbers, the event values will be
added together.
stim_channel : str | None
Name of the stim channel to add to. If None, the config variable
\'MNE_STIM_CHANNEL\' is used. If this is not found, it will default
to \'STI 014\'.
Notes
Data must be preloaded in order to add events.'

def add_events(self, events, stim_channel=None):

    if (not self.preload):
        raise RuntimeError('cannot    add    events    unless    data    are    preloaded')
    events = np.asarray(events)
    if ((events.ndim != 2) or (events.shape[1] != 3)):
        raise ValueError('events    must    be    shape    (n_events,    3)')
    stim_channel = _get_stim_channel(stim_channel, self.info)
    pick = pick_channels(self.ch_names, stim_channel)
    if (len(pick) == 0):
        raise ValueError(('Channel    %s    not    found' % stim_channel))
    pick = pick[0]
    idx = events[:, 0].astype(int)
    if (np.any((idx < self.first_samp)) or np.any((idx > self.last_samp))):
        raise ValueError(('event    sample    numbers    must    be    between    %s    and    %s' % (self.first_samp, self.last_samp)))
    if (not all((idx == events[:, 0]))):
        raise ValueError('event    sample    numbers    must    be    integers')
    self._data[(pick, (idx - self.first_samp))] += events[:, 2]
