Skip to content

Commit

Permalink
Improve test of sampling rotations taking Z-vector to fundamental sector
Browse files Browse the repository at this point in the history
Signed-off-by: Håkon Wiik Ånes <[email protected]>
  • Loading branch information
hakonanes-xn committed Apr 10, 2024
1 parent 574b205 commit 4a978df
Showing 1 changed file with 33 additions and 15 deletions.
48 changes: 33 additions & 15 deletions orix/tests/sampling/test_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import pytest

from orix.quaternion import Rotation
from orix.quaternion.symmetry import C2, C4, C6, D6, get_point_group
from orix.quaternion.symmetry import C2, C4, C6, D6, Oh, get_point_group
from orix.sampling import (
get_sample_fundamental,
get_sample_local,
Expand All @@ -34,6 +34,7 @@
_get_max_grid_angle,
_get_start_and_end_index,
)
from orix.vector import Vector3d


@pytest.fixture(scope="session")
Expand Down Expand Up @@ -182,17 +183,34 @@ def test_get_sample_fundamental_space_group(self, C6_sample):
assert np.isclose(ratio, 3, atol=0.2)

def test_get_sample_reduced_fundamental(self):
rotations = get_sample_reduced_fundamental(resolution=4)
rotations2 = get_sample_reduced_fundamental(resolution=4, point_group=C2)
rotations4 = get_sample_reduced_fundamental(resolution=4, point_group=C4)
rotations6 = get_sample_reduced_fundamental(resolution=4, point_group=C4)

assert (
np.abs(rotations.size / rotations2.size) - 2 < 0.1
) # about 2 times more rotations
assert (
np.abs(rotations2.size / rotations4.size) - 2 < 0.1
) # about 2 times more rotations
assert (
np.abs(rotations.size / rotations6.size) - 6 < 0.1
) # about 6 times more rotations
vz = Vector3d.zvector()

R_C1 = get_sample_reduced_fundamental(resolution=4)
v_C1 = R_C1 * vz
assert np.allclose(v_C1.mean().data, [0, 0, 0])

R_C4 = get_sample_reduced_fundamental(resolution=4, point_group=C4)
v_C4 = R_C4 * vz
assert np.all(v_C4 <= C4.fundamental_sector)

R_C6 = get_sample_reduced_fundamental(resolution=4, point_group=C6)
v_C6 = R_C6 * vz
assert np.all(v_C6 <= C6.fundamental_sector)

R_Oh = get_sample_reduced_fundamental(point_group=Oh)
v_Oh = R_Oh * vz
assert np.all(v_Oh <= Oh.fundamental_sector)

# Some rotations have a phi1 Euler angle of multiples of pi,
# presumably due to rounding errors
phi1_C1 = R_C1.to_euler()[:, 0].round(7)
assert np.allclose(np.unique(phi1_C1), [0, 2 * np.pi], atol=1e-7)
phi1_C4 = R_C4.to_euler()[:, 0].round(7)
assert np.allclose(np.unique(phi1_C4), [0, np.pi / 2], atol=1e-7)
phi1_C6 = R_C6.to_euler()[:, 0].round(7)
assert np.allclose(np.unique(phi1_C6), [0, np.pi / 2], atol=1e-7)
phi1_Oh = R_Oh.to_euler()[:, 0].round(7)
assert np.allclose(np.unique(phi1_Oh), [0, np.pi / 2], atol=1e-7)

R_Oh2 = get_sample_reduced_fundamental(point_group=Oh, method="icosahedral")
assert R_Oh.size > R_Oh2.size

0 comments on commit 4a978df

Please sign in to comment.