def get_current(self): # generate current traces currents = currents_given_v(self.fitter.data.v.values, self.fitter.data.t.values, self.fitter.cell.soma, self.channel_list, self.ion_list, self.fitter.simulation_params['celsius']) # mA/cm**2 # convert units cell_area = get_cellarea(convert_unit_prefix('u', self.fitter.cell.soma.L), convert_unit_prefix('u', self.fitter.cell.soma.diam)) # m**2 currents = convert_unit_prefix('da', currents) * cell_area # A return currents
def solve(candidate): # vclamp currents # channel_list = list(set([problem.path_variables[i][0][2] for i in range(len(problem.path_variables))])) # only works if channel name is at 2 second position in the path! channel_list = ["na8st", "kdr", "pas"] ion_list = get_ionlist(channel_list) celsius = problem.simulation_params["celsius"] dt = problem.simulation_params["dt"] t = problem.data.t.values v = problem.data.v.values i_inj = problem.data.i.values problem.update_cell(candidate) currents = currents_given_v(v, t, problem.cell.soma, channel_list, ion_list, celsius, plot=False) dvdt = np.concatenate((np.array([(v[1] - v[0]) / dt]), np.diff(v) / dt)) # unit conversion dvdt_sc, i_inj_sc, currents_sc, Cm, _ = convert_units( problem.cell.soma.L, problem.cell.soma.diam, problem.cell.soma.cm, dvdt, i_inj, currents ) cmdvdt_sc = dvdt_sc * Cm i_ion_sc = np.sum(currents_sc, 0) # hh equation hh_eq = cmdvdt_sc - i_inj_sc + i_ion_sc # pick points (e.g. where current traces diverge or during current injection) current_start = np.nonzero(i_inj)[0][0] dist = int(np.round(0.5 / dt, 0)) n_points = len(problem.path_variables) points = np.arange(current_start, n_points * dist + dist, dist) points = np.array( [int(np.round(10.8 / dt)), int(np.round(11.35 / dt)), int(np.round(11.5 / dt)), int(np.round(12.0 / dt))] ) # TODO depends on data int(np.round(10.4/dt)), hh_eq_points = hh_eq[points] # TODO # pl.figure() # pl.plot(t, cmdvdt_sc-i_inj_sc, 'k') # pl.plot(t, -i_ion_sc, 'b') # pl.plot(t[points], (cmdvdt_sc-i_inj_sc)[points], 'yo') # pl.plot(t[points], -i_ion_sc[points], 'ro') # pl.show() return hh_eq_points
currents = [problem.cell.soma.record_from(channel_list[k], 'i'+ion_list[k], pos=.5) for k in range(len(channel_list))] v_newdt, t_newdt = run_simulation(problem.cell, **problem.simulation_params) #pl.figure() #pl.plot(t_newdt, v_newdt) #pl.show() # compute parameter 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))
for trial in range(0, n_trials): # get current traces v_exp = problem.data.v.values t_exp = problem.data.t.values i_exp = problem.data.i.values dt = t_exp[1] - t_exp[0] dvdt = np.concatenate((np.array([(v_exp[1]-v_exp[0])/dt]), np.diff(v_exp) / dt)) candidate = np.ones(len(problem.path_variables)) problem.update_cell(candidate) channel_list = get_channel_list(problem.cell, 'soma') ion_list = get_ionlist(channel_list) celsius = problem.simulation_params['celsius'] currents = currents_given_v(v_exp, t_exp, problem.cell.soma, channel_list, ion_list, celsius) # convert units dvdt_sc, i_inj_sc, currents_sc, Cm, cell_area = convert_units(problem.cell.soma.L, problem.cell.soma.diam, problem.cell.soma.cm, dvdt, i_exp, currents) # 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