-
Notifications
You must be signed in to change notification settings - Fork 2
/
sim_index.py
217 lines (163 loc) · 7.43 KB
/
sim_index.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
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
#!/usr/bin/python
# sim_index.py
import numpy as np
import wx
import wx.lib.scrolledpanel as scrolled
class Sim_Index(scrolled.ScrolledPanel):
def __init__(self, parent, simulation, color):
scrolled.ScrolledPanel.__init__(self, parent, id = -1, style = wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER)
sim_color = simulation.sim_color if simulation.sim_color else color
self.sdrdf = simulation.sdrdf#[2.5,1.5,1,.8,2.5,1.5,1,.8,2.5,1.5,1,.8,2.5,1.5,1,.8]
self.sdrdflen = len(self.sdrdf)
self.srdf = simulation.srdf
#fcc_sim = [111,122,220,400,111,122,220,400,111,122,220,400,111,122,220,400]
self.peak_index_labels = simulation.peak_index_labels
wx.StaticText(self, -1, 'Legend Label: ', (20, 5))
self.sim_label_tc = wx.TextCtrl(self, -1, '', (130, 0), (130, -1))
sim_label_text = simulation.sim_label
self.sim_label_tc.SetValue(sim_label_text)
wx.StaticText(self, -1, 'Simulation Intensity: ', (20, 35))
self.sim_intens_tc = wx.TextCtrl(self, -1, '', (200, 30), (60, -1))
sim_intens_text = str(simulation.sim_intens)
self.sim_intens_tc.SetValue(sim_intens_text)
wx.StaticText(self, -1, 'Simulation Color: ', (20, 65))
self.colorpicker = wx.ColourPickerCtrl(self, -1, colour=sim_color, pos=(200, 60),
size=(60, 30), name='Simulation Color')
#self.sim_color_tc = wx.TextCtrl(self, -1, '', (150, 60), (90, -1))
#self.colorDlgBtn = wx.Button(self, -1, "...", (240, 60), (20, -1))
#self.colorDlgBtn.Bind(wx.EVT_BUTTON, self.onColorDlg)
#self.sim_color_tc.SetValue('#ffffff')
vbox = wx.BoxSizer(wx.VERTICAL)
offset = 4
sp = 30
i = offset
for peak, intens in zip(self.sdrdf,self.srdf):
static = wx.StaticText(self, -1, str(i-offset+1) + '-', (20, sp*i+5))
static1 = wx.StaticText(self, -1, 'd:', (60, sp*i+5))
dspace = 1/peak
wx.StaticText(self, -1, str('%.2f' % dspace) + u' \u00c5', (75, sp*i+5))
static2 = wx.StaticText(self, -1,'i:', (140, sp*i+5))
wx.StaticText(self, -1, str('%.2f' % intens), (153, sp*i+5))
i += 1
vbox.Add((250,sp*i+5), wx.EXPAND, 0)
if len(self.peak_index_labels)==0:
i = offset
self.peak_index_tc=[]
for peak_index_label in self.sdrdf:
self.peak_index_tc += [wx.TextCtrl(self, -1, '', (200, sp*i), (60, -1))]
#self.peak_index_tc[i-1].SetValue(str(au_radius))
i += 1
else:
i = offset
self.peak_index_tc=[]
for peak_index_label in self.peak_index_labels[:self.sdrdflen]:
self.peak_index_tc += [wx.TextCtrl(self, -1, '', (200, sp*i), (60, -1))]
self.peak_index_tc[i-offset].SetValue(str(peak_index_label))
i += 1
self.SetSizer(vbox)
self.SetupScrolling()
# def onColorDlg(self, event):
# """
# This is mostly from the wxPython Demo!
# """
# dlg = wx.ColourDialog(self)
#
# # Ensure the full colour dialog is displayed,
# # not the abbreviated version.
# dlg.GetColourData().SetChooseFull(True)
#
# if dlg.ShowModal() == wx.ID_OK:
# data = dlg.GetColourData()
# self.sim_color_tc.SetValue('#%02x%02x%02x' % data.GetColour().Get())
# print ('#%02x%02x%02x' % data.GetColour().Get())
#
# dlg.Destroy()
class Index(wx.Dialog):
def __init__(self, parent, id, title):
window_height = 500
wx.Dialog.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(350, window_height))
wx.StaticText(self, -1, 'Enter or edit the peak indices and title\nfor the imported simulations', (20,20))
nb = wx.Notebook(self, -1, pos = (25, 70), size = (300, 350), style=wx.NB_TOP)
self.parent = parent
self.simulations = parent.simulations
if len(self.simulations) >= 3:
sim_len_i = 3
else:
sim_len_i = len(self.simulations)
print(sim_len_i)#,self.srdfb[sim_len_i[0]],self.sdrdfb[sim_len_i[0]])
color = ['#42D151','#2AA298','#E7E73C']
for i, simulation in enumerate(self.simulations[-sim_len_i:]):
sim = Sim_Index(nb,simulation,color[i])
simulation.sim_tcs = sim
nb.AddPage(sim, simulation.sim_name)
set_btn = wx.Button(self, 1, 'Edit Labels', (70, window_height-55))
set_btn.SetFocus()
clear_btn = wx.Button(self, 2, 'Cancel', (185, window_height-55))
self.Bind(wx.EVT_BUTTON, self.OnIndex, id=1)
self.Bind(wx.EVT_BUTTON, self.OnClose, id=2)
self.Bind(wx.EVT_CLOSE, self.OnClose)
def OnIndex(self, event):
if len(self.simulations) >= 3:
sim_len_i = 3
else:
sim_len_i = len(self.simulations)
print(sim_len_i)#,self.srdfb[sim_len_i[0]],self.sdrdfb[sim_len_i[0]])
for simulation in self.simulations[-sim_len_i:]:
peak_index_labels = []
for peak_index_tc in simulation.sim_tcs.peak_index_tc:
peak_index_labels += [peak_index_tc.GetValue()]
print(simulation.sim_tcs.colorpicker.GetColour(), simulation.sim_tcs.colorpicker.GetColour()[0:3])
simulation.edit_index_labels(peak_index_labels, simulation.sim_tcs.sim_label_tc.GetValue(), simulation.sim_tcs.sim_intens_tc.GetValue(), simulation.sim_tcs.colorpicker.GetColour())
self.Destroy()
self.parent.axes.cla()
self.parent.plot(2,'b')
self.parent.axes.figure.canvas.draw()
def OnClose(self, event):
self.Destroy()
class Simulation:
"""
Simulation label and index
"""
def __init__(self, sim_name, sim_open, peak_index_labels=[]):
if len(sim_open.shape) == 1: # it's a records array
sdrdf = sim_open['inv_d']
srdf = sim_open['intensity']
self.sim_intens = 1
else:
theta_2 = sim_open[:,0]
inv_d = (2*np.sin(((theta_2/180)*np.pi)/2.))/.5
intensity = sim_open[:,1]
intensity /= intensity.max()
print(sim_open.shape, len(theta_2), len(intensity))
srdf = intensity
sdrdf = inv_d
self.sim_intens = 1
sim_index = np.nonzero(srdf!=0)
sdrdf = sdrdf[sim_index]
srdf = srdf[sim_index]
self.sdrdf = sdrdf
self.srdf = srdf
self.sim_name = sim_name
self.sim_label = sim_name
self.peak_index_labels = list(peak_index_labels)
self.sim_tcs = []
self.sim_color = 0
#print(1/array(sim_scatter))
#print(imgcal)
#filen=(simname + '.txt')
#data = loadtxt(filen,skiprows=0)
##print(data)
#srdf = data[:,1]
#sdrdf = data[:,0]
#start =20
#dsdrdf = linspace(0,sdrdf[-1],boxs)
print(self.sdrdf, self.srdf)
def edit_index_labels(self, index_labels, sim_label, sim_intens, sim_color):
self.peak_index_labels = index_labels
self.sim_label = sim_label
self.sim_intens = float(sim_intens)
self.sim_color = '#%02x%02x%02x' % sim_color[0:3]
#app = wx.App()
#dlg = Index(None, -1, 'Index Peaks')
#dlg.Show(True)
#app.MainLoop()