-
Notifications
You must be signed in to change notification settings - Fork 28
/
_detector.py
57 lines (50 loc) · 1.89 KB
/
_detector.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
# Copyright 2019-2023 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/>.
"""Utilities for attaching an EBSD detector,
:class:`kikuchipy.detectors.EBSDDetector` to an EBSD signal,
:class:`kikuchipy.signals.EBSD`.
"""
from kikuchipy.detectors import EBSDDetector
def _detector_is_compatible_with_signal(
detector: EBSDDetector,
nav_shape: tuple,
sig_shape: tuple,
raise_if_not: bool = False,
) -> bool:
"""Check whether a signal's navigation and signal shapes are
compatible with a detector and return a bool or raise a ValueError
if it is not.
"""
compatible = True
error_msg = None
if sig_shape != detector.shape:
compatible = False
error_msg = (
f"Detector shape {detector.shape} must be equal to the signal shape "
f"{sig_shape}."
)
detector_nav_shape = detector.navigation_shape
if detector_nav_shape != (1,) and detector_nav_shape != nav_shape:
compatible = False
error_msg = (
"Detector must have exactly one projection center (PC), or one PC per "
"pattern in an array of shape equal to signal's navigation shape + (3,)."
)
if raise_if_not and not compatible:
raise ValueError(error_msg)
else:
return compatible