Save annotations to FIF, CSV or TXT. Typically annotations get saved in the FIF file for raw data (e.g., as ``raw.annotations``), but this offers the possibility to also save them to disk separately in different file formats which are easier to share between packages
(self, fname, *, overwrite=False, verbose=None)
| 689 | |
| 690 | @verbose |
| 691 | def save(self, fname, *, overwrite=False, verbose=None): |
| 692 | """Save annotations to FIF, CSV or TXT. |
| 693 | |
| 694 | Typically annotations get saved in the FIF file for raw data |
| 695 | (e.g., as ``raw.annotations``), but this offers the possibility |
| 696 | to also save them to disk separately in different file formats |
| 697 | which are easier to share between packages. |
| 698 | |
| 699 | Parameters |
| 700 | ---------- |
| 701 | fname : path-like |
| 702 | The filename to use. |
| 703 | %(overwrite)s |
| 704 | |
| 705 | .. versionadded:: 0.23 |
| 706 | %(verbose)s |
| 707 | |
| 708 | Notes |
| 709 | ----- |
| 710 | The format of the information stored in the saved annotation objects |
| 711 | depends on the chosen file format. :file:`.csv` files store the onset |
| 712 | as timestamps (e.g., ``2002-12-03 19:01:56.676071``), |
| 713 | whereas :file:`.txt` files store onset as seconds since start of the |
| 714 | recording (e.g., ``45.95597082905339``). |
| 715 | """ |
| 716 | check_fname( |
| 717 | fname, |
| 718 | "annotations", |
| 719 | ( |
| 720 | "-annot.fif", |
| 721 | "-annot.fif.gz", |
| 722 | "_annot.fif", |
| 723 | "_annot.fif.gz", |
| 724 | ".txt", |
| 725 | ".csv", |
| 726 | ), |
| 727 | ) |
| 728 | fname = _check_fname(fname, overwrite=overwrite) |
| 729 | if fname.suffix == ".txt": |
| 730 | _write_annotations_txt(fname, self) |
| 731 | elif fname.suffix == ".csv": |
| 732 | _write_annotations_csv(fname, self) |
| 733 | else: |
| 734 | with start_and_end_file(fname) as fid: |
| 735 | _write_annotations(fid, self) |
| 736 | |
| 737 | def _sort(self): |
| 738 | """Sort in place.""" |