Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_mul_rotation(r1, i1, r2, i2, expected, expected_i):
r1 = Rotation(r1)
r1.improper = i1
r2 = Rotation(r2)
r2.improper = i2
r = r1 * r2
assert isinstance(r, Rotation)
assert np.allclose(r.data, expected)
assert np.all(r.improper == expected_i)
import itertools
from orix.quaternion import Quaternion
from orix.quaternion.rotation import Rotation
from orix.vector import Vector3d
rotations = [
(0.707, 0., 0., 0.707),
(0.5, -0.5, -0.5, 0.5),
(0., 0., 0., 1.),
(1., 1., 1., 1.),
(
(0.5, -0.5, -0.5, 0.5),
(0., 0., 0., 1.),
),
Rotation([
(2, 4, 6, 8),
(-1, -2, -3, -4)
]),
np.array((4, 3, 2, 1))
]
quaternions = [
(0.881, 0.665, 0.123, 0.517),
(0.111, 0.222, 0.333, 0.444),
(
(1, 0, 0.5, 0),
(3, 1, -1, -2),
),
[
[[0.343, 0.343, 0, -0.333], [-7, -8, -9, -10],],
[[0.00001, -0.0001, 0.001, -0.01], [0, 0, 0, 0]]
... lattice=Lattice(0.287, 0.287, 0.287, 90, 90, 90)
... )
... ]
>>> cm = CrystalMap(
... rotations=rotations,
... phase_id=phase_id,
... x=x,
... y=y,
... phase_name=["austenite", "ferrite"], # Overwrites Structure.title
... symmetry=["432", "432"],
... structure=structures,
... prop=properties,
... )
"""
# Set rotations
if not isinstance(rotations, Rotation):
raise ValueError(
f"rotations must be of type {Rotation}, not {type(rotations)}."
)
self._rotations = rotations
# Set data size
data_size = rotations.shape[0]
# Set phase IDs
if phase_id is None: # Assume single phase data
phase_id = np.zeros(data_size)
phase_id = phase_id.astype(int)
self._phase_id = phase_id
# Set data point IDs
point_id = np.arange(data_size)
Returns
-------
Rotation
"""
normal_combinations = list(itertools.combinations(self, 3))
if len(normal_combinations) < 1:
return Rotation.empty()
c1, c2, c3 = zip(*normal_combinations)
c1, c2, c3 = (
Rotation.stack(c1).flatten(),
Rotation.stack(c2).flatten(),
Rotation.stack(c3).flatten(),
)
v = Rotation.triple_cross(c1, c2, c3)
v = v[~np.any(np.isnan(v.data), axis=-1)]
v = v[v < self].unique()
surface = np.any(np.isclose(v.dot_outer(self).data, 0), axis=1)
return v[surface]
These angles, as well as :math:`0`, or the identity, expressed as quaternions,
form a group. Applying any operation in the group to any other results in
another member of the group.
Symmetries can consist of rotations or inversions, expressed as
improper rotations. A mirror symmetry is equivalent to a 2-fold rotation
combined with inversion.
"""
import numpy as np
from orix.quaternion.rotation import Rotation
from orix.vector import Vector3d
class Symmetry(Rotation):
"""The set of rotations comprising a point group.
"""
name = ""
def __repr__(self):
cls = self.__class__.__name__
shape = str(self.shape)
data = np.array_str(self.data, precision=4, suppress_small=True)
rep = "{} {}{pad}{}\n{}".format(
cls, shape, self.name, data, pad=self.name and " "
)
return rep
def __and__(self, other):
Parameters
----------
shape : int or tuple of int, optional
The shape of the required object.
alpha : float
Parameter for the VM-F distribution. Lower values lead to "looser"
distributions.
reference : Rotation
The center of the distribution.
eps : float
A small fixed variable.
"""
shape = (shape,) if isinstance(shape, int) else shape
reference = Rotation(reference)
n = int(np.prod(shape))
sample_size = int(alpha) * n
rotations = []
f_max = von_mises(reference, alpha, reference)
while len(rotations) < n:
rotation = cls.random(sample_size)
f = von_mises(rotation, alpha, reference)
x = np.random.rand(sample_size)
rotation = rotation[x * f_max < f]
rotations += list(rotation)
return cls.stack(rotations[:n]).reshape(*shape)
def dot_outer(self, other):
"""Scalar : the outer dot product of this rotation and the other."""
cosines = np.abs(super(Rotation, self).dot_outer(other).data)
if isinstance(other, Rotation):
improper = self.improper.reshape(self.shape + (1,) * len(other.shape))
i = np.logical_xor(improper, other.improper)
cosines = np.minimum(~i, cosines)
else:
cosines[self.improper] = 0
return Scalar(cosines)