-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdials_utils.py
78 lines (55 loc) · 1.96 KB
/
dials_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
76
77
78
from math import radians
from typing import Tuple
import numpy as np
import coords_converter
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 DIALS.
"""
def panel_idx_to_name(idx: int) -> str:
return str(idx).zfill(2)
def panel_name_to_idx(name: str) -> int:
return int(name)
def panel_axes_flipped(fast_axis: vec3float, slow_axis: vec3float) -> bool:
"""
The fast axis is assumed to be in the x direction,
so if it is more closely aligned to the y direction
than the slow_axis, the axes are assumed to be flipped.
"""
y_direction = np.array((0, 1, 0))
fa_dot = abs(np.dot(fast_axis, y_direction))
sa_dot = abs(np.dot(slow_axis, y_direction))
return fa_dot > sa_dot
def panel_axes_direction_flipped(fast_axis: vec3float, slow_axis: vec3float) -> bool:
"""
The slow axis is assumed to be going in the y direction,
and if the slow axis is in the negative y direction the panel
axes directions are assumed to be flipped.
"""
y_direction = np.array((0, 1, 0))
return np.dot(slow_axis, y_direction) < 0
def get_panel_axes(
r_mag: float, gam_in_deg: float, nu_in_deg: float, d_angle: float = 1e-5
) -> Tuple[vec3float, vec3float]:
"""
Calculates the fast and slow axes by
perturbing nu and gam by d_angle
"""
r = coords_converter.spherical_to_vector(
r_mag=r_mag, nu=radians(nu_in_deg), gam=radians(gam_in_deg)
)
ry = coords_converter.spherical_to_vector(
r_mag=r_mag, nu=radians(nu_in_deg - d_angle), gam=radians(gam_in_deg)
)
rx = coords_converter.spherical_to_vector(
r_mag=r_mag, nu=radians(nu_in_deg), gam=radians(gam_in_deg - d_angle)
)
fast_axis = r - rx
slow_axis = r - ry
fast_axis /= np.linalg.norm(fast_axis)
slow_axis /= np.linalg.norm(slow_axis)
return fast_axis, slow_axis