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

Function test_bem_solution

mne/tests/test_bem.py:256–324  ·  view source on GitHub ↗

Test making a BEM solution from Python and OpenMEEG with I/O.

(tmp_path, cond, fname)

Source from the content-addressed store, hash-verified

254 ],
255)
256def test_bem_solution(tmp_path, cond, fname):
257 """Test making a BEM solution from Python and OpenMEEG with I/O."""
258 pytest.importorskip("nibabel")
259 # test degenerate conditions
260 surf = read_bem_surfaces(fname_bem_1)[0]
261 with pytest.raises(RuntimeError, match="2 or less"):
262 _ico_downsample(surf, 10)
263 s_bad = dict(tris=surf["tris"][1:], ntri=surf["ntri"] - 1, rr=surf["rr"])
264 with pytest.raises(RuntimeError, match="Cannot decimate.*isomorphic"):
265 _ico_downsample(s_bad, 1)
266 s_bad = dict(
267 tris=surf["tris"].copy(), ntri=surf["ntri"], rr=surf["rr"]
268 ) # bad triangulation
269 s_bad["tris"][0] = [0, 0, 0]
270 with pytest.raises(RuntimeError, match="ordering is wrong"):
271 _ico_downsample(s_bad, 1)
272 s_bad["id"] = 1
273 with pytest.raises(RuntimeError, match="is not complete"):
274 _assert_complete_surface(s_bad)
275 s_bad = dict(tris=surf["tris"], ntri=surf["ntri"], rr=surf["rr"].copy())
276 s_bad["rr"][0] = 0.0
277 with pytest.raises(RuntimeError, match="No matching vertex"):
278 _get_ico_map(surf, s_bad)
279
280 surfs = read_bem_surfaces(fname_bem_3)
281 with pytest.raises(RuntimeError, match="is not completely inside"):
282 _assert_inside(surfs[0], surfs[1]) # outside
283 surfs[0]["id"] = 100 # bad surfs
284 with pytest.raises(RuntimeError, match="bad surface id"):
285 _order_surfaces(surfs)
286 surfs[1]["rr"] /= 1000.0
287 with pytest.raises(RuntimeError, match="seem too small"):
288 _check_surface_size(surfs[1])
289
290 # actually test functionality
291 fname_temp = tmp_path / "temp-bem-sol.fif"
292 # use a model and solution made in Python
293 for model_type in ("python", "c"):
294 if model_type == "python":
295 model = make_bem_model(
296 "sample", conductivity=cond, ico=2, subjects_dir=subjects_dir
297 )
298 else:
299 model = fname_bem_1 if len(cond) == 1 else fname_bem_3
300 solution = make_bem_solution(model, verbose=True)
301 assert solution["solver"] == "mne"
302 solution_c = read_bem_solution(fname)
303 assert solution_c["solver"] == "mne"
304 _compare_bem_solutions(solution, solution_c)
305 write_bem_solution(fname_temp, solution)
306 solution_read = read_bem_solution(fname_temp)
307 assert solution["solver"] == solution_c["solver"] == "mne"
308 assert solution_read["solver"] == "mne"
309 _compare_bem_solutions(solution, solution_c)
310 _compare_bem_solutions(solution_read, solution_c)
311 # OpenMEEG
312 pytest.importorskip(
313 "openmeeg",

Callers

nothing calls this directly

Calls 15

read_bem_surfacesFunction · 0.90
_ico_downsampleFunction · 0.90
_assert_complete_surfaceFunction · 0.90
_get_ico_mapFunction · 0.90
_assert_insideFunction · 0.90
_order_surfacesFunction · 0.90
_check_surface_sizeFunction · 0.90
make_bem_modelFunction · 0.90
make_bem_solutionFunction · 0.90
read_bem_solutionFunction · 0.90
write_bem_solutionFunction · 0.90
catch_loggingClass · 0.90

Tested by

no test coverage detected