'Get data after a linear (time) transform has been applied.
The transorm is applied to each source time course independently.
Parameters
func : callable
The transform to be applied, including parameters (see, e.g.,
:func:`functools.partial`). The first parameter of the function is
the input data. The first return value is the transformed data,
remaining outputs are ignored. The first dimension of the
transformed data has to be the same as the first dimension of the
input data.
idx : array | None
Indicices of source time courses for which to compute transform.
If None, all time courses are used.
tmin_idx : int | None
Index of first time point to include. If None, the index of the
first time point is used.
tmax_idx : int | None
Index of the first time point not to include. If None, time points
up to (and including) the last time point are included.
Returns
data_t : ndarray
The transformed data.
Notes
Applying transforms can be significantly faster if the
SourceEstimate object was created using "(kernel, sens_data)", for
the "data" parameter as the transform is applied in sensor space.
Inverse methods, e.g., "apply_inverse_epochs", or "lcmv_epochs" do
this automatically (if possible).'

def transform_data(self, func, idx=None, tmin_idx=None, tmax_idx=None):

    if (idx is None):
        idx = slice(None, None)
    if ((self._kernel is None) and (self._sens_data is None)):
        if self._kernel_removed:
            warn_('Performance    can    be    improved    by    not    accessing    the    data    attribute    before    calling    this    method.')
        data_t = func(self.data[idx, tmin_idx:tmax_idx])
        if isinstance(data_t, tuple):
            data_t = data_t[0]
    else:
        sens_data_t = func(self._sens_data[:, tmin_idx:tmax_idx])
        if isinstance(sens_data_t, tuple):
            sens_data_t = sens_data_t[0]
        data_shape = sens_data_t.shape
        if (len(data_shape) > 2):
            sens_data_t = sens_data_t.reshape(data_shape[0], np.prod(data_shape[1:]))
        data_t = np.dot(self._kernel[idx, :], sens_data_t)
        if (len(data_shape) > 2):
            data_t = data_t.reshape(data_t.shape[0], *data_shape[1:])
    return data_t
