'Apply a function to a subset of channels.
The function "fun" is applied to the channels defined in "picks". The
data of the Raw object is modified inplace. If the function returns
a different data type (e.g. numpy.complex) it must be specified using
the dtype parameter, which causes the data type used for representing
the raw data to change.
The Raw object has to have the data loaded e.g. with ``preload=True``
or ``self.load_data()``.
.. note:: If n_jobs > 1, more memory is required as
``len(picks) * n_times`` additional time points need to
be temporaily stored in memory.
.. note:: If the data type changes (dtype != None), more memory is
required since the original and the converted data needs
to be stored in memory.
Parameters
fun : function
A function to be applied to the channels. The first argument of
fun has to be a timeseries (numpy.ndarray). The function must
return an numpy.ndarray with the same size as the input.
picks : array-like of int (default: None)
Indices of channels to apply the function to. If None, all data
channels are used.
dtype : numpy.dtype (default: None)
Data type to use for raw data after applying the function. If None
the data type is not modified.
n_jobs: int (default: 1)
Number of jobs to run in parallel.
*args :
Additional positional arguments to pass to fun (first pos. argument
of fun is the timeseries of a channel).
**kwargs :
Keyword arguments to pass to fun. Note that if "verbose" is passed
as a member of ``kwargs``, it will be consumed and will override
the default mne-python verbose level (see :func:`mne.verbose` and
:ref:`Logging documentation <tut_logging>` for more).
Returns
self : instance of Raw
The raw object with transformed data.'

@verbose
def apply_function(self, fun, picks=None, dtype=None, n_jobs=1, *args, **kwargs):

    _check_preload(self, 'raw.apply_function')
    if (picks is None):
        picks = _pick_data_channels(self.info, exclude=[], with_ref_meg=False)
    if (not callable(fun)):
        raise ValueError('fun    needs    to    be    a    function')
    data_in = self._data
    if ((dtype is not None) and (dtype != self._data.dtype)):
        self._data = self._data.astype(dtype)
    if (n_jobs == 1):
        for idx in picks:
            self._data[idx, :] = _check_fun(fun, data_in[idx, :], *args, **kwargs)
    else:
        (parallel, p_fun, _) = parallel_func(_check_fun, n_jobs)
        data_picks_new = parallel((p_fun(fun, data_in[p], *args, **kwargs) for p in picks))
        for (pp, p) in enumerate(picks):
            self._data[p, :] = data_picks_new[pp]
    return self
