Esempio n. 1
0
 def test_join(self):
     x = np.random.random((5, 13))
     a = Table(x, {
         'F': (3, 3),
         'v': (3, ),
         's': (1, )
     }, ['random test data'])
     y = np.random.random((5, 3))
     b = Table(y, {'u': (3, )}, ['random test data'])
     c = a.join(b)
     assert np.array_equal(c.get('u'), b.get('u'))
Esempio n. 2
0
 def test_append_invalid(self):
     x = np.random.random((5, 13))
     a = Table(x, {
         'F': (3, 3),
         'v': (3, ),
         's': (1, )
     }, ['random test data'])
     b = Table(x, {
         'F': (3, 3),
         'u': (3, ),
         's': (1, )
     }, ['random test data'])
     with pytest.raises(KeyError):
         a.append(b)
Esempio n. 3
0
 def test_sort(self):
     t = Table(np.array([[0,1,],[2,1,]]),
               {'v':(2,)},
               ['test data'])\
         .add('s',np.array(['b','a']))\
         .sort_by('s')
     assert np.all(t.get('v')[:, 0] == np.array([2, 0]))
Esempio n. 4
0
 def test_sort_component(self):
     x = np.random.random((5, 12))
     t = Table(x, {'F': (3, 3), 'v': (3, )}, ['random test data'])
     unsort = t.get('4_F')
     t.sort_by('4_F')
     sort = t.get('4_F')
     assert np.all(np.sort(unsort, 0) == sort)
Esempio n. 5
0
 def test_from_table_recover(self,tmp_path):
     cells = np.random.randint(60,100,3)
     size = np.ones(3)+np.random.rand(3)
     s = seeds.from_random(size,np.random.randint(60,100))
     grid = Grid.from_Voronoi_tessellation(cells,size,s)
     coords = grid_filters.coordinates0_point(cells,size)
     t = Table(np.column_stack((coords.reshape(-1,3,order='F'),grid.material.flatten(order='F'))),{'c':3,'m':1})
     assert grid_equal(grid.sort().renumber(),Grid.from_table(t,'c',['m']))
Esempio n. 6
0
def default():
    """Simple Table."""
    x = np.ones((5, 13), dtype=float)
    return Table(x, {
        'F': (3, 3),
        'v': (3, ),
        's': (1, )
    }, ['test data', 'contains five rows of only ones'])
Esempio n. 7
0
 def test_join_invalid(self):
     x = np.random.random((5, 13))
     a = Table(x, {
         'F': (3, 3),
         'v': (3, ),
         's': (1, )
     }, ['random test data'])
     with pytest.raises(KeyError):
         a.join(a)
Esempio n. 8
0
 def test_append(self):
     x = np.random.random((5, 13))
     a = Table(x, {
         'F': (3, 3),
         'v': (3, ),
         's': (1, )
     }, ['random test data'])
     b = a.append(a)
     assert np.array_equal(b.data[:5].to_numpy(), b.data[5:].to_numpy())
Esempio n. 9
0
 def test_from_table(self):
     grid = np.random.randint(60,100,3)
     size = np.ones(3)+np.random.rand(3)
     coords = grid_filters.cell_coord0(grid,size).reshape(-1,3,order='F')
     z=np.ones(grid.prod())
     z[grid[:2].prod()*int(grid[2]/2):]=0
     t = Table(np.column_stack((coords,z)),{'coords':3,'z':1})
     g = Geom.from_table(t,'coords',['1_coords','z'])
     assert g.N_materials == g.grid[0]*2 and (g.material[:,:,-1]-g.material[:,:,0] == grid[0]).all()
Esempio n. 10
0
 def test_relationship_reference(self, update, ref_path, model, lattice):
     reference = ref_path / f'{lattice}_{model}.txt'
     o = Orientation(lattice=lattice)
     eu = o.related(model).as_Euler_angles(degrees=True)
     if update:
         coords = np.array([(1, i + 1) for i, x in enumerate(eu)])
         Table(eu,{'Eulers':(3,)})\
             .add('pos',coords)\
             .save(reference)
     assert np.allclose(eu, Table.load(reference).get('Eulers'))
Esempio n. 11
0
 def test_sort_scalar(self):
     x = np.random.random((5, 13))
     t = Table(x, {
         'F': (3, 3),
         'v': (3, ),
         's': (1, )
     }, ['random test data'])
     unsort = t.get('s')
     sort = t.sort_by('s').get('s')
     assert np.all(np.sort(unsort, 0) == sort)
Esempio n. 12
0
 def test_rename_equivalent(self):
     x = np.random.random((5, 13))
     t = Table(x, {
         'F': (3, 3),
         'v': (3, ),
         's': (1, )
     }, ['random test data'])
     s = t.get('s')
     u = t.rename('s', 'u').get('u')
     assert np.all(s == u)
Esempio n. 13
0
 def test_from_table(self):
     cells = np.random.randint(60,100,3)
     size = np.ones(3)+np.random.rand(3)
     coords = grid_filters.coordinates0_point(cells,size).reshape(-1,3,order='F')
     z=np.ones(cells.prod())
     z[cells[:2].prod()*int(cells[2]/2):]=0
     t = Table(np.column_stack((coords,z)),{'coords':3,'z':1})
     t = t.add('indicator',t.get('coords')[:,0])
     g = Grid.from_table(t,'coords',['indicator','z'])
     assert g.N_materials == g.cells[0]*2 and (g.material[:,:,-1]-g.material[:,:,0] == cells[0]).all()
Esempio n. 14
0
 def test_Schmid(self, update, ref_path, lattice, mode):
     L = Orientation(lattice=lattice)
     reference = ref_path / f'{lattice}_{mode}.txt'
     P = L.Schmid(mode)
     if update:
         table = Table(P.reshape(-1, 9), {'Schmid': (
             3,
             3,
         )})
         table.save(reference)
     assert np.allclose(P, Table.load(reference).get('Schmid'))
Esempio n. 15
0
 def test_sort(self):
     t = Table(np.array([[
         0,
         1,
     ], [
         2,
         1,
     ]]), {'v': (2, )}, ['test data'])
     t.add('s', np.array(['b', 'a']))
     t.sort_by('s')
     assert np.all(t.get('1_v') == np.array([2, 0]).reshape(2, 1))
Esempio n. 16
0
 def test_from_table(self):
     N = np.random.randint(3,10)
     a = np.vstack((np.hstack((np.arange(N),np.arange(N)[::-1])),
                    np.ones(N*2),np.zeros(N*2),np.ones(N*2),np.ones(N*2),
                    np.ones(N*2),
                   )).T
     t = Table(a,{'varying':1,'constant':4,'ones':1})
     c = ConfigMaterial.from_table(t,**{'phase':'varying','O':'constant','homogenization':'ones'})
     assert len(c['material']) == N
     for i,m in enumerate(c['material']):
         assert m['homogenization'] == 1 and (m['constituents'][0]['O'] == [1,0,1,1]).all()
Esempio n. 17
0
 def test_relationship_reference(self, update, reference_dir, model,
                                 lattice):
     reference = os.path.join(reference_dir, f'{lattice}_{model}.txt')
     ori = Orientation(Rotation(), lattice)
     eu = np.array(
         [o.rotation.as_Eulers(degrees=True) for o in ori.related(model)])
     if update:
         coords = np.array([(1, i + 1) for i, x in enumerate(eu)])
         table = Table(eu, {'Eulers': (3, )})
         table = table.add('pos', coords)
         table.save(reference)
     assert np.allclose(eu, Table.load(reference).get('Eulers'))
Esempio n. 18
0
 def test_Schmid(self, update, ref_path, lattice):
     O = Orientation(lattice=lattice)  # noqa
     for mode in ['slip', 'twin']:
         reference = ref_path / f'{lattice}_{mode}.txt'
         P = O.Schmid(N_slip='*') if mode == 'slip' else O.Schmid(
             N_twin='*')
         if update:
             table = Table(P.reshape(-1, 9), {'Schmid': (
                 3,
                 3,
             )})
             table.save(reference)
         assert np.allclose(P, Table.load(reference).get('Schmid'))
Esempio n. 19
0
 def test_from_table(self):
     N = np.random.randint(3, 10)
     a = np.vstack((np.hstack((np.arange(N), np.arange(N)[::-1])),
                    np.ones(N * 2), np.zeros(N * 2), np.ones(N * 2))).T
     t = Table(a, {'varying': 2, 'constant': 2})
     c = ConfigMaterial.from_table(t,
                                   constituents={
                                       'a': 'varying',
                                       'b': '1_constant'
                                   },
                                   c='2_constant')
     assert len(c['material']) == N
     for i, m in enumerate(c['material']):
         c = m['constituents'][0]
         assert m['c'] == 1 and c['b'] == 0 and c['a'] == [i, 1]
Esempio n. 20
0
 def test_sort_revert(self):
     x = np.random.random((5, 12))
     t = Table(x, {'F': (3, 3), 'v': (3, )}, ['random test data'])
     sort = t.sort_by('F[1,0]', ascending=False).get('F')[:, 1, 0]
     assert np.all(np.sort(sort, 0) == sort[::-1])
Esempio n. 21
0
 def test_invalid_initialization(self):
     x = np.random.random((5, 10))
     with pytest.raises(ValueError):
         Table(x, {'F': (3, 3)})
Esempio n. 22
0
 def test_len(self, N):
     assert len(Table(np.random.rand(N, 3), {'X': 3})) == N