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

Function _surfaces_to_bem

mne/bem.py:594–633  ·  view source on GitHub ↗

Convert surfaces to a BEM.

(
    surfs, ids, sigmas, ico=None, rescale=True, incomplete="raise", extra=""
)

Source from the content-addressed store, hash-verified

592
593
594def _surfaces_to_bem(
595 surfs, ids, sigmas, ico=None, rescale=True, incomplete="raise", extra=""
596):
597 """Convert surfaces to a BEM."""
598 # equivalent of mne_surf2bem
599 # surfs can be strings (filenames) or surface dicts
600 if len(surfs) not in (1, 3) or not (len(surfs) == len(ids) == len(sigmas)):
601 raise ValueError(
602 "surfs, ids, and sigmas must all have the same number of elements (1 or 3)"
603 )
604 for si, surf in enumerate(surfs):
605 if isinstance(surf, str | Path | os.PathLike):
606 surfs[si] = surf = read_surface(surf, return_dict=True)[-1]
607 # Downsampling if the surface is isomorphic with a subdivided icosahedron
608 if ico is not None:
609 for si, surf in enumerate(surfs):
610 surfs[si] = _ico_downsample(surf, ico)
611 for surf, id_ in zip(surfs, ids):
612 # Do topology checks (but don't save data) to fail early
613 surf["id"] = id_
614 _check_complete_surface(surf, copy=True, incomplete=incomplete, extra=extra)
615 surf["coord_frame"] = surf.get("coord_frame", FIFF.FIFFV_COORD_MRI)
616 surf.update(np=len(surf["rr"]), ntri=len(surf["tris"]))
617 if rescale:
618 surf["rr"] /= 1000.0 # convert to meters
619
620 # Shifting surfaces is not implemented here...
621
622 # Order the surfaces for the benefit of the topology checks
623 for surf, sigma in zip(surfs, sigmas):
624 surf["sigma"] = sigma
625 surfs = _order_surfaces(surfs)
626
627 # Check topology as best we can
628 _check_surfaces(surfs, incomplete=incomplete)
629 for surf in surfs:
630 _check_surface_size(surf)
631 _check_thicknesses(surfs)
632 logger.info("Surfaces passed the basic topology checks.")
633 return surfs
634
635
636@verbose

Callers 5

test_iterableFunction · 0.90
make_bem_modelFunction · 0.85
make_watershed_bemFunction · 0.85
write_head_bemFunction · 0.85
make_scalp_surfacesFunction · 0.85

Calls 9

read_surfaceFunction · 0.85
_ico_downsampleFunction · 0.85
_check_complete_surfaceFunction · 0.85
_order_surfacesFunction · 0.85
_check_surfacesFunction · 0.85
_check_surface_sizeFunction · 0.85
_check_thicknessesFunction · 0.85
infoMethod · 0.80
updateMethod · 0.45

Tested by 1

test_iterableFunction · 0.72