How to use the orix.quaternion.Quaternion function in orix

To help you get started, we’ve selected a few orix examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pyxem / orix / tests / test_quaternion.py View on Github external
def test_init(input_length):
    with pytest.raises(DimensionError):
        Quaternion(tuple(range(input_length)))
github pyxem / orix / tests / test_quaternion.py View on Github external
def something(request):
    return Quaternion(request.param)
github pyxem / orix / tests / test_quaternion.py View on Github external
def quaternion(request):
    return Quaternion(request.param)
github pyxem / orix / tests / test_rotation.py View on Github external
def quaternion(request):
    return Quaternion(request.param)
github pyxem / orix / tests / test_quaternion.py View on Github external
def identity():
    return Quaternion((1, 0, 0, 0))
github pyxem / orix / tests / test_quaternion.py View on Github external
import numpy as np
import pytest
from orix.base import DimensionError
from orix.quaternion import Quaternion
from orix.vector import Vector3d

values = [
    (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.),
    ),
    Quaternion([
        [(0., 0., 0., 1.), (0.707, 0., 0., 0.707),],
        [(1., 1., 1., 1.), (0.707, 0., 0., 0.707),]
    ]),
    np.array((4, 3, 2, 1))
]


@pytest.fixture(params=values)
def quaternion(request):
    return Quaternion(request.param)


@pytest.fixture
def identity():
    return Quaternion((1, 0, 0, 0))
github pyxem / orix / tests / test_rotation.py View on Github external
def test_mul_quaternion(rotation, quaternion, expected):
    r = rotation * quaternion
    assert isinstance(r, Quaternion)
    assert np.allclose(r.data, expected)
    rotation.improper = 1
    ri = rotation * quaternion
    assert np.allclose(r.data, ri.data)
github pyxem / orix / orix / quaternion / rotation.py View on Github external
def __mul__(self, other):
        if isinstance(other, Rotation):
            q = Quaternion(self) * Quaternion(other)
            r = other.__class__(q)
            i = np.logical_xor(self.improper, other.improper)
            r.improper = i
            return r
        if isinstance(other, Quaternion):
            q = Quaternion(self) * other
            return q
        if isinstance(other, Vector3d):
            v = Quaternion(self) * other
            improper = (self.improper * np.ones(other.shape)).astype(bool)
            v[improper] = -v[improper]
            return v
        if isinstance(other, int) or isinstance(other, list):  # has to plus/minus 1
            other = np.atleast_1d(other).astype(int)
        if isinstance(other, np.ndarray):
            assert np.all(
github pyxem / orix / orix / quaternion / orientation_region.py View on Github external
def __gt__(self, other):
        """
        overidden greater than method. Applying this to an Orientation
        will return only orientations those that lie within the OrientationRegion
        """

        c = Quaternion(self).dot_outer(Quaternion(other)).data
        inside = np.logical_or(
            np.all(np.greater_equal(c, -EPSILON), axis=0),
            np.all(np.less_equal(c, +EPSILON), axis=0),
        )
        return inside
github pyxem / orix / orix / quaternion / rotation.py View on Github external
if convention == "Krakow_Hielscher":
            # To be applied to the data found at:
            # https://www.repository.cam.ac.uk/handle/1810/263510
            euler = np.array(euler)
            n = euler.shape[:-1]
            alpha, beta, gamma = euler[..., 0], euler[..., 1], euler[..., 2]
            alpha -= np.pi / 2
            gamma -= 3 * np.pi / 2
            zero = np.zeros(n)
            qalpha = Quaternion(
                np.stack((np.cos(alpha / 2), zero, zero, np.sin(alpha / 2)), axis=-1)
            )
            qbeta = Quaternion(
                np.stack((np.cos(beta / 2), zero, np.sin(beta / 2), zero), axis=-1)
            )
            qgamma = Quaternion(
                np.stack((np.cos(gamma / 2), zero, zero, np.sin(gamma / 2)), axis=-1)
            )
            data = qalpha * qbeta * qgamma

            rot = cls(data.data)
            rot.improper = zero
            return rot

        elif convention == "bunge":
            euler = np.array(euler)
            n = euler.shape[:-1]

            # Uses A.5 & A.6 from Modelling Simul. Mater. Sci. Eng. 23 (2015) 083501

            alpha = euler[..., 0]  # psi1
            beta = euler[..., 1]  # Psi