tonic.utils#

Module Contents#

Functions#

plot_event_grid(events[, axis_array, plot_frame_number])

Plot events accumulated as frames equal to the product of axes for visual inspection.

plot_animation(frames[, figsize])

Helper function that animates a tensor of frames of shape (TCHW). If you run this in a

tonic.utils.plot_event_grid(events: numpy.ndarray, axis_array: Tuple[int, int] = (1, 3), plot_frame_number: bool = False)[source]#

Plot events accumulated as frames equal to the product of axes for visual inspection.

Parameters:
  • events (numpy.ndarray) – Structured numpy array of shape [num_events, num_event_channels].

  • axis_array (Tuple[int, int]) – dimensions of plotting grid. The larger the grid, the more fine-grained the events will be sliced in time.

  • plot_frame_number (bool) – optional index of frame when plotting

Example

>>> import tonic
>>> dataset = tonic.datasets.NMNIST(save_to='./data')
>>> events, target = dataset[100]
>>> tonic.utils.plot_event_grid(events)
Returns:

None

Parameters:
  • events (numpy.ndarray) –

  • axis_array (Tuple[int, int]) –

  • plot_frame_number (bool) –

tonic.utils.plot_animation(frames: numpy.ndarray, figsize: Tuple[int, int] = (5, 5))[source]#

Helper function that animates a tensor of frames of shape (TCHW). If you run this in a Jupyter notebook, you can display the animation inline like shown in the example below.

Parameters:
  • frames (numpy.ndarray) – numpy array or tensor of shape (TCHW)

  • figsize (Tuple[int, int]) –

Example

>>> import tonic
>>> nmnist = tonic.datasets.NMNIST(save_to='./data', train=False)
>>> events, label = nmnist[0]
>>>
>>> transform = tonic.transforms.ToFrame(
>>>     sensor_size=nmnist.sensor_size,
>>>     time_window=10000,
>>> )
>>>
>>> frames = transform(events)
>>> animation = tonic.utils.plot_animation(frames)
>>>
>>> # Display the animation inline in a Jupyter notebook
>>> from IPython.display import HTML
>>> HTML(animation.to_jshtml())
Returns:

The animation object. Store this in a variable to keep it from being garbage collected until displayed.

Parameters:
  • frames (numpy.ndarray) –

  • figsize (Tuple[int, int]) –