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
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
p2 = trace_plot(grand_pulse_trace, color=avg_color, plot=p2, x_range=[0, 27e-3], name=('n = %d' % len(grand_pulse_response))) if len(grand_induction) > 0: for f, freq in enumerate(freqs): if freq in grand_induction: offset = offset_ind[freq] ind_pass_qc = train_qc(grand_induction[freq], offset, amp=amp_thresh, sign=sign) n = len(ind_pass_qc[0]) if n > 0: ind_amp = train_amp(ind_pass_qc, offset, sign) grand_ind_amp = np.nanmean(ind_amp, 0) ind_amp_sem = stats.sem(ind_amp) if freq not in ind_index.keys(): ind_index[freq] = {} if key not in ind_index[freq].keys(): ind_index[freq][key] = [] for n in range(ind_amp.shape[0]): ind_index[freq][key].append(ind_amp[n, 7] / ind_amp[n, 0]) if freq == 50: grand_ind_trace = TSeriesList( ind_pass_qc[0]).mean() grand_rec_trace = TSeriesList( ind_pass_qc[1]).mean() for ind in ind_pass_qc[0]:
for f, freq in enumerate(freqs): if freq not in induction_grand.keys(): print("%d Hz not represented in data set for %s" % (freq, c_type)) continue ind_offsets = pulse_offset_ind[freq] qc_plot.clear() ind_pass_qc = train_qc(induction_grand[freq], ind_offsets, amp=qc_params[1][c], sign=qc_params[0], plot=qc_plot) n_synapses = len(ind_pass_qc[0]) if n_synapses > 0: induction_grand_trace = TraceList(ind_pass_qc[0]).mean() ind_rec_grand_trace = TraceList(ind_pass_qc[1]).mean() ind_amp = train_amp(ind_pass_qc, ind_offsets, '+') ind_amp_grand = np.nanmean(ind_amp, 0) if f == 0: ind_plot[f, c].setTitle(connection_types[c]) type = pg.LabelItem('%s -> %s' % connection_types[c]) type.setParentItem(summary_plot[c, 0]) type.setPos(50, 0) if c == 0: label = pg.LabelItem('%d Hz Induction' % freq) label.setParentItem(ind_plot[f, c].vb) label.setPos(50, 0) summary_plot[c, 0].setTitle('Induction') ind_plot[f, c].addLegend() [ ind_plot[f, c].plot(ind.time_values, ind.data, pen=trace_color)
uid=(expt.uid, pre, post)) recovery_grand, pulse_offset_rec = recovery_summary(train_response, rec_t, holding, thresh=sweep_threshold, rec_dict=recovery_grand, offset_dict=pulse_offset_rec, uid=(expt.uid, pre, post)) for f, freq in enumerate(freqs): if freq not in induction_grand.keys(): print ("%d Hz not represented in data set for %s" % (freq, c_type)) continue ind_offsets = pulse_offset_ind[freq] qc_plot.clear() ind_pass_qc = train_qc(induction_grand[freq], ind_offsets, amp=qc_params[1][c], sign=qc_params[0], plot=qc_plot) n_synapses = len(ind_pass_qc[0]) if n_synapses > 0: induction_grand_trace = TraceList(ind_pass_qc[0]).mean() ind_rec_grand_trace = TraceList(ind_pass_qc[1]).mean() ind_amp = train_amp(ind_pass_qc, ind_offsets, '+') ind_amp_grand = np.nanmean(ind_amp, 0) if f == 0: ind_plot[f, c].setTitle(connection_types[c]) type = pg.LabelItem('%s -> %s' % connection_types[c]) type.setParentItem(summary_plot[c, 0]) type.setPos(50, 0) if c == 0: label = pg.LabelItem('%d Hz Induction' % freq) label.setParentItem(ind_plot[f, c].vb) label.setPos(50, 0) summary_plot[c, 0].setTitle('Induction') ind_plot[f, c].addLegend() [ind_plot[f, c].plot(ind.time_values, ind.data, pen=trace_color) for ind in ind_pass_qc[0]] [ind_plot[f, c].plot(rec.time_values, rec.data, pen=trace_color) for rec in ind_pass_qc[1]]