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 [1]:
import nix
import numpy as np
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 [2]:
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 [5]:
video = [a for a in b.data_arrays if a.name == "video"][0]

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 [4]:
# get the tag linking tracking and video data
tag = [t for t in b.multi_tags if t.name == "tracking"][0]

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


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-4-7bec3dd06d10> in <module>()
      3 
      4 fig = plt.figure(facecolor='white', figsize=(1024 / 90, 768 / 90), dpi=90)
----> 5 pb = Playback(fig, video, tracking_tag=tag)
      6 pb.start()

NameError: name 'video' is not defined

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 [6]:
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 [7]:
nix_file.close()

In [ ]: