(bem, extra_allow=(), name="bem")
| 2302 | |
| 2303 | |
| 2304 | def _ensure_bem_surfaces(bem, extra_allow=(), name="bem"): |
| 2305 | # by default only allow path-like and list, but handle None and |
| 2306 | # ConductorModel properly if need be. Always return a ConductorModel |
| 2307 | # even though it's incomplete (and might have is_sphere=True). |
| 2308 | assert all(extra in (None, ConductorModel) for extra in extra_allow) |
| 2309 | allowed = ("path-like", list) + extra_allow |
| 2310 | _validate_type(bem, allowed, name) |
| 2311 | if isinstance(bem, path_like): |
| 2312 | # Load the surfaces |
| 2313 | logger.info(f"Loading BEM surfaces from {bem}...") |
| 2314 | bem = read_bem_surfaces(bem) |
| 2315 | bem = ConductorModel(is_sphere=False, surfs=bem) |
| 2316 | elif isinstance(bem, list): |
| 2317 | for ii, this_surf in enumerate(bem): |
| 2318 | _validate_type(this_surf, dict, f"{name}[{ii}]") |
| 2319 | if isinstance(bem, list): |
| 2320 | bem = ConductorModel(is_sphere=False, surfs=bem) |
| 2321 | # add surfaces in the spherical case |
| 2322 | if isinstance(bem, ConductorModel) and bem["is_sphere"]: |
| 2323 | bem = bem.copy() |
| 2324 | bem["surfs"] = [] |
| 2325 | if len(bem["layers"]) == 4: |
| 2326 | for idx, id_ in enumerate(_sm_surf_dict.values()): |
| 2327 | bem["surfs"].append(_complete_sphere_surf(bem, idx, 4, complete=False)) |
| 2328 | bem["surfs"][-1]["id"] = id_ |
| 2329 | |
| 2330 | return bem |
| 2331 | |
| 2332 | |
| 2333 | def _check_file(fname, overwrite): |
no test coverage detected