示例#1
0
def test_lsa_cylinder_dipole_ratio():
    """test if v of dipole falls with 1/r2"""
    y_pos = 1e3
    pos = np.array([-L, y_pos, 0])
    coord = np.hstack([conf_cylinder((-L, 0, 0))[0], conf_cylinder((0, 0, 0))[0]])
    I = np.array([[-1, 1]])
    v1 = field.estimate_lsa(pos, coord, I, eta=eta)
    v2 = field.estimate_lsa(2 * pos, coord, I, eta=eta)

    assert_almost_equal(v1 / v2, 4, decimal=5)
示例#2
0
def test_lsa_cylinder_dipole_ratio():
    """test if v of dipole falls with 1/r2"""
    y_pos = 1e3
    pos = np.array([-L, y_pos, 0])
    coord = np.hstack(
        [conf_cylinder((-L, 0, 0))[0],
         conf_cylinder((0, 0, 0))[0]])
    I = np.array([[-1, 1]])
    v1 = field.estimate_lsa(pos, coord, I, eta=eta)
    v2 = field.estimate_lsa(2 * pos, coord, I, eta=eta)

    assert_almost_equal(v1 / v2, 4, decimal=5)
示例#3
0
def test_lsa_tripole_cylinder():
    L = 1.
    cable = [conf_cylinder((i * L, 0, 0), L=L)[0] for i in range(3)]
    cable = np.hstack(cable)
    I = np.zeros((1, 3))
    I[0, 0] = I_0
    I[0, 1:] = -I_0 / 2.

    v1 = field.estimate_lsa((-1.5, 7, 0), cable, I)
    v2 = field.estimate_lsa((5, 7, 0), cable, I)

    #show_potential_on_grid(cable, I)
    assert v1 > 0, "Potential is negative"
    assert v2 < 0, "Potential is positive"
示例#4
0
def test_lsa_tripole_cylinder():
    L = 1.0
    cable = [conf_cylinder((i * L, 0, 0), L=L)[0] for i in range(3)]
    cable = np.hstack(cable)
    I = np.zeros((1, 3))
    I[0, 0] = I_0
    I[0, 1:] = -I_0 / 2.0

    v1 = field.estimate_lsa((-1.5, 7, 0), cable, I)
    v2 = field.estimate_lsa((5, 7, 0), cable, I)

    # show_potential_on_grid(cable, I)
    assert v1 > 0, "Potential is negative"
    assert v2 < 0, "Potential is positive"
示例#5
0
def test_lsa_cylinder_longl():
    x_pos = -1.0
    pos = (x_pos, 0, 0)
    coord, I = conf_cylinder()
    v = field.estimate_lsa(pos, coord, I, eta=eta)
    v_analytical = 1e6 / (4 * np.pi) * eta * I_0 * 1e4 * (np.pi * diam * 1e-6) * np.log((L - x_pos) / (-x_pos))
    np.testing.assert_almost_equal(v[0], v_analytical)
示例#6
0
def test_lsa_cylinder_radial_inv():
    y_pos = 1.
    pos = (0, 1., 0)
    coord, I = conf_cylinder((-1., 0., 0.))
    v = field.estimate_lsa(pos, coord, I, eta=eta)
    v_analytical = (1e6 / (4 * np.pi) * eta * I_0 * 1E4 *
                    (np.pi * diam * 1E-6) * np.log(
                        (L + np.sqrt(y_pos**2 + L**2)) / y_pos))

    np.testing.assert_almost_equal(v[0], v_analytical)
示例#7
0
def test_lsa_cylinder_longl():
    x_pos = -1.
    pos = (x_pos, 0, 0)
    coord, I = conf_cylinder()
    v = field.estimate_lsa(pos, coord, I, eta=eta)
    v_analytical = 1e6 / (4 * np.pi) * eta * I_0 * 1E4 * (np.pi * diam *
                                                          1E-6) * np.log(
                                                              (L - x_pos) /
                                                              (-x_pos))
    np.testing.assert_almost_equal(v[0], v_analytical)
示例#8
0
def test_lsa_symmetry():
    coord1, I1 = conf_cylinder((-L / 2., 0, 0))
    coord2, I2 = conf_cylinder((0, -L / 2, 0), theta=np.pi / 2.)

    coord = np.hstack((coord1, coord2))
    I = np.hstack((I1, I2))

    pos = (1., 1., 0)
    v1 = field.estimate_lsa(pos, coord, I, eta=eta)
    pos = (-1., 1., 0)
    v2 = field.estimate_lsa(pos, coord, I, eta=eta)
    pos = (1., -1., 0)
    v3 = field.estimate_lsa(pos, coord, I, eta=eta)
    pos = (-1., -1., 0)
    v4 = field.estimate_lsa(pos, coord, I, eta=eta)

    assert_almost_equal(v1, v2)
    assert_almost_equal(v2, v3)
    assert_almost_equal(v3, v4)
示例#9
0
def test_lsa_symmetry():
    coord1, I1 = conf_cylinder((-L / 2.0, 0, 0))
    coord2, I2 = conf_cylinder((0, -L / 2, 0), theta=np.pi / 2.0)

    coord = np.hstack((coord1, coord2))
    I = np.hstack((I1, I2))

    pos = (1.0, 1.0, 0)
    v1 = field.estimate_lsa(pos, coord, I, eta=eta)
    pos = (-1.0, 1.0, 0)
    v2 = field.estimate_lsa(pos, coord, I, eta=eta)
    pos = (1.0, -1.0, 0)
    v3 = field.estimate_lsa(pos, coord, I, eta=eta)
    pos = (-1.0, -1.0, 0)
    v4 = field.estimate_lsa(pos, coord, I, eta=eta)

    assert_almost_equal(v1, v2)
    assert_almost_equal(v2, v3)
    assert_almost_equal(v3, v4)
示例#10
0
def test_lsa_cylinder_radial_inv():
    y_pos = 1.0
    pos = (0, 1.0, 0)
    coord, I = conf_cylinder((-1.0, 0.0, 0.0))
    v = field.estimate_lsa(pos, coord, I, eta=eta)
    v_analytical = (
        1e6 / (4 * np.pi) * eta * I_0 * 1e4 * (np.pi * diam * 1e-6) * np.log((L + np.sqrt(y_pos ** 2 + L ** 2)) / y_pos)
    )

    np.testing.assert_almost_equal(v[0], v_analytical)
示例#11
0
def test_lsa_symmetric_cylinders():
    coord1, I1 = conf_cylinder()
    coord2, I2 = conf_cylinder((-L, 0, 0))

    coord = np.hstack((coord1, coord2))
    I = np.hstack((I1, -I2))
    print coord

    pos = (0, 10, 0)
    v = field.estimate_lsa(pos, coord, I, eta=eta)

    assert_almost_equal(v[0], 0)
示例#12
0
def test_lsa_symmetric_cylinders():
    coord1, I1 = conf_cylinder()
    coord2, I2 = conf_cylinder((-L, 0, 0))

    coord = np.hstack((coord1, coord2))
    I = np.hstack((I1, -I2))
    print coord

    pos = (0, 10, 0)
    v = field.estimate_lsa(pos, coord, I, eta=eta)

    assert_almost_equal(v[0], 0)
示例#13
0
def test_lsa_cylinder_divide():

    pos = np.random.randn(3) * 10
    theta = np.random.rand() * np.pi
    coord_total, I = conf_cylinder(theta=theta)

    N = 10
    dl = np.array([L * 1.0], dtype=np.float64) / N
    first, _ = conf_cylinder((0, 0, 0), theta=theta, L=dl)
    short_cylinders = [first]
    new = first
    for i in range(N - 1):
        new, _ = conf_cylinder((new["x1"][0], new["y1"][0], new["z1"][0]), theta=theta, L=dl)
        short_cylinders.append(new)

    coord_division = np.hstack(short_cylinders)

    I_div = np.ones((1, len(coord_division))) * I_0
    v_division = field.estimate_lsa(pos, coord_division, I_div)
    v_total = field.estimate_lsa(pos, coord_total, I)

    assert_almost_equal(v_total, v_division, decimal=4)
示例#14
0
def test_lsa_cylinder_divide():

    pos = np.random.randn(3) * 10
    theta = np.random.rand() * np.pi
    coord_total, I = conf_cylinder(theta=theta)

    N = 10
    dl = np.array([L * 1.], dtype=np.float64) / N
    first, _ = conf_cylinder((0, 0, 0), theta=theta, L=dl)
    short_cylinders = [first]
    new = first
    for i in range(N - 1):
        new, _ = conf_cylinder((new['x1'][0], new['y1'][0], new['z1'][0]),
                               theta=theta,
                               L=dl)
        short_cylinders.append(new)

    coord_division = np.hstack(short_cylinders)

    I_div = np.ones((1, len(coord_division))) * I_0
    v_division = field.estimate_lsa(pos, coord_division, I_div)
    v_total = field.estimate_lsa(pos, coord_total, I)

    assert_almost_equal(v_total, v_division, decimal=4)
示例#15
0
文件: fig1.py 项目: btel/neuroneap
cutoff   = 800. #high-pass cutoff, Hz
order    = 401  #filter order

# Electrode position and filter
pos = (dist*np.sin(alpha)*1000, dist*np.cos(alpha)*1000, 0)
fir = 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
coords = cell.get_seg_coords()
v_ext = field.estimate_lsa(pos, coords, I) 

# PLOTS
fig = plt.figure()
fig.subplots_adjust(left=0.05, wspace=0)
ax1= fig.add_subplot(1,2,1, frameon=False)
graph.plot_neuron(coords)
plt.plot([pos[0]], [pos[1]], 'ro')
ax1.text(0.05, 0.9, 'A', weight='bold',
         transform=ax1.transAxes)

## scalebar
xp, yp =  -1500, -2000
w, h = 1000, 1000
ax1.plot([xp, xp], [yp, yp+h], 'k-')
ax1.plot([xp, xp+h], [yp, yp], 'k-')
示例#16
0
cutoff = 800.  #high-pass cutoff, Hz
order = 401  #filter order

# Electrode position and filter
pos = (dist * np.sin(alpha) * 1000, dist * np.cos(alpha) * 1000, 0)
fir = 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
coords = cell.get_seg_coords()
v_ext = field.estimate_lsa(pos, coords, I)

# PLOTS
fig = plt.figure()
fig.subplots_adjust(left=0.05, wspace=0)
ax1 = fig.add_subplot(1, 2, 1, frameon=False)
graph.plot_neuron(coords)
plt.plot([pos[0]], [pos[1]], 'ro')
ax1.text(0.05, 0.9, 'A', weight='bold', transform=ax1.transAxes)

## scalebar
xp, yp = -1500, -2000
w, h = 1000, 1000
ax1.plot([xp, xp], [yp, yp + h], 'k-')
ax1.plot([xp, xp + h], [yp, yp], 'k-')
ax1.text(xp - 100,
示例#17
0
文件: fig2.py 项目: btel/neuroneap
dend = field.select_sections(coords, "dend")
soma = field.select_sections(coords, "soma")
axon = field.select_sections(coords, "(node)|(myelin)")
iseg = field.select_sections(coords, "iseg")
hill = field.select_sections(coords, "hill")
all  = field.select_sections(coords, ".*")

colors = {"dend": "r",
          "soma": "c",
          "axon": "b",
          "all" : "k",
          "iseg" : "g",
          "hill" : "m"}

# Calculation of field
v_dend = field.estimate_lsa(pos, coords[dend], I[:, dend])
v_soma = field.estimate_lsa(pos, coords[soma], I[:, soma])
v_axon = field.estimate_lsa(pos, coords[axon], I[:, axon])
v_iseg = field.estimate_lsa(pos, coords[iseg], I[:, iseg])
v_hill = field.estimate_lsa(pos, coords[hill], I[:, hill])

# PLOTS
fig = plt.figure()
fig.subplots_adjust(hspace=0.15, wspace=0.2, left=0.05, right=0.95)
ax1= fig.add_subplot(1,2,1, frameon=False)
l_dend = graph.plot_neuron(coords[dend], colors=colors['dend'])
l_axon = graph.plot_neuron(coords[axon], colors=colors['axon'])
l_iseg = graph.plot_neuron(coords[iseg], colors=colors['iseg'])
l_hill = graph.plot_neuron(coords[hill], colors=colors['hill'])
l_soma = graph.plot_neuron(coords[soma], colors=colors['soma'])
plt.legend((l_dend, l_axon, l_iseg, l_hill, l_soma), 
示例#18
0
axon = field.select_sections(coords, "(node)|(myelin)")
iseg = field.select_sections(coords, "iseg")
hill = field.select_sections(coords, "hill")
all = field.select_sections(coords, ".*")

colors = {
    "dend": "r",
    "soma": "c",
    "axon": "b",
    "all": "k",
    "iseg": "g",
    "hill": "m"
}

# Calculation of field
v_dend = field.estimate_lsa(pos, coords[dend], I[:, dend])
v_soma = field.estimate_lsa(pos, coords[soma], I[:, soma])
v_axon = field.estimate_lsa(pos, coords[axon], I[:, axon])
v_iseg = field.estimate_lsa(pos, coords[iseg], I[:, iseg])
v_hill = field.estimate_lsa(pos, coords[hill], I[:, hill])

# PLOTS
fig = plt.figure()
fig.subplots_adjust(hspace=0.15, wspace=0.2, left=0.05, right=0.95)
ax1 = fig.add_subplot(1, 2, 1, frameon=False)
l_dend = graph.plot_neuron(coords[dend], colors=colors['dend'])
l_axon = graph.plot_neuron(coords[axon], colors=colors['axon'])
l_iseg = graph.plot_neuron(coords[iseg], colors=colors['iseg'])
l_hill = graph.plot_neuron(coords[hill], colors=colors['hill'])
l_soma = graph.plot_neuron(coords[soma], colors=colors['soma'])
plt.legend((l_dend, l_axon, l_iseg, l_hill, l_soma),