Convert surfaces to a BEM.
(
surfs, ids, sigmas, ico=None, rescale=True, incomplete="raise", extra=""
)
| 592 | |
| 593 | |
| 594 | def _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 |