def calc_field(all_params, seg_coords,results_sim): # run the simulation for t_length print 'simulate neuron' grid_size = all_params['grid_size'] external_resistivity = all_params['external_resistivity'] record_x_range = all_params[ 'record_x_range'] # the grid with defined cells might be of different size that the one where we calculate record_y_range = all_params['record_y_range'] # estimates the field in every defined point of the grid print 'estimate the field' n_samp = grid_size # grid size will be n_samp x n_samp xx, yy = field.calc_grid(record_x_range, record_y_range, n_samp) # define grid v_ext = field.estimate_on_grid(seg_coords, results_sim['I'], xx, yy, eta=external_resistivity) # find dipole moment for this cell Q = field.calc_dipole_moment(seg_coords, results_sim['I_axial']) Q_len = np.sqrt(np.sum(Q ** 2, 0)) results_sim = {'xx': xx, # grid xx 'yy': yy, # grid yy 'Q': Q, # dipole 'Q_len': Q_len, # dipole length 'v_ext': np.array(v_ext), # potential 'seg_coords': seg_coords} return results_sim
def show_potential_on_grid(cable, I): import matplotlib.pyplot as plt xx, yy = field.calc_grid([-10, 10], [-10, 10], 10) v_ext = field.estimate_on_grid(cable, I, xx, yy) cs = plt.contour(xx, yy, v_ext[0, :, :]) plt.clabel(cs) plt.show()
def show_potential_on_grid(cable, I): import matplotlib.pyplot as plt xx, yy = field.calc_grid([-10,10], [-10,10], 10) v_ext = field.estimate_on_grid(cable, I, xx, yy) cs=plt.contour(xx, yy, v_ext[0,:,:]) plt.clabel(cs) plt.show()
def calc_field(data, record_x_range, record_y_range, n_samp, savename): ext_resist = 3.5 # Ohm.m dt = data['dt'] I = data['I'] t=data['t'] seg_coords=data['seg_coords'] xx, yy = field.calc_grid(record_x_range, record_y_range, n_samp) # define grid v_ext = field.estimate_on_grid(seg_coords, I, xx, yy, eta=ext_resist) # field # save calculated lfp np.savez(savename+'.npz', v_ext=v_ext, xx=xx,yy=yy, n_samp=n_samp, dt=dt, x_range = record_x_range, y_range = record_y_range, t=t)
#filter = None pt_idx = 1094 filter = field.hp_fir(order, cutoff, dt) # Simulation cell.load_model('models/Mainen/demo_ext.hoc', 'models/Mainen/%s/.libs/libnrnmech.so' % ARCH) cell.initialize(dt=dt) t, I = cell.integrate(tstop) # Calculation of field xrange = np.array([-600, 600])-150 yrange = [-1500, 600] coords = cell.get_seg_coords() xx, yy = field.calc_grid(xrange, yrange, n_samp=Nsamp) v_ext = field.estimate_on_grid(coords, I, xx, yy) if filter: for i in range(v_ext.shape[1]): for j in range(v_ext.shape[2]): v_ext[:, i, j] = filter(v_ext[:, i, j]) #sample spike waveforms spikes = np.mgrid[xrange[0]:xrange[1]:n_waveforms*1j, yrange[0]:yrange[1]:n_waveforms*1j] xx_sp, yy_sp = spikes xx_sp, yy_sp = xx_sp.flatten(), yy_sp.flatten() xx_sp, yy_sp = xx_sp[:, np.newaxis], yy_sp[:, np.newaxis] v_samples = field.estimate_on_grid(coords, I, xx_sp, yy_sp)
def plot_contour(x_range, y_range, n_contours=15): xx, yy = field.calc_grid(x_range, y_range, n_samp=Nsamp) vext = field.estimate_on_grid(coords, I, xx, yy) vext_p2p = vext.max(0) - vext.min(0) graph.logcontour(xx, yy, vext_p2p / 1000., n_contours=n_contours, linecolors='0.8', linewidths=1, unit=r'$\mathrm{\mu}$V', fontsize=8)
# Simulation cell.load_model('models/Mainen/demo_ext.hoc', 'models/Mainen/i686/.libs/libnrnmech.so') cell.initialize(dt=dt) t, I = cell.integrate(tstop) tmin, tmax = win I = I[(t>tmin) & (t<tmax), :] t = t[(t>tmin) & (t<tmax)] # Calculation of field xrange = [-3000, 3000] yrange = [-3000, 3000] coords = cell.get_seg_coords() xx, yy = field.calc_grid(xrange, yrange, n_samp=Nsamp) v_ext = field.estimate_on_grid(coords, I, xx, yy) #Filter filter = field.hp_fir(order, cutoff, dt) if filter: for i in range(v_ext.shape[1]): for j in range(v_ext.shape[2]): v_ext[:, i, j] = filter(v_ext[:, i, j]) n_frames = 9 n_timepts = v_ext.shape[0] shift = n_timepts/n_frames fig = plt.figure()
cell.initialize(dt=dt) t, I_cell = cell.integrate(t_length, i_axial=False, neuron_cells=cells) # CALCULATION OF THE FIELD seg_coords = cell.get_seg_coords() n_samp = 40 x_range = [-210, 430] y_range = [-255, 725] # define grid xx, yy = field.calc_grid(x_range, y_range, n_samp) # join the currents together I = I_cell.swapaxes(0, 1).reshape(I_cell.shape[1], -1) v_ext = field.estimate_on_grid(seg_coords, I, xx, yy) # PLOTS synapses = [s for s in cell.get_point_processes()] # plot neurons shape graph.plot_neuron(seg_coords, colors='0.4') # plot field potential plt.imshow((v_ext[time_to_plot, :, :]), interpolation="nearest", extent=(x_range[0], x_range[1], y_range[0], y_range[1]), origin='lower') cbar = plt.colorbar() plt.xlabel(r'$\mu m$')
#filter = None pt_idx = 1094 filter = field.hp_fir(order, cutoff, dt) # Simulation cell.load_model('models/Mainen/demo_ext.hoc', 'models/Mainen/%s/.libs/libnrnmech.so' % ARCH) cell.initialize(dt=dt) t, I = cell.integrate(tstop) # Calculation of field xrange = np.array([-600, 600]) - 150 yrange = [-1500, 600] coords = cell.get_seg_coords() xx, yy = field.calc_grid(xrange, yrange, n_samp=Nsamp) v_ext = field.estimate_on_grid(coords, I, xx, yy) if filter: for i in range(v_ext.shape[1]): for j in range(v_ext.shape[2]): v_ext[:, i, j] = filter(v_ext[:, i, j]) #sample spike waveforms spikes = np.mgrid[xrange[0]:xrange[1]:n_waveforms * 1j, yrange[0]:yrange[1]:n_waveforms * 1j] xx_sp, yy_sp = spikes xx_sp, yy_sp = xx_sp.flatten(), yy_sp.flatten() xx_sp, yy_sp = xx_sp[:, np.newaxis], yy_sp[:, np.newaxis] v_samples = field.estimate_on_grid(coords, I, xx_sp, yy_sp)