'Setter for annotations.
This setter checks if they are inside the data range.
Parameters
annotations : Instance of mne.Annotations
Annotations to set.
emit_warning : bool
Whether to emit warnings when limiting or omitting annotations.'

@annotations.setter
def annotations(self, annotations, emit_warning=True):

    if (annotations is not None):
        if (not isinstance(annotations, Annotations)):
            raise ValueError(('Annotations    must    be    an    instance    of    mne.Annotations.    Got    %s.' % annotations))
        meas_date = self.info['meas_date']
        if (meas_date is None):
            meas_date = 0
        elif (not np.isscalar(meas_date)):
            if (len(meas_date) > 1):
                meas_date = (meas_date[0] + (meas_date[1] / 1000000.0))
        if (annotations.orig_time is not None):
            offset = ((annotations.orig_time - meas_date) - (self.first_samp / self.info['sfreq']))
        else:
            offset = 0
        omit_ind = list()
        omitted = limited = 0
        for (ind, onset) in enumerate(annotations.onset):
            onset += offset
            if (onset > self.times[(-1)]):
                omitted += 1
                omit_ind.append(ind)
            elif (onset < self.times[0]):
                if ((onset + annotations.duration[ind]) < self.times[0]):
                    omitted += 1
                    omit_ind.append(ind)
                else:
                    limited += 1
                    duration = (annotations.duration[ind] + onset)
                    annotations.duration[ind] = duration
                    annotations.onset[ind] = (self.times[0] - offset)
            elif ((onset + annotations.duration[ind]) > self.times[(-1)]):
                limited += 1
                annotations.duration[ind] = (self.times[(-1)] - onset)
        annotations.onset = np.delete(annotations.onset, omit_ind)
        annotations.duration = np.delete(annotations.duration, omit_ind)
        annotations.description = np.delete(annotations.description, omit_ind)
        if emit_warning:
            if (omitted > 0):
                warn(('Omitted    %s    annotation(s)    that    were    outside    data    range.' % omitted))
            if (limited > 0):
                warn(('Limited    %s    annotation(s)    that    were    expanding    outside    the    data    range.' % limited))
    self._annotations = annotations
