Exemplo n.º 1
0
def plot_spike_amplitudes(obj, pid, uid, axis):
    units = obj.units
    frameTimes = obj.frameAppearTimes
    last_behavior_time = obj.lastBehaviorTime

    spikes = units[pid][uid]['times']
    amplitudes = units[pid][uid]['amplitudes']

    num_spikes_to_plot = 1000.
    if spikes.size > num_spikes_to_plot:
        num_spikes_to_skip = int(spikes.size / num_spikes_to_plot)
    else:
        num_spikes_to_skip = 1

    axis.plot(amplitudes[::num_spikes_to_skip],
              frameTimes[-1] - spikes[::num_spikes_to_skip],
              'ko',
              alpha=0.2)

    axis.set_ylim([0, int(frameTimes[-1])])
    axis.set_yticks([0, int(frameTimes[-1])])
    axis.set_yticklabels([int(frameTimes[-1]), 0])
    axis.plot([axis.get_xlim()[0], axis.get_xlim()[1]], [
        frameTimes[-1] - last_behavior_time,
        frameTimes[-1] - last_behavior_time
    ], 'k--')
    formatFigure(plt.gcf(),
                 axis,
                 xLabel='Template Scale Factor',
                 yLabel='Time (s)')
    axis.yaxis.labelpad = -20
Exemplo n.º 2
0
def plot_lick_triggered_fr(obj,
                           spikes,
                           axis=None,
                           min_inter_lick_time=0.5,
                           preTime=1,
                           postTime=2,
                           plot=True,
                           sdfSigma=0.01,
                           returnSDF=False):
    if axis is None and plot:
        fig, axis = plt.subplots()

    frameTimes = obj.frameAppearTimes

    trial_start_frames = np.array(obj.trials['startframe'])
    trial_end_frames = np.array(obj.trials['endframe'])
    trial_start_times = frameTimes[trial_start_frames]
    trial_end_times = frameTimes[trial_end_frames]

    lick_times = probeSync.get_sync_line_data(obj.syncDataset,
                                              'lick_sensor')[0]
    first_lick_times = lick_times[np.insert(
        np.diff(lick_times) >= min_inter_lick_time, 0, True)]
    first_lick_trials = analysis_utils.get_trial_by_time(
        first_lick_times, trial_start_times, trial_end_times)

    #    hit = np.array(obj.trials['response_type']=='HIT')
    #    earlyResponse = np.array(obj.trials['response_type']=='EARLY_RESPONSE')
    #    falseAlarm = np.array(obj.trials['response_type']=='FA')
    hit = obj.hit
    earlyResponse = obj.earlyResponse
    falseAlarm = obj.falseAlarm

    hit_lick_times = first_lick_times[np.where(hit[first_lick_trials])[0]]
    bad_lick_times = first_lick_times[np.where(
        falseAlarm[first_lick_trials] | earlyResponse[first_lick_trials])[0]]

    hit_psth, t = analysis_utils.getSDF(spikes,
                                        hit_lick_times - preTime,
                                        preTime + postTime,
                                        sigma=sdfSigma)
    bad_psth, t = analysis_utils.getSDF(spikes,
                                        bad_lick_times - preTime,
                                        preTime + postTime,
                                        sigma=sdfSigma)

    if plot:
        hit, = axis.plot(t - 1, hit_psth, 'k')
        bad, = axis.plot(t - 1, bad_psth, 'r')
        axis.legend((hit, bad), ('hit', 'aborted/FA'),
                    loc='best',
                    prop={'size': 8})
        formatFigure(plt.gcf(),
                     axis,
                     xLabel='Time to lick (s)',
                     yLabel='Lick-Trig. FR (Hz)')
        axis.plot([0, 0], axis.get_ylim(), 'k--')

    if returnSDF:
        return hit_psth, bad_psth
Exemplo n.º 3
0
def plot_run_triggered_fr(obj, spikes, axis=None, preTime=1, postTime=2): 
    if axis is None:
        fig, axis = plt.subplots()
        
    if len(obj.behaviorRunStartTimes)>0:
        run_psth, t = analysis_utils.getSDF(spikes,obj.behaviorRunStartTimes-preTime,preTime+postTime)
        axis.plot(t-1,run_psth, 'k')
        axis.plot([0,0], axis.get_ylim(), 'k--')
        formatFigure(plt.gcf(), axis, xLabel='Time to run (s)', yLabel='Run-Trig. FR (Hz)')
Exemplo n.º 4
0
                'number of mice'
            ])):
        if i < len(axes) - 1:
            metricmean = np.nanmean(
                metric[:, num_mice_qualifying >= min_num_mice], axis=0)
            metricsem = np.nanstd(
                metric[:, num_mice_qualifying >= min_num_mice], axis=0
            ) / (num_mice_qualifying[num_mice_qualifying >= min_num_mice])**0.5
            ax.plot(metricmean, color + 'o-')
            ax.fill_between(np.arange(metricmean.size),
                            metricmean - metricsem,
                            metricmean + metricsem,
                            color=color,
                            alpha=0.5)
            ax.set_xticks([], [])
            formatFigure(fig, ax, yLabel=title)
        else:
            ax.plot(metric[num_mice_qualifying >= min_num_mice], color)
            formatFigure(fig, ax, xLabel=xlabel, yLabel=title)
    fig.tight_layout()
    all_axes.append(axes)

for a1, a2 in zip(*all_axes):
    amin = np.min([a1.get_ylim(), a2.get_ylim()])
    amax = np.max([a1.get_ylim(), a2.get_ylim()])

    a1.set_ylim([amin, amax])
    a2.set_ylim([amin, amax])

###### Running over training ###########
for mousenum in np.arange(len(trainingDate)):
Exemplo n.º 5
0
        firstLickLatencies = firstLickLatencies[firstLickLatencies < 1]

        fig, ax = plt.subplots()
        fig.suptitle(exp)
        ax.hist(firstLickLatencies, 500)
        lickLatencies_session.append(firstLickLatencies)
        lickLatencies_all.extend(firstLickLatencies)

lickLatencies_all = np.array(lickLatencies_all)

fig, ax = plt.subplots()
bins = np.linspace(0, 1, 200)
ax.hist(lickLatencies_all[lickLatencies_all < 0.15], bins, color='0.5')
ax.hist(lickLatencies_all[(0.15 < lickLatencies_all)
                          & (lickLatencies_all < 0.75)],
        bins,
        color='g')
ax.hist(lickLatencies_all[0.75 < lickLatencies_all], bins, color='r')
ax.set_xticks(np.arange(0, 1, 0.25))
ax.set_yticks(np.arange(0, 100, round(lickLatencies_all.size / 100)))
ax.set_yticklabels(
    np.round(
        np.arange(0, 100, round(lickLatencies_all.size / 100)) /
        lickLatencies_all.size, 2))

formatFigure(fig,
             ax,
             xLabel='Time from Change (s)',
             yLabel='Fraction of licks')
Exemplo n.º 6
0
            
            np.save(os.path.join(figSaveDir, t + 'to' + s + '_' + state + '_lagdist.npy'), peak_pos)
            #ccg_lag_array[istate][isrc][itgt] = peak_pos
            ccg_lag_median_array[istate][isrc][itgt] = np.nanmedian(peak_pos)
            #ax.hist(peak_pos-10, bins=21)
            
            #ccg_peak_array[istate][isrc][itgt] = np.max(thismean_conv[175:225])
            all_ccgs[istate].append(thismean_conv)
            if plot:
                x = np.linspace(-200, 200, 401)
                ax.plot(x,thismean_conv, color)
                ax.fill_between(x, thismean_conv-thissem_conv, thismean_conv+thissem_conv, color=color, alpha=0.5)
                ax.set_xlim([-25, 25])
                if istate==1:
                    ax.text(-10, ax.get_ylim()[1]*0.9, 'n = ' + str(ccg_mean_conv.shape[0]))
                    formatFigure(fig, ax, xLabel='Time (ms)', yLabel='Coincidence per spike')
                    fig.savefig(os.path.join(figSaveDir, t + ' to ' + s + '.pdf'))
                
                
ccg_peak_array = np.array(ccg_peak_array)               
ccg_lag_array = np.array(ccg_lag_array)
ccg_lag_median_array = np.array(ccg_lag_median_array)
ccg_count_array = np.array(ccg_count_array)

plt.figure()
plt.plot(np.mean(all_ccgs[0],axis=0), 'r')
plt.plot(np.mean(all_ccgs[1],axis=0), 'b')

ccg_peak_array = np.array(ccg_peak_array)
diff = ccg_peak_array[0] - ccg_peak_array[1]
ratio = ccg_peak_array[0]/ccg_peak_array[1]
min_num_mice = 5
all_axes = []
for numsessions, rewards, dprime, engaged, color, title, xlabel in ([num_handoff_nsb_sessions, handoff_nsb_rewards, handoff_nsb_dprime, handoff_nsb_probEngaged, 'k', 'NSB', 'Sessions from handoff ready'], [num_rig_sessions, rig_rewards, rig_dprime, rig_probEngaged, 'g', 'NP3', 'Sessions from NSB handoff']):
    num_mice_qualifying = np.array([np.sum(numsessions>nn) for nn in range(numsessions.max())])
    
    fig, axes = plt.subplots(4, 1)
    fig.suptitle(title)
    fig.set_size_inches(6,12)
    for i, (ax, metric, title) in enumerate(zip(axes, [rewards, dprime, engaged, num_mice_qualifying], ['rewards earned', 'dprime engaged', 'fraction engaged', 'number of mice'])):
        if i<len(axes)-1:
            metricmean = np.nanmean(metric[:, num_mice_qualifying>=min_num_mice], axis=0)
            metricsem = np.nanstd(metric[:, num_mice_qualifying>=min_num_mice], axis=0)/(num_mice_qualifying[num_mice_qualifying>=min_num_mice])**0.5
            ax.plot(metricmean, color +'o-')
            ax.fill_between(np.arange(metricmean.size), metricmean-metricsem, metricmean+metricsem, color=color, alpha=0.5)
            ax.set_xticks([],[])
            formatFigure(fig,ax, yLabel=title)
        else:
            ax.plot(metric[num_mice_qualifying>=min_num_mice], color)
            formatFigure(fig,ax, xLabel=xlabel, yLabel=title)
    fig.tight_layout()
    all_axes.append(axes)
    
    
for a1, a2 in zip(*all_axes):
    amin = np.min([a1.get_ylim(), a2.get_ylim()])
    amax = np.max([a1.get_ylim(), a2.get_ylim()])
    
    a1.set_ylim([amin, amax])
    a2.set_ylim([amin, amax])