tonic.slicers
#
Module Contents#
Classes#
Base protocol class for slicers in Tonic. |
|
Slices an event array along fixed time window and overlap size. The number of bins depends |
|
Slices data and targets along fixed number of bins of time length time_duration / bin_count * (1 + overlap). |
|
Slices data and targets along a fixed number of events and overlap size. The number of bins |
|
Slices an event array along fixed number of bins that each have n_events // bin_count * (1 + overlap) events. |
|
Slices data at the specified event indices. Targets are copied. |
|
Slice the data at the specified time points. |
Functions#
|
|
|
|
|
|
|
|
|
|
|
- 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]
- 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]
- 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]
- 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]
- 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]
- 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]
- 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) –