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

Function _get_trans

mne/transforms.py:486–516  ·  view source on GitHub ↗

Get mri_head_t (from=mri, to=head) from mri filename.

(trans, fro="mri", to="head", allow_none=True, *, extra="")

Source from the content-addressed store, hash-verified

484
485
486def _get_trans(trans, fro="mri", to="head", allow_none=True, *, extra=""):
487 """Get mri_head_t (from=mri, to=head) from mri filename."""
488 types = (Transform, "path-like")
489 if allow_none:
490 types += (None,)
491 _validate_type(trans, types, "trans", extra=extra)
492 if _path_like(trans):
493 if trans == "fsaverage":
494 trans = Path(__file__).parent / "data" / "fsaverage" / "fsaverage-trans.fif"
495 trans = Path(trans)
496 if not trans.is_file():
497 raise OSError(f'trans file "{trans}" not found')
498 if trans.suffix in [".fif", ".gz"]:
499 fro_to_t = read_trans(trans)
500 else:
501 # convert "-trans.txt" to "-trans.fif" mri-type equivalent
502 # these are usually actually in to_fro form
503 t = np.genfromtxt(trans)
504 if t.ndim != 2 or t.shape != (4, 4):
505 raise RuntimeError(f'File "{trans}" did not have 4x4 entries')
506 fro_to_t = Transform(to, fro, t)
507 elif isinstance(trans, Transform):
508 fro_to_t = trans
509 trans = "instance of Transform"
510 else:
511 assert trans is None
512 fro_to_t = Transform(fro, to)
513 trans = "identity"
514 # it's usually a head->MRI transform, so we probably need to invert it
515 fro_to_t = _ensure_trans(fro_to_t, fro, to, extra=extra)
516 return fro_to_t, trans
517
518
519def combine_transforms(t_first, t_second, fro, to):

Callers 15

test_nirsport_v2Function · 0.90
test_nirx_15_2_shortFunction · 0.90
test_nirx_15_3_shortFunction · 0.90
test_nirx_15_2Function · 0.90
test_nirx_15_0Function · 0.90
test_set_montage_mghFunction · 0.90
test_helmetFunction · 0.90
test_get_transFunction · 0.90

Calls 5

_validate_typeFunction · 0.85
_path_likeFunction · 0.85
read_transFunction · 0.85
TransformClass · 0.85
_ensure_transFunction · 0.85

Tested by 14

test_nirsport_v2Function · 0.72
test_nirx_15_2_shortFunction · 0.72
test_nirx_15_3_shortFunction · 0.72
test_nirx_15_2Function · 0.72
test_nirx_15_0Function · 0.72
test_set_montage_mghFunction · 0.72
test_helmetFunction · 0.72
test_get_transFunction · 0.72