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

Function _setup_bem

mne/forward/_make_forward.py:287–323  ·  view source on GitHub ↗

Set up a BEM for forward computation, making a copy and modifying.

(bem, bem_extra, neeg, mri_head_t, allow_none=False, verbose=None)

Source from the content-addressed store, hash-verified

285
286@verbose
287def _setup_bem(bem, bem_extra, neeg, mri_head_t, allow_none=False, verbose=None):
288 """Set up a BEM for forward computation, making a copy and modifying."""
289 if allow_none and bem is None:
290 return None
291 logger.info("")
292 _validate_type(bem, ("path-like", ConductorModel), bem)
293 if not isinstance(bem, ConductorModel):
294 logger.info(f"Setting up the BEM model using {bem_extra}...\n")
295 bem = read_bem_solution(bem)
296 else:
297 bem = bem.copy()
298 if bem["is_sphere"]:
299 logger.info("Using the sphere model.\n")
300 if len(bem["layers"]) == 0 and neeg > 0:
301 raise RuntimeError(
302 "Spherical model has zero shells, cannot use with EEG data"
303 )
304 if bem["coord_frame"] != FIFF.FIFFV_COORD_HEAD:
305 raise RuntimeError("Spherical model is not in head coordinates")
306 else:
307 if bem["surfs"][0]["coord_frame"] != FIFF.FIFFV_COORD_MRI:
308 raise RuntimeError(
309 f"BEM is in {_coord_frame_name(bem['surfs'][0]['coord_frame'])} "
310 "coordinates, should be in MRI"
311 )
312 if neeg > 0 and len(bem["surfs"]) == 1:
313 raise RuntimeError(
314 "Cannot use a homogeneous (1-layer BEM) model "
315 "for EEG forward calculations, consider "
316 "using a 3-layer BEM instead"
317 )
318 logger.info("Employing the head->MRI coordinate transform with the BEM model.")
319 # fwd_bem_set_head_mri_t: Set the coordinate transformation
320 bem["head_mri_t"] = _ensure_trans(mri_head_t, "head", "mri")
321 logger.info(f"BEM model {op.split(bem_extra)[1]} is now set up")
322 logger.info("")
323 return bem
324
325
326@verbose

Callers 2

fit_dipoleFunction · 0.85
_prepare_for_forwardFunction · 0.85

Calls 7

_validate_typeFunction · 0.85
read_bem_solutionFunction · 0.85
_coord_frame_nameFunction · 0.85
_ensure_transFunction · 0.85
infoMethod · 0.80
splitMethod · 0.80
copyMethod · 0.45

Tested by

no test coverage detected