--- Data courtesy of Aleena Garner, Allen Institute for Brain Sciences ---
Here we demonstrate how data from the NWB pvc-7 use-case can be stored in NIX files.
In [1]:
from nixio import *
import numpy as np
import matplotlib.pylab as plt
%matplotlib inline
from utils.notebook import print_stats
from utils.plotting import Plotter
In [2]:
f = File.open("data/pvc-7.nix.h5", FileMode.ReadOnly)
print_stats(f.blocks)
In [3]:
block = f.blocks[0]
print_stats(block.data_arrays)
print_stats(block.tags)
In [4]:
# get recording tag
recording = block.tags[0]
# stimulus combinations array
stimulus = recording.features[0].data
In [5]:
# display the stimulus conditions
for label in stimulus.dimensions[0].labels:
print label + ' :',
print '\n'
# actual stimulus condition values
for cmb in stimulus.data[:]:
for x in cmb:
print "%.2f\t" % x,
print '\n'
In [6]:
# get particular stimulus combination
index = 2
print "a stimulus combination %s" % str(stimulus.data[index])
In [7]:
# find out when stimulus was displayed
start = recording.position[index]
end = recording.extent[index]
print "was displayed from frame %d to frame %d" % (start, end)
In [8]:
# get movie arrays from file
movies = filter(lambda x: x.type == 'movie', recording.references)
print_stats(movies)
In [9]:
# get mouse image at the beginning of the selected stimulus
mouse = movies[1]
image_index = int(np.where(np.array(mouse.dimensions[0].ticks) > start)[0][0])
plt.imshow(mouse.data[image_index])
Out[9]:
In [10]:
# get eye image at the end of the selected stimulus
eye = movies[0]
image_index = int(np.where(np.array(eye.dimensions[0].ticks) > end)[0][0])
plt.imshow(eye.data[image_index])
Out[10]:
In [11]:
# get 2-photon image at the beginning of the selected stimulus
imaging = filter(lambda x: x.type == 'imaging', recording.references)[0]
image_index = int(np.where(np.array(imaging.dimensions[0].ticks) > start)[0][0])
plt.imshow(imaging.data[image_index])
Out[11]:
In [12]:
# plot mouse speed in the whole window (TODO: add stimulus events)
speeds = filter(lambda x: x.type == 'runspeed', recording.references)[0]
p = Plotter()
p.add(speeds)
p.plot()
In [13]:
f.close()
In [13]: