NWB use-case pvc-7 (NIX2)

--- 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.

Context:

  • In vivo calcium imaging of layer 4 cells in mouse primary visual cortex.
  • Two-photon images sampled @ 30 Hz
  • Visual stimuli of sinusoidal moving gratings were presented.
  • In this example, we use a subset of the original data file.
  • We only use image frames 5000 to frame 6000.
  • Image data was 10 times down-sampled.

In [1]:
import nix2
import numpy as np
import matplotlib.pylab as plt
%matplotlib inline
from utils.notebook import print_stats
from utils.plotting import Plotter

Open a file and inspect its content


In [2]:
f = nix2.File("data/pvc-7.nix2.h5", nix2.FileMode.ReadOnly)

print_stats(f.blocks)


Blocks                                             (01)
	type: pvc-7                                (01)

In [3]:
block = f.blocks[0]

print_stats(block.matrix_lists)
print_stats(block.point_lists)
print_stats(block.region_lists)


MatrixLists                                        (04)
	type: runspeed                             (01)
	type: movie                                (02)
	type: imaging                              (01)

PointLists                                         (01)
	type: stimulus                             (01)

RegionLists                                        (01)
	type: recording                            (01)

Explore Stimulus


In [4]:
# get recording tag
recording = block.region_lists[0]

# stimulus combinations array
stimulus = recording.feature_points[0]

In [5]:
# display the stimulus conditions
for dim in stimulus.dims:
    print dim.label + ' :',
print '\n'

# actual stimulus condition values
for cmb in stimulus.all_data[:]:
    for x in cmb:
        print "%.2f\t" % x,
    print '\n'


orientation : SF : TF : contrast : 

90.00	0.02	1.00	0.80	

135.00	0.16	2.00	0.80	

270.00	0.32	1.00	0.80	

45.00	0.02	4.00	0.80	

270.00	0.08	1.00	0.80	

225.00	0.08	4.00	0.80	


In [6]:
# get particular stimulus combination
index = 2
print "a stimulus combination %s" % str(stimulus.all_data[index])


a stimulus combination [ 270.      0.32    1.      0.8 ]

In [7]:
# find out when stimulus was displayed
start = recording.all_data[index][0]
end = recording.all_data[index][1]

print "was displayed from frame %d to frame %d" % (start, end)


was displayed from frame 5314 to frame 5404

Explore video and imaging data


In [8]:
# get movie arrays from file
movies = filter(lambda x: x.type == 'movie', block.matrix_lists)
print_stats(movies)


MatrixLists                                        (02)
	type: movie                                (02)

In [9]:
# get mouse image at the beginning of the selected stimulus
mouse = movies[1][0]  # note the last zero
image_index = int(np.where(mouse.dims[0].scale > start)[0][0])

plt.imshow(mouse[image_index])


Out[9]:
<matplotlib.image.AxesImage at 0x7f926682fc10>

In [10]:
# get eye image at the end of the selected stimulus
eye = movies[0][0]  # note the last zero
image_index = int(np.where(mouse.dims[0].scale > end)[0][0])

plt.imshow(eye[image_index])


Out[10]:
<matplotlib.image.AxesImage at 0x7f9266674c10>

In [11]:
# get 2-photon image at the beginning of the selected stimulus
imaging = filter(lambda x: x.type == 'imaging', block.matrix_lists)[0][0]  # note the last zero

image_index = int(np.where(imaging.dims[0].scale > start)[0][0])

plt.imshow(imaging[image_index])


Out[11]:
<matplotlib.image.AxesImage at 0x7f9264dba710>

In [12]:
%matplotlib inline
from nix2.plot import NixPlot

# plot mouse speed in the whole window (TODO: add stimulus events)
speeds = filter(lambda x: x.type == 'runspeed', block.matrix_lists)[0][0]  # note the last zero

plot = NixPlot()
plot.add(speeds)

plot.plot().show()



In [13]:
f.close()

In [13]: