Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix EBSD orientation refinement on Windows #495

Merged
merged 8 commits into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ best to adhere to `Semantic Versioning <https://semver.org/spec/v2.0.0.html>`_.
Contributors to each release are listed in alphabetical order by first name. List
entries are sorted in descending chronological order.

0.5.7 (2022-01-10)
==================

Contributors
------------
- Håkon Wiik Ånes

Fixed
-----
- EBSD orientation refinement on Windows producing garbage results due to unpredictable
behaviour in Numba function which converts Euler triplet to quaternion.
(`#495 <https://github.com/pyxem/kikuchipy/pull/495>`_)

0.5.6 (2022-01-02)
==================

Expand Down
19 changes: 9 additions & 10 deletions kikuchipy/_rotation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,15 @@ def _rotation_from_euler(alpha: float, beta: float, gamma: float) -> np.ndarray:
This function is optimized with Numba, so care must be taken with
array shapes and data types.
"""
sigma = 0.5 * np.add(alpha, gamma)
delta = 0.5 * np.subtract(alpha, gamma)
c = np.cos(beta / 2)
s = np.sin(beta / 2)

rotation = np.zeros(4)
rotation[0] = c * np.cos(sigma)
rotation[1] = -s * np.cos(delta)
rotation[2] = -s * np.sin(delta)
rotation[3] = -c * np.sin(sigma)
sigma = 0.5 * (alpha + gamma)
delta = 0.5 * (alpha - gamma)
c = np.cos(0.5 * beta)
s = np.sin(0.5 * beta)

rotation = np.array(
(c * np.cos(sigma), -s * np.cos(delta), -s * np.sin(delta), -c * np.sin(sigma)),
dtype=np.float64,
)

if rotation[0] < 0:
rotation = -rotation
Expand Down
51 changes: 51 additions & 0 deletions kikuchipy/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,57 @@ def oxford_binary_file(tmpdir, request):
yield f


@pytest.fixture
def nickel_ebsd_small_di_xmap():
"""Yield an :class:`~orix.crystal_map.CrystalMap` from dictionary
indexing of the :func:`kikuchipy.data.nickel_ebsd_small` data set.

Dictionary indexing was performed with the following script:

.. code-block:: python

import kikuchipy as kp
from orix.sampling import get_sample_fundamental


s = kp.data.nickel_ebsd_small()
s.remove_static_background()
s.remove_dynamic_background()

mp = kp.data.nickel_ebsd_master_pattern_small(energy=20, projection="lambert")
rot = get_sample_fundamental(resolution=1.4, point_group=mp.phase.point_group)
detector = kp.detectors.EBSDDetector(
shape=s.axes_manager.signal_shape[::-1],
sample_tilt=70,
pc=(0.421, 0.7794, 0.5049),
convention="tsl"
)
sim_dict = mp.get_patterns(rotations=rot, detector=detector, energy=20)
xmap = s.dictionary_indexing(dictionary=sim_dict, keep_n=1)
"""
coords, _ = create_coordinate_arrays(shape=(3, 3), step_sizes=(1.5, 1.5))
# fmt: off
grain1 = (0.9542, -0.0183, -0.2806, 0.1018)
grain2 = (0.9542, 0.0608, -0.2295, -0.1818)
xmap = CrystalMap(
rotations=Rotation((
grain1, grain2, grain2,
grain1, grain2, grain2,
grain1, grain2, grain2
)),
x=coords["x"],
y=coords["y"],
prop=dict(scores=np.array((
0.4364652, 0.3772456, 0.4140171,
0.4537009, 0.37445727, 0.43675864,
0.42391658, 0.38740265, 0.41931134
))),
phase_list=PhaseList(Phase("ni", 225, "m-3m")),
)
# fmt: on
yield xmap


# ---------------------- pytest doctest-modules ---------------------- #


Expand Down
6 changes: 3 additions & 3 deletions kikuchipy/indexing/_refinement/_refinement.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ def compute_refine_orientation_results(
refined_xmap
Crystal map with refined orientations and scores.
"""
n_patterns = np.prod(results.shape[:-1])
n_patterns = int(np.prod(results.shape[:-1]))
with ProgressBar():
print(f"Refining {n_patterns} orientation(s):", file=sys.stdout)
time_start = time()
Expand Down Expand Up @@ -798,7 +798,7 @@ def compute_refine_projection_center_results(
new_detector : :class:`~kikuchipy.detectors.EBSDDetector`
EBSD detector with refined projection center parameters.
"""
n_patterns = np.prod(results.shape[:-1])
n_patterns = int(np.prod(results.shape[:-1]))
nav_shape = xmap.shape
with ProgressBar():
print(f"Refining {n_patterns} projection center(s):", file=sys.stdout)
Expand Down Expand Up @@ -847,7 +847,7 @@ def compute_refine_orientation_projection_center_results(
new_detector : :class:`~kikuchipy.detectors.EBSDDetector`
EBSD detector with refined projection center parameters.
"""
n_patterns = np.prod(results.shape[:-1])
n_patterns = int(np.prod(results.shape[:-1]))
nav_shape = xmap.shape
with ProgressBar():
print(
Expand Down
2 changes: 1 addition & 1 deletion kikuchipy/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@
name = "kikuchipy"
platforms = ["Linux", "MacOS X", "Windows"]
status = "Development"
version = "0.5.6"
version = "0.5.7"
23 changes: 23 additions & 0 deletions kikuchipy/signals/tests/test_ebsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1646,6 +1646,29 @@ def test_refine_orientation_chunking(
)
assert dask_array.chunksize == chunksize

def test_refine_orientation_nickel_ebsd_small(
self, nickel_ebsd_small_di_xmap, detector
):
xmap = nickel_ebsd_small_di_xmap

s = kp.data.nickel_ebsd_small()
s.remove_static_background()
s.remove_dynamic_background()

energy = 20
xmap_ref = s.refine_orientation(
xmap=xmap,
detector=detector,
master_pattern=kp.data.nickel_ebsd_master_pattern_small(
energy=energy,
projection="lambert",
hemisphere="north",
),
energy=energy,
)

assert np.all(xmap_ref.scores > xmap.scores)

# ------------------- Refine projection centers ------------------ #

@pytest.mark.parametrize(
Expand Down