nnsa.annotations package
Submodules
nnsa.annotations.annotation module
Code related to a single annotation.
Classes:
|
Universal annotation object. |
- class nnsa.annotations.annotation.Annotation(onset, duration, text)[source]
Bases:
objectUniversal annotation object.
- An Annotation object has four properties:
Annotation.onset (int, float): the onset time of the annotation. Annotation.duration (int, float): the duration of the annotation (same unit as onset). Annotation.text (str): the annotation text. Annotation.offset (int, float): the end time of the annotation (onset + duration).
- Parameters:
onset (int, float) – the onset time of the annotation.
duration (int, float) – the duration of the annotation (same unit as onset).
text (str) – the annotation text.
Attributes:
Return the duration of the annotation in seconds.
Return the end time (onset + duration).
Return the onset of the annotation in seconds.
Return the annotation text.
- property duration
Return the duration of the annotation in seconds.
- Returns:
(float) – the duration of the annotation in seconds.
- property offset
Return the end time (onset + duration).
Clips duration such that it cannot be negative. (sometimes, duration could be set to -1 if there is no duration associated with the Annotation, in this case, make the offset the same as the onset by making the duration 0).
- property onset
Return the onset of the annotation in seconds.
- Returns:
(float) – the onset of the annotation in seconds.
- property text
Return the annotation text.
- Returns:
(str) – the annotation text.
nnsa.annotations.annotation_set module
Code related to annotation sets.
Classes:
|
Holds a collection of annotations (e.g. |
- class nnsa.annotations.annotation_set.AnnotationSet(annotations=None, label='annotations')[source]
Bases:
objectHolds a collection of annotations (e.g. all annotations from one file/investigator).
- Parameters:
annotations (iterable, optional) – iterable collection with Annotation objects (e.g. list, generator).
label (str, optional) – a label for this AnnotationSet (e.g. code/name of the observer).
Methods:
add_postfix(postfix[, inplace])Add postfix to all annotations.
add_prefix(prefix[, inplace])Add prefix to all annotations.
append(annotation[, inplace])Safely append an annotation to the annotation set.
clip_overlaps([how, inplace])Clip annotations if they overlap.
compute_nan_durations([total_duration, inplace])Compute duration from inter-annotation interval for annotations with duration np.nan.
count_neighbors(text)Count the number of times a certain text is a neighbour (in time) of a specified text.
Return the durations of all annotations in the set.
end_time()Return the time at which the last annotation ends.
extend(annotations[, inplace])Safely extend the list with annotation with another annotations from an iterable collection.
extract_epoch([begin, end])Extract epoch specified by begin and end.
fill_unlabeled_periods([label_to_insert, ...])Insert Annotation objects into the AnnotationSet to make the annotations continuous.
filter(patterns[, how, case_sensitive, inplace])Filter the annotation by looking for matching patterns in the texts.
filter_fun(fun[, pass_text, inplace])Filter the annotation keeping only annotations that yield True after evaluating fun on them.
from_df(df[, onset, duration, text])Convert a DataFrame to an AnnotationSet.
from_lists(onsets, durations, texts, **kwargs)Convert a DataFrame to an AnnotationSet.
from_mask(mask[, time, label_mapping, label])Convert a mask with arbitrary number of classes to an annotation set.
Return the unqiue annotation texts and their number of occurences (sorted).
get_overlapping_annotations([begin, end, ...])Return a sub set of the annotations with annotations that (partially) overlap with the specified time interval.
get_text_times(texts)Return the start and end times of a specific annotation text.
interpolate_artefacts([artefact_texts, ...])Interpolate artefact segments.
merge_successive_texts([inplace])Merge successive annotations if there texts are the same.
onsets()Return the onsets of all annotations in the set.
Print all annotations at once using a pandas dataframe.
print_annotation(index[, print_header])Print the onset, text and duration of an annotation specified by the index.
remove(patterns[, case_sensitive, inplace])Filter the annotation by looking for matching patterns in the texts.
replace_in_range(replace_with, begin, end[, ...])Replace the texts of annotations that overlap with the given range with the specified text.
replace_text_by_index(indices, new_text[, ...])Replace the text of annotations with index in indices with new_text.
replace_texts(texts, new_text[, inplace])Replace the text of all annotations with of one texts with new_text.
shade_axis([begin, end, labels_mapping, ...])Shade the areas in the current axis corresponding to the annotations.
sleep_stages(**kwargs)Convert the annotations to sleep stages and return the sleep stages as a SleepStagesResult object.
sort([inplace])Sort the annotations based on onset.
standardize_annotations([inplace])Convert the annotations to standard labels and return a new AnnotationSet with the standard labels.
Return the onset time of the first annotation (in seconds).
subtract_offset(offset[, inplace])Alias for self.subtract_time() for backwards compatibility reasons.
subtract_time(dt[, inplace])Subtract a constant amount of time from the onset of each annotation in the annotation set.
texts()Return the texts of all annotations in the set.
Return a DataFrame with the annotations.
to_df()Alias for self.to_dataframe().
Attributes:
Return the list with annotations.
- add_postfix(postfix, inplace=False)[source]
Add postfix to all annotations.
- Parameters:
prefix (str) – string to add after each Annotation’s text.
inplace (bool, optional) – if True, modify the annotation in place. If False, make a copy and modify the copy.
- Returns:
annotation_set (edfreadpy.AnnotationSet) – new AnnotationSet object with the modified annotations (if inplace is False).
- add_prefix(prefix, inplace=False)[source]
Add prefix to all annotations.
- Parameters:
prefix (str) – string to add in front of each Annotation’s text.
inplace (bool, optional) – if True, modify the annotation in place. If False, make a copy and modify the copy.
- Returns:
annotation_set (edfreadpy.AnnotationSet) – new AnnotationSet object with the modified annotations (if inplace is False).
- property annotations
Return the list with annotations.
- Returns:
(list) – list with edfreadpy.Annotation objects.
- append(annotation, inplace=False)[source]
Safely append an annotation to the annotation set.
- Parameters:
annotation (edfreadpy.Annotation) – Annotation object.
inplace (bool, optional) – if True, appends the annotation in place. If False, a new AnnotationSet object with the appended annotation is returned. Defaults to False.
- Returns:
annotation_set (edfreadpy.AnnotationSet) – new AnnotationSet object with the appended annotation (if inplace is False).
- clip_overlaps(how='first', inplace=False)[source]
Clip annotations if they overlap.
- Parameters:
how (str, optional) – specifies which annotation is clipped. Choose from ‘first’, ‘second’. For two overlapping annotations, either the first one can be shortered (‘first’) by decreasing its duration or the second one (‘second’) can be shortened by increasing its onset.
inplace (bool, optional) – if True, clips the annotations in place. If False, a new AnnotationSet object with the clipped annotations is returned. Defaults to False.
- Returns:
as_out (nnsa.AnnotationSet) – AnnotationSet object with clipped annotations (returned only if inplace is False).
- compute_nan_durations(total_duration=None, inplace=False)[source]
Compute duration from inter-annotation interval for annotations with duration np.nan.
- Parameters:
total_duration (float) – total duration of the annotated recording (needed to determine the duration of the last annotation).
inplace (bool, optional) – apply inplcace (True) or return a new object (False). Defaults to False.
- Returns:
annotations (nnsa.AnnotationSet) – new AnnotationSet with Annotations (if inplace is False).
- count_neighbors(text)[source]
Count the number of times a certain text is a neighbour (in time) of a specified text.
Assumes that the annotations are sorted by onset.
- Parameters:
text (str) – annotation text of which the neighbours should be counted.
- Returns:
(pd.DataFrame) – dataframe with counts where the index represents the left neighbour and the column represents the right neighbour
- durations()[source]
Return the durations of all annotations in the set.
- Returns:
(np.ndarray) – the durations (in seconds) of all annotations in the set.
- end_time()[source]
Return the time at which the last annotation ends.
- Returns:
(float) – the time (in seconds) at which the last annotation ends.
- extend(annotations, inplace=False)[source]
Safely extend the list with annotation with another annotations from an iterable collection.
- Parameters:
annotations (collection) – iterable collection with Annotation objects (e.g. list, generator).
inplace (bool, optional) – if True, extends the annotations in place. If False, a new AnnotationSet object extended with the annotations is returned. Defaults to False.
- Returns:
annotation_set (edfreadpy.AnnotationSet) – new AnnotationSet object with the appended annotations (if inplace is False).
- extract_epoch(begin=None, end=None)[source]
Extract epoch specified by begin and end.
- Parameters:
begin (float) – begin time of epoch (seconds).
end (float) – end time of epoch (seconds).
- Returns:
(nnsa.AnnotationSet) – subset of the current AnnotationSet.
- fill_unlabeled_periods(label_to_insert=None, begin=None, end=None, inplace=False)[source]
Insert Annotation objects into the AnnotationSet to make the annotations continuous.
An Annotation with label label_to_insert is inserted between two succesive annotations if they are not continuous, i.e. the start of the second annotation does not coincide with the end of the first one.
- Parameters:
label_to_insert (str, optional) – the text that is used for the Annotations that are inserted in the unlabeled periods. If None, NO_LABEL is used. Defaults to None.
begin (flaot, optional) – begin time of period to fill. Cannot be greater than the first onset. If None, the first annotation in the set marks the beginning. Defaults to None.
end (float, optional) – end time of period to fill. Cannot be smaller than the end time of the last annotation. If None, the last annotation marks the end. Defaults to None.
inplace (bool, optional) – if True, fills the annotations in place. If False, a new AnnotationSet object with the filled annotations is returned. Defaults to False.
- Returns:
annotation_set (nnsa.AnnotationSet) – new AnnotationSet object that has continuous labels (if inplace is False).
- filter(patterns, how='keep', case_sensitive=True, inplace=False)[source]
Filter the annotation by looking for matching patterns in the texts.
- Parameters:
patterns (str or list) – pattern(s) to find matches for.
how (str, optional) –
whether to keep or remove the annotations that match the patterns. Options:
’keep’
’remove’
Defaults to ‘keep’.
case_sensitive (bool, optional) – whether the pattern matching should be case sensitive. Defaults to True.
inplace (bool, optional) – if True, filters the annotations in place. If False, a new AnnotationSet object with the filtered annotations is returned. Defaults to False.
- Returns:
as_out (edfreadpy.AnnotationSet) – new AnnotationSet with a subset of the annotations.
Examples
>>> annot_set = AnnotationSet() >>> annot_set.append(Annotation(onset=10.25, duration=100, text='QS'), inplace=True) >>> annot_set.append(Annotation(110.25, 200, 'AS'), inplace=True) >>> annot_set.append(Annotation(500, 300, 'QS'), inplace=True) >>> annot_set.append(Annotation(800, 10, 'AS'), inplace=True) >>> annot_set.print_all_annotations() onset duration text 0 10.25 100 QS 1 110.25 200 AS 2 500.00 300 QS 3 800.00 10 AS >>> as_new = annot_set.filter('QS', how='keep') >>> as_new.print_all_annotations() onset duration text 0 10.25 100.0 QS 1 500.00 300.0 QS >>> as_new = annot_set.filter('QS', how='remove') >>> as_new.print_all_annotations() onset duration text 0 110.25 200 AS 1 800.00 10 AS
- filter_fun(fun, pass_text=True, inplace=False)[source]
Filter the annotation keeping only annotations that yield True after evaluating fun on them.
- Parameters:
fun (function) – function that takes in a string or Annotation object (depending on pass_text) and returns True or False. Annotations that yield False are removed.
pass_text (bool) – if Ture, the annotation text (str) is passed to fun, otherwise the Annotation object is passed.
inplace (bool, optional) – if True, filters the annotations in place. If False, a new AnnotationSet object with the filtered annotations is returned. Defaults to False.
- Returns:
as_out (edfreadpy.AnnotationSet) – new AnnotationSet with annotations that match the specified pattern (only retruned if inplace is False).
- from_df(df, onset='onset', duration='duration', text='text', **kwargs)[source]
Convert a DataFrame to an AnnotationSet.
- Parameters:
df (pd.DataFrame) – a DataFrame.
onset (str, optional) – column name in df that corresponds to the onset times (in seconds).
duration – (str, optional): column name in df that corresponds to the duration times (in seconds).
text – (str, optional): column name in df that corresponds to the annotation text.
**kwargs (optional) – optional keyword arguments for AnnotationSet().
- Returns:
annotation_set (AnnotationSet) – AnnotationSet.
- from_lists(onsets, durations, texts, **kwargs)[source]
Convert a DataFrame to an AnnotationSet.
- Parameters:
onsets (list, np.ndarray) – list with the onset times (in seconds).
durations (list, np.ndarray) – list with the duration times (in seconds).
texts (list, np.ndarray) – list with the annotation texts.
**kwargs (optional) – optional keyword arguments for AnnotationSet().
- Returns:
annotation_set (AnnotationSet) – AnnotationSet.
- from_mask(mask, time=None, label_mapping=None, label=None)[source]
Convert a mask with arbitrary number of classes to an annotation set.
- Parameters:
mask (np.ndarray) – 1D mask array containing discrete values.
time (np.ndarray) – time array corresponding to starttimes of mask. If None, the onset and durations in the returned AnnotationSet are in samples.
label_mapping (dict, optional) – dictionary mapping a value in the mask to a label (str). Those labels will become the texts in the annotation set. If None, the mask values will be the labels.
label (str, optional) – label for the annotation set. Defaults to None.
- Returns:
annotation_set (AnnotationSet) – annotation set with onsets, durations and texts.
Examples
>>> time = np.arange(10) >>> mask = [0, 0, 1, 1, 1, 0, 0, 2, 2, 2] >>> AnnotationSet().from_mask(time, mask) AnnotationSet with label: "None" and annotations: onset duration text 0 0 2 0 1 2 3 1 2 5 2 0 3 7 3 2 >>> AnnotationSet().from_mask(time, mask, label_mapping={0: 'null', 1: 'one', 2: 'two'}) AnnotationSet with label: "None" and annotations: onset duration text 0 0 2 null 1 2 3 one 2 5 2 null 3 7 3 two
- get_occurrence_count()[source]
Return the unqiue annotation texts and their number of occurences (sorted).
- Returns:
sorted_text_count (dict) – dictionary that maps unique annotations in the annotation set to the frequency/counts of that annotation in the set.
- get_overlapping_annotations(begin=-inf, end=inf, clip=False, start=None)[source]
Return a sub set of the annotations with annotations that (partially) overlap with the specified time interval.
- Parameters:
begin (float) – begin time in seconds of the time interval.
end (float) – end time in seconds of the time interval.
clip (bool) – if True, clips the first and last annotations to the begin and end times. If False, keeps original lengths.
start (flaot) – overrides begin (for backwards compatibility).
- Returns:
(nnsa.AnnotationSet) – subset of the current AnnotationSet.
- get_text_times(texts)[source]
Return the start and end times of a specific annotation text.
- Parameters:
texts (str or list) – annotation text(s) to get the start and end times for.
- Returns:
begin_times (np.ndarray) – begin (onset) times.
end_times (np.ndarray) – end times.
- interpolate_artefacts(artefact_texts=None, max_duration=180, inplace=False)[source]
Interpolate artefact segments.
Replaces an artefact annotation by the surrounding class labels if the artefact annotation is surrounded by equal class labels and if its duration is less than the specified max_duration.
Assumes the annotations are sorted by onset. Ultimately merges equal succesive labels.
- Parameters:
artefact_texts (str or list, optional) – annotation texts indicating artefact segments, can be a single string or a list of strings when multiple texts indicate artefacts. If None, a default set of artefact-related annotation texts are used. Defaults to None.
max_duration (float, optional) – maximum duration (in seconds) that the artefact annotation can have to get replaced. Defaults to 180.
inplace (bool, optional) – if True, replaces the annotations in place. If False, a new AnnotationSet object with the replaced annotations is returned. Defaults to False.
- Returns:
standardized_annotations (nnsa.AnnotationSet) – new AnnotationSet object with potentially less artefact annotations/labels (if inplace is False).
- merge_successive_texts(inplace=False)[source]
Merge successive annotations if there texts are the same.
- Parameters:
inplace (bool, optional) – if True, merges the annotations in place. If False, a new AnnotationSet object with the merged annotations is returned. Defaults to False.
- Returns:
annotation_set (nnsa.AnnotationSet) – new AnnotationSet object with successive labels merged (if inplace is False).
- onsets()[source]
Return the onsets of all annotations in the set.
- Returns:
(np.ndarray) – the onsets (in seconds) of all annotations in the set.
- print_annotation(index, print_header=True)[source]
Print the onset, text and duration of an annotation specified by the index.
- Parameters:
index (int) – the index of the anntation in self.annotations list to print.
print_header (bool, optional) – if True, a header will be printed, if False, not. Defaults to True.
- remove(patterns, case_sensitive=True, inplace=False)[source]
Filter the annotation by looking for matching patterns in the texts.
- Parameters:
patterns (str or list) – pattern(s) to find matches for.
inplace (bool, optional) – if True, removes the annotations in place. If False, a new AnnotationSet object without the removed annotations is returned. Defaults to False.
- Returns:
as_out (edfreadpy.AnnotationSet) – new AnnotationSet without annotations that match the specified pattern (only retruned if inplace is False).
Examples
>>> annot_set = AnnotationSet() >>> annot_set.append(Annotation(onset=10.25, duration=100, text='QS'), inplace=True) >>> annot_set.append(Annotation(110.25, 200, 'AS'), inplace=True) >>> annot_set.append(Annotation(500, 300, 'QS'), inplace=True) >>> annot_set.append(Annotation(800, 10, 'AS'), inplace=True) >>> annot_set.print_all_annotations() onset duration text 0 10.25 100 QS 1 110.25 200 AS 2 500.00 300 QS 3 800.00 10 AS >>> as_new = annot_set.remove('QS') >>> as_new.print_all_annotations() onset duration text 0 110.25 200 AS 1 800.00 10 AS
- replace_in_range(replace_with, begin, end, resize=False, inplace=False)[source]
Replace the texts of annotations that overlap with the given range with the specified text.
Note: by default, replaces the entire annotation in case of any overlap, see resize parameter.
- Parameters:
replace_with (str) – new text for annotations overlapping with the specified range.
begin (float) – begin of range.
end (float) – end of range.
resize (bool, optional) – if True, the annotations that partially overlap are resized so that they fit. If False, all annotations with any overlap are removed completely.
inplace (bool, optional) – if True, replace the annotations in place. If False, a new AnnotationSet object with the new annotations is returned. Defaults to False.
- Returns:
as_out (nnsa.AnnotationSet) – new object where all annotations that overlap with the range are replaced seconds (if inplace is False).
Examples
>>> ans = AnnotationSet([Annotation(0, 20, '1'), Annotation(20, 50, '2'), Annotation(100, 110, '3')]) >>> ans.replace_in_range('NaN', begin=0, end=10) AnnotationSet with label: "annotations" and annotations: onset duration text 0 0 20 NaN 1 20 50 2 2 100 110 3 >>> ans.replace_in_range('NaN', begin=0, end=10, resize=True) AnnotationSet with label: "annotations" and annotations: onset duration text 0 0 0 1 1 0 10 NaN 2 10 10 1 3 20 50 2 4 100 110 3 >>> ans.replace_in_range('NaN', begin=0, end=30) AnnotationSet with label: "annotations" and annotations: onset duration text 0 0 20 NaN 1 20 50 NaN 2 100 110 3 >>> ans.replace_in_range('NaN', begin=0, end=30, resize=True) AnnotationSet with label: "annotations" and annotations: onset duration text 0 0 0 1 1 0 30 NaN 2 30 50 2 3 100 110 3 >>> ans.replace_in_range('NaN', begin=60, end=70) AnnotationSet with label: "annotations" and annotations: onset duration text 0 0 20 1 1 20 50 NaN 2 100 110 3 >>> ans.replace_in_range('NaN', begin=60, end=70, resize=True) AnnotationSet with label: "annotations" and annotations: onset duration text 0 0 20 1 1 20 40 2 2 60 10 NaN 3 70 0 2 4 100 110 3
- replace_text_by_index(indices, new_text, inplace=False)[source]
Replace the text of annotations with index in indices with new_text.
- Parameters:
indices (list) – list with sorted indices that correspond to the to be replaced annotations in the annotations list.
new_text (str) – new text for the annotations that are to be replaced.
inplace (bool, optional) – if True, replaces the annotation texts in place. If False, a new AnnotationSet object with the replaced annotation texts is returned. Defaults to False.
- Returns:
replaced_annotations (nnsa.AnnotationSet) – new AnnotationSet object with the replaced annotation texts (if inplace is False).
- replace_texts(texts, new_text, inplace=False)[source]
Replace the text of all annotations with of one texts with new_text.
- Parameters:
texts (str or list) – text of annotation to replace or a list of text to replace.
new_text (str) – new text for the annotations that are to be replaced.
inplace (bool, optional) – if True, replaces the annotation texts in place. If False, a new AnnotationSet object with the replaced annotation texts is returned. Defaults to False.
- Returns:
replaced_annotations (nnsa.AnnotationSet) – new AnnotationSet object with the replaced annotation texts (if inplace is False).
- shade_axis(begin=None, end=None, labels_mapping=None, time_scale='seconds', **kwargs)[source]
Shade the areas in the current axis corresponding to the annotations.
- Parameters:
begin (float, optional) – begin time (in same units as time_scale) to start shading. If None, the time of the first annotation is used. Defaults to None.
end (float, optional) – end time (in same units as time_scale) to end shading. If None, the end time of the last annotation is used. Defaults to None.
labels_mapping (dict) – a dictionary mapping each to be included annotation text to a color. If None, all unique annotations will be assigned a unique color. Defaults to None.
time_scale (str, optional) – the time scale to use. Choose from ‘seconds’, ‘minutes’, ‘hours’. Defaults to ‘seconds’.
**kwargs (optional) – optional keyword arguments for shade_axis().
- sleep_stages(**kwargs)[source]
Convert the annotations to sleep stages and return the sleep stages as a SleepStagesResult object.
This is a wrapper that prepares the input for SleepStages.sleep_stages() and returns the result.
- Parameters:
**kwargs (optional) – optional keyword arguments to overrule default parameters of the SleepStages class.
- Returns:
result (nnsa.SleepStagesResult) – SleepStagesResult object containing annotations related to sleep stages.
- sort(inplace=False)[source]
Sort the annotations based on onset.
- Parameters:
inplace (bool, optional) – if True, sorts the annotations in place. If False, a new AnnotationSet object with the sorted annotations is returned. Defaults to False.
- Returns:
sorted_annotations (edfreadpy.AnnotationSet) – new AnnotationSet object with the sorted annotations (if inplace is False).
- standardize_annotations(inplace=False)[source]
Convert the annotations to standard labels and return a new AnnotationSet with the standard labels.
- Parameters:
inplace (bool, optional) – if True, standardizes the annotations in place. If False, a new AnnotationSet object with the standardized annotations is returned. Defaults to False.
- Returns:
standardized_annotations (nnsa.AnnotationSet) – new AnnotationSet object with standard annotations/labels (if inplace is False).
- start_time()[source]
Return the onset time of the first annotation (in seconds).
- Returns:
(float) – onset time of first annotation (in seconds).
- subtract_offset(offset, inplace=False)[source]
Alias for self.subtract_time() for backwards compatibility reasons.
- subtract_time(dt, inplace=False)[source]
Subtract a constant amount of time from the onset of each annotation in the annotation set.
May be used to perfectly align the annotations with the recorded signals, in case the recording of the signals did not start at the exact (whole) second defined as the starttime the fileheader. In EDF+ files, the EDF Annotation channel contains the (fractional) onset of each datarecord w.r.t. the starttime defined in the file header.
- Parameters:
dt (float) – the amount of time to subtract from the annotation onsets (in seconds).
inplace (bool, optional) – if True, subtracts the offset from the annotations in place. If False, a new AnnotationSet object with the edited annotations is returned. Defaults to False.
- Returns:
annotation_set (edfreadpy.AnnotationSet) – new AnnotationSet object with the edited annotations (if inplace is False).
- texts()[source]
Return the texts of all annotations in the set.
- Returns:
(np.ndarray) – the texts of all annotations in the set.
nnsa.annotations.config module
Constants related to sleep stages.
nnsa.annotations.sleep_stages module
Code related to handling annotations containing sleep stages.
Functions:
|
Convert a standard annotation text to a sleep stage label. |
|
Remove redundant text and whitespace from a raw annotation text. |
|
Convert an annotation text to a standard annotation (one of STANDARD_ANNOTATIONS). |
- nnsa.annotations.sleep_stages.annotation_to_label(text, class_labels, include_labels_with_artefacts=True)[source]
Convert a standard annotation text to a sleep stage label.
To control the type of classes for classification of text, see the class_labels argument.
LABEL_ANNOTATIONS_MAPPING maps standard annotation texts to a standard label. This function finds the (standard) sleep label in class_labels which matches the standard annotation in text. If the text matches with multiple labels, the first label it matches with is returned. Texts that can not be labeled as any of the specified labels are labeled as no_label.
- Parameters:
text (str) – standard annotation text to convert to a label, see STANDARD_ANNOTATIONS.
class_labels (list) – a list with labels for the classification of text, see SLEEP_LABELS and LABEL_ANNOTATIONS_MAPPING.
include_labels_with_artefacts (bool) – if True, texts with a sleep label and indicating an artefact are included. If False, any text indicating an artefact is excluded. Defaults to True.
- Returns:
label (str) – the label corresponding to text (one of the specified labels or NL (no_label)).
- nnsa.annotations.sleep_stages.clean_up_text(text)[source]
Remove redundant text and whitespace from a raw annotation text.
- Parameters:
text (str) – annotation text.
- Returns:
clean_text (str) – cleaned up annotation text.
- nnsa.annotations.sleep_stages.standardize_annotation(text)[source]
Convert an annotation text to a standard annotation (one of STANDARD_ANNOTATIONS).
- Parameters:
text (str) – annotation text to convert.
- Returns:
std_text (str) – standard annotation corresponding to the annotation text.
- Raises:
NotImplementedError – if the annotation text cannot be automatically recognized.
Module contents
Code related to analyzing and working with text annotations that have a specific onset time and duration. The classes in this package are for example used to read annotations from an EDF+ file and may be useful for processing sleep stage annotations.
Classes:
|
Universal annotation object. |
|
Holds a collection of annotations (e.g. |
- class nnsa.annotations.Annotation(onset, duration, text)[source]
Bases:
objectUniversal annotation object.
- An Annotation object has four properties:
Annotation.onset (int, float): the onset time of the annotation. Annotation.duration (int, float): the duration of the annotation (same unit as onset). Annotation.text (str): the annotation text. Annotation.offset (int, float): the end time of the annotation (onset + duration).
- Parameters:
onset (int, float) – the onset time of the annotation.
duration (int, float) – the duration of the annotation (same unit as onset).
text (str) – the annotation text.
Attributes:
Return the duration of the annotation in seconds.
Return the end time (onset + duration).
Return the onset of the annotation in seconds.
Return the annotation text.
- property duration
Return the duration of the annotation in seconds.
- Returns:
(float) – the duration of the annotation in seconds.
- property offset
Return the end time (onset + duration).
Clips duration such that it cannot be negative. (sometimes, duration could be set to -1 if there is no duration associated with the Annotation, in this case, make the offset the same as the onset by making the duration 0).
- property onset
Return the onset of the annotation in seconds.
- Returns:
(float) – the onset of the annotation in seconds.
- property text
Return the annotation text.
- Returns:
(str) – the annotation text.
- class nnsa.annotations.AnnotationSet(annotations=None, label='annotations')[source]
Bases:
objectHolds a collection of annotations (e.g. all annotations from one file/investigator).
- Parameters:
annotations (iterable, optional) – iterable collection with Annotation objects (e.g. list, generator).
label (str, optional) – a label for this AnnotationSet (e.g. code/name of the observer).
Methods:
add_postfix(postfix[, inplace])Add postfix to all annotations.
add_prefix(prefix[, inplace])Add prefix to all annotations.
append(annotation[, inplace])Safely append an annotation to the annotation set.
clip_overlaps([how, inplace])Clip annotations if they overlap.
compute_nan_durations([total_duration, inplace])Compute duration from inter-annotation interval for annotations with duration np.nan.
count_neighbors(text)Count the number of times a certain text is a neighbour (in time) of a specified text.
Return the durations of all annotations in the set.
end_time()Return the time at which the last annotation ends.
extend(annotations[, inplace])Safely extend the list with annotation with another annotations from an iterable collection.
extract_epoch([begin, end])Extract epoch specified by begin and end.
fill_unlabeled_periods([label_to_insert, ...])Insert Annotation objects into the AnnotationSet to make the annotations continuous.
filter(patterns[, how, case_sensitive, inplace])Filter the annotation by looking for matching patterns in the texts.
filter_fun(fun[, pass_text, inplace])Filter the annotation keeping only annotations that yield True after evaluating fun on them.
from_df(df[, onset, duration, text])Convert a DataFrame to an AnnotationSet.
from_lists(onsets, durations, texts, **kwargs)Convert a DataFrame to an AnnotationSet.
from_mask(mask[, time, label_mapping, label])Convert a mask with arbitrary number of classes to an annotation set.
Return the unqiue annotation texts and their number of occurences (sorted).
get_overlapping_annotations([begin, end, ...])Return a sub set of the annotations with annotations that (partially) overlap with the specified time interval.
get_text_times(texts)Return the start and end times of a specific annotation text.
interpolate_artefacts([artefact_texts, ...])Interpolate artefact segments.
merge_successive_texts([inplace])Merge successive annotations if there texts are the same.
onsets()Return the onsets of all annotations in the set.
Print all annotations at once using a pandas dataframe.
print_annotation(index[, print_header])Print the onset, text and duration of an annotation specified by the index.
remove(patterns[, case_sensitive, inplace])Filter the annotation by looking for matching patterns in the texts.
replace_in_range(replace_with, begin, end[, ...])Replace the texts of annotations that overlap with the given range with the specified text.
replace_text_by_index(indices, new_text[, ...])Replace the text of annotations with index in indices with new_text.
replace_texts(texts, new_text[, inplace])Replace the text of all annotations with of one texts with new_text.
shade_axis([begin, end, labels_mapping, ...])Shade the areas in the current axis corresponding to the annotations.
sleep_stages(**kwargs)Convert the annotations to sleep stages and return the sleep stages as a SleepStagesResult object.
sort([inplace])Sort the annotations based on onset.
standardize_annotations([inplace])Convert the annotations to standard labels and return a new AnnotationSet with the standard labels.
Return the onset time of the first annotation (in seconds).
subtract_offset(offset[, inplace])Alias for self.subtract_time() for backwards compatibility reasons.
subtract_time(dt[, inplace])Subtract a constant amount of time from the onset of each annotation in the annotation set.
texts()Return the texts of all annotations in the set.
Return a DataFrame with the annotations.
to_df()Alias for self.to_dataframe().
Attributes:
Return the list with annotations.
- add_postfix(postfix, inplace=False)[source]
Add postfix to all annotations.
- Parameters:
prefix (str) – string to add after each Annotation’s text.
inplace (bool, optional) – if True, modify the annotation in place. If False, make a copy and modify the copy.
- Returns:
annotation_set (edfreadpy.AnnotationSet) – new AnnotationSet object with the modified annotations (if inplace is False).
- add_prefix(prefix, inplace=False)[source]
Add prefix to all annotations.
- Parameters:
prefix (str) – string to add in front of each Annotation’s text.
inplace (bool, optional) – if True, modify the annotation in place. If False, make a copy and modify the copy.
- Returns:
annotation_set (edfreadpy.AnnotationSet) – new AnnotationSet object with the modified annotations (if inplace is False).
- property annotations
Return the list with annotations.
- Returns:
(list) – list with edfreadpy.Annotation objects.
- append(annotation, inplace=False)[source]
Safely append an annotation to the annotation set.
- Parameters:
annotation (edfreadpy.Annotation) – Annotation object.
inplace (bool, optional) – if True, appends the annotation in place. If False, a new AnnotationSet object with the appended annotation is returned. Defaults to False.
- Returns:
annotation_set (edfreadpy.AnnotationSet) – new AnnotationSet object with the appended annotation (if inplace is False).
- clip_overlaps(how='first', inplace=False)[source]
Clip annotations if they overlap.
- Parameters:
how (str, optional) – specifies which annotation is clipped. Choose from ‘first’, ‘second’. For two overlapping annotations, either the first one can be shortered (‘first’) by decreasing its duration or the second one (‘second’) can be shortened by increasing its onset.
inplace (bool, optional) – if True, clips the annotations in place. If False, a new AnnotationSet object with the clipped annotations is returned. Defaults to False.
- Returns:
as_out (nnsa.AnnotationSet) – AnnotationSet object with clipped annotations (returned only if inplace is False).
- compute_nan_durations(total_duration=None, inplace=False)[source]
Compute duration from inter-annotation interval for annotations with duration np.nan.
- Parameters:
total_duration (float) – total duration of the annotated recording (needed to determine the duration of the last annotation).
inplace (bool, optional) – apply inplcace (True) or return a new object (False). Defaults to False.
- Returns:
annotations (nnsa.AnnotationSet) – new AnnotationSet with Annotations (if inplace is False).
- count_neighbors(text)[source]
Count the number of times a certain text is a neighbour (in time) of a specified text.
Assumes that the annotations are sorted by onset.
- Parameters:
text (str) – annotation text of which the neighbours should be counted.
- Returns:
(pd.DataFrame) – dataframe with counts where the index represents the left neighbour and the column represents the right neighbour
- durations()[source]
Return the durations of all annotations in the set.
- Returns:
(np.ndarray) – the durations (in seconds) of all annotations in the set.
- end_time()[source]
Return the time at which the last annotation ends.
- Returns:
(float) – the time (in seconds) at which the last annotation ends.
- extend(annotations, inplace=False)[source]
Safely extend the list with annotation with another annotations from an iterable collection.
- Parameters:
annotations (collection) – iterable collection with Annotation objects (e.g. list, generator).
inplace (bool, optional) – if True, extends the annotations in place. If False, a new AnnotationSet object extended with the annotations is returned. Defaults to False.
- Returns:
annotation_set (edfreadpy.AnnotationSet) – new AnnotationSet object with the appended annotations (if inplace is False).
- extract_epoch(begin=None, end=None)[source]
Extract epoch specified by begin and end.
- Parameters:
begin (float) – begin time of epoch (seconds).
end (float) – end time of epoch (seconds).
- Returns:
(nnsa.AnnotationSet) – subset of the current AnnotationSet.
- fill_unlabeled_periods(label_to_insert=None, begin=None, end=None, inplace=False)[source]
Insert Annotation objects into the AnnotationSet to make the annotations continuous.
An Annotation with label label_to_insert is inserted between two succesive annotations if they are not continuous, i.e. the start of the second annotation does not coincide with the end of the first one.
- Parameters:
label_to_insert (str, optional) – the text that is used for the Annotations that are inserted in the unlabeled periods. If None, NO_LABEL is used. Defaults to None.
begin (flaot, optional) – begin time of period to fill. Cannot be greater than the first onset. If None, the first annotation in the set marks the beginning. Defaults to None.
end (float, optional) – end time of period to fill. Cannot be smaller than the end time of the last annotation. If None, the last annotation marks the end. Defaults to None.
inplace (bool, optional) – if True, fills the annotations in place. If False, a new AnnotationSet object with the filled annotations is returned. Defaults to False.
- Returns:
annotation_set (nnsa.AnnotationSet) – new AnnotationSet object that has continuous labels (if inplace is False).
- filter(patterns, how='keep', case_sensitive=True, inplace=False)[source]
Filter the annotation by looking for matching patterns in the texts.
- Parameters:
patterns (str or list) – pattern(s) to find matches for.
how (str, optional) –
whether to keep or remove the annotations that match the patterns. Options:
’keep’
’remove’
Defaults to ‘keep’.
case_sensitive (bool, optional) – whether the pattern matching should be case sensitive. Defaults to True.
inplace (bool, optional) – if True, filters the annotations in place. If False, a new AnnotationSet object with the filtered annotations is returned. Defaults to False.
- Returns:
as_out (edfreadpy.AnnotationSet) – new AnnotationSet with a subset of the annotations.
Examples
>>> annot_set = AnnotationSet() >>> annot_set.append(Annotation(onset=10.25, duration=100, text='QS'), inplace=True) >>> annot_set.append(Annotation(110.25, 200, 'AS'), inplace=True) >>> annot_set.append(Annotation(500, 300, 'QS'), inplace=True) >>> annot_set.append(Annotation(800, 10, 'AS'), inplace=True) >>> annot_set.print_all_annotations() onset duration text 0 10.25 100 QS 1 110.25 200 AS 2 500.00 300 QS 3 800.00 10 AS >>> as_new = annot_set.filter('QS', how='keep') >>> as_new.print_all_annotations() onset duration text 0 10.25 100.0 QS 1 500.00 300.0 QS >>> as_new = annot_set.filter('QS', how='remove') >>> as_new.print_all_annotations() onset duration text 0 110.25 200 AS 1 800.00 10 AS
- filter_fun(fun, pass_text=True, inplace=False)[source]
Filter the annotation keeping only annotations that yield True after evaluating fun on them.
- Parameters:
fun (function) – function that takes in a string or Annotation object (depending on pass_text) and returns True or False. Annotations that yield False are removed.
pass_text (bool) – if Ture, the annotation text (str) is passed to fun, otherwise the Annotation object is passed.
inplace (bool, optional) – if True, filters the annotations in place. If False, a new AnnotationSet object with the filtered annotations is returned. Defaults to False.
- Returns:
as_out (edfreadpy.AnnotationSet) – new AnnotationSet with annotations that match the specified pattern (only retruned if inplace is False).
- from_df(df, onset='onset', duration='duration', text='text', **kwargs)[source]
Convert a DataFrame to an AnnotationSet.
- Parameters:
df (pd.DataFrame) – a DataFrame.
onset (str, optional) – column name in df that corresponds to the onset times (in seconds).
duration – (str, optional): column name in df that corresponds to the duration times (in seconds).
text – (str, optional): column name in df that corresponds to the annotation text.
**kwargs (optional) – optional keyword arguments for AnnotationSet().
- Returns:
annotation_set (AnnotationSet) – AnnotationSet.
- from_lists(onsets, durations, texts, **kwargs)[source]
Convert a DataFrame to an AnnotationSet.
- Parameters:
onsets (list, np.ndarray) – list with the onset times (in seconds).
durations (list, np.ndarray) – list with the duration times (in seconds).
texts (list, np.ndarray) – list with the annotation texts.
**kwargs (optional) – optional keyword arguments for AnnotationSet().
- Returns:
annotation_set (AnnotationSet) – AnnotationSet.
- from_mask(mask, time=None, label_mapping=None, label=None)[source]
Convert a mask with arbitrary number of classes to an annotation set.
- Parameters:
mask (np.ndarray) – 1D mask array containing discrete values.
time (np.ndarray) – time array corresponding to starttimes of mask. If None, the onset and durations in the returned AnnotationSet are in samples.
label_mapping (dict, optional) – dictionary mapping a value in the mask to a label (str). Those labels will become the texts in the annotation set. If None, the mask values will be the labels.
label (str, optional) – label for the annotation set. Defaults to None.
- Returns:
annotation_set (AnnotationSet) – annotation set with onsets, durations and texts.
Examples
>>> time = np.arange(10) >>> mask = [0, 0, 1, 1, 1, 0, 0, 2, 2, 2] >>> AnnotationSet().from_mask(time, mask) AnnotationSet with label: "None" and annotations: onset duration text 0 0 2 0 1 2 3 1 2 5 2 0 3 7 3 2 >>> AnnotationSet().from_mask(time, mask, label_mapping={0: 'null', 1: 'one', 2: 'two'}) AnnotationSet with label: "None" and annotations: onset duration text 0 0 2 null 1 2 3 one 2 5 2 null 3 7 3 two
- get_occurrence_count()[source]
Return the unqiue annotation texts and their number of occurences (sorted).
- Returns:
sorted_text_count (dict) – dictionary that maps unique annotations in the annotation set to the frequency/counts of that annotation in the set.
- get_overlapping_annotations(begin=-inf, end=inf, clip=False, start=None)[source]
Return a sub set of the annotations with annotations that (partially) overlap with the specified time interval.
- Parameters:
begin (float) – begin time in seconds of the time interval.
end (float) – end time in seconds of the time interval.
clip (bool) – if True, clips the first and last annotations to the begin and end times. If False, keeps original lengths.
start (flaot) – overrides begin (for backwards compatibility).
- Returns:
(nnsa.AnnotationSet) – subset of the current AnnotationSet.
- get_text_times(texts)[source]
Return the start and end times of a specific annotation text.
- Parameters:
texts (str or list) – annotation text(s) to get the start and end times for.
- Returns:
begin_times (np.ndarray) – begin (onset) times.
end_times (np.ndarray) – end times.
- interpolate_artefacts(artefact_texts=None, max_duration=180, inplace=False)[source]
Interpolate artefact segments.
Replaces an artefact annotation by the surrounding class labels if the artefact annotation is surrounded by equal class labels and if its duration is less than the specified max_duration.
Assumes the annotations are sorted by onset. Ultimately merges equal succesive labels.
- Parameters:
artefact_texts (str or list, optional) – annotation texts indicating artefact segments, can be a single string or a list of strings when multiple texts indicate artefacts. If None, a default set of artefact-related annotation texts are used. Defaults to None.
max_duration (float, optional) – maximum duration (in seconds) that the artefact annotation can have to get replaced. Defaults to 180.
inplace (bool, optional) – if True, replaces the annotations in place. If False, a new AnnotationSet object with the replaced annotations is returned. Defaults to False.
- Returns:
standardized_annotations (nnsa.AnnotationSet) – new AnnotationSet object with potentially less artefact annotations/labels (if inplace is False).
- merge_successive_texts(inplace=False)[source]
Merge successive annotations if there texts are the same.
- Parameters:
inplace (bool, optional) – if True, merges the annotations in place. If False, a new AnnotationSet object with the merged annotations is returned. Defaults to False.
- Returns:
annotation_set (nnsa.AnnotationSet) – new AnnotationSet object with successive labels merged (if inplace is False).
- onsets()[source]
Return the onsets of all annotations in the set.
- Returns:
(np.ndarray) – the onsets (in seconds) of all annotations in the set.
- print_annotation(index, print_header=True)[source]
Print the onset, text and duration of an annotation specified by the index.
- Parameters:
index (int) – the index of the anntation in self.annotations list to print.
print_header (bool, optional) – if True, a header will be printed, if False, not. Defaults to True.
- remove(patterns, case_sensitive=True, inplace=False)[source]
Filter the annotation by looking for matching patterns in the texts.
- Parameters:
patterns (str or list) – pattern(s) to find matches for.
inplace (bool, optional) – if True, removes the annotations in place. If False, a new AnnotationSet object without the removed annotations is returned. Defaults to False.
- Returns:
as_out (edfreadpy.AnnotationSet) – new AnnotationSet without annotations that match the specified pattern (only retruned if inplace is False).
Examples
>>> annot_set = AnnotationSet() >>> annot_set.append(Annotation(onset=10.25, duration=100, text='QS'), inplace=True) >>> annot_set.append(Annotation(110.25, 200, 'AS'), inplace=True) >>> annot_set.append(Annotation(500, 300, 'QS'), inplace=True) >>> annot_set.append(Annotation(800, 10, 'AS'), inplace=True) >>> annot_set.print_all_annotations() onset duration text 0 10.25 100 QS 1 110.25 200 AS 2 500.00 300 QS 3 800.00 10 AS >>> as_new = annot_set.remove('QS') >>> as_new.print_all_annotations() onset duration text 0 110.25 200 AS 1 800.00 10 AS
- replace_in_range(replace_with, begin, end, resize=False, inplace=False)[source]
Replace the texts of annotations that overlap with the given range with the specified text.
Note: by default, replaces the entire annotation in case of any overlap, see resize parameter.
- Parameters:
replace_with (str) – new text for annotations overlapping with the specified range.
begin (float) – begin of range.
end (float) – end of range.
resize (bool, optional) – if True, the annotations that partially overlap are resized so that they fit. If False, all annotations with any overlap are removed completely.
inplace (bool, optional) – if True, replace the annotations in place. If False, a new AnnotationSet object with the new annotations is returned. Defaults to False.
- Returns:
as_out (nnsa.AnnotationSet) – new object where all annotations that overlap with the range are replaced seconds (if inplace is False).
Examples
>>> ans = AnnotationSet([Annotation(0, 20, '1'), Annotation(20, 50, '2'), Annotation(100, 110, '3')]) >>> ans.replace_in_range('NaN', begin=0, end=10) AnnotationSet with label: "annotations" and annotations: onset duration text 0 0 20 NaN 1 20 50 2 2 100 110 3 >>> ans.replace_in_range('NaN', begin=0, end=10, resize=True) AnnotationSet with label: "annotations" and annotations: onset duration text 0 0 0 1 1 0 10 NaN 2 10 10 1 3 20 50 2 4 100 110 3 >>> ans.replace_in_range('NaN', begin=0, end=30) AnnotationSet with label: "annotations" and annotations: onset duration text 0 0 20 NaN 1 20 50 NaN 2 100 110 3 >>> ans.replace_in_range('NaN', begin=0, end=30, resize=True) AnnotationSet with label: "annotations" and annotations: onset duration text 0 0 0 1 1 0 30 NaN 2 30 50 2 3 100 110 3 >>> ans.replace_in_range('NaN', begin=60, end=70) AnnotationSet with label: "annotations" and annotations: onset duration text 0 0 20 1 1 20 50 NaN 2 100 110 3 >>> ans.replace_in_range('NaN', begin=60, end=70, resize=True) AnnotationSet with label: "annotations" and annotations: onset duration text 0 0 20 1 1 20 40 2 2 60 10 NaN 3 70 0 2 4 100 110 3
- replace_text_by_index(indices, new_text, inplace=False)[source]
Replace the text of annotations with index in indices with new_text.
- Parameters:
indices (list) – list with sorted indices that correspond to the to be replaced annotations in the annotations list.
new_text (str) – new text for the annotations that are to be replaced.
inplace (bool, optional) – if True, replaces the annotation texts in place. If False, a new AnnotationSet object with the replaced annotation texts is returned. Defaults to False.
- Returns:
replaced_annotations (nnsa.AnnotationSet) – new AnnotationSet object with the replaced annotation texts (if inplace is False).
- replace_texts(texts, new_text, inplace=False)[source]
Replace the text of all annotations with of one texts with new_text.
- Parameters:
texts (str or list) – text of annotation to replace or a list of text to replace.
new_text (str) – new text for the annotations that are to be replaced.
inplace (bool, optional) – if True, replaces the annotation texts in place. If False, a new AnnotationSet object with the replaced annotation texts is returned. Defaults to False.
- Returns:
replaced_annotations (nnsa.AnnotationSet) – new AnnotationSet object with the replaced annotation texts (if inplace is False).
- shade_axis(begin=None, end=None, labels_mapping=None, time_scale='seconds', **kwargs)[source]
Shade the areas in the current axis corresponding to the annotations.
- Parameters:
begin (float, optional) – begin time (in same units as time_scale) to start shading. If None, the time of the first annotation is used. Defaults to None.
end (float, optional) – end time (in same units as time_scale) to end shading. If None, the end time of the last annotation is used. Defaults to None.
labels_mapping (dict) – a dictionary mapping each to be included annotation text to a color. If None, all unique annotations will be assigned a unique color. Defaults to None.
time_scale (str, optional) – the time scale to use. Choose from ‘seconds’, ‘minutes’, ‘hours’. Defaults to ‘seconds’.
**kwargs (optional) – optional keyword arguments for shade_axis().
- sleep_stages(**kwargs)[source]
Convert the annotations to sleep stages and return the sleep stages as a SleepStagesResult object.
This is a wrapper that prepares the input for SleepStages.sleep_stages() and returns the result.
- Parameters:
**kwargs (optional) – optional keyword arguments to overrule default parameters of the SleepStages class.
- Returns:
result (nnsa.SleepStagesResult) – SleepStagesResult object containing annotations related to sleep stages.
- sort(inplace=False)[source]
Sort the annotations based on onset.
- Parameters:
inplace (bool, optional) – if True, sorts the annotations in place. If False, a new AnnotationSet object with the sorted annotations is returned. Defaults to False.
- Returns:
sorted_annotations (edfreadpy.AnnotationSet) – new AnnotationSet object with the sorted annotations (if inplace is False).
- standardize_annotations(inplace=False)[source]
Convert the annotations to standard labels and return a new AnnotationSet with the standard labels.
- Parameters:
inplace (bool, optional) – if True, standardizes the annotations in place. If False, a new AnnotationSet object with the standardized annotations is returned. Defaults to False.
- Returns:
standardized_annotations (nnsa.AnnotationSet) – new AnnotationSet object with standard annotations/labels (if inplace is False).
- start_time()[source]
Return the onset time of the first annotation (in seconds).
- Returns:
(float) – onset time of first annotation (in seconds).
- subtract_offset(offset, inplace=False)[source]
Alias for self.subtract_time() for backwards compatibility reasons.
- subtract_time(dt, inplace=False)[source]
Subtract a constant amount of time from the onset of each annotation in the annotation set.
May be used to perfectly align the annotations with the recorded signals, in case the recording of the signals did not start at the exact (whole) second defined as the starttime the fileheader. In EDF+ files, the EDF Annotation channel contains the (fractional) onset of each datarecord w.r.t. the starttime defined in the file header.
- Parameters:
dt (float) – the amount of time to subtract from the annotation onsets (in seconds).
inplace (bool, optional) – if True, subtracts the offset from the annotations in place. If False, a new AnnotationSet object with the edited annotations is returned. Defaults to False.
- Returns:
annotation_set (edfreadpy.AnnotationSet) – new AnnotationSet object with the edited annotations (if inplace is False).
- texts()[source]
Return the texts of all annotations in the set.
- Returns:
(np.ndarray) – the texts of all annotations in the set.