bnl.core.Segment

class bnl.core.Segment(bs, labels=<factory>, *, name=None)[source]

Bases: TimeSpan

An ordered sequence of boundaries that partition a span into labeled sections.

Represents one layer of annotation. While it inherits from TimeSpan, its start and end attributes are automatically derived from the provided boundaries.

Public Data Attributes:

lam

Label Agreement Matrix

bs

labels

start

end

Inherited from TimeSpan

name

duration

Duration in seconds.

start

end

Public Methods:

sections

A list of all the labeled time spans that compose the segment.

itvls

from_jams(segment_annotation[, name])

Data Ingestion from jams format.

from_itvls(itvls, labels[, name])

Data Ingestion from mir_eval format of boundaries and labels.

from_bs(bs[, labels, name])

Creates a Segment from a sequence of boundaries and labels.

plot([colorscale, hatch])

Plots the segment on a plotly figure by warpping it in a MultiSegment.

scrub_labels([replace_with])

Scrubs the labels of the Segment by replacing them with empty strings.

align(span)

Align with a TimeSpan object.


Parameters:
  • bs (Sequence[Boundary])

  • labels (Sequence[str])

  • name (str | None)

property sections: Sequence[TimeSpan]

A list of all the labeled time spans that compose the segment.

property lam: ndarray

Label Agreement Matrix

Returns:

The label agreement matrix.

Return type:

np.ndarray

classmethod from_jams(segment_annotation, name=None)[source]

Data Ingestion from jams format.

Parameters:
  • segment_annotation (Annotation)

  • name (str | None)

Return type:

Segment

classmethod from_itvls(itvls, labels, name=None)[source]

Data Ingestion from mir_eval format of boundaries and labels.

Parameters:
  • itvls (Sequence[Sequence[float]])

  • labels (Sequence[str])

  • name (str | None)

Return type:

Segment

classmethod from_bs(bs, labels=None, name=None)[source]

Creates a Segment from a sequence of boundaries and labels.

Parameters:
  • bs (Sequence[Boundary | Number])

  • labels (Sequence[str] | None)

  • name (str | None)

Return type:

Segment

plot(colorscale='D3', hatch=True)[source]

Plots the segment on a plotly figure by warpping it in a MultiSegment.

Parameters:
  • colorscale (str | list[str])

  • hatch (bool)

Return type:

Figure

scrub_labels(replace_with='')[source]

Scrubs the labels of the Segment by replacing them with empty strings.

Parameters:

replace_with (str | None)

Return type:

Segment

align(span)[source]

Align with a TimeSpan object.

Parameters:

span (TimeSpan)

Return type:

Segment