def train_response_plot(expt_list, name=None, summary_plots=[None, None], color=None):
    ind_base_subtract = []
    rec_base_subtract = []
    train_plots = pg.plot()
    train_plots.setLabels(left=('Vm', 'V'))
    tau =15e-3
    lp = 1000
    for expt in expt_list:
        for pre, post in expt.connections:
            if expt.cells[pre].cre_type == cre_type[0] and expt.cells[post].cre_type == cre_type[1]:
                print ('Processing experiment: %s' % (expt.nwb_file))
                ind = []
                rec = []
                analyzer = DynamicsAnalyzer(expt, pre, post)
                train_responses = analyzer.train_responses
                artifact = analyzer.cross_talk()
                if artifact > 0.03e-3:
                    continue
                for i, stim_params in enumerate(train_responses.keys()):
                     rec_t = int(np.round(stim_params[1] * 1e3, -1))
                     if stim_params[0] == 50 and rec_t == 250:
                        pulse_offsets = analyzer.pulse_offsets
                        if len(train_responses[stim_params][0]) != 0:
                            ind_group = train_responses[stim_params][0]
                            rec_group = train_responses[stim_params][1]
                            for j in range(len(ind_group)):
                                ind.append(ind_group.responses[j])
                                rec.append(rec_group.responses[j])
                if len(ind) > 5:
                    ind_avg = TraceList(ind).mean()
                    rec_avg = TraceList(rec).mean()
                    rec_avg.t0 = 0.3
                    base = float_mode(ind_avg.data[:int(10e-3 / ind_avg.dt)])
                    ind_base_subtract.append(ind_avg.copy(data=ind_avg.data - base))
                    rec_base_subtract.append(rec_avg.copy(data=rec_avg.data - base))
                    train_plots.plot(ind_avg.time_values, ind_avg.data - base)
                    train_plots.plot(rec_avg.time_values, rec_avg.data - base)
                    app.processEvents()
    if len(ind_base_subtract) != 0:
        print (name + ' n = %d' % len(ind_base_subtract))
        ind_grand_mean = TraceList(ind_base_subtract).mean()
        rec_grand_mean = TraceList(rec_base_subtract).mean()
        ind_grand_mean_dec = bessel_filter(exp_deconvolve(ind_grand_mean, tau), lp)
        train_plots.addLegend()
        train_plots.plot(ind_grand_mean.time_values, ind_grand_mean.data, pen={'color': 'g', 'width': 3}, name=name)
        train_plots.plot(rec_grand_mean.time_values, rec_grand_mean.data, pen={'color': 'g', 'width': 3}, name=name)
        #train_plots.plot(ind_grand_mean_dec.time_values, ind_grand_mean_dec.data, pen={'color': 'g', 'dash': [1,5,3,2]})
        train_amps = train_amp([ind_base_subtract, rec_base_subtract], pulse_offsets, '+')
        if ind_grand_mean is not None:
            train_plots = summary_plot_train(ind_grand_mean, plot=summary_plots[0], color=color,
                                             name=(legend + ' 50 Hz induction'))
            train_plots = summary_plot_train(rec_grand_mean, plot=summary_plots[0], color=color)
            train_plots2 = summary_plot_train(ind_grand_mean_dec, plot=summary_plots[1], color=color,
                                              name=(legend + ' 50 Hz induction'))
            return train_plots, train_plots2, train_amps
    else:
        print ("No Traces")
        return None
def train_response_plot(expt_list, name=None, summary_plots=[None, None], color=None):
    grand_train = [[], []]
    train_plots = pg.plot()
    train_plots.setLabels(left=('Vm', 'V'))
    tau =15e-3
    lp = 1000
    for expt in expt_list:
        for pre, post in expt.connections:
            if expt.cells[pre].cre_type == cre_type[0] and expt.cells[post].cre_type == cre_type[1]:
                print ('Processing experiment: %s' % (expt.nwb_file))

                train_responses, artifact = get_response(expt, pre, post, analysis_type='train')
                if artifact > 0.03e-3:
                    continue

                train_filter = response_filter(train_responses['responses'], freq_range=[50, 50], train=0, delta_t=250)
                pulse_offsets = response_filter(train_responses['pulse_offsets'], freq_range=[50, 50], train=0, delta_t=250)

                if len(train_filter[0]) > 5:
                    ind_avg = TraceList(train_filter[0]).mean()
                    rec_avg = TraceList(train_filter[1]).mean()
                    rec_avg.t0 = 0.3
                    grand_train[0].append(ind_avg)
                    grand_train[1].append(rec_avg)
                    train_plots.plot(ind_avg.time_values, ind_avg.data)
                    train_plots.plot(rec_avg.time_values, rec_avg.data)
                    app.processEvents()
    if len(grand_train[0]) != 0:
        print (name + ' n = %d' % len(grand_train[0]))
        ind_grand_mean = TraceList(grand_train[0]).mean()
        rec_grand_mean = TraceList(grand_train[1]).mean()
        ind_grand_mean_dec = bessel_filter(exp_deconvolve(ind_grand_mean, tau), lp)
        train_plots.addLegend()
        train_plots.plot(ind_grand_mean.time_values, ind_grand_mean.data, pen={'color': 'g', 'width': 3}, name=name)
        train_plots.plot(rec_grand_mean.time_values, rec_grand_mean.data, pen={'color': 'g', 'width': 3}, name=name)
        train_amps = train_amp([grand_train[0], grand_train[1]], pulse_offsets, '+')
        if ind_grand_mean is not None:
            train_plots = summary_plot_train(ind_grand_mean, plot=summary_plots[0], color=color,
                                             name=(legend + ' 50 Hz induction'))
            train_plots = summary_plot_train(rec_grand_mean, plot=summary_plots[0], color=color)
            train_plots2 = summary_plot_train(ind_grand_mean_dec, plot=summary_plots[1], color=color,
                                              name=(legend + ' 50 Hz induction'))
            return train_plots, train_plots2, train_amps
    else:
        print ("No Traces")
        return None
Ejemplo n.º 3
0
                            trace_color = (0, 0, 0, 30)
                        trace_plot(avg_trace, trace_color, plot=synapse_plot[c, 0], x_range=[0, 27e-3])
                        app.processEvents()
#                    decay_response = response_filter(pulse_response, freq_range=[0, 20], holding_range=holding)
#                    qc_list = pulse_qc(response_subset, baseline=2, pulse=None, plot=qc_plot)
#                    if len(qc_list) >= sweep_threshold:
#                        avg_trace, avg_amp, amp_sign, peak_t = get_amplitude(qc_list)
#                        if amp_sign is '-':
#                            continue
#                        psp_fits = fit_psp(avg_trace, sign=amp_sign, yoffset=0, amp=avg_amp, method='leastsq', stacked = False,  fit_kws={})
#                        grand_response[type[0]]['decay'].append(psp_fits.best_values['decay_tau'])
    if len(grand_response[type[0]]['trace']) == 0:
        continue
    if len(grand_response[type[0]]['trace']) > 1:
        grand_trace = TraceList(grand_response[type[0]]['trace']).mean()
        grand_trace.t0 = 0
    else:
        grand_trace = grand_response[type[0]]['trace'][0]
    n_synapses = len(grand_response[type[0]]['trace'])
    trace_plot(grand_trace, color={'color': color, 'width': 2}, plot=synapse_plot[c, 0], x_range=[0, 27e-3],
               name=('%s, n = %d' % (connection_types[c], n_synapses)))
    synapse_plot[c, 0].hideAxis('bottom')
    # all_amps = np.hstack(np.asarray(grand_response[cre_type[0]]['fail_rate']))
    # y, x = np.histogram(all_amps, bins=np.linspace(0, 2e-3, 40))
    # synapse_plot[c, 1].plot(x, y, stepMode=True, fillLevel=0, brush='k')
    # synapse_plot[c, 1].setLabels(bottom=('Vm', 'V'))
    # synapse_plot[c, 1].setXRange(0, 2e-3)
    print ('%s kinetics n = %d' % (type[0], len(grand_response[type[0]]['latency'])))
    feature_list = (grand_response[type[0]]['amp'], grand_response[type[0]]['CV'], grand_response[type[0]]['latency'],
                    grand_response[type[0]]['rise'])
    labels = (['Vm', 'V'], ['CV', ''], ['t', 's'], ['t', 's'])
def train_response_plot(expt_list,
                        name=None,
                        summary_plots=[None, None],
                        color=None):
    grand_train = [[], []]
    train_plots = pg.plot()
    train_plots.setLabels(left=('Vm', 'V'))
    tau = 15e-3
    lp = 1000
    for expt in expt_list:
        for pre, post in expt.connections:
            if expt.cells[pre].cre_type == cre_type[0] and expt.cells[
                    post].cre_type == cre_type[1]:
                print('Processing experiment: %s' % (expt.nwb_file))

                train_responses, artifact = get_response(expt,
                                                         pre,
                                                         post,
                                                         analysis_type='train')
                if artifact > 0.03e-3:
                    continue

                train_filter = response_filter(train_responses['responses'],
                                               freq_range=[50, 50],
                                               train=0,
                                               delta_t=250)
                pulse_offsets = response_filter(
                    train_responses['pulse_offsets'],
                    freq_range=[50, 50],
                    train=0,
                    delta_t=250)

                if len(train_filter[0]) > 5:
                    ind_avg = TraceList(train_filter[0]).mean()
                    rec_avg = TraceList(train_filter[1]).mean()
                    rec_avg.t0 = 0.3
                    grand_train[0].append(ind_avg)
                    grand_train[1].append(rec_avg)
                    train_plots.plot(ind_avg.time_values, ind_avg.data)
                    train_plots.plot(rec_avg.time_values, rec_avg.data)
                    app.processEvents()
    if len(grand_train[0]) != 0:
        print(name + ' n = %d' % len(grand_train[0]))
        ind_grand_mean = TraceList(grand_train[0]).mean()
        rec_grand_mean = TraceList(grand_train[1]).mean()
        ind_grand_mean_dec = bessel_filter(exp_deconvolve(ind_grand_mean, tau),
                                           lp)
        train_plots.addLegend()
        train_plots.plot(ind_grand_mean.time_values,
                         ind_grand_mean.data,
                         pen={
                             'color': 'g',
                             'width': 3
                         },
                         name=name)
        train_plots.plot(rec_grand_mean.time_values,
                         rec_grand_mean.data,
                         pen={
                             'color': 'g',
                             'width': 3
                         },
                         name=name)
        train_amps = train_amp([grand_train[0], grand_train[1]], pulse_offsets,
                               '+')
        if ind_grand_mean is not None:
            train_plots = summary_plot_train(ind_grand_mean,
                                             plot=summary_plots[0],
                                             color=color,
                                             name=(legend +
                                                   ' 50 Hz induction'))
            train_plots = summary_plot_train(rec_grand_mean,
                                             plot=summary_plots[0],
                                             color=color)
            train_plots2 = summary_plot_train(ind_grand_mean_dec,
                                              plot=summary_plots[1],
                                              color=color,
                                              name=(legend +
                                                    ' 50 Hz induction'))
            return train_plots, train_plots2, train_amps
    else:
        print("No Traces")
        return None
Ejemplo n.º 5
0
                                                       pre_spike.dt)])
             sweep_list['response'].append(
                 sweep_trace.copy(data=sweep_trace.data - post_base))
             sweep_list['spike'].append(
                 pre_spike.copy(data=pre_spike.data - pre_base))
 if len(sweep_list['response']) > 5:
     n = len(sweep_list['response'])
     if plot_sweeps is True:
         for sweep in range(n):
             current_sweep = sweep_list['response'][sweep]
             current_sweep.t0 = 0
             grid[row[1], 0].plot(current_sweep.time_values,
                                  current_sweep.data,
                                  pen=sweep_color)
     avg_first_pulse = TraceList(sweep_list['response']).mean()
     avg_first_pulse.t0 = 0
     avg_spike = TraceList(sweep_list['spike']).mean()
     avg_spike.t0 = 0
     grid[row[1], 0].setLabels(left=('Vm', 'V'))
     grid[row[1], 0].setLabels(bottom=('t', 's'))
     grid[row[1], 0].setXRange(-2e-3, 27e-3)
     grid[row[1], 0].plot(avg_first_pulse.time_values,
                          avg_first_pulse.data,
                          pen={
                              'color': (255, 0, 255),
                              'width': 2
                          })
     grid[row[0], 0].setLabels(left=('Vm', 'V'))
     sweep_list['spike'][0].t0 = 0
     grid[row[0], 0].plot(avg_spike.time_values, avg_spike.data, pen='k')
     grid[row[0], 0].setXLink(grid[row[1], 0])