tonic.slicers#

Module Contents#

Classes#

Slicer

Base protocol class for slicers in Tonic.

SliceByTime

Slices an event array along fixed time window and overlap size. The number of bins depends

SliceByTimeBins

Slices data and targets along fixed number of bins of time length time_duration / bin_count * (1 + overlap).

SliceByEventCount

Slices data and targets along a fixed number of events and overlap size. The number of bins

SliceByEventBins

Slices an event array along fixed number of bins that each have n_events // bin_count * (1 + overlap) events.

SliceAtIndices

Slices data at the specified event indices. Targets are copied.

SliceAtTimePoints

Slice the data at the specified time points.

Functions#

slice_events_by_time(events, time_window[, overlap, ...])

slice_events_by_time_bins(events, bin_count[, overlap])

slice_events_by_count(events, event_count[, overlap, ...])

slice_events_by_event_bins(events, bin_count[, overlap])

slice_events_at_indices(events, start_indices, end_indices)

slice_events_at_timepoints(→ List[numpy.ndarray])

class tonic.slicers.Slicer[source]#

Bases: typing_extensions.Protocol

Base protocol class for slicers in Tonic.

That means that you don’t have to directly inherit from it, but just implement its methods.

get_slice_metadata(data: Any, targets: Any) List[Tuple[Any]][source]#

This method returns the metadata for each recording that helps with slicing, for example the indices or timestamps at which the data would be sliced. The return value is typically a list of tuples that contain start and stop information for each slice.

Parameters:
  • data (Any) – Normally a tuple of data pieces.

  • target – Normally a tuple of target pieces.

  • targets (Any) –

Returns:

metadata as a list of tuples of start and end indices, timestamps, etc.

Return type:

List[Tuple[Any]]

slice_with_metadata(data: Any, targets: Any, metadata: Any) List[Any][source]#

Given a piece of data and/or targets, cut out a certain part of it based on the start/end information given in metadata.

Parameters:
  • data (Any) – Normally a tuple of data pieces.

  • target – Normally a tuple of target pieces.

  • metadata (Any) – An array that contains start and stop information about one slice.

  • targets (Any) –

Returns:

A subset of the original data/targets which is a slice.

Return type:

List[Any]

slice(data: Any, targets: Any) List[Any][source]#

Generate metadata and return all slices at once.

Parameters:
  • data (Any) – Normally a tuple of data pieces.

  • target – Normally a tuple of target pieces.

  • targets (Any) –

Returns:

The whole data and targets sliced into smaller slices.

Return type:

List[Any]

class tonic.slicers.SliceByTime[source]#

Slices an event array along fixed time window and overlap size. The number of bins depends on the length of the recording. Targets are copied.

> <overlap> >| window1 | > | window2 |

Parameters:
  • time_window (int) – time for window length (same unit as event timestamps)

  • overlap (int) – overlap (same unit as event timestamps)

  • include_incomplete (bool) – include the last incomplete slice that has shorter time

time_window: float#
overlap: float = 0.0#
include_incomplete: bool = False#
slice(data: numpy.ndarray, targets: int) List[numpy.ndarray][source]#
Parameters:
  • data (numpy.ndarray) –

  • targets (int) –

Return type:

List[numpy.ndarray]

get_slice_metadata(data: numpy.ndarray, targets: int) List[Tuple[int, int]][source]#
Parameters:
  • data (numpy.ndarray) –

  • targets (int) –

Return type:

List[Tuple[int, int]]

static slice_with_metadata(data: numpy.ndarray, targets: int, metadata: List[Tuple[int, int]])[source]#
Parameters:
  • data (numpy.ndarray) –

  • targets (int) –

  • metadata (List[Tuple[int, int]]) –

class tonic.slicers.SliceByTimeBins[source]#

Slices data and targets along fixed number of bins of time length time_duration / bin_count * (1 + overlap). This method is good if your recordings all have roughly the same time length and you want an equal number of bins for each recording. Targets are copied.

Parameters:
  • bin_count (int) – number of bins

  • overlap (float) – overlap specified as a proportion of a bin, needs to be smaller than 1. An overlap of 0.1 signifies that the bin will be enlarged by 10%. Amount of bins stays the same.

bin_count: int#
overlap: float = 0#
slice(data: numpy.ndarray, targets: int) List[numpy.ndarray][source]#
Parameters:
  • data (numpy.ndarray) –

  • targets (int) –

Return type:

List[numpy.ndarray]

get_slice_metadata(data: numpy.ndarray, targets: int) List[Tuple[int, int]][source]#
Parameters:
  • data (numpy.ndarray) –

  • targets (int) –

Return type:

List[Tuple[int, int]]

static slice_with_metadata(data: numpy.ndarray, targets: int, metadata: List[Tuple[int, int]])[source]#
Parameters:
  • data (numpy.ndarray) –

  • targets (int) –

  • metadata (List[Tuple[int, int]]) –

class tonic.slicers.SliceByEventCount[source]#

Slices data and targets along a fixed number of events and overlap size. The number of bins depends on the amount of events in the recording. Targets are copied.

Parameters:
  • event_count (int) – number of events for each bin

  • overlap (int) – overlap in number of events

  • include_incomplete (bool) – include the last incomplete slice that has fewer events

event_count: int#
overlap: int = 0#
include_incomplete: bool = False#
slice(data: numpy.ndarray, targets: int) List[numpy.ndarray][source]#
Parameters:
  • data (numpy.ndarray) –

  • targets (int) –

Return type:

List[numpy.ndarray]

get_slice_metadata(data: numpy.ndarray, targets: int) List[Tuple[int, int]][source]#
Parameters:
  • data (numpy.ndarray) –

  • targets (int) –

Return type:

List[Tuple[int, int]]

static slice_with_metadata(data: numpy.ndarray, targets: int, metadata: List[Tuple[int, int]])[source]#
Parameters:
  • data (numpy.ndarray) –

  • targets (int) –

  • metadata (List[Tuple[int, int]]) –

class tonic.slicers.SliceByEventBins[source]#

Slices an event array along fixed number of bins that each have n_events // bin_count * (1 + overlap) events. This slicing method is good if you recordings have all roughly the same amount of overall activity in the scene and you want an equal number of bins for each recording. Targets are copied.

Parameters:
  • bin_count (int) – number of bins

  • overlap (float) – overlap in proportion of a bin, needs to be smaller than 1. An overlap of 0.1 signifies that the bin will be enlarged by 10%. Amount of bins stays the same.

bin_count: int#
overlap: float = 0#
slice(data: numpy.ndarray, targets: int) List[numpy.ndarray][source]#
Parameters:
  • data (numpy.ndarray) –

  • targets (int) –

Return type:

List[numpy.ndarray]

get_slice_metadata(data: numpy.ndarray, targets: int) List[Tuple[int, int]][source]#
Parameters:
  • data (numpy.ndarray) –

  • targets (int) –

Return type:

List[Tuple[int, int]]

static slice_with_metadata(data: numpy.ndarray, targets: int, metadata: List[Tuple[int, int]])[source]#
Parameters:
  • data (numpy.ndarray) –

  • targets (int) –

  • metadata (List[Tuple[int, int]]) –

class tonic.slicers.SliceAtIndices[source]#

Slices data at the specified event indices. Targets are copied.

Parameters:
  • start_indices (list) – List of start indices

  • end_indices (list) – List of end indices (exclusive)

start_indices: numpy.ndarray#
end_indices: numpy.ndarray#
slice(data: numpy.ndarray, targets: int) List[numpy.ndarray][source]#
Parameters:
  • data (numpy.ndarray) –

  • targets (int) –

Return type:

List[numpy.ndarray]

get_slice_metadata(data: numpy.ndarray, targets: int) List[Tuple[int, int]][source]#
Parameters:
  • data (numpy.ndarray) –

  • targets (int) –

Return type:

List[Tuple[int, int]]

static slice_with_metadata(data: numpy.ndarray, targets: int, metadata: List[Tuple[int, int]])[source]#
Parameters:
  • data (numpy.ndarray) –

  • targets (int) –

  • metadata (List[Tuple[int, int]]) –

class tonic.slicers.SliceAtTimePoints[source]#

Slice the data at the specified time points.

Parameters:
  • tw_start (list) – List of start times

  • tw_end (list) – List of end times

start_tw: numpy.ndarray#
end_tw: numpy.ndarray#
slice(data: numpy.ndarray, targets: int) List[numpy.ndarray][source]#
Parameters:
  • data (numpy.ndarray) –

  • targets (int) –

Return type:

List[numpy.ndarray]

get_slice_metadata(data: numpy.ndarray, targets: int) List[Tuple[int, int]][source]#
Parameters:
  • data (numpy.ndarray) –

  • targets (int) –

Return type:

List[Tuple[int, int]]

static slice_with_metadata(data: numpy.ndarray, targets: int, metadata: List[Tuple[int, int]])[source]#
Parameters:
  • data (numpy.ndarray) –

  • targets (int) –

  • metadata (List[Tuple[int, int]]) –

tonic.slicers.slice_events_by_time(events: numpy.ndarray, time_window: int, overlap: int = 0, include_incomplete: bool = False)[source]#
Parameters:
  • events (numpy.ndarray) –

  • time_window (int) –

  • overlap (int) –

  • include_incomplete (bool) –

tonic.slicers.slice_events_by_time_bins(events: numpy.ndarray, bin_count: int, overlap: float = 0.0)[source]#
Parameters:
  • events (numpy.ndarray) –

  • bin_count (int) –

  • overlap (float) –

tonic.slicers.slice_events_by_count(events: numpy.ndarray, event_count: int, overlap: int = 0, include_incomplete: bool = False)[source]#
Parameters:
  • events (numpy.ndarray) –

  • event_count (int) –

  • overlap (int) –

  • include_incomplete (bool) –

tonic.slicers.slice_events_by_event_bins(events: numpy.ndarray, bin_count: int, overlap: float = 0.0)[source]#
Parameters:
  • events (numpy.ndarray) –

  • bin_count (int) –

  • overlap (float) –

tonic.slicers.slice_events_at_indices(events: numpy.ndarray, start_indices, end_indices)[source]#
Parameters:

events (numpy.ndarray) –

tonic.slicers.slice_events_at_timepoints(events: numpy.ndarray, start_tw: numpy.ndarray, end_tw: numpy.ndarray) List[numpy.ndarray][source]#
Parameters:
  • events (numpy.ndarray) –

  • start_tw (numpy.ndarray) –

  • end_tw (numpy.ndarray) –

Return type:

List[numpy.ndarray]