crowsetta.Sequence#
- class crowsetta.Sequence(segments, labels, onsets_s=None, offsets_s=None, onset_samples=None, offset_samples=None)[source]#
Bases:
object
A class that represents a sequence of segments, used to annotate animal acoustic communication.
E.g., a human sentence made up of syllables, or a bout of birdsong made up of “syllables”.
- segments#
A
tuple
ofcrowsetta.Segment
instances.- Type:
- onset_samples#
Numpy array of type int, onset of each annotated segment in sample number.
- Type:
numpy.ndarray or None
- offset_samples#
Numpy array of type int, offset of each annotated segment in sample number.
- Type:
numpy.ndarray or None
- onsets_s#
Numpy array of type float, onset of each annotated segment in seconds.
- Type:
numpy.ndarray or None
- offsets_s#
Numpy array of type float, offset of each annotated segment in seconds.
- Type:
numpy.ndarray or None
- labels#
Numpy array of type char, label for each annotated segment.
- Type:
str, list, or numpy.ndarray
- from_keyword : method
Make a
Sequence
by passing keywords (all arguments except segments)
- from_dict : method
Like from_keyword, but pass a Python dictionary where keys are keywords and values are arguments for those keywords.
- to_dict : method
Convert to a
dict
. The inverse offrom_dict()
.
Examples
A sequence with onsets and offsets given in seconds.
>>> import numpy as np >>> import crowsetta >>> onsets_s = np.array([1.0, 3.0, 5.0]) >>> offsets_s = np.array(2.0, 4.0, 6.0]) >>> labels = np.array(['a', 'a', 'b']) >>> seq = crowsetta.Sequence.from_keyword(labels=labels, onsets_s=onsets_s, offsets_s=offsets_s)
The same sequence could also be made by calling the
from_segments()
class method.>>> segments = [] >>> for onset, offset, label in zip(onsets_s, offsets_s, labels): ... segments.append(crowsetta.Segment(onset_s=onset, offset_s=offset, label=label)) >>> seq2 = crowsetta.Sequence.from_segments(segments)
- __init__(segments, labels, onsets_s=None, offsets_s=None, onset_samples=None, offset_samples=None)[source]#
Initialize a new
Sequence
instance.- Parameters:
segments (tuple) – A
tuple
ofcrowsetta.Segment
instances.onset_samples (numpy.ndarray or None) – Numpy array of type int, onset of each annotated segment in sample number.
offset_samples (numpy.ndarray or None) – Numpy array of type int, offset of each annotated segment in sample number.
onsets_s (numpy.ndarray or None) – Numpy array of type float, onset of each annotated segment in seconds.
offsets_s (numpy.ndarray or None) – Numpy array of type float, offset of each annotated segment in seconds.
labels (str, list, or numpy.ndarray) – Numpy array of type char, label for each annotated segment.
Methods
__init__
(segments, labels[, onsets_s, ...])Initialize a new
Sequence
instance.as_dict
()Convert this
crowsetta.Sequence
to adict
.from_dict
(seq_dict)Construct a
crowsetta.Sequence
from adict
where keys are arguments tofrom_keyword()
.from_keyword
(labels[, onset_samples, ...])Construct a
crowsetta.Sequence
from keyword argumentsfrom_segments
(segments)Construct a
crowsetta.Sequence
from alist
ofcrowsetta.Segment
objects.Attributes
- as_dict() dict [source]#
Convert this
crowsetta.Sequence
to adict
.- Returns:
seq_dict –
- with the following key, value pairs:
- onset_samplesnumpy.ndarray or None
of type int, onset of each annotated segment in samples/second
- offset_samplesnumpy.ndarray or None
of type int, offset of each annotated segment in samples/second
- onsets_snumpy.ndarray or None
of type float, onset of each annotated segment in seconds
- offsets_snumpy.ndarray or None
of type float, offset of each annotated segment in seconds
- labelsnumpy.ndarray
of type str; label for each annotated segment
- Return type:
- classmethod from_dict(seq_dict)[source]#
Construct a
crowsetta.Sequence
from adict
where keys are arguments tofrom_keyword()
.- Parameters:
seq_dict (dict) –
with following key, value pairs onset_samples : numpy.ndarray or None
of type int, onset of each annotated segment in samples/second
- offset_samplesnumpy.ndarray or None
of type int, offset of each annotated segment in samples/second
- onsets_snumpy.ndarray or None
of type float, onset of each annotated segment in seconds
- offsets_snumpy.ndarray or None
of type float, offset of each annotated segment in seconds
- labelsstr, list, or numpy.ndarray
of type str, label for each annotated segment
offsets (seq_dict must specify both onsets and) –
:param : :param either in units of samples or seconds (or both).:
Examples
>>> seq_dict = { ... 'labels': 'abc', ... 'onset_samples': np.asarray([16005, 17925, 19837]), ... 'offset_samples': np.asarray([17602, 19520, 21435]), ... 'file': 'bird0.wav', ... } >>> seq = Sequence.from_dict(seq_dict)
- classmethod from_keyword(labels, onset_samples=None, offset_samples=None, onsets_s=None, offsets_s=None)[source]#
Construct a
crowsetta.Sequence
from keyword arguments- Parameters:
onset_samples (numpy.ndarray or None) – of type int, onset of each annotated segment in samples/second
offset_samples (numpy.ndarray or None) – of type int, offset of each annotated segment in samples/second
onsets_s (numpy.ndarray or None) – of type float, onset of each annotated segment in seconds
offsets_s (numpy.ndarray or None) – of type float, offset of each annotated segment in seconds
labels (str, list, or numpy.ndarray) – of type str, label for each annotated segment
offsets (Must specify both onsets and) –
:param : :param either in units of Hz or seconds (or both).:
- classmethod from_segments(segments)[source]#
Construct a
crowsetta.Sequence
from alist
ofcrowsetta.Segment
objects.