Apply a function to a subset of channels. %(applyfun_summary_epochs)s Parameters ---------- %(fun_applyfun)s %(picks_all_data_noref)s %(dtype_applyfun)s %(n_jobs)s Ignored if ``channel_wise=False`` as the workload is split across
(
self,
fun,
picks=None,
dtype=None,
n_jobs=None,
channel_wise=True,
verbose=None,
**kwargs,
)
| 1954 | |
| 1955 | @verbose |
| 1956 | def apply_function( |
| 1957 | self, |
| 1958 | fun, |
| 1959 | picks=None, |
| 1960 | dtype=None, |
| 1961 | n_jobs=None, |
| 1962 | channel_wise=True, |
| 1963 | verbose=None, |
| 1964 | **kwargs, |
| 1965 | ): |
| 1966 | """Apply a function to a subset of channels. |
| 1967 | |
| 1968 | %(applyfun_summary_epochs)s |
| 1969 | |
| 1970 | Parameters |
| 1971 | ---------- |
| 1972 | %(fun_applyfun)s |
| 1973 | %(picks_all_data_noref)s |
| 1974 | %(dtype_applyfun)s |
| 1975 | %(n_jobs)s Ignored if ``channel_wise=False`` as the workload |
| 1976 | is split across channels. |
| 1977 | %(channel_wise_applyfun_epo)s |
| 1978 | %(verbose)s |
| 1979 | %(kwargs_fun)s |
| 1980 | |
| 1981 | Returns |
| 1982 | ------- |
| 1983 | self : instance of Epochs |
| 1984 | The epochs object with transformed data. |
| 1985 | """ |
| 1986 | _check_preload(self, "epochs.apply_function") |
| 1987 | picks = _picks_to_idx(self.info, picks, exclude=(), with_ref_meg=False) |
| 1988 | |
| 1989 | if not callable(fun): |
| 1990 | raise ValueError("fun needs to be a function") |
| 1991 | |
| 1992 | data_in = self._data |
| 1993 | if dtype is not None and dtype != self._data.dtype: |
| 1994 | self._data = self._data.astype(dtype) |
| 1995 | |
| 1996 | args = getfullargspec(fun).args + getfullargspec(fun).kwonlyargs |
| 1997 | if channel_wise is False: |
| 1998 | if ("ch_idx" in args) or ("ch_name" in args): |
| 1999 | raise ValueError( |
| 2000 | "apply_function cannot access ch_idx or ch_name " |
| 2001 | "when channel_wise=False" |
| 2002 | ) |
| 2003 | if "ch_idx" in args: |
| 2004 | logger.info("apply_function requested to access ch_idx") |
| 2005 | if "ch_name" in args: |
| 2006 | logger.info("apply_function requested to access ch_name") |
| 2007 | |
| 2008 | if channel_wise: |
| 2009 | parallel, p_fun, n_jobs = parallel_func(_check_fun, n_jobs) |
| 2010 | if n_jobs == 1: |
| 2011 | _fun = partial(_check_fun, fun) |
| 2012 | # modify data inplace to save memory |
| 2013 | for ch_idx in picks: |
nothing calls this directly
no test coverage detected