MCPcopy Index your code
hub / github.com/mne-tools/mne-python / _CheckInsideSphere

Class _CheckInsideSphere

mne/surface.py:872–909  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

870
871
872class _CheckInsideSphere:
873 def __init__(self, sphere, *, check="inner"):
874 from .bem import ConductorModel
875
876 assert isinstance(sphere, ConductorModel) and sphere["is_sphere"]
877 self.center = sphere["r0"]
878 assert isinstance(check, str) and check in ("inner", "outer"), check
879 self.check = check
880 # for a sphere, our closest point and farthest are the same
881 if len(sphere["layers"]):
882 self.inner_r = sphere["layers"][0]["rad"]
883 self.outer_r = sphere["layers"][-1]["rad"]
884 else:
885 self.inner_r = self.outer_r = None
886
887 # No need for verbose dec here because no MNE code is called that would log
888 def __call__(self, rr, *, n_jobs=None, verbose=None):
889 assert isinstance(rr, np.ndarray), type(rr)
890 assert rr.ndim == 2 and rr.shape[1] == 3
891 if self.inner_r is None:
892 return np.ones(rr.shape[0], bool)
893 else:
894 return np.linalg.norm(rr - self.center, axis=-1) <= self._check_r
895
896 @property
897 def _check_r(self):
898 return self.inner_r if self.check == "inner" else self.outer_r
899
900 def query(self, rr):
901 """Return the distance to the sphere surface for each point."""
902 assert isinstance(rr, np.ndarray), type(rr)
903 assert rr.ndim == 2 and rr.shape[1] == 3, rr.shape
904 idx = np.zeros(rr.shape[0], int)
905 if self.inner_r is None:
906 dists = np.full(rr.shape[0], np.inf)
907 else:
908 dists = np.abs(np.linalg.norm(rr - self.center, axis=-1) - self._check_r)
909 return dists, idx
910
911
912###############################################################################

Callers 3

_prepare_for_forwardFunction · 0.85
__init__Method · 0.85
_filter_source_spacesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected