/
test_orientation_similarity_map.py
61 lines (54 loc) · 2.23 KB
/
test_orientation_similarity_map.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Copyright 2019-2022 The kikuchipy developers
#
# This file is part of kikuchipy.
#
# kikuchipy is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# kikuchipy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with kikuchipy. If not, see <http://www.gnu.org/licenses/>.
import numpy as np
from orix.crystal_map import CrystalMap
from orix.quaternion import Rotation
import pytest
from kikuchipy.indexing import orientation_similarity_map
class TestOrientationSimilarityMap:
def test_orientation_similarity_map(self):
xmap = CrystalMap(
rotations=Rotation(np.zeros((100, 4))),
prop={"simulation_indices": np.tile(np.arange(5), (100, 1))},
x=np.tile(np.arange(10), 10),
y=np.tile(np.arange(10), 10),
)
assert np.allclose(orientation_similarity_map(xmap), np.full((10, 10), 5))
assert np.allclose(
orientation_similarity_map(xmap, normalize=True), np.ones((10, 10))
)
def test_n_best_too_great(self):
xmap = CrystalMap(
rotations=Rotation(np.zeros((100, 4))),
prop={"simulation_indices": np.ones((100, 5))},
x=np.tile(np.arange(10), 10),
y=np.tile(np.arange(10), 10),
)
with pytest.raises(ValueError, match="n_best 6 cannot be greater than"):
orientation_similarity_map(xmap, n_best=6)
def test_from_n_best(self):
sim_idx_prop = "simulated_indices"
xmap = CrystalMap(
rotations=Rotation(np.zeros((100, 4))),
prop={sim_idx_prop: np.ones((100, 5))},
x=np.tile(np.arange(10), 10),
y=np.tile(np.arange(10), 10),
)
osm = orientation_similarity_map(
xmap, simulation_indices_prop=sim_idx_prop, from_n_best=2
)
assert osm.shape == (10, 10, 4)