Exemplo n.º 1
0
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
Exemplo n.º 2
0
def test_current_dipole_of_single_cylinder():
    cylinder_pos = (0, 0, 0)
    L = 1

    def Q_analytical(L, theta, I0):
        return (L*I0*np.cos(theta)*diam**2/4*1e-8, 
                L*I0*np.sin(theta)*diam**2/4*1e-8, 0)
   
    pi = np.pi
    #length, theta, current, expected dipole moment
    tests = [(L,  0,     1.),
             (L,  pi/2., 1.),
             (L,  pi/4., 1.),
             (L,  pi,    1.),
             (2*L,0,     1.),
             (L,  0.,    2.)
            ]

    for l, theta, I0 in tests:
        coord, I_axial = conf_cylinder(cylinder_pos, 
                                       theta=theta,
                                       L=l,
                                       I_0=I0)
        Q = field.calc_dipole_moment(coord, I_axial)
        Q_expected = Q_analytical(l, theta, I0)

        assert_almost_equal(Q, np.array(Q_expected)[:, None],
            err_msg='failed for theta=%f, l=%f' % (theta,l))
Exemplo n.º 3
0
def test_current_dipole_of_single_cylinder():
    cylinder_pos = (0, 0, 0)
    L = 1

    def Q_analytical(L, theta, I0):
        return (L * I0 * np.cos(theta) * diam**2 / 4 * 1e-8,
                L * I0 * np.sin(theta) * diam**2 / 4 * 1e-8, 0)

    pi = np.pi
    #length, theta, current, expected dipole moment
    tests = [(L, 0, 1.), (L, pi / 2., 1.), (L, pi / 4., 1.), (L, pi, 1.),
             (2 * L, 0, 1.), (L, 0., 2.)]

    for l, theta, I0 in tests:
        coord, I_axial = conf_cylinder(cylinder_pos, theta=theta, L=l, I_0=I0)
        Q = field.calc_dipole_moment(coord, I_axial)
        Q_expected = Q_analytical(l, theta, I0)

        assert_almost_equal(Q,
                            np.array(Q_expected)[:, None],
                            err_msg='failed for theta=%f, l=%f' % (theta, l))
Exemplo n.º 4
0
 def assert_dipole_equal(cylinders, Q_expected):
     coord, I_axial = concat_cylinders(cylinders)
     Q = field.calc_dipole_moment(coord, I_axial)
     assert_almost_equal(Q,
                         np.array(Q_expected)[:, None] * 1e-8 / 4 * diam**2)
Exemplo n.º 5
0
 def assert_dipole_equal(cylinders, Q_expected):
     coord, I_axial = concat_cylinders(cylinders)
     Q = field.calc_dipole_moment(coord, I_axial)
     assert_almost_equal(Q, np.array(Q_expected)[:, None] * 1e-8 / 4 * diam ** 2)