From 24315cef462580987c9ff3220afd77fd5dbe8cf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Wiik=20=C3=85nes?= Date: Sun, 9 Jan 2022 15:28:24 +0100 Subject: [PATCH 1/8] Test refinement of oris. from DI of small Ni EBSD data set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Håkon Wiik Ånes --- kikuchipy/conftest.py | 59 ++++++++++++++++++++++++++++ kikuchipy/signals/tests/test_ebsd.py | 21 ++++++++++ 2 files changed, 80 insertions(+) diff --git a/kikuchipy/conftest.py b/kikuchipy/conftest.py index ca1cf25e..cb6c4f05 100644 --- a/kikuchipy/conftest.py +++ b/kikuchipy/conftest.py @@ -479,6 +479,65 @@ 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) + sig_shape = s.axes_manager.signal_shape[::-1] + detector = kp.detectors.EBSDDetector( + shape=sig_shape, + sample_tilt=70, + pc=(0.421, 0.7794, 0.5049), + convention="tsl" + ) + sim_dict = mp.get_patterns(rotations=rot, detector=detector, energy=20) + signal_mask = ~kp.filters.Window("circular", sig_shape).astype(bool) + xmap = s.dictionary_indexing( + dictionary=sim_dict, signal_mask=signal_mask, keep_n=1, + ) + """ + coords, _ = create_coordinate_arrays(shape=(3, 3), step_sizes=(1.5, 1.5)) + # fmt: off + xmap = CrystalMap( + rotations=Rotation(( + (0.9542, -0.0183, -0.2806, 0.1018), + (0.9542, 0.0608, -0.2295, -0.1818), + (0.9542, 0.0608, -0.2295, -0.1818), + (0.9542, -0.0183, -0.2806, 0.1018), + (0.9542, 0.0608, -0.2295, -0.1818), + (0.9542, 0.0608, -0.2295, -0.1818), + (0.9542, -0.0183, -0.2806, 0.1018), + (0.9542, 0.0608, -0.2295, -0.1818), + (0.9542, 0.0608, -0.2295, -0.1818) + )), + x=coords["x"], + y=coords["y"], + prop=dict(scores=np.array(( + 0.46917585, 0.4075796, 0.4525376, + 0.49076438, 0.41008472, 0.46616974, + 0.4542183, 0.41790304, 0.4655012 + ))), + phase_list=PhaseList(Phase("ni", 225, "m-3m")), + ) + # fmt: on + yield xmap + + # ---------------------- pytest doctest-modules ---------------------- # diff --git a/kikuchipy/signals/tests/test_ebsd.py b/kikuchipy/signals/tests/test_ebsd.py index c43b46db..ca190f62 100644 --- a/kikuchipy/signals/tests/test_ebsd.py +++ b/kikuchipy/signals/tests/test_ebsd.py @@ -1646,6 +1646,27 @@ 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="both", + ), + energy=energy + ) + + assert xmap_ref.scores.mean() > xmap.scores.mean() + # ------------------- Refine projection centers ------------------ # @pytest.mark.parametrize( From dc0d3772245d7702841b0de618c8e7f3443da1a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Wiik=20=C3=85nes?= Date: Sun, 9 Jan 2022 15:36:44 +0100 Subject: [PATCH 2/8] Remove mask from Ni small DI results MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Håkon Wiik Ånes --- kikuchipy/conftest.py | 14 +++++--------- kikuchipy/signals/tests/test_ebsd.py | 2 +- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/kikuchipy/conftest.py b/kikuchipy/conftest.py index cb6c4f05..8a6aefdf 100644 --- a/kikuchipy/conftest.py +++ b/kikuchipy/conftest.py @@ -498,18 +498,14 @@ def nickel_ebsd_small_di_xmap(): 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) - sig_shape = s.axes_manager.signal_shape[::-1] detector = kp.detectors.EBSDDetector( - shape=sig_shape, + 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) - signal_mask = ~kp.filters.Window("circular", sig_shape).astype(bool) - xmap = s.dictionary_indexing( - dictionary=sim_dict, signal_mask=signal_mask, keep_n=1, - ) + 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 @@ -528,9 +524,9 @@ def nickel_ebsd_small_di_xmap(): x=coords["x"], y=coords["y"], prop=dict(scores=np.array(( - 0.46917585, 0.4075796, 0.4525376, - 0.49076438, 0.41008472, 0.46616974, - 0.4542183, 0.41790304, 0.4655012 + 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")), ) diff --git a/kikuchipy/signals/tests/test_ebsd.py b/kikuchipy/signals/tests/test_ebsd.py index ca190f62..6635c3d2 100644 --- a/kikuchipy/signals/tests/test_ebsd.py +++ b/kikuchipy/signals/tests/test_ebsd.py @@ -1665,7 +1665,7 @@ def test_refine_orientation_nickel_ebsd_small( energy=energy ) - assert xmap_ref.scores.mean() > xmap.scores.mean() + assert np.all(xmap_ref.scores > xmap.scores) # ------------------- Refine projection centers ------------------ # From f8ca3df4c646a4634ebb64acee018adfcb8d0256 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Wiik=20=C3=85nes?= Date: Sun, 9 Jan 2022 18:24:59 +0100 Subject: [PATCH 3/8] Rewrite Numba function to get quaternion from Euler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Håkon Wiik Ånes --- kikuchipy/_rotation/__init__.py | 21 ++++++++++--------- kikuchipy/indexing/_refinement/_refinement.py | 6 +++--- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/kikuchipy/_rotation/__init__.py b/kikuchipy/_rotation/__init__.py index ec4131a0..122510ed 100644 --- a/kikuchipy/_rotation/__init__.py +++ b/kikuchipy/_rotation/__init__.py @@ -57,16 +57,17 @@ 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 diff --git a/kikuchipy/indexing/_refinement/_refinement.py b/kikuchipy/indexing/_refinement/_refinement.py index bffbddf6..2c1ea78b 100644 --- a/kikuchipy/indexing/_refinement/_refinement.py +++ b/kikuchipy/indexing/_refinement/_refinement.py @@ -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() @@ -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) @@ -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( From c182d84ae42c38c97dd047d66fa7f2b365898bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Wiik=20=C3=85nes?= Date: Sun, 9 Jan 2022 18:35:49 +0100 Subject: [PATCH 4/8] Add changelog entry for 0.5.7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Håkon Wiik Ånes --- CHANGELOG.rst | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 47ed8e7c..fbf4180d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -12,6 +12,19 @@ best to adhere to `Semantic Versioning `_. 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 `_) + 0.5.6 (2022-01-02) ================== From 1e1a4353c417aea513d6eff759d1be0686cdc60a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Wiik=20=C3=85nes?= Date: Sun, 9 Jan 2022 18:36:21 +0100 Subject: [PATCH 5/8] Bump version to 0.5.7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Håkon Wiik Ånes --- kikuchipy/release.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kikuchipy/release.py b/kikuchipy/release.py index 1085dfab..7e75733f 100644 --- a/kikuchipy/release.py +++ b/kikuchipy/release.py @@ -35,4 +35,4 @@ name = "kikuchipy" platforms = ["Linux", "MacOS X", "Windows"] status = "Development" -version = "0.5.6" +version = "0.5.7" From d350185bd343b01be02243982cb69bfeefdce3d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Wiik=20=C3=85nes?= Date: Sun, 9 Jan 2022 18:51:45 +0100 Subject: [PATCH 6/8] Simplify test a bit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Håkon Wiik Ånes --- kikuchipy/signals/tests/test_ebsd.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kikuchipy/signals/tests/test_ebsd.py b/kikuchipy/signals/tests/test_ebsd.py index 6635c3d2..2c30a859 100644 --- a/kikuchipy/signals/tests/test_ebsd.py +++ b/kikuchipy/signals/tests/test_ebsd.py @@ -1660,9 +1660,11 @@ def test_refine_orientation_nickel_ebsd_small( xmap=xmap, detector=detector, master_pattern=kp.data.nickel_ebsd_master_pattern_small( - energy=energy, projection="lambert", hemisphere="both", + energy=energy, + projection="lambert", + hemisphere="north", ), - energy=energy + energy=energy, ) assert np.all(xmap_ref.scores > xmap.scores) From 8dee7bc30ea62c5a23d941c4d196d71a5dc6807c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Wiik=20=C3=85nes?= Date: Sun, 9 Jan 2022 18:54:34 +0100 Subject: [PATCH 7/8] Simplify fixture MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Håkon Wiik Ånes --- kikuchipy/conftest.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/kikuchipy/conftest.py b/kikuchipy/conftest.py index 8a6aefdf..0659e159 100644 --- a/kikuchipy/conftest.py +++ b/kikuchipy/conftest.py @@ -509,17 +509,13 @@ def nickel_ebsd_small_di_xmap(): """ 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(( - (0.9542, -0.0183, -0.2806, 0.1018), - (0.9542, 0.0608, -0.2295, -0.1818), - (0.9542, 0.0608, -0.2295, -0.1818), - (0.9542, -0.0183, -0.2806, 0.1018), - (0.9542, 0.0608, -0.2295, -0.1818), - (0.9542, 0.0608, -0.2295, -0.1818), - (0.9542, -0.0183, -0.2806, 0.1018), - (0.9542, 0.0608, -0.2295, -0.1818), - (0.9542, 0.0608, -0.2295, -0.1818) + grain1, grain2, grain2, + grain1, grain2, grain2, + grain1, grain2, grain2 )), x=coords["x"], y=coords["y"], From eaa8a75eb7f7582ac543b6ea0d3af92163d7fba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Wiik=20=C3=85nes?= Date: Mon, 10 Jan 2022 09:50:47 +0100 Subject: [PATCH 8/8] Reformat rotation declaration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Håkon Wiik Ånes --- kikuchipy/_rotation/__init__.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/kikuchipy/_rotation/__init__.py b/kikuchipy/_rotation/__init__.py index 122510ed..a5917d19 100644 --- a/kikuchipy/_rotation/__init__.py +++ b/kikuchipy/_rotation/__init__.py @@ -62,12 +62,10 @@ def _rotation_from_euler(alpha: float, beta: float, gamma: float) -> np.ndarray: 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) + 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