-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChart.py
More file actions
232 lines (194 loc) · 5.25 KB
/
Chart.py
File metadata and controls
232 lines (194 loc) · 5.25 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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
"""
CoDE Chart structure
"""
import numpy as np
import matplotlib as mp
import matplotlib.pyplot as plt
import fabio as fabio
# cctbx
# crysfml
class ChartDataPowder(object):
"""
holder for 1d/2d powder profile data
"""
def __init__(self, parent=None):
"""
Initialize chart data fields
"""
# list of x coordinates
self.x = None
# list of y coordinates
self.y = None
# list of x coordinate errors
self.dx = None
# list of y coordinate errors
self.dy = None
# list of intensities up
self.iup = None
# list of intensities down
self.idown = None
def numPoints(self):
"""
Returns the number of points in the set
"""
return len(self.x) * len(self.y)
class ChartDataCrystal(object):
"""
holder for hkl single crystal data
"""
def __init__(self, parent=None):
"""
Initialize chart data fields
"""
# list of h indices
self.h = None
# list of k indices
self.k = None
# list of l indices
self.l = None
# list of intensities
self.intensity = None
# list of errors
self.sigma = None
def numPoints(self):
"""
Returns the number of points in the set
"""
return len(self.intensity)
class Chart(object):
"""
Generic object for various charts
"""
def __init__(self, parent=None, filename=""):
"""
"""
#self._radiation = Radiation()
self.dimension = 1
self.filename = filename
self.data = None
# state of this object
self.state = {}
self.state['data'] = self.data
if filename:
self.load(filename=filename)
self.state['filename'] = filename
def setData1D(self, data):
"""
Grab the 1d data coming from the calculator and convert into ChartDataPowder
[(x_1,y_1),(x_2, y_2),....] -> ChartDataPowder
"""
x = []
y = []
for tup in data:
# cheaper to first create full list than to append to immutable np.array
x.append(tup[0])
y.append(tup[1])
# this is now a ChartDataPowder object
if self.data is None:
self.data = ChartDataPowder()
self.data.x = np.array(x)
self.data.y = np.array(y)
# TODO: extend to dx, dy etc.
def setDataHKL(self, data):
"""
Grab the hkl data coming from the calculator and convert into ChartDataCrystal
[(h,k,l,int), ....] -> ChartDataCrystal
"""
h = []
k = []
l = []
for tup in data:
# cheaper to first create full list than to append to immutable np.array
x.append(tup[0])
y.append(tup[1])
self.data.x = np.array(x)
self.data.y = np.array(y)
# TODO: extend to dx, dy etc.
def load(self, filename=""):
"""
Load the data and set the state
"""
# use fabio
try:
image = fabio.open(filename)
except Exception as ex:
print("Something bad happened: " + str(ex))
return
# convert fabio object into ChartData
self.data = self.fabioToChart(image=image)
def fabioToChart(self, image=None):
"""
Convert fabio object to our ChartData
"""
chart_data = ChartData()
for row in image.rows():
chart_data
def setMplChart(self, chart=None):
"""
Assign a matplotlib chart to the state
"""
plt.clf() # clear figure
ax = plt.gca()
ax.plot(self.data.x, self.data.y / np.max(self.data.y), '.-')
ax.set_xlabel('2$\\theta$')
ax.set_ylabel('Intensity')
#self.mplChart = ax
self.state['mpl'] = plt
def getMplChart(self):
"""
Return the matplotlib representation of the current chart
"""
if 'mpl' not in self.state:
self.setMplChart()
return self.state['mpl']
def evaluateBackground(self):
"""
Find background
"""
pass
def subtractBackground(self):
"""
Subtract found background
"""
pass
def indexPeaks(self):
"""
peak indexing algorithms...
"""
pass
def refinePeaks(self):
"""
Pawley peak finding refinements
"""
pass
def show(self):
"""
Show the current document
"""
if not 'mpl' in self.state:
self.setMplChart()
plt.show()
class PowderDiffractionChart(Chart):
"""
2-theta chart of powder diffraction
"""
def smoothPattern(self):
"""
Apply a data smoothing algorithm on an experimental diffraction pattern
"""
pass
def scalePattern(self):
"""
Perform scaling on an experimental diffraction pattern
"""
pass
def calculateStructure(self):
"""
Perform SA/PT calculations to determine crystal structure
"""
pass
class CrystalDiffractionChart(Chart):
"""
2D diffraction chart for crystal diff
"""
pass