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

Method apply_function

mne/source_estimate.py:643–691  ·  view source on GitHub ↗

Apply a function to a subset of vertices. %(applyfun_summary_stc)s Parameters ---------- %(fun_applyfun_stc)s %(picks_all)s %(dtype_applyfun)s %(n_jobs)s Ignored if ``vertice_wise=False`` as the workload is split across vertices.

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

Source from the content-addressed store, hash-verified

641
642 @verbose
643 def apply_function(
644 self, fun, picks=None, dtype=None, n_jobs=None, verbose=None, **kwargs
645 ):
646 """Apply a function to a subset of vertices.
647
648 %(applyfun_summary_stc)s
649
650 Parameters
651 ----------
652 %(fun_applyfun_stc)s
653 %(picks_all)s
654 %(dtype_applyfun)s
655 %(n_jobs)s Ignored if ``vertice_wise=False`` as the workload
656 is split across vertices.
657 %(verbose)s
658 %(kwargs_fun)s
659
660 Returns
661 -------
662 self : instance of SourceEstimate
663 The SourceEstimate object with transformed data.
664 """
665 _check_preload(self, "source_estimate.apply_function")
666 picks = _picks_to_idx(len(self._data), picks, exclude=(), with_ref_meg=False)
667
668 if not callable(fun):
669 raise ValueError("fun needs to be a function")
670
671 data_in = self._data
672 if dtype is not None and dtype != self._data.dtype:
673 self._data = self._data.astype(dtype)
674
675 # check the dimension of the source estimate data
676 _check_option("source_estimate.ndim", self._data.ndim, [2, 3])
677
678 parallel, p_fun, n_jobs = parallel_func(_check_fun, n_jobs)
679 if n_jobs == 1:
680 # modify data inplace to save memory
681 for idx in picks:
682 self._data[idx, :] = _check_fun(fun, data_in[idx, :], **kwargs)
683 else:
684 # use parallel function
685 data_picks_new = parallel(
686 p_fun(fun, data_in[p, :], **kwargs) for p in picks
687 )
688 for pp, p in enumerate(picks):
689 self._data[p, :] = data_picks_new[pp]
690
691 return self
692
693 @verbose
694 def apply_baseline(self, baseline=(None, 0), *, verbose=None):

Callers

nothing calls this directly

Calls 5

_check_preloadFunction · 0.85
_picks_to_idxFunction · 0.85
_check_optionFunction · 0.85
parallel_funcFunction · 0.85
_check_funFunction · 0.70

Tested by

no test coverage detected