Browse Source

Bin spikes of movie stimulus if present

Sören J. Zapp 9 months ago
parent
commit
fa2d4b78e8
1 changed files with 12 additions and 2 deletions
  1. 12 2
      binspikes.py

+ 12 - 2
binspikes.py

@@ -30,6 +30,10 @@ def binspikes(path):
 
     frozenbin : (k, b, c) numpy.ndarray
         Binned spikes for the repeating "frozen" stimulus parts
+
+    moviebin : (k, b, c) numpy.ndarray
+        Binned spikes for the repeating "movie" stimulus parts. Only
+        returned if the experiment contained the movie stimulation
     """
     # Load stimulus parameters from disk
     path = Path(path).expanduser()
@@ -39,7 +43,7 @@ def binspikes(path):
     # Determine length (number of bins) of one trial
     len_run = p['RunningFrames'] * p['Nblinks']
     len_frz = p['FrozenFrames'] * p['Nblinks']
-    len_mov = p.get('MovieFrames', 0) * p.get('Nblinksmovie', 0)
+    len_mov = p.setdefault('MovieFrames', 0) * p.setdefault('Nblinksmovie', 0)
     len_trial = len_run + len_frz + len_mov
 
     # Load stimulus frame times and spike times from disk
@@ -70,14 +74,20 @@ def binspikes(path):
     # Separate running and frozen parts
     runningbin = spkbin[:, :len_run, :]
     frozenbin = spkbin[:, len_run:len_run+len_frz, :]
+    moviebin = spkbin[:, len_run+len_frz:, :]
 
     # Adjust bins to blinks
     shape_r = (num_trials, p['RunningFrames'], p['Nblinks'], num_cells)
     shape_f = (num_trials, p['FrozenFrames'], p['Nblinks'], num_cells)
+    shape_m = (num_trials, p['MovieFrames'], p['Nblinksmovie'], num_cells)
     runningbin = runningbin.reshape(shape_r).sum(axis=2, dtype='uint8')
     frozenbin = frozenbin.reshape(shape_f).sum(axis=2, dtype='uint8')
+    moviebin = moviebin.reshape(shape_m).sum(axis=2, dtype='uint8')
 
-    return runningbin, frozenbin
+    if p['MovieFrames']:
+        return runningbin, frozenbin, moviebin
+    else:
+        return runningbin, frozenbin
 
 
 if __name__ == '__main__':