-
Notifications
You must be signed in to change notification settings - Fork 0
/
mantid_utils.py
75 lines (53 loc) · 1.52 KB
/
mantid_utils.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from typing import Tuple
import numpy as np
from typing_utils import Array
vec3float = Array["3", float]
vec2float = Array["2", float]
vec3int = Array["3", int]
vec2int = Array["2", int]
"""
Methods for manipulating data required for Mantid.
"""
def rotations_to_spherical_coordinates(
zeroth_pixel_origin: vec2float, rotations: Tuple[Tuple[float, vec3int], ...]
) -> vec2float:
"""
Corrects rotations for zeroth_pixel_origin and returns
the gam and nu angles in spherical coordinates.
"""
gam = rotations[0][0]
try:
nu = rotations[1][0]
except IndexError:
nu = 0
xstart, ystart = zeroth_pixel_origin
if np.sign(xstart) == np.sign(ystart):
if abs(nu) > 0:
nu *= -1
else:
gam *= -1
elif abs(nu) > 0:
gam -= 180
return gam, nu
def spherical_coordinates_to_rotations(
zeroth_pixel_origin: vec2float, gam: float, nu: float
) -> Tuple[Tuple[float, vec3int], ...]:
"""
Corrects gam and nu for zeroth_pixel_origin and returns
Euler angle rotations
"""
xstart, ystart = zeroth_pixel_origin
if np.sign(xstart) == np.sign(ystart):
if abs(nu) > 0:
nu *= -1
else:
gam *= -1
elif abs(gam - 180) < 1e-1:
gam -= 180
elif abs(nu) > 0:
gam += 180
return ((gam, (0, 1, 0)), (nu, (1, 0, 0)))
def panel_idx_to_name(idx: int) -> str:
return f"bank{idx}"
def panel_name_to_idx(name: str) -> int:
return int("".join(filter(str.isdigit, name)))