:py:mod:`tonic.slicers`
=======================

.. py:module:: tonic.slicers


Module Contents
---------------

Classes
~~~~~~~

.. autoapisummary::

   tonic.slicers.Slicer
   tonic.slicers.SliceByTime
   tonic.slicers.SliceByTimeBins
   tonic.slicers.SliceByEventCount
   tonic.slicers.SliceByEventBins
   tonic.slicers.SliceAtIndices
   tonic.slicers.SliceAtTimePoints



Functions
~~~~~~~~~

.. autoapisummary::

   tonic.slicers.slice_events_by_time
   tonic.slicers.slice_events_by_time_bins
   tonic.slicers.slice_events_by_count
   tonic.slicers.slice_events_by_event_bins
   tonic.slicers.slice_events_at_indices
   tonic.slicers.slice_events_at_timepoints



.. py:class:: Slicer


   Bases: :py:obj:`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.

   .. py:method:: get_slice_metadata(data: Any, targets: Any) -> list[tuple[Any]]

      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.

      :param data: Normally a tuple of data pieces.
      :param target: Normally a tuple of target pieces.

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


   .. py:method:: slice_with_metadata(data: Any, targets: Any, metadata: Any) -> list[Any]

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

      :param data: Normally a tuple of data pieces.
      :param target: Normally a tuple of target pieces.
      :param metadata: An array that contains start and stop information about one slice.

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


   .. py:method:: slice(data: Any, targets: Any) -> list[Any]

      Generate metadata and return all slices at once.

      :param data: Normally a tuple of data pieces.
      :param target: Normally a tuple of target pieces.

      :returns: The whole data and targets sliced into smaller slices.



.. py:class:: SliceByTime


   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     |

   :param time_window: time for window length (same unit as event timestamps)
   :type time_window: int
   :param overlap: overlap (same unit as event timestamps)
   :type overlap: int
   :param include_incomplete: include the last incomplete slice that has shorter time
   :type include_incomplete: bool
   :param start_time: optional start time that is used for slicing, otherwise the first event time is used
   :type start_time: int
   :param end_time: optional end time that is used for slicing, otherwise the last event time is used
   :type end_time: int
   :param reset_time: subtract the time_window from each slice. For example, if you have 4 events with
                      timestamps [0, 150, 299, 300], a time_window of 100, and reset_time as True, you will
                      get back 4 slices with timestamps [0], [50], [99], [0]. This is useful when you use
                      start_time / end_time arguments for the ToFrame transform.
   :type reset_time: bool

   .. py:attribute:: time_window
      :type: float

      

   .. py:attribute:: overlap
      :type: float
      :value: 0.0

      

   .. py:attribute:: include_incomplete
      :type: bool
      :value: False

      

   .. py:attribute:: start_time
      :type: float

      

   .. py:attribute:: end_time
      :type: float

      

   .. py:attribute:: reset_time
      :type: bool
      :value: False

      

   .. py:method:: slice(data: numpy.ndarray, targets: int) -> list[numpy.ndarray]


   .. py:method:: get_slice_metadata(data: numpy.ndarray, targets: int) -> list[tuple[int, int]]


   .. py:method:: slice_with_metadata(data: numpy.ndarray, targets: int, metadata: list[tuple[int, int]])
      :staticmethod:



.. py:class:: SliceByTimeBins


   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.

   :param bin_count: number of bins
   :type bin_count: int
   :param overlap: 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.
   :type overlap: float

   .. py:attribute:: bin_count
      :type: int

      

   .. py:attribute:: overlap
      :type: float
      :value: 0

      

   .. py:method:: slice(data: numpy.ndarray, targets: int) -> list[numpy.ndarray]


   .. py:method:: get_slice_metadata(data: numpy.ndarray, targets: int) -> list[tuple[int, int]]


   .. py:method:: slice_with_metadata(data: numpy.ndarray, targets: int, metadata: list[tuple[int, int]])
      :staticmethod:



.. py:class:: SliceByEventCount


   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.

   :param event_count: number of events for each bin
   :type event_count: int
   :param overlap: overlap in number of events
   :type overlap: int
   :param include_incomplete: include the last incomplete slice that has fewer events
   :type include_incomplete: bool

   .. py:attribute:: event_count
      :type: int

      

   .. py:attribute:: overlap
      :type: int
      :value: 0

      

   .. py:attribute:: include_incomplete
      :type: bool
      :value: False

      

   .. py:method:: slice(data: numpy.ndarray, targets: int) -> list[numpy.ndarray]


   .. py:method:: get_slice_metadata(data: numpy.ndarray, targets: int) -> list[tuple[int, int]]


   .. py:method:: slice_with_metadata(data: numpy.ndarray, targets: int, metadata: list[tuple[int, int]])
      :staticmethod:



.. py:class:: SliceByEventBins


   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.

   :param bin_count: number of bins
   :type bin_count: int
   :param overlap: 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.
   :type overlap: float

   .. py:attribute:: bin_count
      :type: int

      

   .. py:attribute:: overlap
      :type: float
      :value: 0

      

   .. py:method:: slice(data: numpy.ndarray, targets: int) -> list[numpy.ndarray]


   .. py:method:: get_slice_metadata(data: numpy.ndarray, targets: int) -> list[tuple[int, int]]


   .. py:method:: slice_with_metadata(data: numpy.ndarray, targets: int, metadata: list[tuple[int, int]])
      :staticmethod:



.. py:class:: SliceAtIndices


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

   :param start_indices: List of start indices
   :type start_indices: list
   :param end_indices: List of end indices (exclusive)
   :type end_indices: list

   .. py:attribute:: start_indices
      :type: numpy.ndarray

      

   .. py:attribute:: end_indices
      :type: numpy.ndarray

      

   .. py:method:: slice(data: numpy.ndarray, targets: int) -> list[numpy.ndarray]


   .. py:method:: get_slice_metadata(data: numpy.ndarray, targets: int) -> list[tuple[int, int]]


   .. py:method:: slice_with_metadata(data: numpy.ndarray, targets: int, metadata: list[tuple[int, int]])
      :staticmethod:



.. py:class:: SliceAtTimePoints


   Slice the data at the specified time points.

   :param tw_start: List of start times
   :type tw_start: list
   :param tw_end: List of end times
   :type tw_end: list

   .. py:attribute:: start_tw
      :type: numpy.ndarray

      

   .. py:attribute:: end_tw
      :type: numpy.ndarray

      

   .. py:method:: slice(data: numpy.ndarray, targets: int) -> list[numpy.ndarray]


   .. py:method:: get_slice_metadata(data: numpy.ndarray, targets: int) -> list[tuple[int, int]]


   .. py:method:: slice_with_metadata(data: numpy.ndarray, targets: int, metadata: list[tuple[int, int]])
      :staticmethod:



.. py:function:: slice_events_by_time(events: numpy.ndarray, time_window: int, overlap: int = 0, include_incomplete: bool = False, start_time=None, end_time=None)


.. py:function:: slice_events_by_time_bins(events: numpy.ndarray, bin_count: int, overlap: float = 0.0)


.. py:function:: slice_events_by_count(events: numpy.ndarray, event_count: int, overlap: int = 0, include_incomplete: bool = False)


.. py:function:: slice_events_by_event_bins(events: numpy.ndarray, bin_count: int, overlap: float = 0.0)


.. py:function:: slice_events_at_indices(events: numpy.ndarray, start_indices, end_indices)


.. py:function:: slice_events_at_timepoints(events: numpy.ndarray, start_tw: numpy.ndarray, end_tw: numpy.ndarray) -> list[numpy.ndarray]


