|
@@ -23,15 +23,15 @@ def binspikes(path):
|
|
|
|
|
|
Returns
|
|
|
-------
|
|
|
- runningbin : (k, b, c) numpy.ndarray
|
|
|
+ runningbin : (k, r, c) numpy.ndarray
|
|
|
Binned spikes for the non-repeating "running" stimulus parts,
|
|
|
- where k is the number of trials, b is the number of bins per
|
|
|
+ where k is the number of trials, r is the number of bins per
|
|
|
part, and c is the number of cells
|
|
|
|
|
|
- frozenbin : (k, b, c) numpy.ndarray
|
|
|
+ frozenbin : (k, f, c) numpy.ndarray
|
|
|
Binned spikes for the repeating "frozen" stimulus parts
|
|
|
|
|
|
- moviebin : (k, b, c) numpy.ndarray
|
|
|
+ moviebin : (k, m, c) numpy.ndarray
|
|
|
Binned spikes for the repeating "movie" stimulus parts. Only
|
|
|
returned if the experiment contained the movie stimulation
|
|
|
"""
|
|
@@ -41,8 +41,8 @@ def binspikes(path):
|
|
|
p = json.loads(filepath.read_text())
|
|
|
|
|
|
# Determine length (number of bins) of one trial
|
|
|
- len_run = p['RunningFrames'] * p['Nblinks']
|
|
|
- len_frz = p['FrozenFrames'] * p['Nblinks']
|
|
|
+ len_run = p.setdefault('RunningFrames', 1500) * p['Nblinks']
|
|
|
+ len_frz = p.setdefault('FrozenFrames', 0) * p['Nblinks']
|
|
|
len_mov = p.setdefault('MovieFrames', 0) * p.setdefault('Nblinksmovie', 0)
|
|
|
len_trial = len_run + len_frz + len_mov
|
|
|
|
|
@@ -59,14 +59,18 @@ def binspikes(path):
|
|
|
e = json.loads(filepath.read_text())
|
|
|
frametimes += e['projector']['delay']
|
|
|
|
|
|
+ # Check frame time frequency with respect to monitor refresh rate
|
|
|
+ ftimes_freq = 1000 / (np.diff(frametimes).mean() * 1000)
|
|
|
+ pulses = int(round(e['projector']['refreshrate'] / ftimes_freq))
|
|
|
+
|
|
|
# Bin the spike times by stimulus frame times
|
|
|
- spkbin = np.zeros((frametimes.size, num_cells), dtype='uint8')
|
|
|
+ spkbin = np.zeros((frametimes.size * pulses, num_cells), dtype='uint8')
|
|
|
frametimes_ext = np.append(frametimes, frametimes[-1]) # Add last bin edge
|
|
|
for i in range(num_cells):
|
|
|
- spkbin[:, i] = np.histogram(spiketimes[i], frametimes_ext)[0]
|
|
|
+ spkbin[::pulses, i] = np.histogram(spiketimes[i], frametimes_ext)[0]
|
|
|
|
|
|
# Reshape binned spikes by trial
|
|
|
- num_trials = int(frametimes.size / len_trial)
|
|
|
+ num_trials = int(frametimes.size*pulses / len_trial)
|
|
|
total_len = num_trials * len_trial
|
|
|
spkbin = spkbin[:total_len]
|
|
|
spkbin = spkbin.reshape(num_trials, len_trial, num_cells)
|
|
@@ -86,8 +90,10 @@ def binspikes(path):
|
|
|
|
|
|
if p['MovieFrames']:
|
|
|
return runningbin, frozenbin, moviebin
|
|
|
- else:
|
|
|
+ elif p['FrozenFrames']:
|
|
|
return runningbin, frozenbin
|
|
|
+ else:
|
|
|
+ return runningbin, # Return tuple for consistency
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|