Read the BEM surfaces from a FIF file. Parameters ---------- fname : path-like The name of the file containing the surfaces. patch_stats : bool, optional (default False) Calculate and add cortical patch statistics to the surfaces. s_id : int | None If int
(
fname, patch_stats=False, s_id=None, on_defects="raise", verbose=None
)
| 1407 | |
| 1408 | @verbose |
| 1409 | def read_bem_surfaces( |
| 1410 | fname, patch_stats=False, s_id=None, on_defects="raise", verbose=None |
| 1411 | ): |
| 1412 | """Read the BEM surfaces from a FIF file. |
| 1413 | |
| 1414 | Parameters |
| 1415 | ---------- |
| 1416 | fname : path-like |
| 1417 | The name of the file containing the surfaces. |
| 1418 | patch_stats : bool, optional (default False) |
| 1419 | Calculate and add cortical patch statistics to the surfaces. |
| 1420 | s_id : int | None |
| 1421 | If int, only read and return the surface with the given ``s_id``. |
| 1422 | An error will be raised if it doesn't exist. If None, all |
| 1423 | surfaces are read and returned. |
| 1424 | %(on_defects)s |
| 1425 | |
| 1426 | .. versionadded:: 0.23 |
| 1427 | %(verbose)s |
| 1428 | |
| 1429 | Returns |
| 1430 | ------- |
| 1431 | surf: list | dict |
| 1432 | A list of dictionaries that each contain a surface. If ``s_id`` |
| 1433 | is not None, only the requested surface will be returned. |
| 1434 | |
| 1435 | See Also |
| 1436 | -------- |
| 1437 | write_bem_surfaces, write_bem_solution, make_bem_model |
| 1438 | """ |
| 1439 | # Open the file, create directory |
| 1440 | _validate_type(s_id, ("int-like", None), "s_id") |
| 1441 | fname = _check_fname(fname, "read", True, "fname") |
| 1442 | if fname.suffix == ".h5": |
| 1443 | surf = _read_bem_surfaces_h5(fname, s_id) |
| 1444 | else: |
| 1445 | surf = _read_bem_surfaces_fif(fname, s_id) |
| 1446 | if s_id is not None and len(surf) != 1: |
| 1447 | raise ValueError(f"surface with id {s_id} not found") |
| 1448 | for this in surf: |
| 1449 | if patch_stats or this["nn"] is None: |
| 1450 | _check_complete_surface(this, incomplete=on_defects) |
| 1451 | return surf[0] if s_id is not None else surf |
| 1452 | |
| 1453 | |
| 1454 | def _read_bem_surfaces_h5(fname, s_id): |