Use-case: Fish tracking

Classical conditioning experiments of weakly electric fish Apteronotus albifrons

-- Benda Lab, University of Tübingen, Germany --

Context:

  • Fish are trained to choose one electical stimulus.
  • Trials are videotaped @25Hz using an IR camera.
  • Fish are tracked, position and orientation extracted.

In [6]:
import nixio as nix
import numpy as np
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
from utils.notebook import print_stats
from utils.video_player import Playback

nix_file = nix.File.open('data/tracking_data.h5', nix.FileMode.ReadOnly)
print_stats(nix_file.blocks)


Blocks                                             (01)
	type: recording                            (01)

In [7]:
b = nix_file.blocks[0]
print_stats(b.data_arrays)
print_stats(b.multi_tags)


DataArrays                                         (06)
	type: nix.stamped_video                    (01)
	type: nix.tracking.orientation             (01)
	type: nix.event.positions                  (02)
	type: nix.event.extents                    (02)

MultiTags                                          (02)
	type: nix.event                            (02)

Storing of video data:

Movies are, depending on the number of color channels, stored as 3D, respectively 4D DataArrays.


In [9]:
video = [a for a in b.data_arrays if a.name == "video"][0]

In [ ]:
fig = plt.figure(facecolor='white', figsize=(1024 / 90, 768 / 90), dpi=90)
pb = Playback(fig,video)
pb.start()

Tracking data:

Tracking data is stored as positions in the 4D Matrix, the fourth dimension specifies the time (frame) at which an objkect was tracked. Link between video data and position data is established using a MultiTag entity.


In [10]:
# get the tag linking tracking and video data
tag = [t for t in b.multi_tags if t.name == "tracking"][0]

In [5]:
fig = plt.figure(facecolor='white', figsize=(1024 / 90, 768 / 90), dpi=90)
pb = Playback(fig, video, tracking_tag=tag)
pb.start()


Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 1536, in __call__
    return self.func(*args)
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 587, in callit
    func(*args)
  File "/usr/local/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 147, in _on_timer
    TimerBase._on_timer(self)
  File "/usr/local/lib/python2.7/site-packages/matplotlib/backend_bases.py", line 1305, in _on_timer
    ret = func(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/matplotlib/animation.py", line 1021, in _step
    still_going = Animation._step(self, *args)
  File "/usr/local/lib/python2.7/site-packages/matplotlib/animation.py", line 827, in _step
    self._draw_next_frame(framedata, self._blit)
  File "/usr/local/lib/python2.7/site-packages/matplotlib/animation.py", line 845, in _draw_next_frame
    self._pre_draw(framedata, blit)
  File "/usr/local/lib/python2.7/site-packages/matplotlib/animation.py", line 858, in _pre_draw
    self._blit_clear(self._drawn_artists, self._blit_cache)
  File "/usr/local/lib/python2.7/site-packages/matplotlib/animation.py", line 898, in _blit_clear
    a.figure.canvas.restore_region(bg_cache[a])
KeyError: <matplotlib.axes._subplots.AxesSubplot object at 0x114952ad0>
utils/video_player.py:47: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  frame[y_pos-radius:y_pos+radius, x_pos-radius:x_pos+radius, 0][index] = 255
utils/video_player.py:48: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  frame[y_pos-radius:y_pos+radius, x_pos-radius:x_pos+radius, 1][index] = 0
utils/video_player.py:49: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  frame[y_pos-radius:y_pos+radius, x_pos-radius:x_pos+radius, 2][index] = 0

Addtional Information:

During tracking additional information, i.e. the fish's orientation, is gathered. For each position there is also an orientation. This information is stored as a Feature of the tracking.


In [ ]:
fig = plt.figure(facecolor='white', figsize=(1024 / 90, 768 / 90), dpi=90)
pb = Playback(fig, video, tracking_tag=tag, show_orientation=True)
pb.start()

In [ ]:
nix_file.close()

In [ ]: