includes some visualizations
# @title Install dependencies
!pip install umap-learn --quiet
|████████████████████████████████| 88 kB 6.4 MB/s |████████████████████████████████| 1.1 MB 49.5 MB/s Building wheel for umap-learn (setup.py) ... done Building wheel for pynndescent (setup.py) ... done
import numpy as np
import matplotlib.pyplot as plt
from umap import UMAP
from scipy.ndimage import uniform_filter1d
from scipy.stats import zscore
from sklearn.decomposition import PCA
# @title Figure settings
from matplotlib import rcParams
rcParams['figure.figsize'] = [20, 4]
rcParams['font.size'] =15
rcParams['axes.spines.top'] = False
rcParams['axes.spines.right'] = False
rcParams['figure.autolayout'] = True
# @title Data retrieval
import os, requests
fname = "stringer_spontaneous.npy"
url = "https://osf.io/dpqaj/download"
if not os.path.isfile(fname):
try:
r = requests.get(url)
except requests.ConnectionError:
print("!!! Failed to download data !!!")
else:
if r.status_code != requests.codes.ok:
print("!!! Failed to download data !!!")
else:
with open(fname, "wb") as fid:
fid.write(r.content)
# @title Data loading
dat = np.load('stringer_spontaneous.npy', allow_pickle=True).item()
print(dat.keys())
dict_keys(['sresp', 'run', 'beh_svd_time', 'beh_svd_mask', 'stat', 'pupilArea', 'pupilCOM', 'xyz'])
dat has fields:
dat['sresp']
: neurons by timebins, a.k.a. the neural response data (11983 by 7018). Timebin = 1.2 sec.dat['run']
: timebins by 1, a.k.a. the running speed of the animal in a.u.dat['xyz']
: three-dimensional position of each neuron in the brain.dat['pupilArea']
: timebins by 1, see FaceMap for details on the pupil trackerdat['pupilCOM']
: timebins by 2, correspond to X and Y position. See FaceMap for details on the pupil tracker.dat['beh_svd_time']
: timebins by 1,000. Timecourses of behavioral SVDs extracted from face movies. See FaceMap for details.dat['beh_svd_mask']
: 240 by 320 by 1,000. Spatial masks of behavioral SVDs. Roughly normalized to each other.dat['beh_svd_mask'] @ dat['beh_svd_time'][T, :]
: reconstruction of the face movie (its motion energy) for frame Tdat['stat']
: 1 by neurons, some statistics for each neuron, see Suite2p for full documentation.print(dat['sresp'].shape)
print(len(dat['stat']))
(11983, 7018) 11983
# @title plot the 3D positions of all neurons
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
x, y, z = dat['xyz']
zunq, iunq = np.unique(z, return_inverse=True)
xc = np.linspace(0.0, 1.0, len(zunq))
cmap = cm.get_cmap('jet')(xc)
fig = plt.figure(figsize=(6, 6))
ax = fig.add_subplot(111, projection='3d')
ax.scatter(x[::-1],y[::-1], z[::-1], 'o', s=4, c=cmap[iunq])
ax.set(xlabel='horizontal(um)', ylabel='vertical(um)', zlabel='depth (um)')
plt.show()
# @title Basic properties of behavioral data using plot and scatter
ax = plt.subplot(1, 5, 1)
plt.plot(dat['pupilArea'][:500, 0])
ax.set(xlabel='timepoints', ylabel='pupil area')
ax = plt.subplot(1, 5, 2)
plt.plot(dat['pupilCOM'][:500, :])
ax.set(xlabel='timepoints', ylabel='pupil XY position')
ax = plt.subplot(1, 5, 3)
plt.plot(dat['beh_svd_time'][:500, 0])
ax.set(xlabel='timepoints', ylabel='face SVD #0')
ax = plt.subplot(1, 5, 4)
plt.plot(dat['beh_svd_time'][:500, 1])
ax.set(xlabel='timepoints', ylabel='face SVD #1')
ax = plt.subplot(1, 5, 5)
plt.scatter(dat['beh_svd_time'][:, 0], dat['beh_svd_time'][:, 1], s=1)
ax.set(xlabel='face SVD #0', ylabel='face SVD #1')
plt.show()