Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def orientation(request):
return Orientation(request.param)
def test_orientation_persistence(symmetry, vector):
v = symmetry.outer(vector).flatten()
o = Orientation.random()
oc = o.set_symmetry(symmetry)
v1 = o * v
v1 = Vector3d(v1.data.round(4))
v2 = oc * v
v2 = Vector3d(v2.data.round(4))
assert v1._tuples == v2._tuples
def __sub__(self, other):
if isinstance(other, Orientation):
misorientation = Misorientation(self * ~other)
m_inside = misorientation.set_symmetry(
self.symmetry, other.symmetry
).squeeze()
return m_inside
return NotImplemented
def orientations(self):
"""Rotations, respecting symmetry, in data."""
# TODO: Consider whether orientations should be calculated upon
# loading since computing orientations are slow (should benefit
# from dask!)
phases = self.phases_in_data
if phases.size == 1:
# Extract top matching rotations per point, if more than one
if self.rotations_per_point > 1:
rotations = self.rotations[:, 0]
else:
rotations = self.rotations
return Orientation(rotations).set_symmetry(phases[:].symmetry)
else:
raise ValueError(
f"Data has the phases {phases.names}, however, you are executing a "
"command that only permits one phase."
-------
Orientation
The instance itself, with equivalent values.
Examples
--------
>>> from orix.quaternion.symmetry import C4
>>> data = np.array([[0.5, 0.5, 0.5, 0.5], [0, 1, 0, 0]])
>>> o = Orientation(data).set_symmetry((C4))
>>> o
Orientation (2,) 4
[[-0.7071 0. -0.7071 0. ]
[ 0. 1. 0. 0. ]]
"""
return super(Orientation, self).set_symmetry(C1, symmetry)
def equivalent(self, grain_exchange=False):
"""Equivalent misorientations
grain_exchange : bool
If true the rotation g and g^{-1} are considered to be identical
Returns
-------
Misorientation
"""
Gl, Gr = self._symmetry
if grain_exchange and (Gl._tuples == Gr._tuples):
orientations = Orientation.stack([self, ~self]).flatten()
else:
orientations = Orientation(self)
equivalent = Gr.outer(orientations.outer(Gl))
return self.__class__(equivalent).flatten()
"""Equivalent misorientations
grain_exchange : bool
If true the rotation g and g^{-1} are considered to be identical
Returns
-------
Misorientation
"""
Gl, Gr = self._symmetry
if grain_exchange and (Gl._tuples == Gr._tuples):
orientations = Orientation.stack([self, ~self]).flatten()
else:
orientations = Orientation(self)
equivalent = Gr.outer(orientations.outer(Gl))
return self.__class__(equivalent).flatten()