- Neuroscience example
- Low cognitive load
- Scalable to the size of small solo project (i.e. multiple scripts, folders, functions)
- Minimal third party dependencies
- Reasonable excuses for unit testing
- Reasonable excuses for GitHub workflows?
Ella's spiking neuron example
We have recordings from 9 different motor cortex neurons from a macaque. We have recorded these neurons while the macaque is reaching to 8 different directions. The spiking data array spikes is 9 by 1000 by 1500. The first dimension corresponds to different neurons, the second to 1000 different trials, and the third to 1500 time bins of width 1 ms each. If the neuron spikes during that time bin on that trial, the entry is 1, otherwise it is 0. The reach movement onset occurs at the 750th time bin. The angles_by_trial array is shape (1000,). It contains the reaching angle on each trial - which is one of 8 unique reach angles.
In the code below, we look at how the firing rate of neuron 2 varies by angle. For a given angle, we compute the mean firing rate in spikes per second for each reach angle. We only consider the 500th to 1000th time bin on each trial(so the chunk of time around reach onset). In the code, we compute the mean firing rate for a given angle by summing up the spikes in this time chunk on all trials of that reach angle and divide by the number of trials of that reach angle and the length of time per trial (0.5 seconds). We then plot the average firing rate per angle vs the angle, and find the angle that lead to the highest firing rate. As you clean up the code, the plot should not change.
import numpy as np
import matplotlib.pyplot as plt
# Compute average firing rate per angle
avfr = np.zeros((8,))
for i in range(8): # loops over angles
ss = 0 # tracks sum of spikes
for j in range(1000): # loops over trials
if trial_angles[j]==reaching_angles[i]: # checks if that trial was that angle
for t in range(500,1000): # loop over relevant time bins
ss=ss+spikes[1,j,t].sum() # sum spikes in that time bin
avfr[i]=ss/100/.5
# Get preferred angle
max_firing_rate = 0
for i_angle in range(8):
if avfr[i_angle] > max_firing_rate:
preferred_angle = reaching_angles[i_angle]
max_firing_rate = avfr[i_angle]
print('The preferred angle for this neuron is ' + str(preferred_angle) + '\n')
# Plot average firing rate per angle
ax = plt.axes()
ax.plot(reaching_angles, avfr)
ax.set(xlabel='Reach angle', ylabel='Mean firing rate')