-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhkl.py
More file actions
58 lines (41 loc) · 1.88 KB
/
hkl.py
File metadata and controls
58 lines (41 loc) · 1.88 KB
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
"""Errors that can be raised when accessing /hkl/ endpoints."""
from typing import Optional
import numpy as np
from diffcalc_api.errors.definitions import (
ALL_RESPONSES,
DiffcalcAPIException,
ErrorCodesBase,
)
class ErrorCodes(ErrorCodesBase):
"""All error codes which hkl routes can raise."""
INVALID_MILLER_INDICES = 400
INVALID_SCAN_BOUNDS = 400
INVALID_SOLUTION_BOUNDS = 400
responses = {code: ALL_RESPONSES[code] for code in np.unique(ErrorCodes.all_codes())}
class InvalidMillerIndicesError(DiffcalcAPIException):
"""Error that gets thrown when provided miller indices are invalid."""
def __init__(self, detail: Optional[str] = None) -> None:
"""Set detail and status code."""
self.detail = (
"At least one of the hkl indices must be non-zero" if not detail else detail
)
self.status_code = ErrorCodes.INVALID_MILLER_INDICES
class InvalidScanBoundsError(DiffcalcAPIException):
"""Error that gets thrown when provided scan bounds are invalid."""
def __init__(self, start: float, stop: float, inc: float) -> None:
"""Set detail and status code."""
self.detail = (
f"numpy range cannot be formed from start: {start}"
f" to stop: {stop} in increments of: {inc}"
)
self.status_code = ErrorCodes.INVALID_SCAN_BOUNDS
class InvalidSolutionBoundsError(DiffcalcAPIException):
"""Error that gets thrown when provided solution bounds are invalid.
The diffraction angle calculator often provides multiple diffractometer
angles as equivalent to a set of miller indices. Solution bounds can be provided
to constrain these, however they must pass some checks before use.
"""
def __init__(self, detail: str) -> None:
"""Set detail and status code."""
self.detail = detail
self.status_code = ErrorCodes.INVALID_SOLUTION_BOUNDS