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

Method set_annotations

mne/io/base.py:707–764  ·  view source on GitHub ↗

Setter for annotations. This setter checks if they are inside the data range. Parameters ---------- annotations : instance of mne.Annotations | None Annotations to set. If None, the annotations is defined but empty. %(emit_warning)s

(
        self, annotations, emit_warning=True, on_missing="raise", *, verbose=None
    )

Source from the content-addressed store, hash-verified

705
706 @verbose
707 def set_annotations(
708 self, annotations, emit_warning=True, on_missing="raise", *, verbose=None
709 ):
710 """Setter for annotations.
711
712 This setter checks if they are inside the data range.
713
714 Parameters
715 ----------
716 annotations : instance of mne.Annotations | None
717 Annotations to set. If None, the annotations is defined
718 but empty.
719 %(emit_warning)s
720 The default is True.
721 %(on_missing_ch_names)s
722 %(verbose)s
723
724 Returns
725 -------
726 self : instance of Raw
727 The raw object with annotations.
728 """
729 meas_date = _handle_meas_date(self.info["meas_date"])
730 if annotations is None:
731 self._annotations = Annotations([], [], [], meas_date)
732 else:
733 _validate_type(annotations, Annotations, "annotations")
734
735 if meas_date is None and annotations.orig_time is not None:
736 raise RuntimeError(
737 "Ambiguous operation. Setting an Annotation object with known "
738 "``orig_time`` to a raw object which has ``meas_date`` set to None "
739 "is ambiguous. Please, either set a meaningful ``meas_date`` to "
740 "the raw object; or set ``orig_time`` to None in which case the "
741 "annotation onsets would be taken in reference to the first sample "
742 "of the raw object."
743 )
744
745 delta = 1.0 / self.info["sfreq"]
746 new_annotations = annotations.copy()
747 new_annotations._prune_ch_names(self.info, on_missing)
748 if annotations.orig_time is None:
749 new_annotations.crop(
750 0, self.times[-1] + delta, emit_warning=emit_warning
751 )
752 new_annotations.onset += self._first_time
753 else:
754 tmin = meas_date + timedelta(0, self._first_time)
755 tmax = tmin + timedelta(seconds=self.times[-1] + delta)
756 new_annotations.crop(tmin=tmin, tmax=tmax, emit_warning=emit_warning)
757 new_annotations.onset -= (
758 meas_date - new_annotations.orig_time
759 ).total_seconds()
760 new_annotations._orig_time = meas_date
761
762 self._annotations = new_annotations
763
764 return self

Callers 15

__init__Method · 0.95
cropMethod · 0.95
appendMethod · 0.95
__init__Method · 0.45
_concatenate_epochsFunction · 0.45
_raw_annotFunction · 0.45
test_flat_bad_acq_skipFunction · 0.45

Calls 6

_handle_meas_dateFunction · 0.85
AnnotationsClass · 0.85
_validate_typeFunction · 0.85
_prune_ch_namesMethod · 0.80
copyMethod · 0.45
cropMethod · 0.45

Tested by 15

_raw_annotFunction · 0.36
test_flat_bad_acq_skipFunction · 0.36
test_muscle_annotationFunction · 0.36
test_annotate_breaksFunction · 0.36
short_raw_epochsFunction · 0.36
test_annotate_nanFunction · 0.36
test_realignFunction · 0.36
test_find_eogFunction · 0.36