Skip to content

Commit

Permalink
Merge #405 from hakonanes/fix-404
Browse files Browse the repository at this point in the history
Change rounding from 12 to 10 decimals when finding unique vectors and rotations
  • Loading branch information
pc494 authored Oct 24, 2022
2 parents 14bc03b + 19ceea2 commit 15ea242
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 8 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ All notable changes to the ``orix`` project are documented in this file.
The format is based on `Keep a Changelog <https://keepachangelog.com/en/1.0.0/>`_, and
this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0.html>`_.

2022-10-25 - version 0.10.2
===========================

Fixed
-----
- ``Miller.symmetrise(unique=True)`` return the correct number of symmetrically
equivalent but unique vectors, by rounding to 10 instead of 12 decimals prior to
finding the unique vectors with NumPy.

Changed
-------
- Unique rotations and vectors are now found by rounding to 10 instead of 12 decimals.

2022-10-03 - version 0.10.1
===========================

Expand Down
2 changes: 1 addition & 1 deletion orix/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__name__ = "orix"
__version__ = "0.10.1"
__version__ = "0.10.2"
__author__ = "orix developers"
__author_email__ = "[email protected]"
__description__ = "orix is an open-source Python library for handling crystal orientation mapping data."
Expand Down
4 changes: 2 additions & 2 deletions orix/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def unique(
The indices of the (flattened) data in the unique array if
``return_inverse=True``.
"""
data = self.flatten()._data.round(12)
data = self.flatten()._data.round(10)
data = data[~np.all(np.isclose(data, 0), axis=1)] # Remove zeros
_, idx, inv = np.unique(data, axis=0, return_index=True, return_inverse=True)
obj = self.__class__(data[np.sort(idx), : self.dim])
Expand Down Expand Up @@ -284,7 +284,7 @@ def transpose(self, *axes: Optional[int]) -> Object3d:
+ f"{tuple(axes)} does not fit with {self.shape}."
)

return self.__class__(self.data.transpose(*axes, -1))
return self.__class__(self.data.transpose(*axes + (-1,)))

def get_random_sample(
self, size: Optional[int] = 1, replace: bool = False, shuffle: bool = False
Expand Down
9 changes: 6 additions & 3 deletions orix/quaternion/rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def unique(
rotation.improper,
],
axis=-1,
).round(12)
).round(10)
_, idx, inv = np.unique(abcd, axis=0, return_index=True, return_inverse=True)
idx_argsort = np.argsort(idx)
idx_sort = idx[idx_argsort]
Expand Down Expand Up @@ -513,7 +513,10 @@ def to_euler(self, **kwargs) -> np.ndarray:
@classmethod
@deprecated_argument("convention", "0.9", "1.0", "direction")
def from_euler(
cls, euler: np.ndarray, direction: str = "lab2crystal", **kwargs
cls,
euler: Union[np.ndarray, list, tuple],
direction: str = "lab2crystal",
**kwargs,
) -> Rotation:
"""Create a rotation from an array of Euler angles in radians.
Expand Down Expand Up @@ -623,7 +626,7 @@ def to_matrix(self) -> np.ndarray:
return om

@classmethod
def from_matrix(cls, matrix: np.ndarray) -> Rotation:
def from_matrix(cls, matrix: Union[np.ndarray, list, tuple]) -> Rotation:
"""Return rotations from the orientation matrices
:cite:`rowenhorst2015consistent`.
Expand Down
22 changes: 22 additions & 0 deletions orix/tests/test_miller.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
TETRAGONAL_PHASE = Phase(
point_group="4", structure=Structure(lattice=TETRAGONAL_LATTICE)
)
HEXAGONAL_PHASE = Phase(
point_group="6/mmm",
structure=Structure(lattice=Lattice(3.073, 3.073, 10.053, 90, 90, 120)),
)
CUBIC_PHASE = Phase(point_group="m-3m")


Expand Down Expand Up @@ -206,6 +210,24 @@ def test_symmetrise(self):
)
assert np.allclose(mult2, [6, 12, 8])

# Test from https://github.com/pyxem/orix/issues/404
m3 = Miller(UVTW=[1, -1, 0, 0], phase=HEXAGONAL_PHASE)
assert np.allclose(m3.multiplicity, 6)
# fmt: off
assert np.allclose(
m3.symmetrise(unique=True).data,
[
[ 4.6095, -2.6613, 0],
[ 0 , 5.3226, 0],
[-4.6095, -2.6613, 0],
[-4.6095, 2.6613, 0],
[ 0 , -5.3226, 0],
[ 4.6095, 2.6613, 0],
],
atol=1e-4,
)
# fmt: on

def test_unique(self):
# From the "Crystal geometry" notebook
diamond = Phase(space_group=227)
Expand Down
2 changes: 1 addition & 1 deletion orix/vector/miller.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ def unique(
operations = self.phase.point_group
n_v = v.size
v2 = operations.outer(v).flatten().reshape(*(n_v, operations.size))
data = v2.data.round(12)
data = v2.data.round(10)
data_sorted = np.zeros_like(data)
for i in range(n_v):
a = data[i]
Expand Down
2 changes: 1 addition & 1 deletion orix/vector/vector3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ def angle_with(self, other: Vector3d) -> np.ndarray:
angles
The angle between the vectors, in radians.
"""
cosines = np.round(self.dot(other) / self.norm / other.norm, 12)
cosines = np.round(self.dot(other) / self.norm / other.norm, 10)
return np.arccos(cosines)

def rotate(
Expand Down

0 comments on commit 15ea242

Please sign in to comment.