# convert units dvdt_sc, i_inj_sc, _, _, cell_area = convert_units(fitter.cell.soma.L, fitter.cell.soma.diam, fitter.cell.soma.cm, dvdt_exp, i_exp, np.zeros(len(t_exp))) # extract part of current injection current_inj = np.nonzero(i_exp)[0] idx_start = current_inj[0] idx_end = current_inj[-1] / dt_exp 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))
dvdt_newdt = np.concatenate((np.array([(v_newdt[1]-v_newdt[0])/dt]), np.diff(v_newdt)/dt)) i_newdt = data_newdt.i.values celsius = problem.simulation_params['celsius'] # get currents candidate = np.ones(len(problem.path_variables)) # gbars should be 1 problem.update_cell(candidate) currents_newdt = currents_given_v(v_newdt, t_newdt, problem.cell.soma, channel_list, ion_list, celsius) # convert units dvdt_sc, i_inj_sc, currents_sc, Cm, _ = convert_units(problem.cell.soma.L, problem.cell.soma.diam, problem.cell.soma.cm, dvdt_newdt, i_newdt, currents_newdt) # linear regression weights, residual, y, X = linear_regression(dvdt_sc, i_inj_sc, currents_sc, i_pas=0, Cm=Cm) # plots #plot_fit(y, X, weights, t_newdt, channel_list) # compute error error_traces[i, j] = rms(y, np.sum(np.array(currents), 0)) error_tmp = [rms(weights_model[k], weights[k]) for k in range(len(weights_model))] error_weights[i, j] = np.mean(error_tmp) # compute mean error of all models print for j, dt in enumerate(dts): print 'Mean error in the weights with dt = '+str(dt)+' ms: ' \