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_rotate(vector, rotation, expected):
r = Vector3d(vector).rotate(Vector3d.zvector(), rotation)
assert isinstance(r, Vector3d)
assert np.allclose(r.data, expected)
def get_highest_order_axis(self):
axis_orders = self.get_axis_orders()
if len(axis_orders) == 0:
return Vector3d.zvector(), np.infty
highest_order = max(axis_orders.values())
axes = Vector3d.stack(
[ao for ao in axis_orders if axis_orders[ao] == highest_order]
).flatten()
return axes, highest_order
def axis(self):
"""Vector3d : the axis of rotation."""
axis = Vector3d(np.stack((self.b.data, self.c.data, self.d.data), axis=-1))
axis[self.a.data < -1e-6] = -axis[self.a.data < -1e-6]
axis[axis.norm.data == 0] = Vector3d.zvector() * np.sign(
self.a[axis.norm.data == 0].data
)
axis.data = axis.data / axis.norm.data[..., np.newaxis]
return axis
def fundamental_sector(self):
from orix.vector.neo_euler import AxAngle
from orix.vector.spherical_region import SphericalRegion
symmetry = self.antipodal
symmetry = symmetry[symmetry.angle > 0]
axes, order = symmetry.get_highest_order_axis()
if order > 6:
return Vector3d.empty()
axis = Vector3d.zvector().get_nearest(axes, inclusive=True)
r = Rotation.from_neo_euler(AxAngle.from_axes_angles(axis, 2 * np.pi / order))
diads = symmetry.diads
nearest_diad = axis.get_nearest(diads)
if nearest_diad.size == 0:
nearest_diad = axis.perpendicular
n1 = axis.cross(nearest_diad).unit
n2 = -(r * n1)
next_diad = r * nearest_diad
n = Vector3d.stack((n1, n2)).flatten()
sr = SphericalRegion(n.unique())
inside = symmetry[symmetry.axis < sr]
if inside.size == 0:
return sr
axes, order = inside.get_highest_order_axis()