Exemplo n.º 1
0
 def test_calc_target_matrices(self, sphere_surf, leadfield_surf):
     idx = [1]
     directions = [2., 0., 0.]
     t = opt_struct.TDCStarget(indexes=idx,
                               directions=directions,
                               mesh=sphere_surf,
                               lf_type='node')
     t_mat, Q_mat = t.calc_target_matrices(leadfield_surf)
     areas = sphere_surf.nodes_volumes_or_areas().value
     idx_ = [0]
     directions_ = [1., 0., 0.]
     t, Q = methods.target_matrices(leadfield_surf, idx_, directions_,
                                    areas)
     assert np.all(np.isclose(t_mat, t))
     assert np.all(np.isclose(Q_mat, Q))
Exemplo n.º 2
0
 def test_calc_Q_in(self, avg_reference):
     A = np.random.random((2, 5, 3))
     targets = [0, 1]
     target_direction = [[1, 0, 0], [1, 0, 0]]
     volumes = np.array([1, 2, 2, 2, 4])
     _, Qin = optimization_methods.target_matrices(A, targets,
                                                   target_direction,
                                                   volumes, avg_reference)
     currents = np.array([1, 0])
     field = np.einsum('ijk, i->jk', A, currents)
     avg_in = np.sum(
         np.linalg.norm(field[targets], axis=1)**2 * volumes[targets])
     avg_in /= np.sum(volumes[targets])
     if avg_reference:
         currents = np.array([-1, 1, 0])
     assert np.allclose(currents.dot(Qin.dot(currents)), avg_in)
Exemplo n.º 3
0
 def test_calc_different_directions(self, avg_reference):
     A = np.random.random((2, 5, 3))
     targets = [0, 1]
     target_direction = np.array([[1, 0, 0], [0, 1, 0]])
     volumes = np.array([1, 2, 2, 2, 2])
     l, _, = optimization_methods.target_matrices(A, targets,
                                                  target_direction, volumes,
                                                  avg_reference)
     currents = [1, 1]
     field_x = A[..., 0].T.dot(currents)
     field_y = A[..., 1].T.dot(currents)
     avg = (field_x[0] * 1 + field_y[1] * 2) / 3
     if avg_reference:
         assert np.allclose(avg, l.dot([-2, 1, 1]))
     else:
         assert np.allclose(avg, l.dot(currents))
Exemplo n.º 4
0
 def test_calc_l(self, avg_reference):
     # test if l.dot(currents) really is the average current
     A = np.random.random((2, 5, 3))
     targets = [0, 1]
     target_direction = [[1, 0, 0], [1, 0, 0]]
     volumes = np.array([1, 2, 2, 2, 2])
     l, _ = optimization_methods.target_matrices(A, targets,
                                                 target_direction, volumes,
                                                 avg_reference)
     currents = [1, 1]
     field_x = A[..., 0].T.dot(currents)
     avg = np.average(field_x[[0, 1]], weights=[1, 2])
     if avg_reference:
         assert np.allclose(avg, l.dot([-2, 1, 1]))
     else:
         assert np.allclose(avg, l.dot(currents))
Exemplo n.º 5
0
    def test_calc_target_matrices_radius(self, sphere_vol, leadfield_vol):
        vols = sphere_vol.elements_volumes_and_areas().value
        bar = sphere_vol.elements_baricenters().value
        idx_ = np.where((np.linalg.norm(bar - bar[0], axis=1) < 20) *
                        (sphere_vol.elm.tag1 == 4))[0]
        directions = [[2., 0., 0.]]

        t = opt_struct.TDCStarget(positions=bar[0],
                                  directions=directions,
                                  mesh=sphere_vol,
                                  lf_type='element',
                                  radius=20,
                                  tissues=4)
        t_mat, Q_mat = t.calc_target_matrices(leadfield_vol)

        directions_ = [(1., 0., 0.)] * len(idx_)
        t, Q = methods.target_matrices(leadfield_vol, idx_, directions_, vols)
        assert np.all(np.isclose(t_mat, t))
        assert np.all(np.isclose(Q_mat, Q))