1 | #GSASII - image data display routines |
---|
2 | ########### SVN repository information ################### |
---|
3 | # $Date: 2011-08-05 19:35:43 +0000 (Fri, 05 Aug 2011) $ |
---|
4 | # $Author: vondreele $ |
---|
5 | # $Revision: 342 $ |
---|
6 | # $URL: trunk/GSASIIimgGUI.py $ |
---|
7 | # $Id: GSASIIimgGUI.py 342 2011-08-05 19:35:43Z vondreele $ |
---|
8 | ########### SVN repository information ################### |
---|
9 | import wx |
---|
10 | import matplotlib as mpl |
---|
11 | import math |
---|
12 | import time |
---|
13 | import cPickle |
---|
14 | import GSASIIpath |
---|
15 | import GSASIIimage as G2img |
---|
16 | import GSASIIplot as G2plt |
---|
17 | import GSASIIIO as G2IO |
---|
18 | import GSASIIgrid as G2gd |
---|
19 | |
---|
20 | VERY_LIGHT_GREY = wx.Colour(235,235,235) |
---|
21 | |
---|
22 | # trig functions in degrees |
---|
23 | sind = lambda x: math.sin(x*math.pi/180.) |
---|
24 | tand = lambda x: math.tan(x*math.pi/180.) |
---|
25 | cosd = lambda x: math.cos(x*math.pi/180.) |
---|
26 | asind = lambda x: 180.*math.asin(x)/math.pi |
---|
27 | |
---|
28 | |
---|
29 | def UpdateImageControls(self,data,masks): |
---|
30 | import ImageCalibrants as calFile |
---|
31 | |
---|
32 | def OnDataType(event): |
---|
33 | data['type'] = typeSel.GetValue()[:4] |
---|
34 | |
---|
35 | def OnNewColorBar(event): |
---|
36 | data['color'] = colSel.GetValue() |
---|
37 | G2plt.PlotExposedImage(self,event=event) |
---|
38 | |
---|
39 | def OnNewCalibrant(event): |
---|
40 | data['calibrant'] = calSel.GetValue() |
---|
41 | data['calibskip'] = calFile.Calibrants[data['calibrant']][2] |
---|
42 | limits = calFile.Calibrants[data['calibrant']][3] |
---|
43 | data['calibdmin'],data['pixLimit'],data['cutoff'] = limits |
---|
44 | pixLimit.SetValue(str(limits[1])) |
---|
45 | cutOff.SetValue('%.1f'%(limits[2])) |
---|
46 | calibSkip.SetValue(str(data['calibskip'])) |
---|
47 | calibDmin.SetValue('%.1f'%(limits[0])) |
---|
48 | |
---|
49 | def OnPixLimit(event): |
---|
50 | data['pixLimit'] = int(pixLimit.GetValue()) |
---|
51 | |
---|
52 | def OnCalibSkip(event): |
---|
53 | data['calibskip'] = int(calibSkip.GetValue()) |
---|
54 | |
---|
55 | def OnSetRings(event): |
---|
56 | if data['setRings']: |
---|
57 | data['setRings'] = False |
---|
58 | else: |
---|
59 | data['setRings'] = True |
---|
60 | G2plt.PlotExposedImage(self,event=event) |
---|
61 | |
---|
62 | def OnCalibDmin(event): |
---|
63 | try: |
---|
64 | dmin = float(calibDmin.GetValue()) |
---|
65 | if dmin < 0.25: |
---|
66 | raise ValueError |
---|
67 | data['calibdmin'] = dmin |
---|
68 | except ValueError: |
---|
69 | pass |
---|
70 | calibDmin.SetValue("%.2f"%(data['calibdmin'])) #reset in case of error |
---|
71 | |
---|
72 | def OnAzmthOff(event): |
---|
73 | try: |
---|
74 | azmthoff = float(azmthOff.GetValue()) |
---|
75 | data['azmthOff'] = azmthoff |
---|
76 | except ValueError: |
---|
77 | pass |
---|
78 | azmthOff.SetValue("%.2f"%(data['azmthOff'])) #reset in case of error |
---|
79 | |
---|
80 | def OnCutOff(event): |
---|
81 | try: |
---|
82 | cutoff = float(cutOff.GetValue()) |
---|
83 | if cutoff < 0.1: |
---|
84 | raise ValueError |
---|
85 | data['cutoff'] = cutoff |
---|
86 | except ValueError: |
---|
87 | pass |
---|
88 | cutOff.SetValue("%.1f"%(data['cutoff'])) #reset in case of error |
---|
89 | |
---|
90 | def OnMaxVal(event): |
---|
91 | try: |
---|
92 | value = min(data['range'][0][1],int(maxVal.GetValue())) |
---|
93 | if value < data['range'][1][0]+1: |
---|
94 | raise ValueError |
---|
95 | data['range'][1][1] = value |
---|
96 | except ValueError: |
---|
97 | pass |
---|
98 | maxVal.SetValue('%.0f'%(data['range'][1][1])) |
---|
99 | DeltOne = data['range'][1][1]-max(0.0,data['range'][0][0]) |
---|
100 | sqrtDeltOne = math.sqrt(DeltOne) |
---|
101 | maxSel.SetValue(int(100*sqrtDeltOne/sqrtDeltZero)) |
---|
102 | minSel.SetValue(int(100*(data['range'][1][0]/DeltOne))) |
---|
103 | G2plt.PlotExposedImage(self,event=event) |
---|
104 | |
---|
105 | def OnMinVal(event): |
---|
106 | try: |
---|
107 | value = int(minVal.GetValue()) |
---|
108 | if value > data['range'][1][1]-1: |
---|
109 | raise ValueError |
---|
110 | data['range'][1][0] = value |
---|
111 | except ValueError: |
---|
112 | pass |
---|
113 | minVal.SetValue('%.0f'%(data['range'][1][0])) |
---|
114 | minSel.SetValue(int(100*(data['range'][1][0]-max(0.0,data['range'][0][0]))/DeltOne)) |
---|
115 | G2plt.PlotExposedImage(self,event=event) |
---|
116 | |
---|
117 | def OnMaxSlider(event): |
---|
118 | sqrtDeltZero = math.sqrt(data['range'][0][1]) |
---|
119 | imax = int(maxSel.GetValue())*sqrtDeltZero/100. |
---|
120 | data['range'][1][1] = imax**2 |
---|
121 | data['range'][1][0] = max(0.0,min(data['range'][1][1]-1,data['range'][1][0])) |
---|
122 | DeltOne = max(1.0,data['range'][1][1]-data['range'][1][0]) |
---|
123 | minSel.SetValue(int(100*(data['range'][1][0]/DeltOne))) |
---|
124 | maxVal.SetValue('%.0f'%(data['range'][1][1])) |
---|
125 | G2plt.PlotExposedImage(self,event=event) |
---|
126 | |
---|
127 | def OnMinSlider(event): |
---|
128 | DeltOne = data['range'][1][1]-data['range'][1][0] |
---|
129 | imin = int(minSel.GetValue())*DeltOne/100. |
---|
130 | data['range'][1][0] = max(0.0,min(data['range'][1][1]-1,imin)) |
---|
131 | minVal.SetValue('%.0f'%(data['range'][1][0])) |
---|
132 | G2plt.PlotExposedImage(self,event=event) |
---|
133 | |
---|
134 | def OnNumOutChans(event): |
---|
135 | try: |
---|
136 | numChans = int(outChan.GetValue()) |
---|
137 | if numChans < 1: |
---|
138 | raise ValueError |
---|
139 | data['outChannels'] = numChans |
---|
140 | except ValueError: |
---|
141 | pass |
---|
142 | outChan.SetValue(str(data['outChannels'])) #reset in case of error |
---|
143 | |
---|
144 | def OnNumOutAzms(event): |
---|
145 | try: |
---|
146 | numAzms = int(outAzim.GetValue()) |
---|
147 | if numAzms < 1: |
---|
148 | raise ValueError |
---|
149 | data['outAzimuths'] = numAzms |
---|
150 | except ValueError: |
---|
151 | pass |
---|
152 | outAzim.SetValue(str(data['outAzimuths'])) #reset in case of error |
---|
153 | G2plt.PlotExposedImage(self,event=event) |
---|
154 | |
---|
155 | def OnWavelength(event): |
---|
156 | try: |
---|
157 | wave = float(waveSel.GetValue()) |
---|
158 | if wave < .01: |
---|
159 | raise ValueError |
---|
160 | data['wavelength'] = wave |
---|
161 | except ValueError: |
---|
162 | pass |
---|
163 | waveSel.SetValue("%6.5f" % (data['wavelength'])) #reset in case of error |
---|
164 | |
---|
165 | def OnShowLines(event): |
---|
166 | if data['showLines']: |
---|
167 | data['showLines'] = False |
---|
168 | else: |
---|
169 | data['showLines'] = True |
---|
170 | G2plt.PlotExposedImage(self,event=event) |
---|
171 | |
---|
172 | def OnSetDefault(event): |
---|
173 | import copy |
---|
174 | if data['setDefault']: |
---|
175 | self.imageDefault = {} |
---|
176 | data['setDefault'] = False |
---|
177 | else: |
---|
178 | self.imageDefault = copy.copy(data) |
---|
179 | data['setDefault'] = True |
---|
180 | |
---|
181 | def OnIOtth(event): |
---|
182 | Ltth = max(float(self.InnerTth.GetValue()),0.001) |
---|
183 | Utth = float(self.OuterTth.GetValue()) |
---|
184 | if Ltth > Utth: |
---|
185 | Ltth,Utth = Utth,Ltth |
---|
186 | data['IOtth'] = [Ltth,Utth] |
---|
187 | self.InnerTth.SetValue("%8.3f" % (Ltth)) |
---|
188 | self.OuterTth.SetValue("%8.2f" % (Utth)) |
---|
189 | G2plt.PlotExposedImage(self,event=event) |
---|
190 | |
---|
191 | def OnFullIntegrate(event): |
---|
192 | Lazm =int(self.Lazim.GetValue()) |
---|
193 | if data['fullIntegrate']: |
---|
194 | data['fullIntegrate'] = False |
---|
195 | data['LRazimuth'] = [Lazm,Lazm+20] |
---|
196 | else: |
---|
197 | data['fullIntegrate'] = True |
---|
198 | data['LRazimuth'] = [Lazm,Lazm+360] |
---|
199 | UpdateImageControls(self,data,masks) |
---|
200 | G2plt.PlotExposedImage(self,event=event) |
---|
201 | |
---|
202 | def OnLRazim(event): |
---|
203 | Lazm =int(self.Lazim.GetValue()) |
---|
204 | if data['fullIntegrate']: |
---|
205 | self.Razim.SetValue("%6d" % (Lazm+360)) |
---|
206 | Razm = int(self.Razim.GetValue()) |
---|
207 | if Lazm > Razm: |
---|
208 | Lazm -= 360 |
---|
209 | data['LRazimuth'] = [Lazm,Razm] |
---|
210 | G2plt.PlotExposedImage(self,event=event) |
---|
211 | |
---|
212 | def OnClearCalib(event): |
---|
213 | data['ring'] = [] |
---|
214 | data['rings'] = [] |
---|
215 | data['ellipses'] = [] |
---|
216 | self.dataFrame.ImageEdit.Enable(id=G2gd.wxID_IMCLEARCALIB,enable=False) |
---|
217 | G2plt.PlotExposedImage(self,event=event) |
---|
218 | |
---|
219 | def OnCalibrate(event): |
---|
220 | self.dataFrame.ImageEdit.Enable(id=G2gd.wxID_IMCLEARCALIB,enable=True) |
---|
221 | self.dataFrame.GetStatusBar().SetStatusText('Select > 4 points on 1st used ring; LB to pick, RB on point to delete else RB to finish') |
---|
222 | self.ifGetRing = True |
---|
223 | |
---|
224 | def OnIntegrate(event): |
---|
225 | self.Integrate = G2img.ImageIntegrate(self.ImageZ,data,masks) |
---|
226 | G2plt.PlotIntegration(self,newPlot=True) |
---|
227 | G2IO.SaveIntegration(self,self.PickId,data) |
---|
228 | self.MakePDF.Enable(True) |
---|
229 | |
---|
230 | def OnIntegrateAll(event): |
---|
231 | print 'integrate all' |
---|
232 | TextList = [[False,'All IMG',0]] |
---|
233 | Names = [] |
---|
234 | if self.PatternTree.GetCount(): |
---|
235 | id, cookie = self.PatternTree.GetFirstChild(self.root) |
---|
236 | while id: |
---|
237 | name = self.PatternTree.GetItemText(id) |
---|
238 | Names.append(name) |
---|
239 | if 'IMG' in name: |
---|
240 | TextList.append([False,name,id]) |
---|
241 | id, cookie = self.PatternTree.GetNextChild(self.root, cookie) |
---|
242 | if len(TextList) == 1: |
---|
243 | self.ErrorDialog('Nothing to integrate','There must some "IMG" patterns') |
---|
244 | return |
---|
245 | dlg = self.CopyDialog(self,'Image integration controls','Select images to integrate:',TextList) |
---|
246 | try: |
---|
247 | if dlg.ShowModal() == wx.ID_OK: |
---|
248 | result = dlg.GetData() |
---|
249 | if result[0][0]: #the 'All IMG' is True |
---|
250 | result = TextList[1:] |
---|
251 | for item in result: item[0] = True |
---|
252 | for item in result: |
---|
253 | ifintegrate,name,id = item |
---|
254 | if ifintegrate: |
---|
255 | id = G2gd.GetPatternTreeItemId(self, self.root, name) |
---|
256 | Npix,imagefile = self.PatternTree.GetItemPyData(id) |
---|
257 | image = G2IO.GetImageData(self,imagefile,True) |
---|
258 | Id = G2gd.GetPatternTreeItemId(self,id, 'Image Controls') |
---|
259 | Data = self.PatternTree.GetItemPyData(Id) |
---|
260 | try: |
---|
261 | Masks = self.PatternTree.GetItemPyData( |
---|
262 | G2gd.GetPatternTreeItemId(self,self.Image, 'Masks')) |
---|
263 | except TypeError: #missing Masks |
---|
264 | Imin,Imax = Data['Range'] |
---|
265 | Masks = {'Points':[],'Rings':[],'Arcs':[],'Polygons':[],'Thresholds':[(Imin,Imax),[Imin,Imax]]} |
---|
266 | self.PatternTree.SetItemPyData( |
---|
267 | G2gd.GetPatternTreeItemId(self,self.Image, 'Masks'),Masks) |
---|
268 | self.Integrate = G2img.ImageIntegrate(image,Data,Masks) |
---|
269 | # G2plt.PlotIntegration(self,newPlot=True,event=event) |
---|
270 | G2IO.SaveIntegration(self,Id,Data) |
---|
271 | finally: |
---|
272 | dlg.Destroy() |
---|
273 | |
---|
274 | def OnCopyControls(event): |
---|
275 | import copy |
---|
276 | TextList = [[False,'All IMG',0]] |
---|
277 | Names = [] |
---|
278 | if self.PatternTree.GetCount(): |
---|
279 | id, cookie = self.PatternTree.GetFirstChild(self.root) |
---|
280 | while id: |
---|
281 | name = self.PatternTree.GetItemText(id) |
---|
282 | Names.append(name) |
---|
283 | if 'IMG' in name: |
---|
284 | if id == self.Image: |
---|
285 | Source = name |
---|
286 | Data = copy.deepcopy(self.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(self,id, 'Image Controls'))) |
---|
287 | Data['showLines'] = True |
---|
288 | Data['ring'] = [] |
---|
289 | Data['rings'] = [] |
---|
290 | Data['ellipses'] = [] |
---|
291 | Data['setDefault'] = False |
---|
292 | else: |
---|
293 | TextList.append([False,name,id]) |
---|
294 | id, cookie = self.PatternTree.GetNextChild(self.root, cookie) |
---|
295 | if len(TextList) == 1: |
---|
296 | self.ErrorDialog('Nothing to copy controls to','There must be more than one "IMG" pattern') |
---|
297 | return |
---|
298 | dlg = self.CopyDialog(self,'Copy image controls','Copy controls from '+Source+' to:',TextList) |
---|
299 | try: |
---|
300 | if dlg.ShowModal() == wx.ID_OK: |
---|
301 | result = dlg.GetData() |
---|
302 | if result[0][0]: |
---|
303 | result = TextList[1:] |
---|
304 | for item in result: item[0] = True |
---|
305 | for i,item in enumerate(result): |
---|
306 | ifcopy,name,id = item |
---|
307 | if ifcopy: |
---|
308 | oldData = copy.deepcopy(self.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(self,id, 'Image Controls'))) |
---|
309 | Data['range'] = oldData['range'] |
---|
310 | Data['size'] = oldData['size'] |
---|
311 | Data['ring'] = [] |
---|
312 | Data['rings'] = [] |
---|
313 | Data['ellipses'] = [] |
---|
314 | self.PatternTree.SetItemPyData(G2gd.GetPatternTreeItemId(self,id, 'Image Controls'),copy.deepcopy(Data)) |
---|
315 | finally: |
---|
316 | dlg.Destroy() |
---|
317 | |
---|
318 | def OnSaveControls(event): |
---|
319 | dlg = wx.FileDialog(self, 'Choose image controls file', '.', '', |
---|
320 | 'image control files (*.imctrl)|*.imctrl',wx.OPEN) |
---|
321 | if self.dirname: |
---|
322 | dlg.SetDirectory(self.dirname) |
---|
323 | try: |
---|
324 | if dlg.ShowModal() == wx.ID_OK: |
---|
325 | filename = dlg.GetPath() |
---|
326 | File = open(filename,'w') |
---|
327 | save = {} |
---|
328 | keys = ['type','wavelength','calibrant','distance','center', |
---|
329 | 'tilt','rotation','azmthOff','fullIntegrate','LRazimuth', |
---|
330 | 'IOtth','outAzimuths'] |
---|
331 | for key in keys: |
---|
332 | File.write(key+':'+str(data[key])+'\n') |
---|
333 | File.close() |
---|
334 | finally: |
---|
335 | dlg.Destroy() |
---|
336 | |
---|
337 | def OnLoadControls(event): |
---|
338 | cntlList = ['wavelength','distance','tilt','rotation', |
---|
339 | 'fullIntegrate','outAzimuths','LRazimuth','IOtth'] |
---|
340 | dlg = wx.FileDialog(self, 'Choose image controls file', '.', '', |
---|
341 | 'image control files (*.imctrl)|*.imctrl',wx.OPEN) |
---|
342 | if self.dirname: |
---|
343 | dlg.SetDirectory(self.dirname) |
---|
344 | try: |
---|
345 | if dlg.ShowModal() == wx.ID_OK: |
---|
346 | filename = dlg.GetPath() |
---|
347 | File = open(filename,'r') |
---|
348 | save = {} |
---|
349 | S = File.readline() |
---|
350 | while S: |
---|
351 | if S[0] == '#': |
---|
352 | S = File.readline() |
---|
353 | continue |
---|
354 | [key,val] = S[:-1].split(':') |
---|
355 | if key in ['type','calibrant',]: |
---|
356 | save[key] = val |
---|
357 | elif key in ['center',]: |
---|
358 | if ',' in val: |
---|
359 | save[key] = eval(val) |
---|
360 | else: |
---|
361 | vals = val.strip('[] ').split() |
---|
362 | save[key] = [float(vals[0]),float(vals[1])] |
---|
363 | elif key in cntlList: |
---|
364 | save[key] = eval(val) |
---|
365 | S = File.readline() |
---|
366 | data.update(save) |
---|
367 | UpdateImageControls(self,data,masks) |
---|
368 | G2plt.PlotExposedImage(self,event=event) |
---|
369 | |
---|
370 | File.close() |
---|
371 | finally: |
---|
372 | dlg.Destroy() |
---|
373 | |
---|
374 | #fix for old files: |
---|
375 | if 'azmthOff' not in data: |
---|
376 | data['azmthOff'] = 0.0 |
---|
377 | #end fix |
---|
378 | |
---|
379 | colorList = [m for m in mpl.cm.datad.keys() if not m.endswith("_r")] |
---|
380 | calList = [m for m in calFile.Calibrants.keys()] |
---|
381 | typeList = ['PWDR - powder diffraction data','SASD - small angle scattering data', |
---|
382 | 'REFL - reflectometry data'] |
---|
383 | if not data.get('type'): #patch for old project files |
---|
384 | data['type'] = 'PWDR' |
---|
385 | typeDict = {'PWDR':typeList[0],'SASD':typeList[1],'REFL':typeList[2]} |
---|
386 | if self.dataDisplay: |
---|
387 | self.dataDisplay.Destroy() |
---|
388 | self.dataFrame.SetMenuBar(self.dataFrame.ImageMenu) |
---|
389 | if not self.dataFrame.GetStatusBar(): |
---|
390 | self.dataFrame.CreateStatusBar() |
---|
391 | self.dataFrame.Bind(wx.EVT_MENU, OnCalibrate, id=G2gd.wxID_IMCALIBRATE) |
---|
392 | self.dataFrame.Bind(wx.EVT_MENU, OnClearCalib, id=G2gd.wxID_IMCLEARCALIB) |
---|
393 | if not data['rings']: |
---|
394 | self.dataFrame.ImageEdit.Enable(id=G2gd.wxID_IMCLEARCALIB,enable=False) |
---|
395 | self.dataFrame.Bind(wx.EVT_MENU, OnIntegrate, id=G2gd.wxID_IMINTEGRATE) |
---|
396 | self.dataFrame.Bind(wx.EVT_MENU, OnIntegrateAll, id=G2gd.wxID_INTEGRATEALL) |
---|
397 | self.dataFrame.Bind(wx.EVT_MENU, OnCopyControls, id=G2gd.wxID_IMCOPYCONTROLS) |
---|
398 | self.dataFrame.Bind(wx.EVT_MENU, OnSaveControls, id=G2gd.wxID_IMSAVECONTROLS) |
---|
399 | self.dataFrame.Bind(wx.EVT_MENU, OnLoadControls, id=G2gd.wxID_IMLOADCONTROLS) |
---|
400 | self.dataDisplay = wx.Panel(self.dataFrame) |
---|
401 | mainSizer = wx.BoxSizer(wx.VERTICAL) |
---|
402 | mainSizer.Add((5,10),0) |
---|
403 | |
---|
404 | comboSizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
405 | comboSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Type of image data: '),0, |
---|
406 | wx.ALIGN_CENTER_VERTICAL) |
---|
407 | typeSel = wx.ComboBox(parent=self.dataDisplay,value=typeDict[data['type']],choices=typeList, |
---|
408 | style=wx.CB_READONLY|wx.CB_DROPDOWN) |
---|
409 | typeSel.SetValue(data['type']) |
---|
410 | typeSel.Bind(wx.EVT_COMBOBOX, OnDataType) |
---|
411 | comboSizer.Add(typeSel,0,wx.ALIGN_CENTER_VERTICAL) |
---|
412 | comboSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Color bar '),0, |
---|
413 | wx.ALIGN_CENTER_VERTICAL) |
---|
414 | colSel = wx.ComboBox(parent=self.dataDisplay,value=data['color'],choices=colorList, |
---|
415 | style=wx.CB_READONLY|wx.CB_DROPDOWN|wx.CB_SORT) |
---|
416 | colSel.Bind(wx.EVT_COMBOBOX, OnNewColorBar) |
---|
417 | comboSizer.Add(colSel,0,wx.ALIGN_CENTER_VERTICAL) |
---|
418 | comboSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Azimuth offset '),0, |
---|
419 | wx.ALIGN_CENTER_VERTICAL) |
---|
420 | azmthOff = wx.TextCtrl(parent=self.dataDisplay,value=("%.2f" % (data['azmthOff'])), |
---|
421 | style=wx.TE_PROCESS_ENTER) |
---|
422 | azmthOff.Bind(wx.EVT_TEXT_ENTER,OnAzmthOff) |
---|
423 | azmthOff.Bind(wx.EVT_KILL_FOCUS,OnAzmthOff) |
---|
424 | comboSizer.Add(azmthOff,0,wx.ALIGN_CENTER_VERTICAL) |
---|
425 | mainSizer.Add(comboSizer,0,wx.ALIGN_LEFT) |
---|
426 | mainSizer.Add((5,5),0) |
---|
427 | |
---|
428 | maxSizer = wx.FlexGridSizer(2,3,0,5) |
---|
429 | maxSizer.AddGrowableCol(1,1) |
---|
430 | maxSizer.SetFlexibleDirection(wx.HORIZONTAL) |
---|
431 | sqrtDeltZero = math.sqrt(data['range'][0][1]-max(0.0,data['range'][0][0])) |
---|
432 | DeltOne = data['range'][1][1]-max(0.0,data['range'][0][0]) |
---|
433 | sqrtDeltOne = math.sqrt(DeltOne) |
---|
434 | maxSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Max intensity'),0, |
---|
435 | wx.ALIGN_CENTER_VERTICAL) |
---|
436 | maxSel = wx.Slider(parent=self.dataDisplay,style=wx.SL_HORIZONTAL, |
---|
437 | value=int(100*sqrtDeltOne/sqrtDeltZero)) |
---|
438 | maxSizer.Add(maxSel,1,wx.EXPAND) |
---|
439 | maxSel.Bind(wx.EVT_SLIDER, OnMaxSlider) |
---|
440 | maxVal = wx.TextCtrl(parent=self.dataDisplay,value='%.0f'%(data['range'][1][1])) |
---|
441 | maxVal.Bind(wx.EVT_TEXT_ENTER,OnMaxVal) |
---|
442 | maxVal.Bind(wx.EVT_KILL_FOCUS,OnMaxVal) |
---|
443 | maxSizer.Add(maxVal,0,wx.ALIGN_CENTER_VERTICAL) |
---|
444 | maxSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Min intensity'),0, |
---|
445 | wx.ALIGN_CENTER_VERTICAL) |
---|
446 | minSel = wx.Slider(parent=self.dataDisplay,style=wx.SL_HORIZONTAL, |
---|
447 | value=int(100*(data['range'][1][0]-max(0.0,data['range'][0][0]))/DeltOne)) |
---|
448 | maxSizer.Add(minSel,1,wx.EXPAND) |
---|
449 | minSel.Bind(wx.EVT_SLIDER, OnMinSlider) |
---|
450 | minVal = wx.TextCtrl(parent=self.dataDisplay,value='%.0f'%(data['range'][1][0])) |
---|
451 | minVal.Bind(wx.EVT_TEXT_ENTER,OnMinVal) |
---|
452 | minVal.Bind(wx.EVT_KILL_FOCUS,OnMinVal) |
---|
453 | maxSizer.Add(minVal,0,wx.ALIGN_CENTER_VERTICAL) |
---|
454 | mainSizer.Add(maxSizer,0,wx.ALIGN_LEFT|wx.EXPAND) |
---|
455 | |
---|
456 | dataSizer = wx.FlexGridSizer(6,4,5,5) |
---|
457 | dataSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Calibration coefficients'),0, |
---|
458 | wx.ALIGN_CENTER_VERTICAL) |
---|
459 | dataSizer.Add((5,0),0) |
---|
460 | dataSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Integration coefficients'),0, |
---|
461 | wx.ALIGN_CENTER_VERTICAL) |
---|
462 | dataSizer.Add((5,0),0) |
---|
463 | |
---|
464 | dataSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Beam center X,Y'),0, |
---|
465 | wx.ALIGN_CENTER_VERTICAL) |
---|
466 | cent = data['center'] |
---|
467 | centText = wx.TextCtrl(parent=self.dataDisplay,value=("%8.3f,%8.3f" % (cent[0],cent[1])),style=wx.TE_READONLY) |
---|
468 | centText.SetBackgroundColour(VERY_LIGHT_GREY) |
---|
469 | dataSizer.Add(centText,0,wx.ALIGN_CENTER_VERTICAL) |
---|
470 | |
---|
471 | dataSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Inner/Outer 2-theta'),0, |
---|
472 | wx.ALIGN_CENTER_VERTICAL) |
---|
473 | |
---|
474 | IOtth = data['IOtth'] |
---|
475 | littleSizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
476 | self.InnerTth = wx.TextCtrl(parent=self.dataDisplay, |
---|
477 | value=("%8.3f" % (IOtth[0])),style=wx.TE_PROCESS_ENTER) |
---|
478 | self.InnerTth.Bind(wx.EVT_TEXT_ENTER,OnIOtth) |
---|
479 | self.InnerTth.Bind(wx.EVT_KILL_FOCUS,OnIOtth) |
---|
480 | littleSizer.Add(self.InnerTth,0,wx.ALIGN_CENTER_VERTICAL) |
---|
481 | self.OuterTth = wx.TextCtrl(parent=self.dataDisplay, |
---|
482 | value=("%8.2f" % (IOtth[1])),style=wx.TE_PROCESS_ENTER) |
---|
483 | self.OuterTth.Bind(wx.EVT_TEXT_ENTER,OnIOtth) |
---|
484 | self.OuterTth.Bind(wx.EVT_KILL_FOCUS,OnIOtth) |
---|
485 | littleSizer.Add(self.OuterTth,0,wx.ALIGN_CENTER_VERTICAL) |
---|
486 | dataSizer.Add(littleSizer,0,) |
---|
487 | |
---|
488 | dataSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Wavelength'),0, |
---|
489 | wx.ALIGN_CENTER_VERTICAL) |
---|
490 | waveSel = wx.TextCtrl(parent=self.dataDisplay,value=("%6.5f" % (data['wavelength'])), |
---|
491 | style=wx.TE_PROCESS_ENTER) |
---|
492 | waveSel.Bind(wx.EVT_TEXT_ENTER,OnWavelength) |
---|
493 | waveSel.Bind(wx.EVT_KILL_FOCUS,OnWavelength) |
---|
494 | dataSizer.Add(waveSel,0,wx.ALIGN_CENTER_VERTICAL) |
---|
495 | |
---|
496 | dataSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Start/End azimuth'),0, |
---|
497 | wx.ALIGN_CENTER_VERTICAL) |
---|
498 | LRazim = data['LRazimuth'] |
---|
499 | littleSizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
500 | self.Lazim = wx.TextCtrl(parent=self.dataDisplay, |
---|
501 | value=("%6d" % (LRazim[0])),style=wx.TE_PROCESS_ENTER) |
---|
502 | self.Lazim.Bind(wx.EVT_TEXT_ENTER,OnLRazim) |
---|
503 | self.Lazim.Bind(wx.EVT_KILL_FOCUS,OnLRazim) |
---|
504 | littleSizer.Add(self.Lazim,0,wx.ALIGN_CENTER_VERTICAL) |
---|
505 | self.Razim = wx.TextCtrl(parent=self.dataDisplay, |
---|
506 | value=("%6d" % (LRazim[1])),style=wx.TE_PROCESS_ENTER) |
---|
507 | self.Razim.Bind(wx.EVT_TEXT_ENTER,OnLRazim) |
---|
508 | self.Razim.Bind(wx.EVT_KILL_FOCUS,OnLRazim) |
---|
509 | if data['fullIntegrate']: |
---|
510 | self.Razim.Enable(False) |
---|
511 | self.Razim.SetBackgroundColour(VERY_LIGHT_GREY) |
---|
512 | self.Razim.SetValue("%6d" % (LRazim[0]+360)) |
---|
513 | littleSizer.Add(self.Razim,0,wx.ALIGN_CENTER_VERTICAL) |
---|
514 | dataSizer.Add(littleSizer,0,) |
---|
515 | |
---|
516 | dataSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Distance'),0, |
---|
517 | wx.ALIGN_CENTER_VERTICAL) |
---|
518 | distSel = wx.TextCtrl(parent=self.dataDisplay,value=("%8.3f"%(data['distance'])),style=wx.TE_READONLY) |
---|
519 | distSel.SetBackgroundColour(VERY_LIGHT_GREY) |
---|
520 | dataSizer.Add(distSel,0,wx.ALIGN_CENTER_VERTICAL) |
---|
521 | |
---|
522 | dataSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' No. 2-theta/azimuth bins'),0, |
---|
523 | wx.ALIGN_CENTER_VERTICAL) |
---|
524 | littleSizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
525 | outChan = wx.TextCtrl(parent=self.dataDisplay,value=str(data['outChannels']),style=wx.TE_PROCESS_ENTER) |
---|
526 | outChan.Bind(wx.EVT_TEXT_ENTER,OnNumOutChans) |
---|
527 | outChan.Bind(wx.EVT_KILL_FOCUS,OnNumOutChans) |
---|
528 | littleSizer.Add(outChan,0,wx.ALIGN_CENTER_VERTICAL) |
---|
529 | outAzim = wx.TextCtrl(parent=self.dataDisplay,value=str(data['outAzimuths']),style=wx.TE_PROCESS_ENTER) |
---|
530 | outAzim.Bind(wx.EVT_TEXT_ENTER,OnNumOutAzms) |
---|
531 | outAzim.Bind(wx.EVT_KILL_FOCUS,OnNumOutAzms) |
---|
532 | littleSizer.Add(outAzim,0,wx.ALIGN_CENTER_VERTICAL) |
---|
533 | dataSizer.Add(littleSizer,0,) |
---|
534 | |
---|
535 | dataSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Tilt angle'),0, |
---|
536 | wx.ALIGN_CENTER_VERTICAL) |
---|
537 | tiltSel = wx.TextCtrl(parent=self.dataDisplay,value=("%9.3f"%(data['tilt'])),style=wx.TE_READONLY) |
---|
538 | tiltSel.SetBackgroundColour(VERY_LIGHT_GREY) |
---|
539 | dataSizer.Add(tiltSel,0,wx.ALIGN_CENTER_VERTICAL) |
---|
540 | showLines = wx.CheckBox(parent=self.dataDisplay,label='Show integration limits?') |
---|
541 | dataSizer.Add(showLines,0,wx.ALIGN_CENTER_VERTICAL) |
---|
542 | showLines.Bind(wx.EVT_CHECKBOX, OnShowLines) |
---|
543 | showLines.SetValue(data['showLines']) |
---|
544 | fullIntegrate = wx.CheckBox(parent=self.dataDisplay,label='Do full integration?') |
---|
545 | dataSizer.Add(fullIntegrate,0,wx.ALIGN_CENTER_VERTICAL) |
---|
546 | fullIntegrate.Bind(wx.EVT_CHECKBOX, OnFullIntegrate) |
---|
547 | fullIntegrate.SetValue(data['fullIntegrate']) |
---|
548 | |
---|
549 | dataSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Tilt rotation'),0, |
---|
550 | wx.ALIGN_CENTER_VERTICAL) |
---|
551 | rotSel = wx.TextCtrl(parent=self.dataDisplay,value=("%9.3f"%(data['rotation']-90.)),style=wx.TE_READONLY) #kluge to get rotation from vertical - see GSASIIimage |
---|
552 | rotSel.SetBackgroundColour(VERY_LIGHT_GREY) |
---|
553 | dataSizer.Add(rotSel,0,wx.ALIGN_CENTER_VERTICAL) |
---|
554 | setDefault = wx.CheckBox(parent=self.dataDisplay,label='Use as default for all images?') |
---|
555 | dataSizer.Add(setDefault,0,wx.ALIGN_CENTER_VERTICAL) |
---|
556 | setDefault.Bind(wx.EVT_CHECKBOX, OnSetDefault) |
---|
557 | setDefault.SetValue(data['setDefault']) |
---|
558 | |
---|
559 | mainSizer.Add((5,5),0) |
---|
560 | mainSizer.Add(dataSizer,0) |
---|
561 | mainSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Calibration controls:'),0, |
---|
562 | wx.ALIGN_CENTER_VERTICAL) |
---|
563 | mainSizer.Add((5,5),0) |
---|
564 | calibSizer = wx.FlexGridSizer(2,3,5,5) |
---|
565 | comboSizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
566 | comboSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Calibrant '),0, |
---|
567 | wx.ALIGN_CENTER_VERTICAL) |
---|
568 | calSel = wx.ComboBox(parent=self.dataDisplay,value=data['calibrant'],choices=calList, |
---|
569 | style=wx.CB_READONLY|wx.CB_DROPDOWN|wx.CB_SORT) |
---|
570 | calSel.Bind(wx.EVT_COMBOBOX, OnNewCalibrant) |
---|
571 | comboSizer.Add(calSel,0,wx.ALIGN_CENTER_VERTICAL) |
---|
572 | calibSizer.Add(comboSizer,0) |
---|
573 | |
---|
574 | comboSizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
575 | comboSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Calib lines to skip '),0, |
---|
576 | wx.ALIGN_CENTER_VERTICAL) |
---|
577 | calibSkip = wx.ComboBox(parent=self.dataDisplay,value=str(data['calibskip']),choices=['0','1','2','3','4','5','6','7','8','9','10'], |
---|
578 | style=wx.CB_READONLY|wx.CB_DROPDOWN) |
---|
579 | calibSkip.Bind(wx.EVT_COMBOBOX, OnCalibSkip) |
---|
580 | comboSizer.Add(calibSkip,0,wx.ALIGN_CENTER_VERTICAL) |
---|
581 | calibSizer.Add(comboSizer,0) |
---|
582 | |
---|
583 | comboSizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
584 | comboSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Min calib d-spacing '),0, |
---|
585 | wx.ALIGN_CENTER_VERTICAL) |
---|
586 | calibDmin = wx.TextCtrl(parent=self.dataDisplay,value=("%.2f" % (data['calibdmin'])), |
---|
587 | style=wx.TE_PROCESS_ENTER) |
---|
588 | calibDmin.Bind(wx.EVT_TEXT_ENTER,OnCalibDmin) |
---|
589 | calibDmin.Bind(wx.EVT_KILL_FOCUS,OnCalibDmin) |
---|
590 | comboSizer.Add(calibDmin,0,wx.ALIGN_CENTER_VERTICAL) |
---|
591 | calibSizer.Add(comboSizer,0) |
---|
592 | |
---|
593 | comboSizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
594 | comboSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Min ring I/Ib '),0, |
---|
595 | wx.ALIGN_CENTER_VERTICAL) |
---|
596 | cutOff = wx.TextCtrl(parent=self.dataDisplay,value=("%.1f" % (data['cutoff'])), |
---|
597 | style=wx.TE_PROCESS_ENTER) |
---|
598 | cutOff.Bind(wx.EVT_TEXT_ENTER,OnCutOff) |
---|
599 | cutOff.Bind(wx.EVT_KILL_FOCUS,OnCutOff) |
---|
600 | comboSizer.Add(cutOff,0,wx.ALIGN_CENTER_VERTICAL) |
---|
601 | calibSizer.Add(comboSizer,0) |
---|
602 | |
---|
603 | comboSizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
604 | comboSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Pixel search range '),0, |
---|
605 | wx.ALIGN_CENTER_VERTICAL) |
---|
606 | pixLimit = wx.ComboBox(parent=self.dataDisplay,value=str(data['pixLimit']),choices=['1','2','5','10','15','20'], |
---|
607 | style=wx.CB_READONLY|wx.CB_DROPDOWN) |
---|
608 | pixLimit.Bind(wx.EVT_COMBOBOX, OnPixLimit) |
---|
609 | comboSizer.Add(pixLimit,0,wx.ALIGN_CENTER_VERTICAL) |
---|
610 | calibSizer.Add(comboSizer,0) |
---|
611 | |
---|
612 | comboSizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
613 | setRings = wx.CheckBox(parent=self.dataDisplay,label='Show ring picks?') |
---|
614 | comboSizer.Add(setRings,0) |
---|
615 | setRings.Bind(wx.EVT_CHECKBOX, OnSetRings) |
---|
616 | setRings.SetValue(data['setRings']) |
---|
617 | calibSizer.Add(comboSizer,0) |
---|
618 | |
---|
619 | mainSizer.Add(calibSizer,0,wx.ALIGN_CENTER_VERTICAL) |
---|
620 | |
---|
621 | mainSizer.Layout() |
---|
622 | self.dataDisplay.SetSizer(mainSizer) |
---|
623 | fitSize = mainSizer.Fit(self.dataFrame) |
---|
624 | self.dataFrame.setSizePosLeft(fitSize) |
---|
625 | self.dataDisplay.SetSize(fitSize) |
---|
626 | |
---|
627 | def UpdateMasks(self,data): |
---|
628 | |
---|
629 | def OnTextMsg(event): |
---|
630 | Obj = event.GetEventObject() |
---|
631 | Obj.SetToolTipString('Drag this mask on 2D Powder Image with mouse to change ') |
---|
632 | |
---|
633 | def OnThreshold(event): |
---|
634 | try: |
---|
635 | lower = max(int(lowerThreshold.GetValue()),thresh[0][0]) |
---|
636 | except ValueError: |
---|
637 | lower = thresh[0][0] |
---|
638 | try: |
---|
639 | upper = min(int(upperThreshold.GetValue()),thresh[0][1]) |
---|
640 | except ValueError: |
---|
641 | upper = thresh[0][1] |
---|
642 | data['Thresholds'][1] = [lower,upper] |
---|
643 | lowerThreshold.SetValue("%8d" % (lower)) |
---|
644 | upperThreshold.SetValue("%8d" % (upper)) |
---|
645 | G2plt.PlotExposedImage(self,event=event) |
---|
646 | |
---|
647 | def OnSpotDiameter(event): |
---|
648 | Obj = event.GetEventObject() |
---|
649 | try: |
---|
650 | diameter = min(100.,max(0.1,float(Obj.GetValue()))) |
---|
651 | except ValueError: |
---|
652 | diameter = 1.0 |
---|
653 | Obj.SetValue("%.2f"%(diameter)) |
---|
654 | data['Points'][spotIds.index(Obj.GetId())][2] = diameter |
---|
655 | G2plt.PlotExposedImage(self,event=event) |
---|
656 | |
---|
657 | def OnDeleteSpot(event): |
---|
658 | Obj = event.GetEventObject() |
---|
659 | del(data['Points'][delSpotId.index(Obj)]) |
---|
660 | UpdateMasks(self,data) |
---|
661 | G2plt.PlotExposedImage(self,event=event) |
---|
662 | |
---|
663 | def OnRingThickness(event): |
---|
664 | Obj = event.GetEventObject() |
---|
665 | try: |
---|
666 | thick = min(1.0,max(0.001,float(Obj.GetValue()))) |
---|
667 | except ValueError: |
---|
668 | thick = 0.1 |
---|
669 | Obj.SetValue("%.3f"%(thick)) |
---|
670 | data['Rings'][ringIds.index(Obj.GetId())][1] = thick |
---|
671 | G2plt.PlotExposedImage(self,event=event) |
---|
672 | |
---|
673 | def OnDeleteRing(event): |
---|
674 | Obj = event.GetEventObject() |
---|
675 | del(data['Rings'][delRingId.index(Obj)]) |
---|
676 | UpdateMasks(self,data) |
---|
677 | G2plt.PlotExposedImage(self,event=event) |
---|
678 | |
---|
679 | def OnArcThickness(event): |
---|
680 | Obj = event.GetEventObject() |
---|
681 | try: |
---|
682 | thick = min(20.0,max(0.001,float(Obj.GetValue()))) |
---|
683 | except ValueError: |
---|
684 | thick = 0.1 |
---|
685 | Obj.SetValue("%.3f"%(thick)) |
---|
686 | data['Arcs'][arcIds.index(Obj.GetId())][2] = thick |
---|
687 | G2plt.PlotExposedImage(self,event=event) |
---|
688 | |
---|
689 | def OnDeleteArc(event): |
---|
690 | Obj = event.GetEventObject() |
---|
691 | del(data['Arcs'][delArcId.index(Obj)]) |
---|
692 | UpdateMasks(self,data) |
---|
693 | G2plt.PlotExposedImage(self,event=event) |
---|
694 | |
---|
695 | def OnDeletePoly(event): |
---|
696 | Obj = event.GetEventObject() |
---|
697 | del(data['Polygons'][delPolyId.index(Obj)]) |
---|
698 | UpdateMasks(self,data) |
---|
699 | G2plt.PlotExposedImage(self,event=event) |
---|
700 | |
---|
701 | def OnCopyMask(event): |
---|
702 | import copy |
---|
703 | TextList = [[False,'All IMG',0]] |
---|
704 | Names = [] |
---|
705 | if self.PatternTree.GetCount(): |
---|
706 | id, cookie = self.PatternTree.GetFirstChild(self.root) |
---|
707 | while id: |
---|
708 | name = self.PatternTree.GetItemText(id) |
---|
709 | Names.append(name) |
---|
710 | if 'IMG' in name: |
---|
711 | if id == self.Image: |
---|
712 | Source = name |
---|
713 | Mask = copy.deepcopy(self.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(self,id, 'Masks'))) |
---|
714 | del Mask['Thresholds'] |
---|
715 | else: |
---|
716 | TextList.append([False,name,id]) |
---|
717 | id, cookie = self.PatternTree.GetNextChild(self.root, cookie) |
---|
718 | if len(TextList) == 1: |
---|
719 | self.ErrorDialog('Nothing to copy mask to','There must be more than one "IMG" pattern') |
---|
720 | return |
---|
721 | dlg = self.CopyDialog(self,'Copy mask information','Copy mask from '+Source+' to:',TextList) |
---|
722 | try: |
---|
723 | if dlg.ShowModal() == wx.ID_OK: |
---|
724 | result = dlg.GetData() |
---|
725 | if result[0][0]: |
---|
726 | result = TextList[1:] |
---|
727 | for item in result: item[0] = True |
---|
728 | for i,item in enumerate(result): |
---|
729 | ifcopy,name,id = item |
---|
730 | if ifcopy: |
---|
731 | mask = self.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(self,id, 'Masks')) |
---|
732 | mask.update(Mask) |
---|
733 | self.PatternTree.SetItemPyData(G2gd.GetPatternTreeItemId(self,id, 'Masks'),copy.deepcopy(mask)) |
---|
734 | finally: |
---|
735 | dlg.Destroy() |
---|
736 | |
---|
737 | def OnSaveMask(event): |
---|
738 | dlg = wx.FileDialog(self, 'Choose image mask file', '.', '', |
---|
739 | 'image mask files (*.immask)|*.immask',wx.OPEN) |
---|
740 | if self.dirname: |
---|
741 | dlg.SetDirectory(self.dirname) |
---|
742 | try: |
---|
743 | if dlg.ShowModal() == wx.ID_OK: |
---|
744 | filename = dlg.GetPath() |
---|
745 | File = open(filename,'w') |
---|
746 | save = {} |
---|
747 | keys = ['Points','Rings','Arcs','Polygons','Thresholds'] |
---|
748 | for key in keys: |
---|
749 | File.write(key+':'+str(data[key])+'\n') |
---|
750 | File.close() |
---|
751 | finally: |
---|
752 | dlg.Destroy() |
---|
753 | |
---|
754 | def OnLoadMask(event): |
---|
755 | dlg = wx.FileDialog(self, 'Choose image mask file', '.', '', |
---|
756 | 'image mask files (*.immask)|*.immask',wx.OPEN) |
---|
757 | if self.dirname: |
---|
758 | dlg.SetDirectory(self.dirname) |
---|
759 | try: |
---|
760 | if dlg.ShowModal() == wx.ID_OK: |
---|
761 | filename = dlg.GetPath() |
---|
762 | File = open(filename,'r') |
---|
763 | save = {} |
---|
764 | S = File.readline() |
---|
765 | while S: |
---|
766 | if S[0] == '#': |
---|
767 | S = File.readline() |
---|
768 | continue |
---|
769 | [key,val] = S[:-1].split(':') |
---|
770 | if key in ['Points','Rings','Arcs','Polygons','Thresholds']: |
---|
771 | save[key] = eval(val) |
---|
772 | S = File.readline() |
---|
773 | data.update(save) |
---|
774 | UpdateMasks(self,data) |
---|
775 | G2plt.PlotExposedImage(self,event=event) |
---|
776 | |
---|
777 | File.close() |
---|
778 | finally: |
---|
779 | dlg.Destroy() |
---|
780 | |
---|
781 | if self.dataDisplay: |
---|
782 | self.dataDisplay.Destroy() |
---|
783 | self.dataFrame.SetMenuBar(self.dataFrame.MaskMenu) |
---|
784 | self.dataFrame.Bind(wx.EVT_MENU, OnCopyMask, id=G2gd.wxID_MASKCOPY) |
---|
785 | self.dataFrame.Bind(wx.EVT_MENU, OnLoadMask, id=G2gd.wxID_MASKLOAD) |
---|
786 | self.dataFrame.Bind(wx.EVT_MENU, OnSaveMask, id=G2gd.wxID_MASKSAVE) |
---|
787 | if not self.dataFrame.GetStatusBar(): |
---|
788 | Status = self.dataFrame.CreateStatusBar() |
---|
789 | Status.SetStatusText("To add mask: On 2D Powder Image, key a:arc, r:ring, s:spot, p:polygon") |
---|
790 | self.dataDisplay = wx.Panel(self.dataFrame) |
---|
791 | mainSizer = wx.BoxSizer(wx.VERTICAL) |
---|
792 | mainSizer.Add((5,10),0) |
---|
793 | |
---|
794 | thresh = data['Thresholds'] #min/max intensity range |
---|
795 | spots = data['Points'] #x,y,radius in mm |
---|
796 | rings = data['Rings'] #radius, thickness |
---|
797 | polygons = data['Polygons'] #3+ x,y pairs |
---|
798 | arcs = data['Arcs'] #radius, start/end azimuth, thickness |
---|
799 | |
---|
800 | littleSizer = wx.FlexGridSizer(2,3,0,5) |
---|
801 | littleSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Lower/Upper limits '),0, |
---|
802 | wx.ALIGN_CENTER_VERTICAL) |
---|
803 | Text = wx.TextCtrl(self.dataDisplay,value=("%8d" % (thresh[0][0])),style=wx.TE_READONLY) |
---|
804 | littleSizer.Add(Text,0,wx.ALIGN_CENTER_VERTICAL) |
---|
805 | Text.SetBackgroundColour(VERY_LIGHT_GREY) |
---|
806 | Text = wx.TextCtrl(self.dataDisplay,value=("%8d" % (thresh[0][1])),style=wx.TE_READONLY) |
---|
807 | littleSizer.Add(Text,0,wx.ALIGN_CENTER_VERTICAL) |
---|
808 | Text.SetBackgroundColour(VERY_LIGHT_GREY) |
---|
809 | littleSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Lower/Upper thresholds '), |
---|
810 | 0,wx.ALIGN_CENTER_VERTICAL) |
---|
811 | lowerThreshold = wx.TextCtrl(parent=self.dataDisplay, |
---|
812 | value=("%8d" % (thresh[1][0])),style=wx.TE_PROCESS_ENTER) |
---|
813 | lowerThreshold.Bind(wx.EVT_TEXT_ENTER,OnThreshold) |
---|
814 | lowerThreshold.Bind(wx.EVT_KILL_FOCUS,OnThreshold) |
---|
815 | littleSizer.Add(lowerThreshold,0,wx.ALIGN_CENTER_VERTICAL) |
---|
816 | upperThreshold = wx.TextCtrl(parent=self.dataDisplay, |
---|
817 | value=("%8d" % (thresh[1][1])),style=wx.TE_PROCESS_ENTER) |
---|
818 | upperThreshold.Bind(wx.EVT_TEXT_ENTER,OnThreshold) |
---|
819 | upperThreshold.Bind(wx.EVT_KILL_FOCUS,OnThreshold) |
---|
820 | littleSizer.Add(upperThreshold,0,wx.ALIGN_CENTER_VERTICAL) |
---|
821 | mainSizer.Add(littleSizer,0,) |
---|
822 | spotIds = [] |
---|
823 | delSpotId = [] |
---|
824 | if spots: |
---|
825 | littleSizer = wx.FlexGridSizer(len(spots)+2,3,0,5) |
---|
826 | littleSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Spot masks:'),0, |
---|
827 | wx.ALIGN_CENTER_VERTICAL) |
---|
828 | littleSizer.Add((5,0),0) |
---|
829 | littleSizer.Add((5,0),0) |
---|
830 | littleSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' position, mm'),0, |
---|
831 | wx.ALIGN_CENTER_VERTICAL) |
---|
832 | littleSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' diameter, mm'),0, |
---|
833 | wx.ALIGN_CENTER_VERTICAL) |
---|
834 | littleSizer.Add((5,0),0) |
---|
835 | for x,y,d in spots: |
---|
836 | spotText = wx.TextCtrl(parent=self.dataDisplay,value=("%.2f,%.2f" % (x,y)), |
---|
837 | style=wx.TE_READONLY) |
---|
838 | spotText.SetBackgroundColour(VERY_LIGHT_GREY) |
---|
839 | littleSizer.Add(spotText,0,wx.ALIGN_CENTER_VERTICAL) |
---|
840 | spotText.Bind(wx.EVT_ENTER_WINDOW,OnTextMsg) |
---|
841 | spotDiameter = wx.TextCtrl(parent=self.dataDisplay,value=("%.2f" % (d)), |
---|
842 | style=wx.TE_PROCESS_ENTER) |
---|
843 | littleSizer.Add(spotDiameter,0,wx.ALIGN_CENTER_VERTICAL) |
---|
844 | spotDiameter.Bind(wx.EVT_TEXT_ENTER,OnSpotDiameter) |
---|
845 | spotDiameter.Bind(wx.EVT_KILL_FOCUS,OnSpotDiameter) |
---|
846 | spotIds.append(spotDiameter.GetId()) |
---|
847 | spotDelete = wx.CheckBox(parent=self.dataDisplay,label='delete?') |
---|
848 | spotDelete.Bind(wx.EVT_CHECKBOX,OnDeleteSpot) |
---|
849 | delSpotId.append(spotDelete) |
---|
850 | littleSizer.Add(spotDelete,0,wx.ALIGN_CENTER_VERTICAL) |
---|
851 | mainSizer.Add(littleSizer,0,) |
---|
852 | ringIds = [] |
---|
853 | delRingId = [] |
---|
854 | if rings: |
---|
855 | littleSizer = wx.FlexGridSizer(len(rings)+2,3,0,5) |
---|
856 | littleSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Ring masks:'),0, |
---|
857 | wx.ALIGN_CENTER_VERTICAL) |
---|
858 | littleSizer.Add((5,0),0) |
---|
859 | littleSizer.Add((5,0),0) |
---|
860 | littleSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' 2-theta,deg'),0, |
---|
861 | wx.ALIGN_CENTER_VERTICAL) |
---|
862 | littleSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' thickness, deg'),0, |
---|
863 | wx.ALIGN_CENTER_VERTICAL) |
---|
864 | littleSizer.Add((5,0),0) |
---|
865 | for tth,thick in rings: |
---|
866 | ringText = wx.TextCtrl(parent=self.dataDisplay,value=("%.3f" % (tth)), |
---|
867 | style=wx.TE_READONLY) |
---|
868 | ringText.SetBackgroundColour(VERY_LIGHT_GREY) |
---|
869 | ringText.Bind(wx.EVT_ENTER_WINDOW,OnTextMsg) |
---|
870 | littleSizer.Add(ringText,0,wx.ALIGN_CENTER_VERTICAL) |
---|
871 | ringThick = wx.TextCtrl(parent=self.dataDisplay,value=("%.3f" % (thick)), |
---|
872 | style=wx.TE_PROCESS_ENTER) |
---|
873 | littleSizer.Add(ringThick,0,wx.ALIGN_CENTER_VERTICAL) |
---|
874 | ringThick.Bind(wx.EVT_TEXT_ENTER,OnRingThickness) |
---|
875 | ringThick.Bind(wx.EVT_KILL_FOCUS,OnRingThickness) |
---|
876 | ringIds.append(ringThick.GetId()) |
---|
877 | ringDelete = wx.CheckBox(parent=self.dataDisplay,label='delete?') |
---|
878 | ringDelete.Bind(wx.EVT_CHECKBOX,OnDeleteRing) |
---|
879 | delRingId.append(ringDelete) |
---|
880 | littleSizer.Add(ringDelete,0,wx.ALIGN_CENTER_VERTICAL) |
---|
881 | mainSizer.Add(littleSizer,0,) |
---|
882 | arcIds = [] |
---|
883 | delArcId = [] |
---|
884 | if arcs: |
---|
885 | littleSizer = wx.FlexGridSizer(len(rings)+2,4,0,5) |
---|
886 | littleSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Arc masks:'),0, |
---|
887 | wx.ALIGN_CENTER_VERTICAL) |
---|
888 | littleSizer.Add((5,0),0) |
---|
889 | littleSizer.Add((5,0),0) |
---|
890 | littleSizer.Add((5,0),0) |
---|
891 | littleSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' 2-theta,deg'),0, |
---|
892 | wx.ALIGN_CENTER_VERTICAL) |
---|
893 | littleSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' azimuth, deg'),0, |
---|
894 | wx.ALIGN_CENTER_VERTICAL) |
---|
895 | littleSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' thickness, deg'),0, |
---|
896 | wx.ALIGN_CENTER_VERTICAL) |
---|
897 | littleSizer.Add((5,0),0) |
---|
898 | for tth,azimuth,thick in arcs: |
---|
899 | arcText = wx.TextCtrl(parent=self.dataDisplay,value=("%.3f" % (tth)), |
---|
900 | style=wx.TE_READONLY) |
---|
901 | arcText.SetBackgroundColour(VERY_LIGHT_GREY) |
---|
902 | arcText.Bind(wx.EVT_ENTER_WINDOW,OnTextMsg) |
---|
903 | littleSizer.Add(arcText,0,wx.ALIGN_CENTER_VERTICAL) |
---|
904 | azmText = wx.TextCtrl(parent=self.dataDisplay,value=("%d,%d" % (azimuth[0],azimuth[1])), |
---|
905 | style=wx.TE_READONLY) |
---|
906 | azmText.SetBackgroundColour(VERY_LIGHT_GREY) |
---|
907 | azmText.Bind(wx.EVT_ENTER_WINDOW,OnTextMsg) |
---|
908 | littleSizer.Add(azmText,0,wx.ALIGN_CENTER_VERTICAL) |
---|
909 | arcThick = wx.TextCtrl(parent=self.dataDisplay,value=("%.3f" % (thick)), |
---|
910 | style=wx.TE_PROCESS_ENTER) |
---|
911 | littleSizer.Add(arcThick,0,wx.ALIGN_CENTER_VERTICAL) |
---|
912 | arcThick.Bind(wx.EVT_TEXT_ENTER,OnArcThickness) |
---|
913 | arcThick.Bind(wx.EVT_KILL_FOCUS,OnArcThickness) |
---|
914 | arcIds.append(arcThick.GetId()) |
---|
915 | arcDelete = wx.CheckBox(parent=self.dataDisplay,label='delete?') |
---|
916 | arcDelete.Bind(wx.EVT_CHECKBOX,OnDeleteArc) |
---|
917 | delArcId.append(arcDelete) |
---|
918 | littleSizer.Add(arcDelete,0,wx.ALIGN_CENTER_VERTICAL) |
---|
919 | mainSizer.Add(littleSizer,0,) |
---|
920 | polyIds = [] |
---|
921 | delPolyId = [] |
---|
922 | if polygons: |
---|
923 | littleSizer = wx.FlexGridSizer(len(polygons)+2,2,0,5) |
---|
924 | littleSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Polygon masks:'),0, |
---|
925 | wx.ALIGN_CENTER_VERTICAL) |
---|
926 | littleSizer.Add((5,0),0) |
---|
927 | for polygon in polygons: |
---|
928 | if polygon: |
---|
929 | polyList = [] |
---|
930 | for x,y in polygon: |
---|
931 | polyList.append("%.2f, %.2f"%(x,y)) |
---|
932 | polyText = wx.ComboBox(self.dataDisplay,value=polyList[0],choices=polyList,style=wx.CB_READONLY) |
---|
933 | littleSizer.Add(polyText,0,wx.ALIGN_CENTER_VERTICAL) |
---|
934 | polyDelete = wx.CheckBox(parent=self.dataDisplay,label='delete?') |
---|
935 | polyDelete.Bind(wx.EVT_CHECKBOX,OnDeletePoly) |
---|
936 | delPolyId.append(polyDelete) |
---|
937 | littleSizer.Add(polyDelete,0,wx.ALIGN_CENTER_VERTICAL) |
---|
938 | mainSizer.Add(littleSizer,0,) |
---|
939 | mainSizer.Layout() |
---|
940 | self.dataDisplay.SetSizer(mainSizer) |
---|
941 | self.dataDisplay.SetSize(mainSizer.Fit(self.dataFrame)) |
---|
942 | self.dataFrame.setSizePosLeft(mainSizer.Fit(self.dataFrame)) |
---|