from __future__ import division, print_function
We need to get some tracking data to run the toy model simulation on. We will use a short segment of the Blair test data set, but long enough to at least coarsely visit most locations in the environment.
The data is stored in MATLAB files, so we need MATLAB loading functions.
import scipy.io as sio
The test data set for rat 10 day 8 is located under the root folder ~/theta-data/
.
import os
root = '/Users/joe/data/blab/'
dataset = os.path.join(root, 'OTheta10/OTheta10_Day8')
assert os.path.isdir(dataset)
Load the trackdata.mat
file into the workspace.
tracking_file = os.path.join(dataset, 'trackdata.mat')
trackdata = sio.loadmat(tracking_file)
print(*sorted(trackdata.keys()), sep=', ')
Position_AV, Position_HD, Position_MD, Position_Speed, Position_X, Position_Y, __globals__, __header__, __version__, avint_ccw, avint_cw, avint_straight, ds_0, ds_120, ds_150, ds_180, ds_210, ds_240, ds_270, ds_30, ds_300, ds_330, ds_60, ds_90, fastints, slowints, stillints
start = 1000.0 # s
duration = 1500.0 # s
fs = 30.0 # s
res = 5.25 # pixels/cm
t0 = int(start * fs)
N = int(duration * fs)
t_slice = slice(t0, t0 + N)
print('Starting at sample %d for a total of %d samples.' % (t0, N))
Starting at sample 30000 for a total of 45000 samples.
x, t = trackdata['Position_X'][t_slice].T
y = trackdata['Position_Y'][t_slice,0]
print('Data starts at t = %f.' % t[0])
# Convert from pixels to cm
x /= res
y /= res
import numpy as np
pos = np.c_[t, x, y].T
print('New position shape = ', pos.shape)
Data starts at t = 1101.453375. New position shape = (3, 45000)
Using matplotlib inline
%matplotlib inline
import matplotlib.pyplot as plt
plt.plot(x, y, 'k-', alpha=0.7)
plt.axis('equal')
plt.xlabel('x')
plt.ylabel('y')
<matplotlib.text.Text at 0x10ff8fad0>
Store the data as numpy array in modeling data subdirectory.
model_path = '/Users/joe/source/phase_model'
data_path = os.path.join(model_path, 'data')
assert os.path.isdir(data_path)
save_file = os.path.join(data_path, 'pos.npy')
np.save(save_file, pos)
print('Saved:', save_file)
Saved: /Users/joe/source/phase_model/data/pos.npy
Position data file pos.npy is a row-wise matrix of time, x-position, and y-position.
Load the saved binary array data from the model directory to verify.
pos_saved = np.load(save_file)
plt.plot(pos_saved[1], pos_saved[2], 'b-', alpha=0.7)
plt.axis('equal')
(-40.0, 40.0, -40.0, 40.0)