'Resample all channels.
The Raw object has to have the data loaded e.g. with ``preload=True``
or ``self.load_data()``.
.. warning:: The intended purpose of this function is primarily to
speed up computations (e.g., projection calculation) when
precise timing of events is not required, as downsampling
raw data effectively jitters trigger timings. It is
generally recommended not to epoch downsampled data,
but instead epoch and then downsample, as epoching
downsampled data jitters triggers.
For more, see
`this illustrative gist <https://gist.github.com/Eric89GXL/01642cb3789992fbca59>`_.
If resampling the continuous data is desired, it is
recommended to construct events using the original data.
The event onsets can be jointly resampled with the raw
data using the \'events\' parameter.
Parameters
sfreq : float
New sample rate to use.
npad : int | str
Amount to pad the start and end of the data.
Can also be "auto" to use a padding that will result in
a power-of-two size (can be much faster).
window : string or tuple
Frequency-domain window to use in resampling.
See :func:`scipy.signal.resample`.
stim_picks : array of int | None
Stim channels. These channels are simply subsampled or
supersampled (without applying any filtering). This reduces
resampling artifacts in stim channels, but may lead to missing
triggers. If None, stim channels are automatically chosen using
:func:`mne.pick_types`.
n_jobs : int | str
Number of jobs to run in parallel. Can be \'cuda\' if scikits.cuda
is installed properly and CUDA is initialized.
events : 2D array, shape (n_events, 3) | None
An optional event matrix. When specified, the onsets of the events
are resampled jointly with the data.
verbose : bool, str, int, or None
If not None, override default verbose level (see
:func:`mne.verbose` and :ref:`Logging documentation <tut_logging>`
for more). Defaults to self.verbose.
Returns
raw : instance of Raw
The resampled version of the raw object.
See Also
mne.io.Raw.filter
mne.Epochs.resample
Notes
For some data, it may be more accurate to use ``npad=0`` to reduce
artifacts. This is dataset dependent -- check your data!'

@verbose
def resample(self, sfreq, npad='auto', window='boxcar', stim_picks=None, n_jobs=1, events=None, verbose=None):

    _check_preload(self, 'raw.resample')
    if (events is None):
        try:
            original_events = find_events(self)
        except:
            pass
    sfreq = float(sfreq)
    o_sfreq = float(self.info['sfreq'])
    offsets = np.concatenate(([0], np.cumsum(self._raw_lengths)))
    new_data = list()
    ratio = (sfreq / o_sfreq)
    if (stim_picks is None):
        stim_picks = pick_types(self.info, meg=False, ref_meg=False, stim=True, exclude=[])
    stim_picks = np.asanyarray(stim_picks)
    for ri in range(len(self._raw_lengths)):
        data_chunk = self._data[:, offsets[ri]:offsets[(ri + 1)]]
        new_data.append(resample(data_chunk, sfreq, o_sfreq, npad, window=window, n_jobs=n_jobs))
        new_ntimes = new_data[ri].shape[1]
        if (len(stim_picks) > 0):
            stim_resampled = _resample_stim_channels(data_chunk[stim_picks], new_data[ri].shape[1], data_chunk.shape[1])
            new_data[ri][stim_picks] = stim_resampled
        self._first_samps[ri] = int((self._first_samps[ri] * ratio))
        self._last_samps[ri] = ((self._first_samps[ri] + new_ntimes) - 1)
        self._raw_lengths[ri] = new_ntimes
    self._data = np.concatenate(new_data, axis=1)
    self.info['sfreq'] = sfreq
    if (self.info.get('lowpass') is not None):
        self.info['lowpass'] = min(self.info['lowpass'], (sfreq / 2.0))
    self._update_times()
    if (events is None):
        try:
            resampled_events = find_events(self)
            if (len(resampled_events) != len(original_events)):
                warn('Resampling    of    the    stim    channels    caused    event    information    to    become    unreliable.    Consider    finding    events    on    the    original    data    and    passing    the    event    matrix    as    a    parameter.')
        except:
            pass
        return self
    else:
        if copy:
            events = events.copy()
        events[:, 0] = np.minimum(np.round((events[:, 0] * ratio)).astype(int), self._data.shape[1])
        return (self, events)
