Skip to content

Commit

Permalink
Replace numpy-quaternion with quaternionic.
Browse files Browse the repository at this point in the history
  • Loading branch information
CSSFrancis committed Jul 29, 2024
1 parent e658e7b commit f8871cc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
30 changes: 15 additions & 15 deletions orix/quaternion/quaternion.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import dask.array as da
from dask.diagnostics import ProgressBar
import numpy as np
import quaternion
import quaternionic as quaternion

# import quaternion
from scipy.spatial.transform import Rotation as SciPyRotation

from orix._base import Object3d
Expand Down Expand Up @@ -214,8 +216,8 @@ def conj(self) -> Quaternion:
r"""Return the conjugate of the quaternion
:math:`Q^* = a - bi - cj - dk`.
"""
Q = quaternion.from_float_array(self.data).conj()
return self.__class__(quaternion.as_float_array(Q))
Q = quaternion.array(self.data).conj()
return self.__class__(quaternion.array(Q))

# ------------------------ Dunder methods ------------------------ #

Expand All @@ -224,17 +226,15 @@ def __invert__(self) -> Quaternion:

def __mul__(self, other: Union[Quaternion, Vector3d]):
if isinstance(other, Quaternion):
Q1 = quaternion.from_float_array(self.data)
Q2 = quaternion.from_float_array(other.data)
return other.__class__(quaternion.as_float_array(Q1 * Q2))
Q1 = quaternion.array(self.data)
Q2 = quaternion.array(other.data)
return other.__class__(quaternion.array(Q1 * Q2))
elif isinstance(other, Vector3d):
# check broadcast shape is correct before calculation, as
# quaternion.rotat_vectors will perform outer product
# this keeps current __mul__ broadcast behaviour
Q1 = quaternion.from_float_array(self.data)
v = quaternion.as_vector_part(
(Q1 * quaternion.from_vector_part(other.data)) * ~Q1
)
Q1 = quaternion.array(self.data)
v = ((Q1 * other.data.from_vector_part) * ~Q1).to_vector_part
if isinstance(other, Miller):
m = other.__class__(xyz=v, phase=other.phase)
m.coordinate_format = other.coordinate_format
Expand Down Expand Up @@ -1120,11 +1120,11 @@ def outer(
else:
da.store(darr, arr)
else:
Q1 = quaternion.from_float_array(self.data)
Q2 = quaternion.from_float_array(other.data)
Q1 = quaternion.array(self.data)
Q2 = quaternion.array(other.data)
# np.outer works with flattened array
Q = np.outer(Q1, Q2).reshape(Q1.shape + Q2.shape)
arr = quaternion.as_float_array(Q)
arr = quaternion.array(Q)
return other.__class__(arr)
elif isinstance(other, Vector3d):
if lazy:
Expand All @@ -1136,8 +1136,8 @@ def outer(
else:
da.store(darr, arr)
else:
Q = quaternion.from_float_array(self.data)
arr = quaternion.rotate_vectors(Q, other.data)
Q = quaternion.array(self.data)
arr = Q.rotate(other.data)
if isinstance(other, Miller):
m = other.__class__(xyz=arr, phase=other.phase)
m.coordinate_format = other.coordinate_format
Expand Down
3 changes: 2 additions & 1 deletion orix/quaternion/rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import dask.array as da
from dask.diagnostics import ProgressBar
import numpy as np
import quaternionic as quaternion
from scipy.special import hyp0f1

from orix.quaternion import Quaternion
Expand Down Expand Up @@ -96,7 +97,7 @@ def improper(self) -> np.ndarray:

@improper.setter
def improper(self, value: np.ndarray):
self._data[..., -1] = value
self._data[..., -1] = quaternion.array(value)

@property
def antipodal(self) -> Rotation:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"matplotlib-scalebar",
"numba",
"numpy",
"numpy-quaternion",
"quaternionic",
"pooch >= 0.13",
"scipy",
"tqdm",
Expand Down

0 comments on commit f8871cc

Please sign in to comment.