MCPcopy
hub / github.com/mne-tools/mne-python / apply_function

Method apply_function

mne/io/base.py:1062–1151  ·  view source on GitHub ↗

Apply a function to a subset of channels. %(applyfun_summary_raw)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 cha

(
        self,
        fun,
        picks=None,
        dtype=None,
        n_jobs=None,
        channel_wise=True,
        verbose=None,
        **kwargs,
    )

Source from the content-addressed store, hash-verified

1060
1061 @verbose
1062 def apply_function(
1063 self,
1064 fun,
1065 picks=None,
1066 dtype=None,
1067 n_jobs=None,
1068 channel_wise=True,
1069 verbose=None,
1070 **kwargs,
1071 ):
1072 """Apply a function to a subset of channels.
1073
1074 %(applyfun_summary_raw)s
1075
1076 Parameters
1077 ----------
1078 %(fun_applyfun)s
1079 %(picks_all_data_noref)s
1080 %(dtype_applyfun)s
1081 %(n_jobs)s Ignored if ``channel_wise=False`` as the workload
1082 is split across channels.
1083 %(channel_wise_applyfun)s
1084
1085 .. versionadded:: 0.18
1086 %(verbose)s
1087 %(kwargs_fun)s
1088
1089 Returns
1090 -------
1091 self : instance of Raw
1092 The raw object with transformed data.
1093 """
1094 _check_preload(self, "raw.apply_function")
1095 picks = _picks_to_idx(self.info, picks, exclude=(), with_ref_meg=False)
1096
1097 if not callable(fun):
1098 raise ValueError("fun needs to be a function")
1099
1100 data_in = self._data
1101 if dtype is not None and dtype != self._data.dtype:
1102 self._data = self._data.astype(dtype)
1103
1104 args = getfullargspec(fun).args + getfullargspec(fun).kwonlyargs
1105 if channel_wise is False:
1106 if ("ch_idx" in args) or ("ch_name" in args):
1107 raise ValueError(
1108 "apply_function cannot access ch_idx or ch_name "
1109 "when channel_wise=False"
1110 )
1111 if "ch_idx" in args:
1112 logger.info("apply_function requested to access ch_idx")
1113 if "ch_name" in args:
1114 logger.info("apply_function requested to access ch_name")
1115
1116 if channel_wise:
1117 parallel, p_fun, n_jobs = parallel_func(_check_fun, n_jobs)
1118 if n_jobs == 1:
1119 # modify data inplace to save memory

Callers 14

rescaleMethod · 0.95
apply_pca_obsFunction · 0.45
convert_unitsFunction · 0.45
test_apply_functionFunction · 0.45
test_apply_function_stcFunction · 0.45
test_apply_function_evkFunction · 0.45

Calls 6

_check_preloadFunction · 0.85
_picks_to_idxFunction · 0.85
parallel_funcFunction · 0.85
infoMethod · 0.80
_check_funFunction · 0.50
updateMethod · 0.45