def make_raster(spikedata, experiment, prestim, poststim, dest): # get number of units, number of stims cells = btsf.get_cluids(spikedata) stim_names = btsf.get_stim_names(spikedata) for stimn in stim_names: ntrials = btsf.get_num_trials(spikedata, stimn) for cluid in cells: cellstimdata = btsf.find_spikes_by_stim_name(btsf.find_spikes_by_cluid(spikedata, cluid), stimn) cell_clugroup = btsf.get_clugroups(cellstimdata) raster = plt.figure() for trialnum in range(ntrials): spikes_to_plot = btsf.find_spikes_by_stim_trial(cellstimdata, stimn, trialnum) [stim_start_samps, stim_end_samps] = btsf.get_stim_times(cellstimdata, stimn, trialnum) stim_start = (stim_start_samps - stim_start_samps)/info['fs'] stim_end = (stim_end_samps - stim_start_samps)/info['fs'] nspikes = btsf.get_num_spikes(spikes_to_plot) spiketimes = btsf.get_spike_times_seconds_stim_aligned(spikes_to_plot) ylimits = [trialnum, trialnum+1] for j in range(nspikes): ydata = ylimits xdata = [spiketimes[j], spiketimes[j]] plt.plot(xdata, ydata, 'b') stim_start_x = [stim_start, stim_start] stim_end_x = [stim_end, stim_end] stim_start_y = [0, ntrials] stim_end_y = [0, ntrials] plt.plot(stim_start_x, stim_start_y, 'r') plt.plot(stim_end_x, stim_end_y, 'r') plt.title("Bird: " + experiment['name'] + " Cell: " + str(cluid) + " Type: " + str(cell_clugroup) + " Stim: " + stimn) plt.xlabel('Time (s)') plt.ylabel('Trial') plt.xlim(-1.0*prestim, poststim + stim_end) plt.ylim(0, ntrials) save_raster(raster, dest, experiment['name'], cluid, stimn)
def make_cell_groups(spikedata, win_dt, win_n, prestim_dt, fs, clu_group, destdir): stim_names = spf.get_stim_names(spikedata) for stim in stim_names: ntrials = spf.get_num_trials(spikedata, stim) for trial in range(ntrials): debug_print('make_cell_groups: Stim %s, Trial %s...\n' % (stim, trial)) stim_period_vert_list = set() prestim_vert_list = set() debug_print('- Extracting spikes\n') stimtimes = spf.get_stim_times(spikedata, stim, trial) trialdata = spf.find_spikes_by_stim_trial(spikedata, stim, trial) prestimwin = [stimtimes[0] - 2.0, stimtimes[0]] debug_print('- Creating Windows\n') # Subdivide a given time period into windows prestim_cg_win_list = win_subdivide(prestimwin, win_n, win_dt, fs) stim_cg_win_list = win_subdivide(stimtimes, win_n, win_dt, fs) debug_print('- Extracting stim period cell groups\n') for winl, winh in stim_cg_win_list: # debug_print('WinL: %s WinH: %s\n' % (winl, winh)) # Get cell groups cgs = spf.get_cluster_group(trialdata, winl, winh) #debug_print(str(cgs) + '\n') # Convert to tuple and add to the vertex set list. stim_period_vert_list.add(tuple(cgs)) #debug_print('Vert list size: %s\n' % len(stim_period_vert_list)) debug_print('- Extracting prestim period cell groups\n') for winl, winh in prestim_cg_win_list: cgs = spf.get_cluster_group(trialdata, winl, winh) prestim_vert_list.add(tuple(cgs)) debug_print('- Writing perseus input files\n') write_vert_list_to_perseus(stim_period_vert_list, destdir, stim, trial, bird, clu_group) write_vert_list_to_perseus(prestim_vert_list, destdir, 'pretrial'+stim, trial, bird, clu_group) debug_print('DONE\n')