Skip to content

Commit

Permalink
Added test of property sample_to_detector to TestEBSDDetector class
Browse files Browse the repository at this point in the history
The new EBSDDetector property sample_to_detector returns a Rotation.
The test checks the type is correct and that values are correct according
to some expected values for different parameters.

Signed-off-by: tgwoodcock <tgwoodcock@users.noreply.github.com>
  • Loading branch information
tgwoodcock committed Dec 10, 2024
1 parent 0063232 commit 07ed838
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/test_detectors/test_ebsd_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import matplotlib.pyplot as plt
import numpy as np
from orix.crystal_map import PhaseList
from orix.quaternion import Rotation
import pytest

import kikuchipy as kp
Expand Down Expand Up @@ -212,6 +213,59 @@ def test_gnomonic_scale(self, pc1, shape, desired_x_scale, desired_y_scale):
assert np.allclose(detector.x_scale, desired_x_scale, atol=1e-6)
assert np.allclose(detector.y_scale, desired_y_scale, atol=1e-6)

@pytest.mark.parametrize(
"tilt, azimuthal, twist, sample_tilt, expected_angle, expected_axis, expected_rotation",
[
(
0,
0,
0,
90,
90.0,
np.array([0.0, 0.0, 1.0]),
np.array([[0.70710678, 0.0, 0.0, 0.70710678]]),
),
(
0,
0,
0,
70,
91.7279410723505,
np.array([0.17108787, 0.17108787, 0.97028753]),
np.array([[0.69636424, 0.1227878, 0.1227878, 0.69636424]]),
),
(
8.3,
4.7,
1.02,
70,
94.94104636971042,
np.array([0.19765823, 0.27176174, 0.94184754]),
np.array([[0.67596942, 0.14566022, 0.20026929, 0.69407539]]),
),
],
)
def test_sample_to_detector(
self,
tilt,
azimuthal,
twist,
sample_tilt,
expected_angle,
expected_axis,
expected_rotation,
):
"""Check the Rotation sample_to_detector has the correct type and values."""
detector = kp.detectors.EBSDDetector(
tilt=tilt, azimuthal=azimuthal, twist=twist, sample_tilt=sample_tilt
)
smpl_to_det = detector.sample_to_detector

assert isinstance(smpl_to_det, Rotation)
assert np.allclose(np.rad2deg(smpl_to_det.angle)[0], expected_angle)
assert np.allclose(smpl_to_det.axis.data.squeeze(), expected_axis)
assert np.allclose(smpl_to_det.data, expected_rotation)

def test_coordinate_conversion_factors(self):
"""Factors for converting between pixel and gonomic coords."""
s = kp.data.nickel_ebsd_small()
Expand Down

0 comments on commit 07ed838

Please sign in to comment.