jams.AnnotationArray
- class jams.AnnotationArray(annotations=None)[source]
Bases:
listThis list subclass provides serialization and search/filtering for annotation collections.
Fancy-indexing can be used to directly search for annotations belonging to a particular namespace. Three types of indexing are supported:
integer or slice : acts just as in list, e.g., arr[0] or arr[1:3]
string : acts like a search, e.g., arr[‘beat’] == arr.search(namespace=’beat’)
(string, integer or slice) acts like a search followed by index/slice
Examples
>>> # Retrieve the first annotation with simple indexing >>> ann = jam.annotations[0]
>>> # Retrieve the first three annotations >>> anns = jam.annotations[:3]
>>> # Retrieve a list of beat annotations >>> # equivalent to jam.search(namespace='beat') >>> beat_anns = jam.annotations['beat']
>>> # Retrieve the second beat annotation >>> # equivalent to jam.search(namespace='beat')[1] >>> beat2 = jam.annotations['beat', 1]
>>> # Retrieve everything after the second salami annotation >>> seg_anns = jam.annotations['segment_salami_.*', 2:]
- __init__(annotations=None)[source]
Create an AnnotationArray.
- Parameters:
- annotationslist
List of Annotations, or appropriately formatted dicts is consistent with Annotation.
Methods
__init__([annotations])Create an AnnotationArray.
append(object, /)Append object to the end of the list.
clear(/)Remove all items from list.
copy(/)Return a shallow copy of the list.
count(value, /)Return number of occurrences of value.
extend(iterable, /)Extend list by appending elements from the iterable.
index(value[, start, stop])Return first index of value.
insert(index, object, /)Insert object before index.
pop([index])Remove and return item at index (default last).
remove(value, /)Remove first occurrence of value.
reverse(/)Reverse IN PLACE.
search(**kwargs)Filter the annotation array down to only those Annotation objects matching the query.
slice(start_time, end_time[, strict])Slice every annotation contained in the annotation array using
Annotation.sliceand return as a new AnnotationArraysort(*[, key, reverse])Sort the list in ascending order and return None.
trim(start_time, end_time[, strict])Trim every annotation contained in the annotation array using
Annotation.trimand return as a newAnnotationArray.- search(**kwargs)[source]
Filter the annotation array down to only those Annotation objects matching the query.
- Parameters:
- **kwargssearch parameters
See JObject.search
- Returns:
- resultsAnnotationArray
An annotation array of the objects matching the query
See also
- slice(start_time, end_time, strict=False)[source]
Slice every annotation contained in the annotation array using
Annotation.sliceand return as a new AnnotationArraySee
Annotation.slicefor details about slicing. This function does not modify the annotations in the original annotation array.- Parameters:
- start_timefloat
The desired start time for slicing in seconds.
- end_time
The desired end time for slicing in seconds. Must be greater than
start_time.- strictbool
When
False(default) observations that lie at the boundaries of the slicing range (seeAnnotation.slicefor details) will have their time and/or duration adjusted such that only the part of the observation that lies within the trim range is kept. WhenTruesuch observations are discarded and not included in the sliced annotation.
- Returns:
- sliced_arrayAnnotationArray
An annotation array where every annotation has been sliced.
- trim(start_time, end_time, strict=False)[source]
Trim every annotation contained in the annotation array using
Annotation.trimand return as a newAnnotationArray.See
Annotation.trimfor details about trimming. This function does not modify the annotations in the original annotation array.- Parameters:
- start_timefloat
The desired start time for the trimmed annotations in seconds.
- end_time
The desired end time for trimmed annotations in seconds. Must be greater than
start_time.- strictbool
When
False(default) observations that lie at the boundaries of the trimming range (seeAnnotation.trimfor details) will have their time and/or duration adjusted such that only the part of the observation that lies within the trim range is kept. WhenTruesuch observations are discarded and not included in the trimmed annotation.
- Returns:
- trimmed_arrayAnnotationArray
An annotation array where every annotation has been trimmed.