diff --git a/kikuchipy/indexing/_hough_indexing.py b/kikuchipy/indexing/_hough_indexing.py index 87cd7353..1e68c02c 100644 --- a/kikuchipy/indexing/_hough_indexing.py +++ b/kikuchipy/indexing/_hough_indexing.py @@ -452,10 +452,11 @@ def _phase_lists_are_compatible( if n_phases != n_phases_pei: compatible = False msg = ( - f"`phase_list` and `indexer.phaselist` have unequal lengths {n_phases} and " - f"{n_phases_pei}" + f"`phase_list` ({n_phases}) and `indexer.phaselist` ({n_phases_pei}) have " + "unequal number of phases" ) else: + i = 0 for (_, phase), phase_pei in zip(phase_list, phase_list_pei): lat = phase.structure.lattice.abcABG() lat_pei = phase_pei.latticeparameter @@ -465,7 +466,7 @@ def _phase_lists_are_compatible( if not np.allclose(lat, lat_pei, atol=1e-12): compatible = False msg = ( - f"Phase '{phase.name}' in `phase_list` and {phase_pei} in " + f"Phase '{phase.name}' in `phase_list` and phase number {i} in " f"`indexer.phaselist` have unequal lattice parameters {lat} and " f"{lat_pei}" ) @@ -473,12 +474,14 @@ def _phase_lists_are_compatible( elif sg != sg_pei: compatible = False msg = ( - f"Phase '{phase.name}' in `phase_list` and {phase_pei} in " + f"Phase '{phase.name}' in `phase_list` and phase number {i} in " f"`indexer.phaselist` have unequal space group numbers {sg} and " f"{sg_pei}" ) break + i += 1 + if raise_if_not and not compatible: raise ValueError(msg) else: diff --git a/kikuchipy/signals/tests/test_ebsd_hough_indexing.py b/kikuchipy/signals/tests/test_ebsd_hough_indexing.py index 9008cd1d..67fb66d6 100644 --- a/kikuchipy/signals/tests/test_ebsd_hough_indexing.py +++ b/kikuchipy/signals/tests/test_ebsd_hough_indexing.py @@ -18,7 +18,7 @@ from diffpy.structure import Lattice, Structure from diffsims.crystallography import ReciprocalLatticeVector import numpy as np -from orix.crystal_map import CrystalMap, PhaseList +from orix.crystal_map import CrystalMap, Phase, PhaseList import pytest import kikuchipy as kp @@ -135,7 +135,9 @@ def test_hough_indexing_return_band_data(self): def test_hough_indexing_raises_dissimilar_phase_lists(self): phase_list = PhaseList(names=["a", "b"], space_groups=[225, 229]) - with pytest.raises(ValueError, match=r"`phase_list` and `indexer.phaselist` "): + with pytest.raises( + ValueError, match=r"`phase_list` \(2\) and `indexer.phaselist` \(1\) have " + ): _ = self.signal.hough_indexing(phase_list, self.indexer) def test_indexer_is_compatible_with_signal(self): @@ -227,6 +229,21 @@ def test_reflector_list(self): assert np.allclose(indexer.phaselist[0].polefamilies, hkl) + def test_reflector_lists(self): + phase_list = PhaseList(names=["a", "b"], space_groups=[186, 225]) + hkl = [ + [[0, 0, 6], [0, 0, -6], [1, 0, 0], [2, 0, 0]], + [[2, 0, 0], [2, 2, 0]], + [[1, 1, 1], [3, 1, 1], [3, 3, 1]], + ] + + _ = self.signal.detector.get_indexer(phase_list, hkl[:2]) + _ = self.signal.detector.get_indexer(phase_list, [hkl[0], None]) + _ = self.signal.detector.get_indexer(phase_list, [None, None]) + + with pytest.raises(ValueError, match="One set of reflectors or None must be "): + _ = self.signal.detector.get_indexer(phase_list, hkl) + def test_compatible_phase_lists(self): phase_list = PhaseList( names=["a", "b"], @@ -240,6 +257,32 @@ def test_compatible_phase_lists(self): assert _phase_lists_are_compatible(phase_list, indexer, True) + # Differing number of phases + phase_list2 = phase_list.deepcopy() + phase_list2.add(Phase("c", space_group=1)) + assert not _phase_lists_are_compatible(phase_list2, indexer) + with pytest.raises( + ValueError, match=r"`phase_list` \(3\) and `indexer.phaselist` \(2\)" + ): + _ = _phase_lists_are_compatible(phase_list2, indexer, True) + + # Differing lattice parameters + phase_list3 = phase_list.deepcopy() + lat = phase_list3["a"].structure.lattice + lat.setLatPar(lat.a * 10) + with pytest.raises( + ValueError, match="Phase 'a' in `phase_list` and phase number 0 in " + ): + _ = _phase_lists_are_compatible(phase_list3, indexer, True) + + # Differing space groups + phase_list4 = phase_list.deepcopy() + phase_list4["b"].space_group = 224 + with pytest.raises( + ValueError, match="Phase 'b' in `phase_list` and phase number 1 in " + ): + _ = _phase_lists_are_compatible(phase_list4, indexer, True) + @pytest.mark.skipif( not kp._pyebsdindex_installed, reason="pyebsdindex is not installed"