dvdt_cut = dvdt_sc[idx_start:idx_end] t_cut = t_exp[idx_start:idx_end] i_exp_cut = i_inj_sc[idx_start:idx_end] currents_cut = np.zeros(len(t_cut)) # linear regression weights, residual, y, X = linear_regression(dvdt_cut, i_exp_cut, currents_cut, i_pas=0, cell_area=cell_area) # plots pl.figure() pl.plot(t_exp, dvdt_exp, 'k') pl.plot(t_cut, dvdt_cut, 'r') pl.title('Visualize cut of dV/dt') pl.show() plot_fit(y, X, weights, t_cut, []) # transform into change in cell area # 1) area_new = area_old * cm_fit area_new = cell_area * weights[-1] # 2) r=L = np.sqrt(area_new / (2*np.pi*1e-8)) r = np.sqrt(area_new / (2*np.pi*1e-8)) L = np.sqrt(area_new / (2*np.pi*1e-8)) # 3) diam = 2*r diam = 2*r fitter.cell.soma.L = L fitter.cell.soma.diam = diam cell_area = fitter.cell.soma(.5).area() * 1e-8 print 'L: ' + str(L) print 'diam: ' + str(diam) print 'cell area: ' + str(cell_area * 1e8)
# linear regression weights, residual, y, X = linear_regression(dvdt_sc, i_inj_sc, currents_sc, i_pas=0, Cm=Cm) #weights, residual, y, X = linear_regression(dvdt_sc, i_inj_sc, currents_sc, i_pas=0, Cm=None, cell_area=cell_area) # output print 'channels: ' + str(channel_list) print 'weights: ' + str(weights) # plot fit # plot in three parts merge_points = [0, 22999, 26240, 550528] for i in range(len(merge_points)-1): y_plot = y[merge_points[i]:merge_points[i+1]] X_plot = X[merge_points[i]:merge_points[i+1], :] t_plot = t_exp[merge_points[i]:merge_points[i+1]] plot_fit(y_plot, X_plot, weights, t_plot, channel_list, save_dir=save_dir+str(i)) # save np.savetxt(save_dir+'/best_candidate_'+str(trial)+'.txt', weights) np.savetxt(save_dir+'/error_'+str(trial)+'.txt', np.array([residual])) # simulate #cm = weights[-1] for i, w in enumerate(weights[:]): keys = ['soma', '0.5', channel_list[i], 'gbar'] if channel_list[i] == 'pas': keys = ['soma', '0.5', channel_list[i], 'g'] problem.cell.update_attr(keys, w) elif 'ion' in channel_list[i]: keys = None else: