:py:mod:`tonic.io`
==================

.. py:module:: tonic.io


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


Functions
~~~~~~~~~

.. autoapisummary::

   tonic.io.make_structured_array
   tonic.io.read_aedat4
   tonic.io.read_dvs_128
   tonic.io.read_dvs_ibm
   tonic.io.read_dvs_red
   tonic.io.read_davis_346
   tonic.io.read_dvs_346mini
   tonic.io.read_mnist_file
   tonic.io.read_aedat_header_from_file
   tonic.io.get_aer_events_from_file



Attributes
~~~~~~~~~~

.. autoapisummary::

   tonic.io.events_struct


.. py:data:: events_struct

   

.. py:function:: make_structured_array(*args, dtype=events_struct)

   Make a structured array given a variable number of argument values.

   :param \*args: Values in the form of nested lists or tuples or numpy arrays.
                  Every except the first argument can be of a primitive data type like int or float.

   :returns: numpy structured array with the shape of the first argument
   :rtype: struct_arr


.. py:function:: read_aedat4(in_file)

   Get the aer events from version 4 of .aedat file.

   :param in_file: str The name of the .aedat file

   :returns: numpy structured array of events
   :rtype: events


.. py:function:: read_dvs_128(filename)

   Get the aer events from DVS with resolution of rows and cols are (128, 128)

   :param filename: filename

   :returns:     (height, width) of the sensor array
             xytp: numpy structured array of events
   :rtype: shape (tuple)


.. py:function:: read_dvs_ibm(filename)

   Get the aer events from DVS with ibm gesture dataset.

   :param filename: filename

   :returns:     (height, width) of the sensor array
             xytp: numpy structured array of events
   :rtype: shape (tuple)


.. py:function:: read_dvs_red(filename)

   Get the aer events from DVS with resolution of (260, 346)

   :param filename: filename

   :returns:     (height, width) of the sensor array

             events: numpy structured array of events
   :rtype: shape (tuple)


.. py:function:: read_davis_346(filename)

   Get the aer events from DAVIS346 with resolution of (260, 346)

   :param filename: filename

   :returns:     (height, width) of the sensor array

             events: numpy structured array of events
   :rtype: shape (tuple)


.. py:function:: read_dvs_346mini(filename)

   Get the aer events from DVS with resolution of (132,104)

   :param filename: filename

   :returns:     (height, width) of the sensor array
             xytp: numpy structure of xytp
   :rtype: shape (tuple)


.. py:function:: read_mnist_file(bin_file: str | BinaryIO, dtype: numpy.dtype, is_stream: bool = False)

   Reads the events contained in N-MNIST/N-CALTECH101 datasets.

   Code adapted from https://github.com/gorchard/event-Python/blob/master/eventvision.py


.. py:function:: read_aedat_header_from_file(filename)

   Get the aedat file version and start index of the binary data.

   :param filename: The name of the .aedat file
   :type filename: str

   :returns: The version of the .aedat file
             data_start (int):       The start index of the data
             start_timestamp (int):  The start absolute system timestamp in micro-seconds
   :rtype: data_version (float)


.. py:function:: get_aer_events_from_file(filename, data_version, data_start)

   Get aer events from an aer file.

   :param filename: The name of the .aedat file
   :type filename: str
   :param data_version: The version of the .aedat file
   :type data_version: float
   :param data_start: The start index of the data
   :type data_start: int

   :returns:

             Numpy structured array:
                                      ['address'] the address of a neuron which fires
                                      ['timeStamp'] the timeStamp in mus when a neuron fires
   :rtype: all_events


