예제 #1
0
 def test_disorientation_blending(self, lattice, a, b):
     o = Orientation.from_random(lattice=lattice, shape=a)
     p = Orientation.from_random(lattice=lattice, shape=b)
     blend = util.shapeblender(o.shape, p.shape)
     for loc in np.random.randint(0, blend, (10, len(blend))):
         assert o[tuple(loc[:len(o.shape)])].disorientation(p[tuple(loc[-len(p.shape):])]) \
                .isclose(o.disorientation(p)[tuple(loc)])
예제 #2
0
 def test_relationship_vectorize(self, set_of_quaternions, lattice, model):
     r = Orientation(rotation=set_of_quaternions[:200].reshape((50, 4, 4)),
                     lattice=lattice).related(model)
     for i in range(200):
         assert (r.reshape(
             (-1, 200))[:, i] == Orientation(set_of_quaternions[i],
                                             lattice).related(model)).all()
예제 #3
0
 def test_in_FZ_vectorization(self, set_of_rodrigues, lattice):
     result = Orientation.from_Rodrigues_vector(
         rho=set_of_rodrigues.reshape(
             (-1, 4, 4)), lattice=lattice).in_FZ.reshape(-1)
     for r, rho in zip(result, set_of_rodrigues[:len(result)]):
         assert r == Orientation.from_Rodrigues_vector(
             rho=rho, lattice=lattice).in_FZ
예제 #4
0
 def test_relationship_vectorize(self, set_of_quaternions, lattice, model):
     result = Orientation(set_of_quaternions[:200].reshape(50, 4, 4),
                          lattice).related(model)
     ref_qu = result.rotation.quaternion.reshape(-1, 200, 4)
     for i in range(200):
         single = Orientation(set_of_quaternions[i],
                              lattice).related(model).rotation.quaternion
         assert np.allclose(ref_qu[:, i, :], single)
예제 #5
0
 def test_add_IPF_color(self, default, d):
     default.add_IPF_color(d, 'O')
     qu = default.place('O')
     crystal_structure = qu.dtype.metadata['lattice']
     c = Orientation(rotation=qu, lattice=crystal_structure)
     in_memory = np.uint8(c.IPF_color(np.array(d)) * 255)
     in_file = default.place('IPFcolor_({} {} {})'.format(*d))
     assert np.allclose(in_memory, in_file)
예제 #6
0
 def test_average(self, angle, lattice):
     R_1 = Orientation(
         Rotation.from_axis_angle([0, 0, 1, 10], degrees=True), lattice)
     R_2 = Orientation(
         Rotation.from_axis_angle([0, 0, 1, angle], degrees=True), lattice)
     avg_angle = R_1.average(R_2).rotation.as_axis_angle(degrees=True,
                                                         pair=True)[1]
     assert np.isclose(avg_angle, 10 + (angle - 10) / 2.)
예제 #7
0
 def test_reduced_equivalent(self, lattice):
     i = Orientation(lattice=lattice)
     o = Orientation.from_random(lattice=lattice)
     eq = o.equivalent
     FZ = np.argmin(
         abs(
             eq.misorientation(i.broadcast_to(
                 len(eq))).as_axis_angle(pair=True)[1]))
     assert o.reduced == eq[FZ]
예제 #8
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'))
예제 #9
0
 def test_disorientation_blending(self, family, left, right):
     o = Orientation.from_random(family=family, shape=left)
     p = Orientation.from_random(family=family, shape=right)
     blend = util.shapeblender(o.shape, p.shape)
     for loc in np.random.randint(0, blend, (10, len(blend))):
         # print(f'{a}/{b} @ {loc}')
         # print(o[tuple(loc[:len(o.shape)])].disorientation(p[tuple(loc[-len(p.shape):])]))
         # print(o.disorientation(p)[tuple(loc)])
         assert o[tuple(loc[:len(o.shape)])].disorientation(p[tuple(loc[-len(p.shape):])]) \
                .isclose(o.disorientation(p)[tuple(loc)])
예제 #10
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'))
예제 #11
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'))
예제 #12
0
 def test_to_frame_to_lattice(self, lattice, a, b, c, alpha, beta, gamma,
                              vector, keyFrame, keyLattice):
     L = Orientation(lattice=lattice,
                     a=a,
                     b=b,
                     c=c,
                     alpha=alpha,
                     beta=beta,
                     gamma=gamma)
     assert np.allclose(
         vector,
         L.to_frame(**{keyFrame: L.to_lattice(**{keyLattice: vector})}))
예제 #13
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'))
예제 #14
0
    def test_disorientation(self, lattice, N):
        o = Orientation.from_random(lattice=lattice, shape=N)
        p = Orientation.from_random(lattice=lattice, shape=N)

        d, ops = o.disorientation(p, return_operators=True)

        for n in range(N):
            assert np.allclose(d[n].as_quaternion(),
                               o[n].equivalent[ops[n][0]]
                                   .misorientation(p[n].equivalent[ops[n][1]])
                                   .as_quaternion()) \
                or np.allclose((~d)[n].as_quaternion(),
                                  o[n].equivalent[ops[n][0]]
                                      .misorientation(p[n].equivalent[ops[n][1]])
                                      .as_quaternion())
예제 #15
0
 def test_relationship_reference(self, update, reference_dir, model,
                                 lattice):
     reference = os.path.join(reference_dir,
                              '{}_{}.txt'.format(lattice, model))
     ori = Orientation(Rotation(), lattice)
     eu = np.array([
         o.rotation.as_Eulers(degrees=True)
         for o in ori.relatedOrientations(model)
     ])
     if update:
         coords = np.array([(1, i + 1) for i, x in enumerate(eu)])
         table = damask.Table(eu, {'Eulers': (3, )})
         table.add('pos', coords)
         table.to_ASCII(reference)
     assert np.allclose(eu,
                        damask.Table.from_ASCII(reference).get('Eulers'))
예제 #16
0
 def test_average(self, angle, lattice):
     o = Orientation.from_axis_angle(lattice=lattice,
                                     axis_angle=[[0, 0, 1, 10],
                                                 [0, 0, 1, angle]],
                                     degrees=True)
     avg_angle = o.average().as_axis_angle(degrees=True, pair=True)[1]
     assert np.isclose(avg_angle, 10 + (angle - 10) / 2.)
예제 #17
0
 def test_add_IPF_color(self, default, d):
     default.add_IPF_color('O', d)
     loc = {
         'orientation': default.get_dataset_location('O'),
         'color':
         default.get_dataset_location('IPFcolor_[{} {} {}]'.format(*d))
     }
     qu = default.read_dataset(loc['orientation']).view(np.double).reshape(
         -1, 4)
     crystal_structure = default.get_crystal_structure()
     in_memory = np.empty((qu.shape[0], 3), np.uint8)
     for i, q in enumerate(qu):
         o = Orientation(q, crystal_structure).reduced
         in_memory[i] = np.uint8(o.IPF_color(np.array(d)) * 255)
     in_file = default.read_dataset(loc['color'])
     assert np.allclose(in_memory, in_file)
예제 #18
0
 def test_IPF_color_vectorization(self, lattice, shape, vector, proper,
                                  in_SST):
     o = Orientation.from_random(lattice=lattice, shape=shape)
     for r, theO in zip(
             o.IPF_color(vector, in_SST=in_SST, proper=proper).reshape(
                 (-1, 3)), o.flatten()):
         assert np.allclose(
             r, theO.IPF_color(vector, in_SST=in_SST, proper=proper))
예제 #19
0
 def test_Schmid_vectorization(self, lattice):
     O = Orientation.from_random(shape=4, lattice=lattice)  # noqa
     for mode in ['slip', 'twin']:
         Ps = O.Schmid(N_slip='*') if mode == 'slip' else O.Schmid(
             N_twin='*')
         for i in range(4):
             P = O[i].Schmid(N_slip='*') if mode == 'slip' else O[i].Schmid(
                 N_twin='*')
             assert np.allclose(P, Ps[:, i])
예제 #20
0
 def test_to_SST_blending(self, family, left, right):
     o = Orientation.from_random(family=family, shape=left)
     v = np.random.random(right + (3, ))
     blend = util.shapeblender(o.shape, v.shape[:-1])
     for loc in np.random.randint(0, blend, (10, len(blend))):
         assert np.allclose(
             o[tuple(loc[:len(o.shape)])].to_SST(v[tuple(
                 loc[-len(v.shape[:-1]):])]),
             o.to_SST(v)[tuple(loc)])
예제 #21
0
 def test_from_directions(self, kwargs):
     for a, b in np.random.random((10, 2, 3)):
         c = np.cross(b, a)
         if np.all(np.isclose(c, 0)): continue
         o = Orientation.from_directions(uvw=a, hkl=c, **kwargs)
         x = o.to_pole(uvw=a)
         z = o.to_pole(hkl=c)
         assert np.isclose(np.dot(x/np.linalg.norm(x),np.array([1,0,0])),1) \
            and np.isclose(np.dot(z/np.linalg.norm(z),np.array([0,0,1])),1)
예제 #22
0
 def test_reduced_corner_cases(self, lattice):
     # test whether there is always a sym-eq rotation that falls into the FZ
     N = np.random.randint(10, 40)
     size = np.ones(3) * np.pi**(2. / 3.)
     grid = grid_filters.coordinates0_node([N + 1, N + 1, N + 1], size,
                                           -size * .5)
     evenly_distributed = Orientation.from_cubochoric(x=grid[:-2, :-2, :-2],
                                                      lattice=lattice)
     assert evenly_distributed.shape == evenly_distributed.reduced.shape
예제 #23
0
 def test_bases_contraction(self, lattice, a, b, c, alpha, beta, gamma):
     L = Orientation(lattice=lattice,
                     a=a,
                     b=b,
                     c=c,
                     alpha=alpha,
                     beta=beta,
                     gamma=gamma)
     assert np.allclose(
         np.eye(3), np.einsum('ik,jk', L.basis_real, L.basis_reciprocal))
예제 #24
0
 def test_unknown_relation_lattice(self, relation, lattice, a, b, c, alpha,
                                   beta, gamma):
     with pytest.raises(KeyError):
         Orientation(lattice=lattice,
                     a=a,
                     b=b,
                     c=c,
                     alpha=alpha,
                     beta=beta,
                     gamma=gamma).related(relation)  # noqa
예제 #25
0
 def test_negative_angle(self):
     with pytest.raises(ValueError):
         Orientation(lattice='aP',
                     a=1,
                     b=2,
                     c=3,
                     alpha=45,
                     beta=45,
                     gamma=-45,
                     degrees=True)  # noqa
예제 #26
0
 def test_excess_angle(self):
     with pytest.raises(ValueError):
         Orientation(lattice='aP',
                     a=1,
                     b=2,
                     c=3,
                     alpha=45,
                     beta=45,
                     gamma=90.0001,
                     degrees=True)  # noqa
예제 #27
0
 def test_to_SST_blending(self, lattice, a, b):
     o = Orientation.from_random(lattice=lattice, shape=a)
     v = np.random.random(b + (3, ))
     blend = util.shapeblender(o.shape, b)
     for loc in np.random.randint(0, blend, (10, len(blend))):
         print(f'{a}/{b} @ {loc}')
         print(o[tuple(loc[:len(o.shape)])].to_SST(v[tuple(loc[-len(b):])]))
         print(o.to_SST(v)[tuple(loc)])
         assert np.allclose(
             o[tuple(loc[:len(o.shape)])].to_SST(v[tuple(loc[-len(b):])]),
             o.to_SST(v)[tuple(loc)])
예제 #28
0
 def test_to_pole(self, shape, lattice, a, b, c, alpha, beta, gamma, vector,
                  kw, with_symmetry):
     o = Orientation.from_random(shape=shape,
                                 lattice=lattice,
                                 a=a,
                                 b=b,
                                 c=c,
                                 alpha=alpha,
                                 beta=beta,
                                 gamma=gamma)
     assert o.to_pole(**{kw:vector,'with_symmetry':with_symmetry}).shape \
         == o.shape + (o.symmetry_operations.shape if with_symmetry else ()) + vector.shape
예제 #29
0
 def test_from_fiber_component(self):
     r = Rotation.from_fiber_component(alpha=np.zeros(2),
                                       beta=np.zeros(2),
                                       sigma=0.0,
                                       N=1,
                                       rng_seed=0)
     assert np.all(
         Orientation.from_fiber_component(alpha=np.zeros(2),
                                          beta=np.zeros(2),
                                          sigma=0.0,
                                          N=1,
                                          rng_seed=0,
                                          lattice='triclinic').quaternion ==
         r.quaternion)
예제 #30
0
 def test_add_pole(self, default, options):
     default.add_pole(**options)
     rot = default.place('O')
     in_memory = Orientation(
         rot, lattice=rot.dtype.metadata['lattice']).to_pole(**options)
     brackets = ['[[]', '[]]'] if 'uvw' in options.keys() else [
         '(', ')'
     ]  # escape fnmatch
     label = '{}{} {} {}{}'.format(brackets[0],
                                   *(list(options.values())[0]),
                                   brackets[1])
     in_file = default.place(f'p^{label}')
     print(in_file - in_memory)
     assert np.allclose(in_memory, in_file)