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

Function read_bem_solution

mne/bem.py:1575–1668  ·  view source on GitHub ↗

Read the BEM solution from a file. Parameters ---------- fname : path-like The file containing the BEM solution. %(verbose)s Returns ------- bem : instance of ConductorModel The BEM solution. See Also -------- read_bem_surfaces write_bem

(fname, *, verbose=None)

Source from the content-addressed store, hash-verified

1573
1574@verbose
1575def read_bem_solution(fname, *, verbose=None):
1576 """Read the BEM solution from a file.
1577
1578 Parameters
1579 ----------
1580 fname : path-like
1581 The file containing the BEM solution.
1582 %(verbose)s
1583
1584 Returns
1585 -------
1586 bem : instance of ConductorModel
1587 The BEM solution.
1588
1589 See Also
1590 --------
1591 read_bem_surfaces
1592 write_bem_surfaces
1593 make_bem_solution
1594 write_bem_solution
1595 """
1596 fname = _check_fname(fname, "read", True, "fname")
1597 # mirrors fwd_bem_load_surfaces from fwd_bem_model.c
1598 if fname.suffix == ".h5":
1599 read_hdf5, _ = _import_h5io_funcs()
1600 logger.info("Loading surfaces and solution...")
1601 bem = read_hdf5(fname)
1602 if "solver" not in bem:
1603 bem["solver"] = "mne"
1604 else:
1605 bem = _read_bem_solution_fif(fname)
1606
1607 if len(bem["surfs"]) == 3:
1608 logger.info("Three-layer model surfaces loaded.")
1609 needed = np.array(
1610 [
1611 FIFF.FIFFV_BEM_SURF_ID_HEAD,
1612 FIFF.FIFFV_BEM_SURF_ID_SKULL,
1613 FIFF.FIFFV_BEM_SURF_ID_BRAIN,
1614 ]
1615 )
1616 if not all(x["id"] in needed for x in bem["surfs"]):
1617 raise RuntimeError("Could not find necessary BEM surfaces")
1618 # reorder surfaces as necessary (shouldn't need to?)
1619 reorder = [None] * 3
1620 for x in bem["surfs"]:
1621 reorder[np.where(x["id"] == needed)[0][0]] = x
1622 bem["surfs"] = reorder
1623 elif len(bem["surfs"]) == 1:
1624 if not bem["surfs"][0]["id"] == FIFF.FIFFV_BEM_SURF_ID_BRAIN:
1625 raise RuntimeError("BEM Surfaces not found")
1626 logger.info("Homogeneous model surface loaded.")
1627
1628 assert set(bem.keys()) == set(("surfs", "solution", "bem_method", "solver"))
1629 bem = ConductorModel(bem)
1630 bem["is_sphere"] = False
1631 # sanity checks and conversions
1632 _check_option(

Callers 13

test_volume_source_spaceFunction · 0.90
test_setup_forward_modelFunction · 0.90
_compute_depthFunction · 0.90
test_io_bemFunction · 0.90
test_bem_solutionFunction · 0.90
test_distance_to_bemFunction · 0.90
test_simulate_round_tripFunction · 0.90
_setup_bemFunction · 0.85

Calls 8

_check_fnameFunction · 0.85
_import_h5io_funcsFunction · 0.85
_read_bem_solution_fifFunction · 0.85
setFunction · 0.85
ConductorModelClass · 0.85
_check_optionFunction · 0.85
_add_gamma_multipliersFunction · 0.85
infoMethod · 0.80

Tested by 11

test_volume_source_spaceFunction · 0.72
test_setup_forward_modelFunction · 0.72
_compute_depthFunction · 0.72
test_io_bemFunction · 0.72
test_bem_solutionFunction · 0.72
test_distance_to_bemFunction · 0.72
test_simulate_round_tripFunction · 0.72