-
Notifications
You must be signed in to change notification settings - Fork 0
/
peak_table.py
140 lines (119 loc) · 3.84 KB
/
peak_table.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import numpy as np
class PeakTable:
"""
Class to store peak properties that different readers
can understand.
"""
def __init__(
self,
spectra_idx_1D: np.array,
intensity: np.array,
energy: np.array, # keV
wavelength: np.array, # A
d_spacing: np.array,
tof: np.array, # usec
miller_indices: np.array = None,
) -> None:
self._size = None
self._spectra_idx_1D = None
self._intensity = None
self._energy = None
self._wavelength = None
self._d_spacing = None
self._tof = None
self._miller_indices = None
self.spectra_idx_1D = spectra_idx_1D
self.intensity = intensity
self.energy = energy
self.wavelength = wavelength
self.d_spacing = d_spacing
self.tof = tof
self.miller_indices = miller_indices
self._dict = {
"spectra_idx_1D": self.spectra_idx_1D,
"intensity": self.intensity,
"energy": self.energy,
"wavelength": self.wavelength,
"d_spacing": self.d_spacing,
"tof": self.tof,
"miller_indices": self.miller_indices,
}
def __len__(self):
return self._size
def __getitem__(self, index):
return self._dict[index]
def __setitem__(self, index, value):
self._dict[index] = value
@property
def spectra_idx_1D(self):
return self._spectra_idx_1D
@spectra_idx_1D.setter
def spectra_idx_1D(self, value):
if self._size is None:
self._size = len(value)
elif len(value) != self._size:
raise ValueError("Size is not consistent with current values")
self._spectra_idx_1D = value
@property
def intensity(self):
return self._intensity
@intensity.setter
def intensity(self, value):
if self._size is None:
self._size = len(value)
elif len(value) != self._size:
raise ValueError("Size is not consistent with current values")
self._intensity = value
@property
def energy(self):
return self._energy
@energy.setter
def energy(self, value):
if self._size is None:
self._size = len(value)
elif len(value) != self._size:
raise ValueError("Size is not consistent with current values")
self._energy = value
@property
def wavelength(self):
return self._wavelength
@wavelength.setter
def wavelength(self, value):
if self._size is None:
self._size = len(value)
elif len(value) != self._size:
raise ValueError("Size is not consistent with current values")
self._wavelength = value
@property
def d_spacing(self):
return self._d_spacing
@d_spacing.setter
def d_spacing(self, value):
if self._size is None:
self._size = len(value)
elif len(value) != self._size:
raise ValueError("Size is not consistent with current values")
self._d_spacing = value
@property
def tof(self):
return self._tof
@tof.setter
def tof(self, value):
if self._size is None:
self._size = len(value)
elif len(value) != self._size:
raise ValueError("Size is not consistent with current values")
self._tof = value
@property
def miller_indices(self):
return self._miller_indices
@miller_indices.setter
def miller_indices(self, value):
if self._size is None:
self._size = len(value)
elif value is None:
self._miller_indices = np.zeros(3 * self._size).reshape(self._size, 3)
elif len(value) != self._size:
raise ValueError("Size is not consistent with current values")
else:
self._miller_indices = value