Skip to content

Commit

Permalink
Merge pull request #504 from hakonanes/minor-dev-updates
Browse files Browse the repository at this point in the history
Minor dev updates
  • Loading branch information
hakonanes committed May 14, 2024
2 parents 006e85d + 1a4f344 commit 688ee4a
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 278 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ name: build

on:
push:
branches:
- '*'
branches-ignore:
- 'pre-commit-ci-update-config'
pull_request:
branches:
- '*'
workflow_dispatch:
workflow: '*'

jobs:
code:
Expand Down
5 changes: 5 additions & 0 deletions .zenodo.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
"name": "Anders Christian Mathisen",
"affiliation": "Norwegian University of Science and Technology"
},
{
"name": "Zhou Xu",
"orcid": "0000-0002-7599-1166",
"affiliation": "Monash Centre for Electron Microscopy"
},
{
"name": "Carter Francis",
"orcid": "0000-0003-2564-1851",
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ Changed

Removed
-------
- Removed deprecated ``from_neo_euler()`` method for ``Quaternion`` and its subclasses.
- Removed deprecated argument ``convention`` in ``from_euler()`` and ``to_euler()``
methods for ``Quaternion`` and its subclasses. Use ``direction`` instead. Passing
``convention`` will now raise an error.

Deprecated
----------
Expand Down
1 change: 1 addition & 0 deletions orix/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"Duncan Johnstone",
"Niels Cautaerts",
"Anders Christian Mathisen",
"Zhou Xu",
"Carter Francis",
"Simon Høgås",
"Viljar Johan Femoen",
Expand Down
33 changes: 2 additions & 31 deletions orix/quaternion/orientation.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@
import numpy as np
from scipy.spatial.transform import Rotation as SciPyRotation

from orix._util import deprecated
from orix.quaternion.misorientation import Misorientation
from orix.quaternion.rotation import Rotation
from orix.quaternion.symmetry import C1, Symmetry, _get_unique_symmetry_elements
from orix.vector import Miller, NeoEuler, Vector3d
from orix.vector import Miller, Vector3d


class Orientation(Misorientation):
Expand Down Expand Up @@ -107,15 +106,13 @@ def __sub__(self, other: Orientation) -> Misorientation:

# ------------------------ Class methods ------------------------- #

# TODO: Remove use of **kwargs in 1.0
@classmethod
def from_euler(
cls,
euler: Union[np.ndarray, tuple, list],
symmetry: Optional[Symmetry] = None,
direction: str = "lab2crystal",
degrees: bool = False,
**kwargs,
) -> Orientation:
"""Create orientations from sets of Euler angles
:cite:`rowenhorst2015consistent`.
Expand All @@ -141,7 +138,7 @@ def from_euler(
O
Orientations.
"""
O = super().from_euler(euler, direction=direction, degrees=degrees, **kwargs)
O = super().from_euler(euler, direction=direction, degrees=degrees)
if symmetry:
O.symmetry = symmetry
return O
Expand Down Expand Up @@ -261,32 +258,6 @@ def from_matrix(
O.symmetry = symmetry
return O

# TODO: Remove before 0.13.0
@classmethod
@deprecated(since="0.12", removal="0.13", alternative="from_axes_angles")
def from_neo_euler(
cls, neo_euler: NeoEuler, symmetry: Optional[Symmetry] = None
) -> Orientation:
"""Create orientations from a neo-euler (vector) representation.
Parameters
----------
neo_euler
Vector parametrization of orientation(s).
symmetry
Symmetry of orientation(s). If not given (default), no
symmetry is set.
Returns
-------
O
Orientations.
"""
O = super().from_neo_euler(neo_euler)
if symmetry:
O.symmetry = symmetry
return O

@classmethod
def from_axes_angles(
cls,
Expand Down
40 changes: 2 additions & 38 deletions orix/quaternion/quaternion.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,9 @@
from scipy.spatial.transform import Rotation as SciPyRotation

from orix._base import Object3d
from orix._util import deprecated, deprecated_argument
from orix.quaternion import _conversions
from orix.vector import AxAngle, Homochoric, Miller, Rodrigues, Vector3d

# Used to round values below 1e-16 to zero
_FLOAT_EPS = np.finfo(float).eps


class Quaternion(Object3d):
r"""Quaternions.
Expand Down Expand Up @@ -259,31 +255,6 @@ def __eq__(self, other: Union[Any, Quaternion]) -> bool:

# ------------------------ Class methods ------------------------- #

# TODO: Remove before 0.13.0
@classmethod
@deprecated(since="0.12", removal="0.13", alternative="from_axes_angles")
def from_neo_euler(cls, neo_euler: "NeoEuler") -> Quaternion:
"""Create unit quaternion(s) from a neo-euler (vector)
representation.
Parameters
----------
neo_euler
Vector parametrization of quaternions.
Returns
-------
Q
Unit quaternion(s).
"""
s = np.sin(neo_euler.angle / 2)
a = np.cos(neo_euler.angle / 2)
b = s * neo_euler.axis.x
c = s * neo_euler.axis.y
d = s * neo_euler.axis.z
Q = cls(np.stack([a, b, c, d], axis=-1)).unit
return Q

@classmethod
def from_axes_angles(
cls,
Expand Down Expand Up @@ -485,15 +456,12 @@ def from_rodrigues(

return Q

# TODO: Remove decorator, **kwargs, and use of "convention" in 0.13
@classmethod
@deprecated_argument("convention", "0.9", "0.13", "direction")
def from_euler(
cls,
euler: Union[np.ndarray, tuple, list],
direction: str = "lab2crystal",
degrees: bool = False,
**kwargs,
) -> Quaternion:
"""Create unit quaternions from Euler angle sets
:cite:`rowenhorst2015consistent`.
Expand All @@ -517,9 +485,7 @@ def from_euler(
Unit quaternions.
"""
direction = direction.lower()
if direction == "mtex" or (
"convention" in kwargs and kwargs["convention"] == "mtex"
):
if direction == "mtex":
# MTEX' rotations are transformations from the crystal to
# the lab reference frames. See
# https://mtex-toolbox.github.io/MTEXvsBungeConvention.html
Expand Down Expand Up @@ -804,9 +770,7 @@ def identity(cls, shape: Union[int, tuple] = (1,)) -> Quaternion:

# ---------------------- All "to_*" methods- --------------------- #

# TODO: Remove decorator and **kwargs in 0.13
@deprecated_argument("convention", since="0.9", removal="0.13")
def to_euler(self, degrees: bool = False, **kwargs) -> np.ndarray:
def to_euler(self, degrees: bool = False) -> np.ndarray:
r"""Return the unit quaternions as Euler angles in the Bunge
convention :cite:`rowenhorst2015consistent`.
Expand Down
3 changes: 0 additions & 3 deletions orix/quaternion/rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
from orix.quaternion import Quaternion
from orix.vector import Vector3d

# Used to round values below 1e-16 to zero
_FLOAT_EPS = np.finfo(float).eps


class Rotation(Quaternion):
r"""Rotations of coordinate systems, leaving objects in place.
Expand Down
73 changes: 2 additions & 71 deletions orix/tests/quaternion/test_orientation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
# You should have received a copy of the GNU General Public License
# along with orix. If not, see <http://www.gnu.org/licenses/>.

import warnings

from diffpy.structure import Lattice, Structure
import matplotlib.pyplot as plt
import numpy as np
Expand All @@ -43,7 +41,7 @@
_groups,
_proper_groups,
)
from orix.vector import AxAngle, Miller, Vector3d
from orix.vector import Miller, Vector3d
# isort: on
# fmt: on

Expand Down Expand Up @@ -522,22 +520,7 @@ def test_from_align_vectors(self):
):
_ = Orientation.from_align_vectors(a, b)

def test_from_neo_euler_symmetry(self):
v = AxAngle.from_axes_angles(axes=Vector3d.zvector(), angles=np.pi / 2)
with pytest.warns(np.VisibleDeprecationWarning):
o1 = Orientation.from_neo_euler(v)
assert np.allclose(o1.data, [0.7071, 0, 0, 0.7071])
assert o1.symmetry.name == "1"
with pytest.warns(np.VisibleDeprecationWarning):
o2 = Orientation.from_neo_euler(v, symmetry=Oh)
o2 = o2.map_into_symmetry_reduced_zone()
assert np.allclose(o2.data, [-1, 0, 0, 0])
assert o2.symmetry.name == "m-3m"
o3 = Orientation(o1.data, symmetry=Oh)
o3 = o3.map_into_symmetry_reduced_zone()
assert np.allclose(o3.data, o2.data)

def test_from_axes_angles(self, rotations):
def test_from_axes_angles(self):
axis = Vector3d.xvector() - Vector3d.yvector()
angle = np.pi / 2
o1 = Orientation.from_axes_angles(axis, angle, Oh)
Expand Down Expand Up @@ -587,58 +570,6 @@ def test_from_scipy_rotation(self):
with pytest.raises(TypeError, match="Value must be an instance of"):
_ = Orientation.from_scipy_rotation(r_scipy, (Oh, Oh))

# TODO: Remove in 0.13
def test_from_euler_warns(self):
"""Orientation.from_euler() warns only once when "convention"
argument is passed.
"""
euler = np.random.rand(10, 3)

with warnings.catch_warnings():
warnings.filterwarnings("error")
_ = Orientation.from_euler(euler)

msg = (
r"Argument `convention` is deprecated and will be removed in version 0.13. "
r"To avoid this warning, please do not use `convention`. "
r"Use `direction` instead. See the documentation of `from_euler\(\)` for "
"more details."
)
with pytest.warns(np.VisibleDeprecationWarning, match=msg) as record2:
_ = Orientation.from_euler(euler, convention="whatever")
assert len(record2) == 1

# TODO: Remove in 0.13
def test_from_euler_convention_mtex(self):
"""Passing convention="mtex" to Orientation.from_euler() works
but warns once.
"""
euler = np.random.rand(10, 3)
ori1 = Orientation.from_euler(euler, direction="crystal2lab")
with pytest.warns(np.VisibleDeprecationWarning, match=r"Argument `convention`"):
ori2 = Orientation.from_euler(euler, convention="mtex")
assert np.allclose(ori1.data, ori2.data)

# TODO: Remove in 0.13
def test_to_euler_convention_warns(self):
"""Orientation.to_euler() warns only once when "convention"
argument is passed.
"""
ori1 = Orientation.from_euler(np.random.rand(10, 3))

with warnings.catch_warnings():
warnings.filterwarnings("error")
ori2 = ori1.to_euler()

msg = (
r"Argument `convention` is deprecated and will be removed in version 0.13. "
r"To avoid this warning, please do not use `convention`. "
r"See the documentation of `to_euler\(\)` for more details."
)
with pytest.warns(np.VisibleDeprecationWarning, match=msg):
ori3 = ori1.to_euler(convention="whatever")
assert np.allclose(ori2, ori3)


class TestOrientation:
@pytest.mark.parametrize("symmetry", [C1, C2, C3, C4, D2, D3, D6, T, O, Oh])
Expand Down
Loading

0 comments on commit 688ee4a

Please sign in to comment.