예제 #1
0
 def test_create_mat_struct(self):
     targets = [
         opt_struct.TDCSavoid(indexes=1, radius=5),
         opt_struct.TDCSavoid(positions=[1., 0., 3.],
                              weight=1e4,
                              tissues=[3, 4])
     ]
     m = opt_struct._save_TDCSavoid_mat(targets)
     assert np.all(m[0]['indexes'] == 1)
     assert np.all(m[0]['radius'] == 5)
     assert np.all(m[1]['positions'] == [1, 0., 3.])
     assert np.all(m[1]['weight'] == 1e4)
     assert np.all(m[1]['tissues'] == [3, 4])
예제 #2
0
 def test_avoid_mean_field_norm_node(self, sphere_surf):
     a = opt_struct.TDCSavoid(tissues=[1003],
                              weight=1e4,
                              lf_type='node',
                              mesh=sphere_surf)
     field = mesh_io.NodeData(np.ones((sphere_surf.nodes.nr, 3)))
     assert np.isclose(a.mean_field_norm_in_region(field), np.sqrt(3))
예제 #3
0
 def test_avoid_mean_field_norm_elm(self, sphere_surf):
     a = opt_struct.TDCSavoid(tissues=[1003],
                              weight=1e4,
                              lf_type='element',
                              mesh=sphere_surf)
     field = mesh_io.ElementData(np.ones((sphere_surf.elm.nr, 3)))
     field[sphere_surf.elm.tag1 == 1003] = [2, 0, 0]
     assert np.isclose(a.mean_field_norm_in_region(field), 2)
예제 #4
0
 def test_avoid_field_none_elm(self, sphere_surf):
     a = opt_struct.TDCSavoid(tissues=[1003],
                              weight=1e4,
                              lf_type='element',
                              mesh=sphere_surf)
     f = a.avoid_field()
     assert np.allclose(f[sphere_surf.elm.tag1 == 1003], 1e4)
     assert np.allclose(f[sphere_surf.elm.tag1 != 1003], 1)
예제 #5
0
 def test_avoid_field_none_node(self, sphere_surf):
     a = opt_struct.TDCSavoid(tissues=[1003],
                              weight=1e4,
                              lf_type='node',
                              mesh=sphere_surf)
     f = a.avoid_field()
     roi = np.linalg.norm(sphere_surf.nodes[:], axis=1) < 86
     assert np.allclose(f[roi], 1e4)
     assert np.allclose(f[~roi], 1)
예제 #6
0
 def test_avoid_field_elm(self, sphere_surf):
     a = opt_struct.TDCSavoid(indexes=2,
                              weight=1e4,
                              lf_type='element',
                              mesh=sphere_surf)
     f = a.avoid_field()
     in_r = np.zeros(sphere_surf.elm.nr, dtype=bool)
     in_r[1] = True
     assert np.allclose(f[in_r], 1e4)
     assert np.allclose(f[~in_r], 1)
예제 #7
0
 def test_avoid_field_elm_radius(self, sphere_surf):
     bar = sphere_surf.elements_baricenters()[:]
     a = opt_struct.TDCSavoid(positions=bar[0],
                              radius=10,
                              weight=1e4,
                              lf_type='element',
                              mesh=sphere_surf)
     f = a.avoid_field()
     in_r = np.linalg.norm(bar - bar[0], axis=1) < 10
     assert np.allclose(f[in_r], 1e4)
     assert np.allclose(f[~in_r], 1)