Skip to content

Commit

Permalink
Complete tests of compatible phase lists and reflector lists
Browse files Browse the repository at this point in the history
Signed-off-by: Håkon Wiik Ånes <[email protected]>
  • Loading branch information
hakonanes committed Oct 29, 2023
1 parent d4fc96b commit fb834b9
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
11 changes: 7 additions & 4 deletions kikuchipy/indexing/_hough_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -465,20 +466,22 @@ 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}"
)
break
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:
Expand Down
47 changes: 45 additions & 2 deletions kikuchipy/signals/tests/test_ebsd_hough_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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"],
Expand All @@ -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"
Expand Down

0 comments on commit fb834b9

Please sign in to comment.