Read a ``-trans.fif`` file. Parameters ---------- fname : path-like The name of the file. return_all : bool If True, return all transformations in the file. False (default) will only return the first. .. versionadded:: 0.15 %(verbose)s Retur
(fname, return_all=False, verbose=None)
| 570 | |
| 571 | @verbose |
| 572 | def read_trans(fname, return_all=False, verbose=None): |
| 573 | """Read a ``-trans.fif`` file. |
| 574 | |
| 575 | Parameters |
| 576 | ---------- |
| 577 | fname : path-like |
| 578 | The name of the file. |
| 579 | return_all : bool |
| 580 | If True, return all transformations in the file. |
| 581 | False (default) will only return the first. |
| 582 | |
| 583 | .. versionadded:: 0.15 |
| 584 | %(verbose)s |
| 585 | |
| 586 | Returns |
| 587 | ------- |
| 588 | trans : dict | list of dict |
| 589 | The transformation dictionary from the fif file. |
| 590 | |
| 591 | See Also |
| 592 | -------- |
| 593 | write_trans |
| 594 | mne.transforms.Transform |
| 595 | """ |
| 596 | fname = _check_fname(fname, overwrite="read", must_exist=True) |
| 597 | fid, tree, directory = fiff_open(fname) |
| 598 | |
| 599 | trans = list() |
| 600 | with fid: |
| 601 | for t in directory: |
| 602 | if t.kind == FIFF.FIFF_COORD_TRANS: |
| 603 | trans.append(read_tag(fid, t.pos).data) |
| 604 | if not return_all: |
| 605 | break |
| 606 | if len(trans) == 0: |
| 607 | raise OSError("This does not seem to be a -trans.fif file.") |
| 608 | return trans if return_all else trans[0] |
| 609 | |
| 610 | |
| 611 | @verbose |