crowsetta.Segment#

class crowsetta.Segment(label, onset_s=None, offset_s=None, onset_sample=None, offset_sample=None)[source]#

Bases: object

A class that represents a segment of a time series, used to annotate animal communication.

Typically, a single unit such as a syllable in human speech or a “syllable” in birdsong.

label#

The string label for the segment.

Type:

str

onset_s#

The onset time of the segment, in seconds.

Type:

float, optional

offset_s#

The offset time of the segment, in seconds.

Type:

float, optional

onset_sample#

The onset time of the segment, in samples (i.e., the index of the onset in the audio).

Type:

float, optional

offset_sample#

The offset time of the segment, in samples (i.e., the index of the offset in the audio).

Type:

float, optional

Notes

At least one of (onset_s, offset_s) or (onset_sample, offset_sample) must be specified. Both can be specified, but no validation is done by this class to make sure the time in seconds matches the sample number (since this would require the sampling frequency).

Examples

A segment with onset and offset given in seconds.

>>> from crowsetta import Segment
>>> Segment(label='a', onset_s=1.0, offset_s=2.0)
Segment(label='a', onset_s=1.0, offset_s=2.0, onset_sample=None, offset_sample=None)

A segment with onset and offset given in sample number.

>>> Segment(label=1, onset_sample=32000, offset_sample=64000)
Segment(label='1', onset_s=None, offset_s=None, onset_sample=32000, offset_sample=64000)

A segment with onset and offset given in both seconds and sample number. Notice we give the label as an integer and it is converted to a string; labels are always strings.

>>> Segment(label=1, onset_s=1.0, offset_s=2.0, onset_sample=32000, offset_sample=64000)
Segment(label='1', onset_s=1.0, offset_s=2.0, onset_sample=32000, offset_sample=64000)
__init__(label, onset_s=None, offset_s=None, onset_sample=None, offset_sample=None) None#

Method generated by attrs for class Segment.

Methods

__init__(label[, onset_s, offset_s, ...])

Method generated by attrs for class Segment.

asdict([recurse, filter, dict_factory, ...])

Return the attrs attribute values of inst as a dict.

asdict(recurse=True, filter=None, dict_factory=<class 'dict'>, retain_collection_types=False, value_serializer=None)#

Return the attrs attribute values of inst as a dict.

Optionally recurse into other attrs-decorated classes.

Parameters:
  • inst – Instance of an attrs-decorated class.

  • recurse (bool) – Recurse into classes that are also attrs-decorated.

  • filter (callable) – A callable whose return code determines whether an attribute or element is included (True) or dropped (False). Is called with the attrs.Attribute as the first argument and the value as the second argument.

  • dict_factory (callable) – A callable to produce dictionaries from. For example, to produce ordered dictionaries instead of normal Python dictionaries, pass in collections.OrderedDict.

  • retain_collection_types (bool) – Do not convert to list when encountering an attribute whose type is tuple or set. Only meaningful if recurse is True.

  • value_serializer (Optional[callable]) – A hook that is called for every attribute or dict key/value. It receives the current instance, field and value and must return the (updated) value. The hook is run after the optional filter has been applied.

Return type:

return type of dict_factory

Raises:

attrs.exceptions.NotAnAttrsClassError – If cls is not an attrs class.

New in version 16.0.0: dict_factory

New in version 16.1.0: retain_collection_types

New in version 20.3.0: value_serializer

New in version 21.3.0: If a dict has a collection for a key, it is serialized as a tuple.