bnl.core.MultiSegment

class bnl.core.MultiSegment(raw_layers=<factory>, *, name=None)[source]

Bases: TimeSpan

The primary input object for analysis, containing multiple Segment layers.

Public Data Attributes:

itvls

Returns a list of all the intervals for each layer in the MultiSegment.

labels

Returns a list of all the labels for each layer in the MultiSegment.

raw_layers

A sequence of Segment objects representing different layers of annotation.

start

end

name

Inherited from TimeSpan

name

duration

Duration in seconds.

start

end

Public Methods:

layers

Returns the layers aligned to a unified time span.

from_json(json_data[, name])

Data Ingestion from adobe json format.

from_itvls(itvls, labels[, name])

plot([colorscale, hatch])

Plots the MultiSegment on a Plotly figure.

contour([strategy])

Calculates boundary salience and converts to a BoundaryContour.

scrub_labels()

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

find_span(layers[, mode])

Finds the span of a list of Segment layers.

align(span)

Align with a TimeSpan object.

prune_layers([relabel])

Prunes identical layers from the MultiSegment.

squeeze_layers([times, relabel])

Remove the least informative layer from the MultiSegment according to vmeasure.


Parameters:
  • raw_layers (Sequence[Segment])

  • name (str | None)

raw_layers: Sequence[Segment]

A sequence of Segment objects representing different layers of annotation.

property layers: Sequence[Segment]

Returns the layers aligned to a unified time span.

property itvls: Sequence[ndarray]

Returns a list of all the intervals for each layer in the MultiSegment.

property labels: Sequence[Sequence[str]]

Returns a list of all the labels for each layer in the MultiSegment.

classmethod from_json(json_data, name=None)[source]

Data Ingestion from adobe json format.

Parameters:
  • json_data (list) – A list of layers, where each layer is a tuple of (intervals, labels). intervals is a list of [start, end] times, and labels is a list of strings.

  • name (str, optional) – Name for the created MultiSegment.

Return type:

MultiSegment

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

Plots the MultiSegment on a Plotly figure.

Parameters:
  • colorscale (str | list[str], optional) – Plotly colorscale to use. Can be a qualitative scale name (e.g., “Set3”, “Pastel”) or a list of colors.

  • hatch (bool, optional) – Whether to use hatch patterns for different labels. Defaults to True.

Return type:

Figure

contour(strategy='depth', **kwargs)[source]

Calculates boundary salience and converts to a BoundaryContour.

Parameters:
  • strategy (str)

  • kwargs (Any)

Return type:

BoundaryContour

scrub_labels()[source]

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

Return type:

MultiSegment

static find_span(layers, mode='common')[source]

Finds the span of a list of Segment layers.

Parameters:
  • mode (str, optional) – The alignment mode. Can be “union” or “common”. Defaults to “common”.

  • layers (Sequence[Segment])

Return type:

TimeSpan

align(span)[source]

Align with a TimeSpan object.

Parameters:

span (TimeSpan)

Return type:

MultiSegment

prune_layers(relabel=True)[source]

Prunes identical layers from the MultiSegment.

This also gets rid of layers with no inner boundaries.

Parameters:

relabel (bool)

Return type:

MultiSegment

squeeze_layers(times=1, relabel=True)[source]

Remove the least informative layer from the MultiSegment according to vmeasure.

Returns a new MultiSegment with the most redundant layer removed.

Parameters:
  • times (int)

  • relabel (bool)

Return type:

MultiSegment