示例#1
0
    def setUpClass(cls):
        sc = 1e6
        #Very branchy neuron (for testing morphology loop)
        cls.data = LoadData(os.path.join(sample_data_path, "gang_7x7_200"))
        cls.data.morphology[:,2:6] = cls.data.morphology[:,2:6]/sc
        n_src = 1000
        cls.cell = sKCSDcell(cls.data.morphology,cls.data.ele_pos/sc,n_src)
        cls.branch_points = []
        for loop in cls.cell.loops:
            if loop[0] != loop[1]+1 and loop[0] != loop[1]-1:
                cls.branch_points.append(loop.tolist())
        cls.morpho = cls.cell.morphology[:,2:5]
        cls.coor3D, cls.zero = cls.cell.point_coordinates(cls.morpho)

        #ball and stick neuron
        data = LoadData(os.path.join(sample_data_path, "ball_and_stick_8"))
        data.morphology[:,2:6] = data.morphology[:,2:6]/sc
        cls.cell_small = sKCSDcell(data.morphology,data.ele_pos/sc, 104)
        cls.cell_small_segment_coordinates_loops = cls.cell_small.coordinates_3D_loops()
        cls.small_points = np.zeros((len(cls.cell_small.morphology),))
        dic = cls.cell_small_segment_coordinates_loops
        for seg in dic:
            ps = dic[seg]
            for p in ps:
                cls.small_points[p[2]] += 1
        cls.cell_small_segment_coordinates = cls.cell_small.coordinates_3D_segments()

        #Y-shaped neuron
        data = LoadData(os.path.join(sample_data_path, "Y_shaped_neuron"))
        data.morphology[:,2:6] = data.morphology[:,2:6]/sc
        cls.cell_y = sKCSDcell(data.morphology,data.ele_pos/sc, 200)
        cls.cell_y_segment_coordinates_loops = cls.cell_y.coordinates_3D_loops()
        cls.cell_y_segment_coordinates = cls.cell_y.coordinates_3D_segments()
示例#2
0
def make_larger_cell(data, n_sources=n_src):
    if data.ele_pos[:, 0].max() > data.morphology[:, 2].max():
        xmax = data.ele_pos[:, 0].max() + 50e-6
    else:
        xmax = data.morphology[:, 2].max() + 50e-6
    if data.ele_pos[:, 0].min() < data.morphology[:, 2].min():
        xmin = data.ele_pos[:, 0].min() - 50e-6
    else:
        xmin = data.morphology[:, 2].min() - 50e-6
    
    if data.ele_pos[:, 1].max() > data.morphology[:, 3].max():
        ymax = data.ele_pos[:, 1].max() + 50e-6
    else:
        ymax = data.morphology[:, 3].max() + 50e-6
    if data.ele_pos[:, 1].min() < data.morphology[:, 3].min():
        ymin = data.ele_pos[:, 1].min() - 50e-6
    else:
        ymin = data.morphology[:, 3].min() - 50e-6

    if data.ele_pos[:, 2].max() > data.morphology[:, 4].max():
        zmax = data.ele_pos[:, 2].max() + 50e-6
    else:
        zmax = data.morphology[:, 4].max() + 50e-6
    if data.ele_pos[:, 2].min() < data.morphology[:, 4].min():
        zmin = data.ele_pos[:, 2].min() - 50e-6
    else:
        zmin = data.morphology[:, 4].min() - 50e-6
   
    return sKCSDcell(data.morphology, data.ele_pos, n_sources, xmin=xmin, xmax=xmax, zmin=zmin, zmax=zmax, ymin=ymin, ymax=ymax, tolerance=2e-6)
示例#3
0
def load_sim(path):
    """
    Load sKCSD estimation results (CSD, potential and cell specifics).
    
    Parameters
    ----------
    path: str

    Returns
    -------
    est_csd : np.array
    est_pot : np.array
    cell_obj : sKCSDcell object
    """
    est_csd = np.load(os.path.join(path, "csd.npy"))
    est_pot = np.load(os.path.join(path, "pot.npy"))
    try:
        with open(os.path.join(path, "cell_data"), 'r') as handle:
            cell_data = json.load(handle)
    except Exception as error:
        print('Could not load', os.path.join(path, "cell_data"))
        return est_csd, est_pot, None
    morphology = np.array(cell_data['morphology'])
    ele_pos = np.array(cell_data['ele_pos'])
    cell_obj = kcsd.sKCSDcell(morphology, ele_pos, cell_data['n_src'])
    return est_csd, est_pot, cell_obj
def load_sim(path):
    """
    Load sKCSD estimation results (CSD, potential and cell specifics).
    
    Parameters
    ----------
    path: str

    Returns
    -------
    est_csd : np.array
    est_pot : np.array
    cell_obj : sKCSDcell object
    """
    est_csd = np.load(os.path.join(path, "csd.npy"))
    est_pot = np.load(os.path.join(path, "pot.npy"))
    try:
        with open(os.path.join(path, "cell_data"), 'r') as handle:
            cell_data = json.load(handle)
    except Exception as error:
        print('Could not load', os.path.join(path, "cell_data"))
        return est_csd, est_pot, None
    morphology = np.array(cell_data['morphology'])
    ele_pos = np.array(cell_data['ele_pos'])
    cell_obj = kcsd.sKCSDcell(morphology, ele_pos, cell_data['n_src'])
    return est_csd, est_pot, cell_obj
示例#5
0
    def setUpClass(cls):
        sc = 1e6
        #Very branchy neuron (for testing morphology loop)
        cls.data = LoadData(os.path.join(sample_data_path, "gang_7x7_200"))
        cls.data.morphology[:,2:6] = cls.data.morphology[:,2:6]/sc
        n_src = 1000
        cls.cell = sKCSDcell(cls.data.morphology,cls.data.ele_pos/sc,n_src)
        cls.cell.distribute_srcs_3D_morph()
        cls.branch_points = []
        for loop in cls.cell.loops:
            if loop[0] != loop[1]+1 and loop[0] != loop[1]-1:
                cls.branch_points.append(loop.tolist())

        cls.morpho = cls.cell.morphology[:,2:5]
        cls.coor3D, cls.zero = cls.cell.point_coordinates(cls.morpho)

        #ball and stick neuron
        data = LoadData(os.path.join(sample_data_path, "ball_and_stick_8"))
        data.morphology[:,2:6] = data.morphology[:,2:6]/sc
        cls.cell_small = sKCSDcell(data.morphology,data.ele_pos/sc,10)
        cls.cell_small.distribute_srcs_3D_morph()
        cls.cell_small_segment_coordinates_loops = cls.cell_small.coordinates_3D_loops()
        cls.small_points = np.zeros((len(cls.cell_small.morphology),))
        dic = cls.cell_small_segment_coordinates_loops
        for seg in dic:
            ps = dic[seg]
            for p in ps:
                cls.small_points[p[2]] += 1
        cls.cell_small_segment_coordinates = cls.cell_small.coordinates_3D_segments()

        #Y-shaped neuron
        data = LoadData(os.path.join(sample_data_path, "Y_shaped_neuron"))
        data.morphology[:,2:6] = data.morphology[:,2:6]/sc
        cls.cell_y = sKCSDcell(data.morphology,data.ele_pos/sc,10)
        cls.cell_y.distribute_srcs_3D_morph()
        cls.cell_y_segment_coordinates_loops = cls.cell_y.coordinates_3D_loops()
        cls.y_points = {}
        dic = cls.cell_y_segment_coordinates_loops
        for seg in dic:
            ps = dic[seg]
            for p in ps:
                s = '%d%d%d'%(p[0],p[1],p[2])
                if s not in cls.y_points:
                    cls.y_points[s] = 1
                else:
                    cls.y_points[s] += 1
        cls.cell_y_segment_coordinates = cls.cell_y.coordinates_3D_segments()
示例#6
0
    seglen = np.loadtxt(os.path.join(data_dir[0], 'seglength'))
    ground_truth = np.loadtxt(os.path.join(
        data_dir[0], 'membcurr')) / seglen[:, None] * 1e-3
    somav = np.loadtxt(os.path.join(data_dir[0], 'somav.txt'))
    time = np.linspace(0, tstop, len(somav))
    plt.figure()
    plt.plot(time, somav)

    dt = c.cell_parameters['dt']
    t0 = int(247.5 / dt)  #np.argmax(somav)
    print(t0 * dt)
    L1 = []
    cell_itself = sKCSDcell(morphology,
                            ele_pos,
                            n_src,
                            tolerance=tolerance,
                            xmin=-1000e-6,
                            xmax=1000e-6,
                            ymin=-1000e-6,
                            ymax=1000e-6)
    ground_truth_3D = cell_itself.transform_to_3D(ground_truth, what="morpho")
    ground_truth_t0 = ground_truth_3D[:, :, :, t0].sum(axis=2)
    vmax, vmin = pl.get_min_max(ground_truth_t0)
    morpho, extent = cell_itself.draw_cell2D(axis=2)
    extent = [extent[-2], extent[-1], extent[0], extent[1]]
    lambd = l / (2 * (2 * np.pi)**3 * R**2 * n_src)
    fig, ax = plt.subplots(3, 3, figsize=(8, 20))
    pl.make_map_plot(ax[0, 0], morpho, extent=extent, circles=False)
    pl.make_map_plot(ax[0, 0],
                     ground_truth_t0,
                     extent=extent,
                     title="Ground truth",
示例#7
0
              sigma=0.3)
    path = os.path.join(data_dir, 'lambda_%f_R_%f_n_src_%d' % (lambd, R, n_src))
    if sys.version_info < (3, 0):
        path = os.path.join(path, "preprocessed_data/Python_2")
    else:
        path = os.path.join(path, "preprocessed_data/Python_3")
    if not os.path.exists(path):
        print("Creating", path)
        os.makedirs(path)
    try:
        utils.save_sim(path, k)
    except NameError:
        pass

    skcsd, pot, morphology_file, ele_pos, n_src  = utils.load_sim(path)
    cell_obj = sKCSDcell(morphology_file, ele_pos, n_src)
    csd = cell_obj.transform_to_segments(skcsd)
    draw_ground_truth_skcsd_segments(ax, ground_truth, csd, time, gvmin, gvmax)
    csd_3D = cell_itself.transform_to_3D(skcsd[:, toplot])
    gt_3D = cell_itself.transform_to_3D(ground_truth[:, toplot],
                                        what="morpho")
    draw_ground_truth_skcsd_3D(ax, gt_3D, csd_3D, data,
                                gvmin, gvmax, time[toplot])
    
   

    fig.subplots_adjust(wspace=0.5)
    fig.subplots_adjust(hspace=0.5)
    add_figure_labels(ax, ax_somav)
    plt.savefig(fig_name,
                bbox_inches='tight',
示例#8
0
    fig, ax = plt.subplots(2, 3, figsize=(8, 20))
    fname = "Figure_9.png"
    fig_name = sKCSD_utils.make_fig_names(fname)

    data = utils.LoadData(data_dir)
    ele_pos = data.ele_pos / scaling_factor
    data.LFP = data.LFP / scaling_factor_LFP
    morphology = data.morphology
    morphology[:, 2:6] = morphology[:, 2:6] / scaling_factor
    std = data.LFP.var()**.5
    shape = data.LFP.shape
    cell = sKCSDcell(morphology,
                     ele_pos,
                     n_src,
                     tolerance=2e-6,
                     xmin=-120e-6,
                     xmax=120e-6,
                     zmin=-50e-6,
                     zmax=550e-6)
    ground_truth_grid = cell.transform_to_3D(ground_truth, what="morpho")
    vmax, vmin = pl.get_min_max(ground_truth_grid[:, :, :, t1].sum(axis=1))
    gdt1 = ground_truth_grid[:, :, :, t1].sum(axis=1)
    morpho, extent = cell.draw_cell2D(axis=1)
    extent = [extent[-2], extent[-1], extent[0], extent[1]]
    new_ele_pos = np.array([ele_pos[:, 2], ele_pos[:, 0]]).T
    pl.make_map_plot(ax[0, 0],
                     gdt1,
                     vmin=vmin,
                     vmax=vmax,
                     extent=extent,
                     alpha=.9,
示例#9
0
 ground_truth = np.loadtxt(os.path.join(data_dir[0],
                                        'membcurr'))/seglen[:, None]*1e-3
 somav = np.loadtxt(os.path.join(data_dir[0],
                                        'somav.txt'))
 time = np.linspace(0, tstop, len(somav))
 plt.figure()
 plt.plot(time, somav)
 
 dt = c.cell_parameters['dt']
 t0 = int(247.5/dt)#np.argmax(somav)
 print(t0*dt)
 L1 = []
 cell_itself = sKCSDcell(morphology,
                         ele_pos,
                         n_src,
                         tolerance=tolerance,
                         xmin=-1000e-6,
                         xmax=1000e-6,
                         ymin=-1000e-6,
                         ymax=1000e-6)
 cell_itself.distribute_srcs_3D_morph()
 ground_truth_3D = cell_itself.transform_to_3D(ground_truth,
                                               what="morpho")
 ground_truth_t0 = ground_truth_3D[:, :, :, t0].sum(axis=2)
 vmax, vmin = pl.get_min_max(ground_truth_t0)
 morpho, extent = cell_itself.draw_cell2D(axis=2)
 lambd = l/(2*(2*np.pi)**3*R**2*n_src)
 fig, ax = plt.subplots(3, 3, figsize=(8, 20))
 pl.make_map_plot(ax[0, 0], morpho, extent=extent)
 pl.make_map_plot(ax[0, 0], ground_truth_t0, extent=extent, title="Ground truth", vmin=vmin, vmax=vmax, alpha=.75)
 vmax, vmin = pl.get_min_max(ground_truth_t0)
 
示例#10
0
    data.LFP = data.LFP / scale_factor_LFP
    morphology = data.morphology
    morphology[:, 2:6] = morphology[:, 2:6] / scale_factor
    seglen = np.loadtxt(os.path.join(data_dir, 'seglength'))
    ground_truth = np.loadtxt(os.path.join(
        data_dir, 'membcurr')) / seglen[:, None] * 1e-3
    dt = c.cell_parameters['dt']

    somav = np.loadtxt(os.path.join(data_dir, 'somav.txt'))
    time = np.linspace(0, tstop, len(somav))
    t0 = np.argmax(somav[int(400. / dt):int(600. / dt)]) + int(400. / dt)

    cell_itself = sKCSDcell(morphology,
                            ele_pos,
                            n_src,
                            tolerance=tolerance,
                            xmin=xmin,
                            xmax=xmax,
                            ymin=ymin,
                            ymax=ymax)
    cell_itself.distribute_srcs_3D_morph()
    ground_truth_3D = cell_itself.transform_to_3D(ground_truth, what="morpho")
    vmax, vmin = pl.get_min_max(ground_truth_3D[:, :, :,
                                                t0 - tt:t0 + tt].sum(axis=(2,
                                                                           3)))
    morpho, extent = cell_itself.draw_cell2D(axis=2)
    gvmax, gvmin = pl.get_min_max(ground_truth)
    l = 0.1

    R = 64. / np.sqrt(2) / scale_factor
    fig2 = plt.figure()
    axfig21 = fig2.add_subplot(2, 1, 1)
示例#11
0
    
    ground_truth = ground_truth/seglen[:, None]*1e-3
    
    fig, ax = plt.subplots(2, 3, figsize=(8,20))
    fname = "Figure_9.png"
    fig_name = sKCSD_utils.make_fig_names(fname)
    
    data = utils.LoadData(data_dir)
    ele_pos = data.ele_pos/scaling_factor
    data.LFP = data.LFP/scaling_factor_LFP
    morphology = data.morphology
    morphology[:, 2:6] = morphology[:, 2:6]/scaling_factor
    std = data.LFP.var()**.5
    shape = data.LFP.shape
    cell =  sKCSDcell(morphology, ele_pos, n_src,
                      tolerance=2e-6,
                      xmin=-120e-6, xmax=120e-6,
                      zmin=-50e-6, zmax=550e-6)
    cell.distribute_srcs_3D_morph()
    ground_truth_grid = cell.transform_to_3D(ground_truth, what="morpho")
    vmax, vmin = pl.get_min_max(ground_truth_grid[:, :, :, t1].sum(axis=1))
    gdt1 = ground_truth_grid[:,:,:,t1].sum(axis=1)
    morpho, extent = cell.draw_cell2D(axis=1)

   
    pl.make_map_plot(ax[0, 0],
                     gdt1,
                     vmin=vmin,
                     vmax=vmax,
                     extent=extent,
                     alpha=.9,
                     morphology=morpho,
示例#12
0
                          weight=0.01,
                          n_syn=100,
                          simulate_what="symmetric",
                          electrode_orientation=electrode_orientation,
                          dt=dt)
 data_dir.append(c.return_paths_skCSD_python())
 data = utils.LoadData(data_dir[i])
 ele_pos = data.ele_pos/scaling_factor
 morphology = data.morphology
 morphology[:, 2:6] = morphology[:, 2:6]/scaling_factor
 if i == 0:
     cell_itself.append(sKCSDcell(morphology,
                                  ele_pos,
                                  n_src,
                                  xmin=-120e-6,
                                  xmax=120e-6,
                                  ymin=-200e-6,
                                  ymax=200e-6,
                                  zmin=-150e-6,
                                  zmax=550e-6))
 else:
     cell_itself.append(sKCSDcell(morphology,
                                  ele_pos,
                                  n_src,
                                  xmin=-120e-6,
                                  xmax=120e-6,
                                  ymin=-200e-6,
                                  ymax=200e-6,
                                  zmin=-150e-6,
                                  zmax=550e-6))
 morpho, extent = cell_itself[i].draw_cell2D(axis=1)
示例#13
0
                          weight=0.01,
                          n_syn=100,
                          simulate_what="symmetric",
                          electrode_orientation=electrode_orientation,
                          dt=dt)
 data_dir.append(c.return_paths_skCSD_python())
 data = utils.LoadData(data_dir[i])
 ele_pos = data.ele_pos/scaling_factor
 morphology = data.morphology
 morphology[:, 2:6] = morphology[:, 2:6]/scaling_factor
 if i == 0:
     cell_itself.append(sKCSDcell(morphology,
                                  ele_pos,
                                  n_src,
                                  xmin=-120e-6,
                                  xmax=120e-6,
                                  ymin=-200e-6,
                                  ymax=200e-6,
                                  zmin=-150e-6,
                                  zmax=550e-6))
 else:
     cell_itself.append(sKCSDcell(morphology,
                                  ele_pos,
                                  n_src,
                                  xmin=-120e-6,
                                  xmax=120e-6,
                                  ymin=-200e-6,
                                  ymax=200e-6,
                                  zmin=-150e-6,
                                  zmax=550e-6))
 
示例#14
0
    ele_pos = data.ele_pos/scale_factor
    data.LFP = data.LFP/scale_factor_LFP
    morphology = data.morphology
    morphology[:, 2:6] = morphology[:, 2:6]/scale_factor
    seglen = np.loadtxt(os.path.join(data_dir,
                                     'seglength'))
    ground_truth = np.loadtxt(os.path.join(data_dir,
                                           'membcurr'))/seglen[:, None]*1e-3
    dt = c.cell_parameters['dt']
   
    somav = np.loadtxt(os.path.join(data_dir,
                                           'somav.txt'))
    time = np.linspace(0, tstop, len(somav))
    t0 = np.argmax(somav[int(400./dt):int(600./dt)])+int(400./dt)
 
    cell_itself = sKCSDcell(morphology, ele_pos, n_src, tolerance=tolerance, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax)
    cell_itself.distribute_srcs_3D_morph()
    ground_truth_3D = cell_itself.transform_to_3D(ground_truth,
                                                  what="morpho")
    vmax, vmin = pl.get_min_max(ground_truth_3D[:, :, :, t0-tt:t0+tt].sum(axis=(2,3)))
    morpho, extent = cell_itself.draw_cell2D(axis=2)
    gvmax, gvmin = pl.get_min_max(ground_truth)
    l = 0.1
    
    R = 64./np.sqrt(2)/scale_factor
    fig2 = plt.figure()
    axfig21 = fig2.add_subplot(2,1,1)
    axfig22 = fig2.add_subplot(2,1,2)
    axfig21.imshow(ground_truth, interpolation="none", origin="lower", vmin=gvmin, vmax=gvmax, cmap=plt.cm.bwr_r)
    lambd = l/(2*(2*np.pi)**3*R**2*n_src)
    fig = plt.figure(figsize=(8, 20))