1 | # -*- coding: utf-8 -*- |
---|
2 | #GSASIIpwdGUI - powder data display routines |
---|
3 | ########### SVN repository information ################### |
---|
4 | # $Date: 2015-06-19 20:59:22 +0000 (Fri, 19 Jun 2015) $ |
---|
5 | # $Author: vondreele $ |
---|
6 | # $Revision: 1898 $ |
---|
7 | # $URL: trunk/GSASIIpwdGUI.py $ |
---|
8 | # $Id: GSASIIpwdGUI.py 1898 2015-06-19 20:59:22Z vondreele $ |
---|
9 | ########### SVN repository information ################### |
---|
10 | ''' |
---|
11 | *GSASIIpwdGUI: Powder Pattern GUI routines* |
---|
12 | ------------------------------------------- |
---|
13 | |
---|
14 | Used to define GUI controls for the routines that interact |
---|
15 | with the powder histogram (PWDR) data tree items. |
---|
16 | |
---|
17 | ''' |
---|
18 | import sys |
---|
19 | import os.path |
---|
20 | import wx |
---|
21 | import wx.grid as wg |
---|
22 | import wx.lib.scrolledpanel as wxscroll |
---|
23 | import numpy as np |
---|
24 | import numpy.ma as ma |
---|
25 | import math |
---|
26 | import time |
---|
27 | import copy |
---|
28 | import random as ran |
---|
29 | import cPickle |
---|
30 | import scipy.interpolate as si |
---|
31 | import GSASIIpath |
---|
32 | GSASIIpath.SetVersionNumber("$Revision: 1898 $") |
---|
33 | import GSASIImath as G2mth |
---|
34 | import GSASIIpwd as G2pwd |
---|
35 | import GSASIIIO as G2IO |
---|
36 | import GSASIIlattice as G2lat |
---|
37 | import GSASIIspc as G2spc |
---|
38 | import GSASIIindex as G2indx |
---|
39 | import GSASIIplot as G2plt |
---|
40 | import GSASIIgrid as G2gd |
---|
41 | import GSASIIctrls as G2G |
---|
42 | import GSASIIElemGUI as G2elemGUI |
---|
43 | import GSASIIElem as G2elem |
---|
44 | import GSASIIsasd as G2sasd |
---|
45 | import GSASIIexprGUI as G2exG |
---|
46 | VERY_LIGHT_GREY =Â wx.Colour(235,235,235) |
---|
47 | WACV =Â wx.ALIGN_CENTER_VERTICAL |
---|
48 | Pwr10 =Â unichr(0x0b9)+unichr(0x0b0) |
---|
49 | Pwr20 =Â unichr(0x0b2)+unichr(0x0b0) |
---|
50 | Pwrm1 =Â unichr(0x207b)+unichr(0x0b9) |
---|
51 | Pwrm2 =Â unichr(0x207b)+unichr(0x0b2) |
---|
52 | Pwrm4 =Â unichr(0x207b)+unichr(0x2074)Â Â #really -d but looks like -4 as a superscript |
---|
53 | # trig functions in degrees |
---|
54 | sind = lambda x: math.sin(x*math.pi/180.) |
---|
55 | tand = lambda x: math.tan(x*math.pi/180.) |
---|
56 | cosd = lambda x: math.cos(x*math.pi/180.) |
---|
57 | asind = lambda x: 180.*math.asin(x)/math.pi |
---|
58 | Â Â |
---|
59 | def IsHistogramInAnyPhase(G2frame,histoName): |
---|
60 | Â Â 'Needs a doc string' |
---|
61 | Â Â phases =Â G2gd.GetPatternTreeItemId(G2frame,G2frame.root,'Phases') |
---|
62 |   if phases: |
---|
63 |     item, cookie = G2frame.PatternTree.GetFirstChild(phases) |
---|
64 |     while item: |
---|
65 | Â Â Â Â Â Â data =Â G2frame.PatternTree.GetItemPyData(item) |
---|
66 | Â Â Â Â Â Â histoList =Â data['Histograms'].keys() |
---|
67 |       if histoName in histoList: |
---|
68 |         return G2frame.PatternTree.GetItemText(item) |
---|
69 |       item, cookie = G2frame.PatternTree.GetNextChild(phases, cookie) |
---|
70 |     return False |
---|
71 | Â Â else: |
---|
72 |     return False |
---|
73 | |
---|
74 | def SetDefaultSample(): |
---|
75 | Â Â 'Fills in default items for the Sample dictionary' |
---|
76 |   return { |
---|
77 | Â Â Â Â 'InstrName':'', |
---|
78 | Â Â Â Â 'ranId':ran.randint(0,sys.maxint), |
---|
79 | Â Â Â Â 'Scale':[1.0,True],'Type':'Debye-Scherrer','Absorption':[0.0,False], |
---|
80 | Â Â Â Â 'DisplaceX':[0.0,False],'DisplaceY':[0.0,False],'Diffuse':[], |
---|
81 | Â Â Â Â 'Temperature':300.,'Pressure':0.1,'Time':0.0, |
---|
82 | Â Â Â Â 'FreePrm1':0.,'FreePrm2':0.,'FreePrm3':0., |
---|
83 | Â Â Â Â 'Gonio. radius':200.0, |
---|
84 | Â Â Â Â 'Omega':0.0,'Chi':0.0,'Phi':0.0,'Azimuth':0.0, |
---|
85 | #SASD items |
---|
86 | Â Â Â Â 'Materials':[{'Name':'vacuum','VolFrac':1.0,},{'Name':'vacuum','VolFrac':0.0,}], |
---|
87 |     'Thick':1.0,'Contrast':[0.0,0.0],    #contrast & anomalous contrast |
---|
88 |     'Trans':1.0,              #measured transmission |
---|
89 |     'SlitLen':0.0,             #Slit length - in Q(A-1) |
---|
90 | Â Â Â Â } |
---|
91 | def SetupSampleLabels(histName,dataType,histType): |
---|
92 | Â Â '''Setup a list of labels and number formatting for use in |
---|
93 | Â Â labeling sample parameters. |
---|
94 | Â Â :param str histName: Name of histogram, ("PWDR ...") |
---|
95 | Â Â :param str dataType: |
---|
96 | Â Â ''' |
---|
97 | Â Â parms =Â [] |
---|
98 | Â Â parms.append(['Scale','Histogram scale factor: ',[10,7]]) |
---|
99 |   if 'C' in histType: |
---|
100 | Â Â Â Â parms.append(['Gonio. radius','Goniometer radius (mm): ',[10,3]]) |
---|
101 |   if 'PWDR' in histName: |
---|
102 |     if dataType == 'Debye-Scherrer': |
---|
103 | Â Â Â Â Â Â parms +=Â [['DisplaceX',u'Sample X displ. perp. to beam (\xb5m): ',[10,3]], |
---|
104 | Â Â Â Â Â Â Â Â ['DisplaceY',u'Sample Y displ. || to beam (\xb5m): ',[10,3]], |
---|
105 | Â Â Â Â Â Â Â Â ['Absorption',u'Sample absorption (\xb5\xb7r): ',[10,4]],] |
---|
106 |       if 'T' in histType: |
---|
107 | Â Â Â Â Â Â Â Â parms[-1]Â =Â ['Absorption',u'Sample absorption (\xb5\xb7r/l): ',[10,4]] |
---|
108 |     elif dataType == 'Bragg-Brentano': |
---|
109 | Â Â Â Â Â Â parms +=Â [['Shift',u'Sample displacement(\xb5m): ',[10,4]], |
---|
110 | Â Â Â Â Â Â Â Â ['Transparency',u'Sample transparency(1/\xb5eff, cm): ',[10,3]], |
---|
111 | Â Â Â Â Â Â Â Â ['SurfRoughA','Surface roughness A: ',[10,4]], |
---|
112 | Â Â Â Â Â Â Â Â ['SurfRoughB','Surface roughness B: ',[10,4]]] |
---|
113 |   elif 'SASD' in histName: |
---|
114 | Â Â Â Â parms.append(['Thick','Sample thickness (mm)',[10,3]]) |
---|
115 | Â Â Â Â parms.append(['Trans','Transmission (meas)',[10,3]]) |
---|
116 | Â Â Â Â parms.append(['SlitLen',u'Slit length (Q,\xc5'+Pwrm1+')',[10,3]]) |
---|
117 | Â Â parms.append(['Omega','Goniometer omega:',[10,3]]) |
---|
118 | Â Â parms.append(['Chi','Goniometer chi:',[10,3]]) |
---|
119 | Â Â parms.append(['Phi','Goniometer phi:',[10,3]]) |
---|
120 | Â Â parms.append(['Azimuth','Detector azimuth:',[10,3]]) |
---|
121 | Â Â parms.append(['Time','Clock time (s):',[12,3]]) |
---|
122 | Â Â parms.append(['Temperature','Sample temperature (K): ',[10,3]]) |
---|
123 | Â Â parms.append(['Pressure','Sample pressure (MPa): ',[10,3]]) |
---|
124 |   return parms |
---|
125 | |
---|
126 | def SetDefaultSASDModel(): |
---|
127 | Â Â 'Fills in default items for the SASD Models dictionary'Â Â |
---|
128 |   return {'Back':[0.0,False],'Size':{'MinDiam':50,'MaxDiam':10000,'Nbins':100,'logBins':True,'Method':'MaxEnt','Distribution':[], |
---|
129 | Â Â Â Â 'Shape':['Spheroid',1.0],'MaxEnt':{'Niter':100,'Precision':0.01,'Sky':-3}, |
---|
130 |     'IPG':{'Niter':100,'Approach':0.8,'Power':-1},'Reg':{},},      |
---|
131 | Â Â Â Â 'Particle':{'Matrix':{'Name':'vacuum','VolFrac':[0.0,False]},'Levels':[],}, |
---|
132 | Â Â Â Â 'Current':'Size dist.','BackFile':'', |
---|
133 | Â Â Â Â } |
---|
134 | Â Â Â Â |
---|
135 | def SetDefaultSubstances(): |
---|
136 | Â Â 'Fills in default items for the SASD Substances dictionary' |
---|
137 |   return {'Substances':{'vacuum':{'Elements':{},'Volume':1.0,'Density':0.0,'Scatt density':0.0}}} |
---|
138 | |
---|
139 | def GetHistsLikeSelected(G2frame): |
---|
140 | Â Â '''Get the histograms that match the current selected one: |
---|
141 | Â Â The histogram prefix and data type (PXC etc.), the number of |
---|
142 | Â Â wavelengths and the instrument geometry (Debye-Scherrer etc.) |
---|
143 | Â Â must all match. The current histogram is not included in the list. |
---|
144 | |
---|
145 | Â Â :param wx.Frame G2frame: pointer to main GSAS-II data tree |
---|
146 | Â Â ''' |
---|
147 | Â Â histList =Â [] |
---|
148 | Â Â inst,inst2 =Â G2frame.PatternTree.GetItemPyData( |
---|
149 | Â Â Â Â G2gd.GetPatternTreeItemId( |
---|
150 |       G2frame,G2frame.PatternId, 'Instrument Parameters') |
---|
151 | Â Â Â Â ) |
---|
152 | Â Â hType =Â inst['Type'][0] |
---|
153 |   if 'Lam1' in inst: |
---|
154 | Â Â Â Â hLam =Â 2 |
---|
155 |   elif 'Lam' in inst: |
---|
156 | Â Â Â Â hLam =Â 1 |
---|
157 | Â Â else: |
---|
158 | Â Â Â Â hLam =Â 0 |
---|
159 | Â Â sample =Â G2frame.PatternTree.GetItemPyData( |
---|
160 | Â Â Â Â G2gd.GetPatternTreeItemId( |
---|
161 |       G2frame,G2frame.PatternId, 'Sample Parameters') |
---|
162 | Â Â Â Â ) |
---|
163 | Â Â hGeom =Â sample.get('Type') |
---|
164 | Â Â hstName =Â G2frame.PatternTree.GetItemText(G2frame.PatternId) |
---|
165 | Â Â hPrefix =Â hstName.split()[0]+' ' |
---|
166 | Â Â # cycle through tree looking for items that match the above |
---|
167 |   item, cookie = G2frame.PatternTree.GetFirstChild(G2frame.root)    |
---|
168 |   while item: |
---|
169 | Â Â Â Â name =Â G2frame.PatternTree.GetItemText(item) |
---|
170 |     if name.startswith(hPrefix) and name != hstName: |
---|
171 |       cGeom,cType,cLam, = '?','?',-1 |
---|
172 |       subitem, subcookie = G2frame.PatternTree.GetFirstChild(item) |
---|
173 |       while subitem: |
---|
174 | Â Â Â Â Â Â Â Â subname =Â G2frame.PatternTree.GetItemText(subitem) |
---|
175 |         if subname == 'Sample Parameters': |
---|
176 | Â Â Â Â Â Â Â Â Â Â sample =Â G2frame.PatternTree.GetItemPyData(subitem) |
---|
177 | Â Â Â Â Â Â Â Â Â Â cGeom =Â sample.get('Type') |
---|
178 |         elif subname == 'Instrument Parameters': |
---|
179 | Â Â Â Â Â Â Â Â Â Â inst,inst2 =Â G2frame.PatternTree.GetItemPyData(subitem) |
---|
180 | Â Â Â Â Â Â Â Â Â Â cType =Â inst['Type'][0] |
---|
181 |           if 'Lam1' in inst: |
---|
182 | Â Â Â Â Â Â Â Â Â Â Â Â cLam =Â 2 |
---|
183 |           elif 'Lam' in inst: |
---|
184 | Â Â Â Â Â Â Â Â Â Â Â Â cLam =Â 1 |
---|
185 | Â Â Â Â Â Â Â Â Â Â else: |
---|
186 | Â Â Â Â Â Â Â Â Â Â Â Â cLam =Â 0 |
---|
187 |         subitem, subcookie = G2frame.PatternTree.GetNextChild(item, subcookie) |
---|
188 |       if cLam == hLam and cType == hType and cGeom == hGeom: |
---|
189 |         if name not in histList: histList.append(name) |
---|
190 |     item, cookie = G2frame.PatternTree.GetNextChild(G2frame.root, cookie) |
---|
191 |   return histList |
---|
192 | |
---|
193 | def SetCopyNames(histName,dataType,addNames=[]): |
---|
194 | Â Â '''Determine the items in the sample parameters that should be copied, |
---|
195 | Â Â depending on the histogram type and the instrument type. |
---|
196 | Â Â ''' |
---|
197 | Â Â copyNames =Â ['Scale',] |
---|
198 | Â Â histType =Â 'HKLF' |
---|
199 |   if 'PWDR' in histName: |
---|
200 | Â Â Â Â histType =Â 'PWDR' |
---|
201 |     if 'Debye' in dataType: |
---|
202 | Â Â Â Â Â Â copyNames +=Â ['DisplaceX','DisplaceY','Absorption'] |
---|
203 | Â Â Â Â else:Â Â Â Â #Bragg-Brentano |
---|
204 | Â Â Â Â Â Â copyNames +=Â ['Shift','Transparency','SurfRoughA','SurfRoughB'] |
---|
205 |   elif 'SASD' in histName: |
---|
206 | Â Â Â Â histType =Â 'SASD' |
---|
207 | Â Â Â Â copyNames +=Â ['Materials','Thick',] |
---|
208 |   if len(addNames): |
---|
209 | Â Â Â Â copyNames +=Â addNames |
---|
210 |   return histType,copyNames |
---|
211 | Â Â |
---|
212 | def CopyPlotCtrls(G2frame): |
---|
213 | Â Â '''Global copy: Copy plot controls from current histogram to others. |
---|
214 | Â Â ''' |
---|
215 | Â Â hst =Â G2frame.PatternTree.GetItemText(G2frame.PatternId) |
---|
216 | Â Â histList =Â GetHistsLikeSelected(G2frame) |
---|
217 |   if not histList: |
---|
218 | Â Â Â Â G2frame.ErrorDialog('No match','No other histograms match '+hst,G2frame.dataFrame) |
---|
219 | Â Â Â Â return |
---|
220 | Â Â sourceData =Â G2frame.PatternTree.GetItemPyData(G2frame.PatternId) |
---|
221 | Â Â |
---|
222 |   if 'Offset' not in sourceData[0]:  #patch for old data |
---|
223 | Â Â Â Â sourceData[0].update({'Offset':[0.0,0.0],'delOffset':0.02,'refOffset':-1.0, |
---|
224 | Â Â Â Â Â Â 'refDelt':0.01,'qPlot':False,'dPlot':False,'sqrtPlot':False}) |
---|
225 | Â Â Â Â G2frame.PatternTree.SetItemPyData(G2frame.PatternId,sourceData) |
---|
226 | Â Â Â Â |
---|
227 | Â Â dlg =Â G2G.G2MultiChoiceDialog( |
---|
228 |     G2frame.dataFrame, |
---|
229 | Â Â Â Â 'Copy plot controls from\n'+str(hst[5:])+' to...', |
---|
230 |     'Copy plot controls', histList) |
---|
231 | Â Â results =Â [] |
---|
232 | Â Â try: |
---|
233 |     if dlg.ShowModal() == wx.ID_OK: |
---|
234 | Â Â Â Â Â Â results =Â dlg.GetSelections() |
---|
235 | Â Â finally: |
---|
236 | Â Â Â Â dlg.Destroy() |
---|
237 | Â Â copyList =Â [] |
---|
238 |   for i in results: |
---|
239 | Â Â Â Â copyList.append(histList[i]) |
---|
240 | |
---|
241 | Â Â keys =Â ['Offset','delOffset','refOffset','refDelt','qPlot','dPlot','sqrtPlot'] |
---|
242 |   source = dict(zip(keys,[sourceData[0][item] for item in keys])) |
---|
243 |   for hist in copyList: |
---|
244 | Â Â Â Â Id =Â G2gd.GetPatternTreeItemId(G2frame,G2frame.root,hist) |
---|
245 | Â Â Â Â data =Â G2frame.PatternTree.GetItemPyData(Id) |
---|
246 | Â Â Â Â data[0].update(source) |
---|
247 | Â Â Â Â G2frame.PatternTree.SetItemPyData(Id,data) |
---|
248 |   print 'Copy of plot controls successful' |
---|
249 | |
---|
250 | def CopySelectedHistItems(G2frame): |
---|
251 | Â Â '''Global copy: Copy items from current histogram to others. |
---|
252 | Â Â ''' |
---|
253 | Â Â hst =Â G2frame.PatternTree.GetItemText(G2frame.PatternId) |
---|
254 | Â Â histList =Â GetHistsLikeSelected(G2frame) |
---|
255 |   if not histList: |
---|
256 | Â Â Â Â G2frame.ErrorDialog('No match','No other histograms match '+hst,G2frame.dataFrame) |
---|
257 | Â Â Â Â return |
---|
258 | Â Â choices =Â ['Limits','Background','Instrument Parameters','Sample Parameters'] |
---|
259 | Â Â dlg =Â G2G.G2MultiChoiceDialog( |
---|
260 |     G2frame.dataFrame, |
---|
261 | Â Â Â Â 'Copy which histogram sections from\n'+str(hst[5:]), |
---|
262 |     'Select copy sections', choices, filterBox=False) |
---|
263 | Â Â dlg.SetSelections(range(len(choices))) |
---|
264 | Â Â choiceList =Â [] |
---|
265 |   if dlg.ShowModal() == wx.ID_OK: |
---|
266 |     choiceList = [choices[i] for i in dlg.GetSelections()] |
---|
267 |   if not choiceList: return |
---|
268 | Â Â |
---|
269 | Â Â dlg =Â G2G.G2MultiChoiceDialog( |
---|
270 |     G2frame.dataFrame, |
---|
271 | Â Â Â Â 'Copy parameters from\n'+str(hst[5:])+' to...', |
---|
272 |     'Copy parameters', histList) |
---|
273 | Â Â results =Â [] |
---|
274 | Â Â try: |
---|
275 |     if dlg.ShowModal() == wx.ID_OK: |
---|
276 | Â Â Â Â Â Â results =Â dlg.GetSelections() |
---|
277 | Â Â finally: |
---|
278 | Â Â Â Â dlg.Destroy() |
---|
279 | Â Â copyList =Â [] |
---|
280 |   for i in results: |
---|
281 | Â Â Â Â copyList.append(histList[i]) |
---|
282 | |
---|
283 |   if 'Limits' in choiceList: # Limits |
---|
284 | Â Â Â Â data =Â G2frame.PatternTree.GetItemPyData( |
---|
285 | Â Â Â Â Â Â G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId,'Limits')) |
---|
286 |     for item in copyList: |
---|
287 | Â Â Â Â Â Â Id =Â G2gd.GetPatternTreeItemId(G2frame,G2frame.root,item) |
---|
288 | Â Â Â Â Â Â G2frame.PatternTree.SetItemPyData( |
---|
289 | Â Â Â Â Â Â Â Â G2gd.GetPatternTreeItemId(G2frame,Id,'Limits'), |
---|
290 | Â Â Â Â Â Â Â Â copy.deepcopy(data)) |
---|
291 |   if 'Background' in choiceList: # Background |
---|
292 | Â Â Â Â data =Â G2frame.PatternTree.GetItemPyData( |
---|
293 | Â Â Â Â Â Â G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId,'Background')) |
---|
294 |     for item in copyList: |
---|
295 | Â Â Â Â Â Â Id =Â G2gd.GetPatternTreeItemId(G2frame,G2frame.root,item) |
---|
296 | Â Â Â Â Â Â G2frame.PatternTree.SetItemPyData( |
---|
297 | Â Â Â Â Â Â Â Â G2gd.GetPatternTreeItemId(G2frame,Id,'Background'), |
---|
298 | Â Â Â Â Â Â Â Â copy.deepcopy(data)) |
---|
299 |   if 'Instrument Parameters' in choiceList: # Instrument Parameters |
---|
300 | Â Â Â Â # for now all items in Inst. parms are copied |
---|
301 | Â Â Â Â data,data1 =Â G2frame.PatternTree.GetItemPyData( |
---|
302 | Â Â Â Â Â Â G2gd.GetPatternTreeItemId( |
---|
303 | Â Â Â Â Â Â Â Â G2frame,G2frame.PatternId,'Instrument Parameters')) |
---|
304 |     for item in copyList: |
---|
305 | Â Â Â Â Â Â Id =Â G2gd.GetPatternTreeItemId(G2frame,G2frame.root,item) |
---|
306 | Â Â Â Â Â Â G2frame.PatternTree.GetItemPyData( |
---|
307 | Â Â Â Â Â Â Â Â G2gd.GetPatternTreeItemId(G2frame,Id,'Instrument Parameters') |
---|
308 | Â Â Â Â Â Â Â Â )[0].update(copy.deepcopy(data)) |
---|
309 | Â Â Â Â Â Â G2frame.PatternTree.GetItemPyData( |
---|
310 | Â Â Â Â Â Â Â Â G2gd.GetPatternTreeItemId(G2frame,Id,'Instrument Parameters') |
---|
311 | Â Â Â Â Â Â Â Â )[1].update(copy.deepcopy(data1)) |
---|
312 |   if 'Sample Parameters' in choiceList: # Sample Parameters |
---|
313 | Â Â Â Â data =Â G2frame.PatternTree.GetItemPyData( |
---|
314 | Â Â Â Â Â Â G2gd.GetPatternTreeItemId( |
---|
315 | Â Â Â Â Â Â Â Â G2frame,G2frame.PatternId,'Sample Parameters')) |
---|
316 | Â Â Â Â # selects items to be copied |
---|
317 | Â Â Â Â histType,copyNames =Â SetCopyNames(hst,data['Type'], |
---|
318 | Â Â Â Â Â Â addNames =Â ['Omega','Chi','Phi','Gonio. radius','InstrName']) |
---|
319 |     copyDict = {parm:data[parm] for parm in copyNames} |
---|
320 |     for item in copyList: |
---|
321 | Â Â Â Â Â Â Id =Â G2gd.GetPatternTreeItemId(G2frame,G2frame.root,item) |
---|
322 | Â Â Â Â Â Â G2frame.PatternTree.GetItemPyData( |
---|
323 | Â Â Â Â Â Â Â Â G2gd.GetPatternTreeItemId(G2frame,Id,'Sample Parameters') |
---|
324 | Â Â Â Â Â Â Â Â ).update(copy.deepcopy(copyDict)) |
---|
325 | Â Â Â Â Â Â Â Â Â Â Â Â Â |
---|
326 | ################################################################################ |
---|
327 | #####Â Powder Peaks |
---|
328 | ################################################################################Â Â Â Â Â Â |
---|
329 | Â Â Â Â |
---|
330 | def UpdatePeakGrid(G2frame, data): |
---|
331 | Â Â '''respond to selection of PWDR powder peaks data tree item. |
---|
332 | Â Â ''' |
---|
333 |   if G2frame.dataDisplay: |
---|
334 | Â Â Â Â G2frame.dataFrame.Clear() |
---|
335 | Â Â Â Â |
---|
336 |   def OnAutoSearch(event): |
---|
337 | Â Â Â Â PatternId =Â G2frame.PatternId |
---|
338 | Â Â Â Â PickId =Â G2frame.PickId |
---|
339 |     limits = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Limits'))[1] |
---|
340 |     inst,inst2 = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Instrument Parameters')) |
---|
341 | Â Â Â Â profile =Â G2frame.PatternTree.GetItemPyData(PatternId)[1] |
---|
342 | Â Â Â Â x0 =Â profile[0] |
---|
343 | Â Â Â Â iBeg =Â np.searchsorted(x0,limits[0]) |
---|
344 | Â Â Â Â iFin =Â np.searchsorted(x0,limits[1]) |
---|
345 | Â Â Â Â x =Â x0[iBeg:iFin] |
---|
346 | Â Â Â Â y0 =Â profile[1][iBeg:iFin] |
---|
347 | Â Â Â Â y1 =Â copy.copy(y0) |
---|
348 | Â Â Â Â ysig =Â np.std(y1) |
---|
349 | Â Â Â Â offset =Â [-1,1] |
---|
350 | Â Â Â Â ymask =Â ma.array(y0,mask=(y0<ysig)) |
---|
351 |     for off in offset: |
---|
352 | Â Â Â Â Â Â ymask =Â ma.array(ymask,mask=(ymask-np.roll(y0,off)<=0.)) |
---|
353 | Â Â Â Â indx =Â ymask.nonzero() |
---|
354 | Â Â Â Â mags =Â ymask[indx] |
---|
355 | Â Â Â Â poss =Â x[indx] |
---|
356 | Â Â Â Â refs =Â zip(poss,mags) |
---|
357 |     if 'C' in Inst['Type'][0]:  |
---|
358 | Â Â Â Â Â Â refs =Â G2mth.sortArray(refs,0,reverse=True)Â Â Â #small 2-Thetas first |
---|
359 | Â Â Â Â else:Â Â #'T'OF |
---|
360 | Â Â Â Â Â Â refs =Â G2mth.sortArray(refs,0,reverse=False)Â Â #big TOFs first |
---|
361 |     for i,ref1 in enumerate(refs): |
---|
362 |       for ref2 in refs[i+1:]: |
---|
363 |         if abs(ref2[0]-ref1[0]) < 0.1*G2pwd.getFWHM(ref1[0],inst): |
---|
364 | Â Â Â Â Â Â Â Â Â Â del(refs[i]) |
---|
365 |     if 'C' in Inst['Type'][0]:  |
---|
366 | Â Â Â Â Â Â refs =Â G2mth.sortArray(refs,1,reverse=True) |
---|
367 | Â Â Â Â else:Â Â #'T'OF |
---|
368 | Â Â Â Â Â Â refs =Â G2mth.sortArray(refs,1,reverse=False) |
---|
369 |     for pos,mag in refs: |
---|
370 | Â Â Â Â Â Â data['peaks'].append(G2mth.setPeakparms(inst,inst2,pos,mag)) |
---|
371 | Â Â Â Â UpdatePeakGrid(G2frame,data) |
---|
372 | Â Â Â Â G2plt.PlotPatterns(G2frame,plotType='PWDR') |
---|
373 | Â Â Â Â |
---|
374 |   def OnCopyPeaks(event): |
---|
375 | Â Â Â Â hst =Â G2frame.PatternTree.GetItemText(G2frame.PatternId) |
---|
376 | Â Â Â Â histList =Â GetHistsLikeSelected(G2frame) |
---|
377 |     if not histList: |
---|
378 | Â Â Â Â Â Â G2frame.ErrorDialog('No match','No histograms match '+hst,G2frame.dataFrame) |
---|
379 | Â Â Â Â Â Â return |
---|
380 | Â Â Â Â copyList =Â [] |
---|
381 | Â Â Â Â dlg =Â G2G.G2MultiChoiceDialog( |
---|
382 |       G2frame.dataFrame, |
---|
383 | Â Â Â Â Â Â 'Copy peak list from\n'+str(hst[5:])+' to...', |
---|
384 |       'Copy peaks', histList) |
---|
385 | Â Â Â Â try: |
---|
386 |       if dlg.ShowModal() == wx.ID_OK: |
---|
387 |         for i in dlg.GetSelections(): |
---|
388 | Â Â Â Â Â Â Â Â Â Â copyList.append(histList[i]) |
---|
389 | Â Â Â Â finally: |
---|
390 | Â Â Â Â Â Â dlg.Destroy() |
---|
391 |     for item in copyList: |
---|
392 | Â Â Â Â Â Â Id =Â G2gd.GetPatternTreeItemId(G2frame,G2frame.root,item) |
---|
393 | Â Â Â Â Â Â G2frame.PatternTree.SetItemPyData( |
---|
394 | Â Â Â Â Â Â Â Â G2gd.GetPatternTreeItemId(G2frame,Id,'Peak List'),copy.deepcopy(data)) |
---|
395 | Â Â |
---|
396 |   def OnUnDo(event): |
---|
397 | Â Â Â Â DoUnDo() |
---|
398 | Â Â Â Â G2frame.dataFrame.UnDo.Enable(False) |
---|
399 | Â Â Â Â |
---|
400 |   def DoUnDo(): |
---|
401 |     print 'Undo last refinement' |
---|
402 | Â Â Â Â file =Â open(G2frame.undofile,'rb') |
---|
403 | Â Â Â Â PatternId =Â G2frame.PatternId |
---|
404 |     for item in ['Background','Instrument Parameters','Peak List']: |
---|
405 |       G2frame.PatternTree.SetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, item),cPickle.load(file)) |
---|
406 |       if G2frame.dataDisplay.GetName() == item: |
---|
407 |         if item == 'Background': |
---|
408 |           UpdateBackground(G2frame,G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, item))) |
---|
409 |         elif item == 'Instrument Parameters': |
---|
410 |           UpdateInstrumentGrid(G2frame,G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, item))) |
---|
411 |         elif item == 'Peak List': |
---|
412 |           UpdatePeakGrid(G2frame,G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, item))) |
---|
413 |       print item,' recovered' |
---|
414 | Â Â Â Â file.close() |
---|
415 | Â Â Â Â |
---|
416 |   def SaveState(): |
---|
417 | Â Â Â Â G2frame.undofile =Â os.path.join(G2frame.dirname,'GSASII.save') |
---|
418 | Â Â Â Â file =Â open(G2frame.undofile,'wb') |
---|
419 | Â Â Â Â PatternId =Â G2frame.PatternId |
---|
420 |     for item in ['Background','Instrument Parameters','Peak List']: |
---|
421 | Â Â Â Â Â Â cPickle.dump(G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId,item)),file,1) |
---|
422 | Â Â Â Â file.close() |
---|
423 | Â Â Â Â G2frame.dataFrame.UnDo.Enable(True) |
---|
424 | Â Â Â Â |
---|
425 |   def OnLSQPeakFit(event): |
---|
426 |     if not G2frame.GSASprojectfile:      #force a save of the gpx file so SaveState can wirte in the same directory |
---|
427 | Â Â Â Â Â Â G2frame.OnFileSaveas(event) |
---|
428 | Â Â Â Â OnPeakFit('LSQ') |
---|
429 | Â Â Â Â |
---|
430 |   def OnOneCycle(event): |
---|
431 | Â Â Â Â OnPeakFit('LSQ',oneCycle=True) |
---|
432 | Â Â Â Â |
---|
433 |   def OnSeqPeakFit(event): |
---|
434 | Â Â Â Â hst =Â G2frame.PatternTree.GetItemText(G2frame.PatternId) |
---|
435 | Â Â Â Â histList =Â GetHistsLikeSelected(G2frame) |
---|
436 |     if not histList: |
---|
437 | Â Â Â Â Â Â G2frame.ErrorDialog('No match','No histograms match '+hst,G2frame.dataFrame) |
---|
438 | Â Â Â Â Â Â return |
---|
439 | Â Â Â Â sel =Â [] |
---|
440 |     dlg = G2G.G2MultiChoiceDialog(G2frame.dataFrame, 'Sequential peak fits', |
---|
441 | Â Â Â Â Â Â Â 'Select dataset to include',histList) |
---|
442 | Â Â Â Â dlg.SetSelections(sel) |
---|
443 | Â Â Â Â names =Â [] |
---|
444 |     if dlg.ShowModal() == wx.ID_OK: |
---|
445 |       for sel in dlg.GetSelections(): |
---|
446 | Â Â Â Â Â Â Â Â names.append(histList[sel]) |
---|
447 | Â Â Â Â dlg.Destroy() |
---|
448 | Â Â Â Â SeqResult =Â {} |
---|
449 | Â Â Â Â Reverse =Â False |
---|
450 | Â Â Â Â CopyForward =Â False |
---|
451 | Â Â Â Â choice =Â ['Reverse sequence','Copy from prev.',] |
---|
452 | Â Â Â Â dlg =Â wx.MultiChoiceDialog(G2frame.dataFrame,'Sequential controls','Select controls',choice) |
---|
453 |     if dlg.ShowModal() == wx.ID_OK: |
---|
454 |       for sel in dlg.GetSelections(): |
---|
455 |         if sel: |
---|
456 | Â Â Â Â Â Â Â Â Â Â CopyForward =Â True |
---|
457 | Â Â Â Â Â Â Â Â else: |
---|
458 | Â Â Â Â Â Â Â Â Â Â Reverse =Â True |
---|
459 | Â Â Â Â dlg.Destroy() |
---|
460 |     dlg = wx.ProgressDialog('Sequential peak fit','Data set name = '+names[0],len(names), |
---|
461 | Â Â Â Â Â Â style =Â wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE|wx.PD_REMAINING_TIME|wx.PD_CAN_ABORT) |
---|
462 |     Controls = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.root, 'Controls')) |
---|
463 | Â Â Â Â controls =Â {'deriv type':'analytic','min dM/M':0.0001,} |
---|
464 | Â Â Â Â Controls['ShowCell']Â =Â False |
---|
465 |     print 'Peak Fitting with '+controls['deriv type']+' derivatives:' |
---|
466 | Â Â Â Â oneCycle =Â False |
---|
467 | Â Â Â Â FitPgm =Â 'LSQ' |
---|
468 | Â Â Â Â prevVaryList =Â [] |
---|
469 | Â Â Â Â Names =Â [] |
---|
470 |     if Reverse: |
---|
471 | Â Â Â Â Â Â names.reverse() |
---|
472 | Â Â Â Â try: |
---|
473 |       for i,name in enumerate(names): |
---|
474 |         print ' Sequential fit for ',name |
---|
475 | Â Â Â Â Â Â Â Â GoOn =Â dlg.Update(i,newmsg='Data set name = '+name)[0] |
---|
476 |         if not GoOn: |
---|
477 | Â Â Â Â Â Â Â Â Â Â break |
---|
478 | Â Â Â Â Â Â Â Â PatternId =Â G2gd.GetPatternTreeItemId(G2frame,G2frame.root,name) |
---|
479 |         if i and CopyForward: |
---|
480 |           G2frame.PatternTree.SetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Peak List'),copy.deepcopy(peaks)) |
---|
481 | Â Â Â Â Â Â Â Â Â Â prevVaryList =Â varyList[:] |
---|
482 |         peaks = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Peak List')) |
---|
483 |         background = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Background')) |
---|
484 |         limits = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Limits'))[1] |
---|
485 |         inst,inst2 = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Instrument Parameters')) |
---|
486 | Â Â Â Â Â Â Â Â data =Â G2frame.PatternTree.GetItemPyData(PatternId)[1] |
---|
487 | Â Â Â Â Â Â Â Â wx.BeginBusyCursor() |
---|
488 |         dlg2 = wx.ProgressDialog('Residual','Peak fit Rwp = ',101.0, |
---|
489 | Â Â Â Â Â Â Â Â Â Â style =Â wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE|wx.PD_REMAINING_TIME|wx.PD_CAN_ABORT) |
---|
490 | Â Â Â Â Â Â Â Â screenSize =Â wx.ClientDisplayRect() |
---|
491 | Â Â Â Â Â Â Â Â Size =Â dlg.GetSize() |
---|
492 |         if 50 < Size[0] < 500: # sanity check on size, since this fails w/Win & wx3.0 |
---|
493 | Â Â Â Â Â Â Â Â Â Â dlg2.SetSize((int(Size[0]*1.2),Size[1]))Â # increase size a bit along x |
---|
494 | Â Â Â Â Â Â Â Â Â Â dlg2.SetPosition(wx.Point(screenSize[2]-Size[0]-305,screenSize[1]+5)) |
---|
495 | Â Â Â Â Â Â Â Â try: |
---|
496 | Â Â Â Â Â Â Â Â Â Â peaks['sigDict'],result,sig,Rvals,varyList,parmDict,fullvaryList,badVary =Â G2pwd.DoPeakFit(FitPgm,peaks['peaks'], |
---|
497 | Â Â Â Â Â Â Â Â Â Â Â Â background,limits,inst,inst2,data,prevVaryList,oneCycle,controls,dlg2) |
---|
498 | Â Â Â Â Â Â Â Â finally: |
---|
499 | Â Â Â Â Â Â Â Â Â Â dlg2.Destroy() |
---|
500 |         if len(result[0]) != len(fullvaryList): |
---|
501 |           print ' ***** Sequential peak fit stopped at '+name+' *****' |
---|
502 | Â Â Â Â Â Â Â Â Â Â break |
---|
503 | Â Â Â Â Â Â Â Â else: |
---|
504 | Â Â Â Â Â Â Â Â Â Â Names.append(name)Â Â |
---|
505 |           G2frame.PatternTree.SetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Peak List'),copy.deepcopy(peaks)) |
---|
506 | Â Â Â Â Â Â Â Â Â Â SeqResult[name]Â =Â {'variables':result[0],'varyList':varyList,'sig':sig,'Rvals':Rvals, |
---|
507 | Â Â Â Â Â Â Â Â Â Â Â Â 'covMatrix':np.eye(len(result[0])),'title':name,'parmDict':parmDict, |
---|
508 | Â Â Â Â Â Â Â Â Â Â Â Â 'fullVary':fullvaryList,'badVary':badVary} |
---|
509 | Â Â Â Â Â Â dlg.Destroy() |
---|
510 |       print ' ***** Sequential peak fit successful *****' |
---|
511 | Â Â Â Â finally: |
---|
512 | Â Â Â Â Â Â wx.EndBusyCursor() |
---|
513 | Â Â Â Â SeqResult['histNames']Â =Â Names |
---|
514 | Â Â Â Â Id =Â G2gd.GetPatternTreeItemId(G2frame,G2frame.root,'Sequential results') |
---|
515 |     if Id: |
---|
516 | Â Â Â Â Â Â G2frame.PatternTree.SetItemPyData(Id,SeqResult) |
---|
517 | Â Â Â Â else: |
---|
518 | Â Â Â Â Â Â Id =Â G2frame.PatternTree.AppendItem(parent=G2frame.root,text='Sequential results') |
---|
519 | Â Â Â Â Â Â G2frame.PatternTree.SetItemPyData(Id,SeqResult) |
---|
520 | Â Â Â Â G2frame.PatternTree.SelectItem(Id) |
---|
521 | Â Â Â Â |
---|
522 |   def OnClearPeaks(event): |
---|
523 | Â Â Â Â dlg =Â wx.MessageDialog(G2frame,'Delete all peaks?','Clear peak list',wx.OK|wx.CANCEL) |
---|
524 | Â Â Â Â try: |
---|
525 |       if dlg.ShowModal() == wx.ID_OK: |
---|
526 | Â Â Â Â Â Â Â Â peaks =Â {'peaks':[],'sigDict':{}} |
---|
527 | Â Â Â Â finally: |
---|
528 | Â Â Â Â Â Â dlg.Destroy() |
---|
529 | Â Â Â Â UpdatePeakGrid(G2frame,peaks) |
---|
530 | Â Â Â Â G2plt.PlotPatterns(G2frame,plotType='PWDR') |
---|
531 | Â Â Â Â |
---|
532 |   def OnPeakFit(FitPgm,oneCycle=False): |
---|
533 | Â Â Â Â SaveState() |
---|
534 |     controls = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.root, 'Controls')) |
---|
535 |     if not controls: |
---|
536 | Â Â Â Â Â Â controls =Â {'deriv type':'analytic','min dM/M':0.0001,}Â Â Â #fill in defaults if needed |
---|
537 |     print 'Peak Fitting with '+controls['deriv type']+' derivatives:' |
---|
538 | Â Â Â Â PatternId =Â G2frame.PatternId |
---|
539 | Â Â Â Â PickId =Â G2frame.PickId |
---|
540 |     peaks = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Peak List')) |
---|
541 |     if not peaks: |
---|
542 | Â Â Â Â Â Â G2frame.ErrorDialog('No peaks!','Nothing to fit!') |
---|
543 | Â Â Â Â Â Â return |
---|
544 |     background = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Background')) |
---|
545 |     limits = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Limits'))[1] |
---|
546 |     inst,inst2 = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Instrument Parameters')) |
---|
547 | Â Â Â Â data =Â G2frame.PatternTree.GetItemPyData(PatternId)[1] |
---|
548 | Â Â Â Â wx.BeginBusyCursor() |
---|
549 |     dlg = wx.ProgressDialog('Residual','Peak fit Rwp = ',101.0, |
---|
550 | Â Â Â Â Â Â style =Â wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE|wx.PD_REMAINING_TIME|wx.PD_CAN_ABORT) |
---|
551 | Â Â Â Â screenSize =Â wx.ClientDisplayRect() |
---|
552 | Â Â Â Â Size =Â dlg.GetSize() |
---|
553 |     if 50 < Size[0] < 500: # sanity check on size, since this fails w/Win & wx3.0 |
---|
554 | Â Â Â Â Â Â dlg.SetSize((int(Size[0]*1.2),Size[1]))Â # increase size a bit along x |
---|
555 | Â Â Â Â Â Â dlg.SetPosition(wx.Point(screenSize[2]-Size[0]-305,screenSize[1]+5)) |
---|
556 | Â Â Â Â try: |
---|
557 | Â Â Â Â Â Â peaks['sigDict']Â =Â G2pwd.DoPeakFit(FitPgm,peaks['peaks'],background,limits,inst,inst2,data,[],oneCycle,controls,dlg)[0] |
---|
558 | Â Â Â Â finally: |
---|
559 | Â Â Â Â Â Â wx.EndBusyCursor()Â Â |
---|
560 |     G2frame.PatternTree.SetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Peak List'),copy.copy(peaks)) |
---|
561 | Â Â Â Â UpdatePeakGrid(G2frame,copy.copy(peaks)) |
---|
562 | Â Â Â Â G2plt.PlotPatterns(G2frame,plotType='PWDR') |
---|
563 |     print 'finished' |
---|
564 | Â Â Â Â return |
---|
565 | Â Â Â Â |
---|
566 |   def OnResetSigGam(event): |
---|
567 | Â Â Â Â PatternId =Â G2frame.PatternId |
---|
568 | Â Â Â Â PickId =Â G2frame.PickId |
---|
569 |     Inst,Inst2 = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Instrument Parameters')) |
---|
570 |     peaks = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Peak List')) |
---|
571 |     if not peaks['peaks']: |
---|
572 | Â Â Â Â Â Â G2frame.ErrorDialog('No peaks!','Nothing to do!') |
---|
573 | Â Â Â Â Â Â return |
---|
574 | Â Â Â Â newpeaks =Â {'peaks':[],'sigDict':{}} |
---|
575 |     for peak in peaks['peaks']: |
---|
576 | Â Â Â Â Â Â newpeaks['peaks'].append(G2mth.setPeakparms(Inst,Inst2,peak[0],peak[2])) |
---|
577 |     G2frame.PatternTree.SetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Peak List'),newpeaks) |
---|
578 | Â Â Â Â UpdatePeakGrid(G2frame,newpeaks) |
---|
579 | Â Â Â Â Â Â Â Â |
---|
580 |   def RefreshPeakGrid(event): |
---|
581 | Â Â Â Â r,c =Â event.GetRow(),event.GetCol() |
---|
582 | Â Â Â Â |
---|
583 | Â Â Â Â event.StopPropagation() |
---|
584 | Â Â Â Â data['peaks']Â =Â G2frame.PeakTable.GetData() |
---|
585 | Â Â Â Â T =Â [] |
---|
586 |     for peak in data['peaks']:T.append(peak[0]) |
---|
587 | Â Â Â Â D =Â dict(zip(T,data['peaks'])) |
---|
588 | Â Â Â Â T.sort() |
---|
589 | Â Â Â Â X =Â [] |
---|
590 |     for key in T: X.append(D[key]) |
---|
591 | Â Â Â Â data['peaks']Â =Â XÂ Â Â Â |
---|
592 | Â Â Â Â |
---|
593 |   def setBackgroundColors(): |
---|
594 |     for r in range(G2frame.dataDisplay.GetNumberRows()): |
---|
595 |       for c in range(G2frame.dataDisplay.GetNumberCols()): |
---|
596 |         if G2frame.dataDisplay.GetColLabelValue(c) in ['position','intensity','alpha','beta','sigma','gamma']: |
---|
597 |           if float(G2frame.dataDisplay.GetCellValue(r,c)) < 0.: |
---|
598 | Â Â Â Â Â Â Â Â Â Â Â Â G2frame.dataDisplay.SetCellBackgroundColour(r,c,wx.RED) |
---|
599 | Â Â Â Â Â Â Â Â Â Â else: |
---|
600 | Â Â Â Â Â Â Â Â Â Â Â Â G2frame.dataDisplay.SetCellBackgroundColour(r,c,wx.WHITE) |
---|
601 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
---|
602 |   def KeyEditPeakGrid(event): |
---|
603 | Â Â Â Â rowList =Â G2frame.dataDisplay.GetSelectedRows() |
---|
604 | Â Â Â Â colList =Â G2frame.dataDisplay.GetSelectedCols() |
---|
605 | Â Â Â Â selectList =Â G2frame.dataDisplay.GetSelectedCells() |
---|
606 | Â Â Â Â data =Â G2frame.PatternTree.GetItemPyData(G2frame.PickId) |
---|
607 |     if event.GetKeyCode() == wx.WXK_RETURN: |
---|
608 | Â Â Â Â Â Â event.Skip(True) |
---|
609 |     elif event.GetKeyCode() == wx.WXK_CONTROL: |
---|
610 | Â Â Â Â Â Â event.Skip(True) |
---|
611 |     elif event.GetKeyCode() == wx.WXK_SHIFT: |
---|
612 | Â Â Â Â Â Â event.Skip(True) |
---|
613 |     elif rowList: |
---|
614 | Â Â Â Â Â Â G2frame.dataDisplay.ClearSelection() |
---|
615 |       if event.GetKeyCode() == wx.WXK_DELETE: |
---|
616 | Â Â Â Â Â Â Â Â G2frame.dataDisplay.ClearGrid() |
---|
617 | Â Â Â Â Â Â Â Â rowList.sort() |
---|
618 | Â Â Â Â Â Â Â Â rowList.reverse() |
---|
619 | Â Â Â Â Â Â Â Â nDel =Â 0 |
---|
620 |         for row in rowList: |
---|
621 | Â Â Â Â Â Â Â Â Â Â G2frame.PeakTable.DeleteRow(row) |
---|
622 | Â Â Â Â Â Â Â Â Â Â nDel +=Â 1 |
---|
623 |         if nDel: |
---|
624 |           msg = wg.GridTableMessage(G2frame.PeakTable, |
---|
625 | Â Â Â Â Â Â Â Â Â Â Â Â wg.GRIDTABLE_NOTIFY_ROWS_DELETED,0,nDel) |
---|
626 | Â Â Â Â Â Â Â Â Â Â G2frame.dataDisplay.ProcessTableMessage(msg) |
---|
627 | Â Â Â Â Â Â Â Â data =Â G2frame.PeakTable.GetData() |
---|
628 | Â Â Â Â Â Â Â Â G2frame.PatternTree.SetItemPyData(G2frame.PickId,data['peaks'][:-nDel]) |
---|
629 | Â Â Â Â Â Â Â Â G2frame.dataDisplay.ForceRefresh() |
---|
630 | Â Â Â Â Â Â Â Â setBackgroundColors() |
---|
631 | Â Â Â Â Â Â Â Â Â Â Â Â |
---|
632 |     elif colList: |
---|
633 | Â Â Â Â Â Â G2frame.dataDisplay.ClearSelection() |
---|
634 | Â Â Â Â Â Â key =Â event.GetKeyCode() |
---|
635 |       for col in colList: |
---|
636 |         if G2frame.PeakTable.GetTypeName(0,col) == wg.GRID_VALUE_BOOL: |
---|
637 |           if key == 89: #'Y' |
---|
638 |             for row in range(G2frame.PeakTable.GetNumberRows()): data['peaks'][row][col]=True |
---|
639 |           elif key == 78: #'N' |
---|
640 |             for row in range(G2frame.PeakTable.GetNumberRows()): data['peaks'][row][col]=False |
---|
641 |     elif selectList: |
---|
642 | Â Â Â Â Â Â G2frame.dataDisplay.ClearSelection() |
---|
643 | Â Â Â Â Â Â key =Â event.GetKeyCode() |
---|
644 |       for row,col in selectList: |
---|
645 |         if G2frame.PeakTable.GetTypeName(row,col) == wg.GRID_VALUE_BOOL: |
---|
646 |           if key == 89: #'Y' |
---|
647 | Â Â Â Â Â Â Â Â Â Â Â Â data['peaks'][row][col]=True |
---|
648 |           elif key == 78: #'N' |
---|
649 | Â Â Â Â Â Â Â Â Â Â Â Â data['peaks'][row][col]=False |
---|
650 | Â Â Â Â G2plt.PlotPatterns(G2frame,plotType='PWDR') |
---|
651 | Â Â Â Â Â Â |
---|
652 | Â Â G2gd.SetDataMenuBar(G2frame,G2frame.dataFrame.PeakMenu) |
---|
653 |   if not G2frame.dataFrame.GetStatusBar(): |
---|
654 | Â Â Â Â Status =Â G2frame.dataFrame.CreateStatusBar() |
---|
655 | Â Â Status.SetStatusText('Global refine: select refine column & press Y or N') |
---|
656 |   G2frame.Bind(wx.EVT_MENU, OnAutoSearch, id=G2gd.wxID_AUTOSEARCH) |
---|
657 |   G2frame.Bind(wx.EVT_MENU, OnCopyPeaks, id=G2gd.wxID_PEAKSCOPY) |
---|
658 |   G2frame.Bind(wx.EVT_MENU, OnUnDo, id=G2gd.wxID_UNDO) |
---|
659 |   G2frame.Bind(wx.EVT_MENU, OnLSQPeakFit, id=G2gd.wxID_LSQPEAKFIT) |
---|
660 |   G2frame.Bind(wx.EVT_MENU, OnOneCycle, id=G2gd.wxID_LSQONECYCLE) |
---|
661 |   G2frame.Bind(wx.EVT_MENU, OnSeqPeakFit, id=G2gd.wxID_SEQPEAKFIT) |
---|
662 |   G2frame.Bind(wx.EVT_MENU, OnClearPeaks, id=G2gd.wxID_CLEARPEAKS) |
---|
663 |   G2frame.Bind(wx.EVT_MENU, OnResetSigGam, id=G2gd.wxID_RESETSIGGAM) |
---|
664 |   if data['peaks']: |
---|
665 | Â Â Â Â G2frame.dataFrame.AutoSearch.Enable(False) |
---|
666 | Â Â Â Â G2frame.dataFrame.PeakCopy.Enable(True) |
---|
667 | Â Â Â Â G2frame.dataFrame.PeakFit.Enable(True) |
---|
668 | Â Â Â Â G2frame.dataFrame.PFOneCycle.Enable(True) |
---|
669 | Â Â Â Â G2frame.dataFrame.SeqPeakFit.Enable(True) |
---|
670 | Â Â else: |
---|
671 | Â Â Â Â G2frame.dataFrame.PeakFit.Enable(False) |
---|
672 | Â Â Â Â G2frame.dataFrame.PeakCopy.Enable(False) |
---|
673 | Â Â Â Â G2frame.dataFrame.PFOneCycle.Enable(False) |
---|
674 | Â Â Â Â G2frame.dataFrame.AutoSearch.Enable(True) |
---|
675 | Â Â Â Â G2frame.dataFrame.SeqPeakFit.Enable(False) |
---|
676 | Â Â G2frame.PickTable =Â [] |
---|
677 | Â Â rowLabels =Â [] |
---|
678 | Â Â PatternId =Â G2frame.PatternId |
---|
679 |   Inst = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Instrument Parameters'))[0] |
---|
680 |   for i in range(len(data['peaks'])): rowLabels.append(str(i+1)) |
---|
681 |   if 'C' in Inst['Type'][0]: |
---|
682 | Â Â Â Â colLabels =Â ['position','refine','intensity','refine','sigma','refine','gamma','refine'] |
---|
683 | Â Â Â Â Types =Â [wg.GRID_VALUE_FLOAT+':10,4',wg.GRID_VALUE_BOOL, |
---|
684 | Â Â Â Â Â Â wg.GRID_VALUE_FLOAT+':10,1',wg.GRID_VALUE_BOOL, |
---|
685 | Â Â Â Â Â Â wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_BOOL, |
---|
686 | Â Â Â Â Â Â wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_BOOL] |
---|
687 | Â Â else: |
---|
688 | Â Â Â Â colLabels =Â ['position','refine','intensity','refine','alpha','refine', |
---|
689 | Â Â Â Â Â Â 'beta','refine','sigma','refine','gamma','refine'] |
---|
690 | Â Â Â Â Types =Â [wg.GRID_VALUE_FLOAT+':10,1',wg.GRID_VALUE_BOOL, |
---|
691 | Â Â Â Â Â Â wg.GRID_VALUE_FLOAT+':10,4',wg.GRID_VALUE_BOOL, |
---|
692 | Â Â Â Â Â Â wg.GRID_VALUE_FLOAT+':10,4',wg.GRID_VALUE_BOOL, |
---|
693 | Â Â Â Â Â Â wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_BOOL, |
---|
694 | Â Â Â Â Â Â wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_BOOL, |
---|
695 | Â Â Â Â Â Â wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_BOOL] |
---|
696 | Â Â T =Â [] |
---|
697 |   for peak in data['peaks']: |
---|
698 | Â Â Â Â T.append(peak[0]) |
---|
699 | Â Â D =Â dict(zip(T,data['peaks'])) |
---|
700 | Â Â T.sort() |
---|
701 |   if 'T' in Inst['Type'][0]: #want big TOF's first |
---|
702 | Â Â Â Â T.reverse() |
---|
703 | Â Â X =Â [] |
---|
704 |   for key in T: X.append(D[key]) |
---|
705 | Â Â data['peaks']Â =Â X |
---|
706 | Â Â G2frame.PatternTree.SetItemPyData(G2frame.PickId,data) |
---|
707 | Â Â G2frame.PeakTable =Â G2G.Table(data['peaks'],rowLabels=rowLabels,colLabels=colLabels,types=Types) |
---|
708 | Â Â G2frame.dataFrame.SetLabel('Peak List') |
---|
709 | Â Â G2frame.dataDisplay =Â G2G.GSGrid(parent=G2frame.dataFrame) |
---|
710 |   G2frame.dataDisplay.SetTable(G2frame.PeakTable, True) |
---|
711 | Â Â setBackgroundColors()Â Â Â Â Â Â Â Â Â Â Â Â Â |
---|
712 |   G2frame.dataDisplay.Bind(wg.EVT_GRID_CELL_CHANGE, RefreshPeakGrid) |
---|
713 |   G2frame.dataDisplay.Bind(wx.EVT_KEY_DOWN, KeyEditPeakGrid) |
---|
714 | Â Â G2frame.dataDisplay.SetMargins(0,0) |
---|
715 | Â Â G2frame.dataDisplay.AutoSizeColumns(False) |
---|
716 | Â Â G2frame.dataFrame.setSizePosLeft([535,350]) |
---|
717 | Â Â G2frame.dataFrame.SendSizeEvent() |
---|
718 | Â Â Â Â |
---|
719 | ################################################################################ |
---|
720 | #####Â Background |
---|
721 | ################################################################################Â Â Â Â Â Â |
---|
722 | Â Â Â Â |
---|
723 | def UpdateBackground(G2frame,data): |
---|
724 | Â Â '''respond to selection of PWDR background data tree item. |
---|
725 | Â Â ''' |
---|
726 |   if len(data) < 2:    #add Debye diffuse & peaks scattering here |
---|
727 | Â Â Â Â data.append({'nDebye':0,'debyeTerms':[],'nPeaks':0,'peaksList':[]}) |
---|
728 |   if 'nPeaks' not in data[1]: |
---|
729 | Â Â Â Â data[1].update({'nPeaks':0,'peaksList':[]}) |
---|
730 | Â Â ValObj =Â {} |
---|
731 | Â Â |
---|
732 |   def OnBackFlagCopy(event): |
---|
733 | Â Â Â Â flag =Â data[0][1] |
---|
734 | Â Â Â Â backDict =Â data[-1] |
---|
735 |     if backDict['nDebye']: |
---|
736 | Â Â Â Â Â Â DBflags =Â [] |
---|
737 |       for term in backDict['debyeTerms']: |
---|
738 | Â Â Â Â Â Â Â Â DBflags.append(term[1::2]) |
---|
739 |     if backDict['nPeaks']: |
---|
740 | Â Â Â Â Â Â PKflags =Â [] |
---|
741 |       for term in backDict['peaksList']: |
---|
742 | Â Â Â Â Â Â Â Â PKflags.append(term[1::2])Â Â Â Â Â Â |
---|
743 | Â Â Â Â hst =Â G2frame.PatternTree.GetItemText(G2frame.PatternId) |
---|
744 | Â Â Â Â histList =Â GetHistsLikeSelected(G2frame) |
---|
745 |     if not histList: |
---|
746 | Â Â Â Â Â Â G2frame.ErrorDialog('No match','No histograms match '+hst,G2frame.dataFrame) |
---|
747 | Â Â Â Â Â Â return |
---|
748 | Â Â Â Â dlg =Â G2G.G2MultiChoiceDialog( |
---|
749 |       G2frame.dataFrame, |
---|
750 | Â Â Â Â Â Â 'Copy bkg ref. flags from\n'+str(hst[5:])+' to...', |
---|
751 |       'Copy bkg flags', histList) |
---|
752 | Â Â Â Â copyList =Â [] |
---|
753 | Â Â Â Â try: |
---|
754 |       if dlg.ShowModal() == wx.ID_OK: |
---|
755 |         for i in dlg.GetSelections(): |
---|
756 | Â Â Â Â Â Â Â Â Â Â copyList.append(histList[i]) |
---|
757 | Â Â Â Â finally: |
---|
758 | Â Â Â Â Â Â dlg.Destroy() |
---|
759 |     for item in copyList: |
---|
760 | Â Â Â Â Â Â Id =Â G2gd.GetPatternTreeItemId(G2frame,G2frame.root,item) |
---|
761 | Â Â Â Â Â Â backData =Â G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Id,'Background')) |
---|
762 | Â Â Â Â Â Â backData[0][1]Â =Â copy.copy(flag) |
---|
763 | Â Â Â Â Â Â bkDict =Â backData[-1] |
---|
764 |       if bkDict['nDebye'] == backDict['nDebye']: |
---|
765 |         for i,term in enumerate(bkDict['debyeTerms']): |
---|
766 | Â Â Â Â Â Â Â Â Â Â term[1::2]Â =Â copy.copy(DBflags[i]) |
---|
767 |       if bkDict['nPeaks'] == backDict['nPeaks']: |
---|
768 |         for i,term in enumerate(bkDict['peaksList']): |
---|
769 | Â Â Â Â Â Â Â Â Â Â term[1::2]Â =Â copy.copy(PKflags[i])Â Â Â Â Â Â Â Â Â Â |
---|
770 | Â Â Â Â Â Â |
---|
771 |   def OnBackCopy(event): |
---|
772 | Â Â Â Â hst =Â G2frame.PatternTree.GetItemText(G2frame.PatternId) |
---|
773 | Â Â Â Â histList =Â GetHistsLikeSelected(G2frame) |
---|
774 |     if not histList: |
---|
775 | Â Â Â Â Â Â G2frame.ErrorDialog('No match','No histograms match '+hst,G2frame.dataFrame) |
---|
776 | Â Â Â Â Â Â return |
---|
777 | Â Â Â Â copyList =Â [] |
---|
778 | Â Â Â Â dlg =Â G2G.G2MultiChoiceDialog( |
---|
779 |       G2frame.dataFrame, |
---|
780 | Â Â Â Â Â Â 'Copy bkg params from\n'+str(hst[5:])+' to...', |
---|
781 |       'Copy parameters', histList) |
---|
782 | Â Â Â Â try: |
---|
783 |       if dlg.ShowModal() == wx.ID_OK: |
---|
784 |         for i in dlg.GetSelections(): |
---|
785 | Â Â Â Â Â Â Â Â Â Â copyList.append(histList[i]) |
---|
786 | Â Â Â Â finally: |
---|
787 | Â Â Â Â Â Â dlg.Destroy() |
---|
788 |     for item in copyList: |
---|
789 | Â Â Â Â Â Â Id =Â G2gd.GetPatternTreeItemId(G2frame,G2frame.root,item) |
---|
790 | Â Â Â Â Â Â G2frame.PatternTree.SetItemPyData( |
---|
791 | Â Â Â Â Â Â Â Â G2gd.GetPatternTreeItemId(G2frame,Id,'Background'),copy.copy(data)) |
---|
792 | |
---|
793 |   def OnBkgFit(event): |
---|
794 |     def SetInstParms(Inst): |
---|
795 | Â Â Â Â Â Â dataType =Â Inst['Type'][0] |
---|
796 | Â Â Â Â Â Â insVary =Â [] |
---|
797 | Â Â Â Â Â Â insNames =Â [] |
---|
798 | Â Â Â Â Â Â insVals =Â [] |
---|
799 |       for parm in Inst: |
---|
800 | Â Â Â Â Â Â Â Â insNames.append(parm) |
---|
801 | Â Â Â Â Â Â Â Â insVals.append(Inst[parm][1]) |
---|
802 |         if parm in ['U','V','W','X','Y','SH/L','I(L2)/I(L1)','alpha', |
---|
803 |           'beta-0','beta-1','beta-q','sig-0','sig-1','sig-2','sig-q',] and Inst[parm][2]: |
---|
804 | Â Â Â Â Â Â Â Â Â Â Â Â insVary.append(parm) |
---|
805 | Â Â Â Â Â Â instDict =Â dict(zip(insNames,insVals)) |
---|
806 | Â Â Â Â Â Â instDict['X']Â =Â max(instDict['X'],0.01) |
---|
807 | Â Â Â Â Â Â instDict['Y']Â =Â max(instDict['Y'],0.01) |
---|
808 |       if 'SH/L' in instDict: |
---|
809 | Â Â Â Â Â Â Â Â instDict['SH/L']Â =Â max(instDict['SH/L'],0.002) |
---|
810 |       return dataType,instDict,insVary |
---|
811 | Â Â |
---|
812 |     PatternId = G2frame.PatternId    |
---|
813 |     controls = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.root, 'Controls')) |
---|
814 |     background = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Background')) |
---|
815 |     limits = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Limits'))[1] |
---|
816 |     inst,inst2 = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Instrument Parameters')) |
---|
817 | Â Â Â Â # sort the points for convenience and then separate them; extend the range if needed |
---|
818 |     background[1]['FixedPoints'] = sorted(background[1]['FixedPoints'],key=lambda pair:pair[0])    |
---|
819 |     X = [x for x,y in background[1]['FixedPoints']] |
---|
820 |     Y = [y for x,y in background[1]['FixedPoints']] |
---|
821 |     if X[0] > limits[0]: |
---|
822 | Â Â Â Â Â Â X =Â [limits[0]]Â +Â X |
---|
823 | Â Â Â Â Â Â Y =Â [Y[0]]Â +Â Y |
---|
824 |     if X[-1] < limits[1]: |
---|
825 | Â Â Â Â Â Â X +=Â [limits[1]] |
---|
826 | Â Â Â Â Â Â Y +=Â [Y[-1]] |
---|
827 | Â Â Â Â # interpolate the fixed points onto the grid of data points within limits |
---|
828 | Â Â Â Â pwddata =Â G2frame.PatternTree.GetItemPyData(PatternId)[1] |
---|
829 | Â Â Â Â xBeg =Â np.searchsorted(pwddata[0],limits[0]) |
---|
830 | Â Â Â Â xFin =Â np.searchsorted(pwddata[0],limits[1]) |
---|
831 | Â Â Â Â xdata =Â pwddata[0][xBeg:xFin] |
---|
832 | Â Â Â Â ydata =Â si.interp1d(X,Y)(xdata) |
---|
833 | Â Â Â Â #GSASIIpath.IPyBreak() |
---|
834 | Â Â Â Â W =Â [1]*len(xdata) |
---|
835 | Â Â Â Â Z =Â [0]*len(xdata) |
---|
836 | |
---|
837 | Â Â Â Â # load instrument and background params |
---|
838 | Â Â Â Â dataType,insDict,insVary =Â SetInstParms(inst) |
---|
839 | Â Â Â Â bakType,bakDict,bakVary =Â G2pwd.SetBackgroundParms(background) |
---|
840 | Â Â Â Â # how many background parameters are refined? |
---|
841 |     if len(bakVary)*1.5 > len(X): |
---|
842 | Â Â Â Â Â Â msg =Â ("You are attempting to vary "+str(len(bakVary))+ |
---|
843 | Â Â Â Â Â Â Â Â Â Â " background terms with only "+str(len(X))+" background points"+ |
---|
844 | Â Â Â Â Â Â Â Â Â Â "\nAdd more points or reduce the number of terms") |
---|
845 |       print msg |
---|
846 | Â Â Â Â Â Â G2frame.ErrorDialog('Too few points',msg) |
---|
847 | Â Â Â Â Â Â return |
---|
848 | Â Â Â Â |
---|
849 | Â Â Â Â wx.BeginBusyCursor() |
---|
850 | Â Â Â Â try: |
---|
851 | Â Â Â Â Â Â G2pwd.DoPeakFit('LSQ',[],background,limits,inst,inst2, |
---|
852 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â np.array((xdata,ydata,W,Z,Z,Z)),bakVary,False,controls) |
---|
853 | Â Â Â Â finally: |
---|
854 | Â Â Â Â Â Â wx.EndBusyCursor() |
---|
855 | Â Â Â Â # compute the background values and plot them |
---|
856 | Â Â Â Â parmDict =Â {} |
---|
857 | Â Â Â Â bakType,bakDict,bakVary =Â G2pwd.SetBackgroundParms(background) |
---|
858 | Â Â Â Â parmDict.update(bakDict) |
---|
859 | Â Â Â Â parmDict.update(insDict) |
---|
860 | Â Â Â Â pwddata[3]Â *=Â 0 |
---|
861 | Â Â Â Â pwddata[5]Â *=Â 0 |
---|
862 | Â Â Â Â pwddata[4][xBeg:xFin]Â =Â G2pwd.getBackground( |
---|
863 | Â Â Â Â Â Â '',parmDict,bakType,dataType,xdata)[0] |
---|
864 | Â Â Â Â G2plt.PlotPatterns(G2frame,plotType='PWDR') |
---|
865 | Â Â Â Â # show the updated background values |
---|
866 | Â Â Â Â wx.CallLater(100,UpdateBackground,G2frame,data) |
---|
867 | Â Â Â Â |
---|
868 |   def OnBkgClear(event): |
---|
869 |     if 'FixedPoints' not in data[1]: |
---|
870 | Â Â Â Â Â Â return |
---|
871 | Â Â Â Â else: |
---|
872 |       del data[1]['FixedPoints'] |
---|
873 | Â Â Â Â Â Â G2plt.PlotPatterns(G2frame,plotType='PWDR') |
---|
874 | Â Â |
---|
875 |   def OnPeaksMove(event): |
---|
876 |     if not data[1]['nPeaks']: |
---|
877 | Â Â Â Â Â Â G2frame.ErrorDialog('Error','No peaks to move') |
---|
878 | Â Â Â Â Â Â return |
---|
879 | Â Â Â Â Peaks =Â {'peaks':[],'sigDict':{}} |
---|
880 |     for peak in data[1]['peaksList']: |
---|
881 | Â Â Â Â Â Â Peaks['peaks'].append([peak[0],0,peak[2],0,peak[4],0,peak[6],0]) |
---|
882 |     G2frame.PatternTree.SetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId, 'Peak List'),Peaks) |
---|
883 | Â Â Â Â |
---|
884 |   def BackSizer(): |
---|
885 | Â Â Â Â |
---|
886 |     def OnNewType(event): |
---|
887 | Â Â Â Â Â Â data[0][0]Â =Â bakType.GetValue() |
---|
888 | Â Â Â Â Â Â |
---|
889 |     def OnBakRef(event): |
---|
890 | Â Â Â Â Â Â data[0][1]Â =Â bakRef.GetValue() |
---|
891 | Â Â Â Â Â Â |
---|
892 |     def OnBakTerms(event): |
---|
893 | Â Â Â Â Â Â data[0][2]Â =Â int(bakTerms.GetValue()) |
---|
894 | Â Â Â Â Â Â M =Â len(data[0]) |
---|
895 | Â Â Â Â Â Â N =Â data[0][2]+3 |
---|
896 | Â Â Â Â Â Â item =Â data[0] |
---|
897 |       if N > M:    #add terms |
---|
898 |         for i in range(M,N): |
---|
899 | Â Â Â Â Â Â Â Â Â Â item.append(0.0) |
---|
900 |       elif N < M:   #delete terms |
---|
901 |         for i in range(N,M): |
---|
902 | Â Â Â Â Â Â Â Â Â Â del(item[-1]) |
---|
903 | Â Â Â Â Â Â G2frame.PatternTree.SetItemPyData(BackId,data) |
---|
904 | Â Â Â Â Â Â #wx.CallAfter(UpdateBackground,G2frame,data) |
---|
905 | Â Â Â Â Â Â wx.CallLater(100,UpdateBackground,G2frame,data) |
---|
906 | Â Â Â Â Â Â |
---|
907 |     def OnBakVal(event): |
---|
908 | Â Â Â Â Â Â Obj =Â event.GetEventObject() |
---|
909 | Â Â Â Â Â Â item =Â ValObj[Obj.GetId()][0] |
---|
910 | Â Â Â Â Â Â try: |
---|
911 | Â Â Â Â Â Â Â Â value =Â float(Obj.GetValue()) |
---|
912 |       except ValueError: |
---|
913 | Â Â Â Â Â Â Â Â value =Â data[0][item] |
---|
914 | Â Â Â Â Â Â data[0][item]Â =Â value |
---|
915 | Â Â Â Â Â Â Obj.SetValue('%10.4f'%(value)) |
---|
916 | Â Â Â Â |
---|
917 | Â Â Â Â backSizer =Â wx.BoxSizer(wx.VERTICAL) |
---|
918 | Â Â Â Â topSizer =Â wx.BoxSizer(wx.HORIZONTAL) |
---|
919 | Â Â Â Â topSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,' Background function: '),0,WACV) |
---|
920 | Â Â Â Â bakType =Â wx.ComboBox(G2frame.dataDisplay,value=data[0][0], |
---|
921 | Â Â Â Â Â Â Â Â choices=Choices,style=wx.CB_READONLY|wx.CB_DROPDOWN) |
---|
922 |     bakType.Bind(wx.EVT_COMBOBOX, OnNewType) |
---|
923 | Â Â Â Â topSizer.Add(bakType) |
---|
924 | Â Â Â Â topSizer.Add((5,0),0) |
---|
925 | Â Â Â Â bakRef =Â wx.CheckBox(G2frame.dataDisplay,label=' Refine?') |
---|
926 | Â Â Â Â bakRef.SetValue(bool(data[0][1])) |
---|
927 |     bakRef.Bind(wx.EVT_CHECKBOX, OnBakRef) |
---|
928 | Â Â Â Â topSizer.Add(bakRef,0,WACV) |
---|
929 | Â Â Â Â topSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,' No. coeff.: '),0,WACV) |
---|
930 |     bakTerms = wx.ComboBox(G2frame.dataDisplay,-1,value=str(data[0][2]),choices=[str(i+1) for i in range(36)], |
---|
931 | Â Â Â Â Â Â style=wx.CB_READONLY|wx.CB_DROPDOWN) |
---|
932 | Â Â Â Â bakTerms.Bind(wx.EVT_COMBOBOX,OnBakTerms) |
---|
933 | Â Â Â Â topSizer.Add(bakTerms,0,WACV) |
---|
934 | Â Â Â Â topSizer.Add((5,0),0) |
---|
935 | Â Â Â Â backSizer.Add(topSizer) |
---|
936 | Â Â Â Â backSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,' Background coefficients:'),0,WACV) |
---|
937 | Â Â Â Â bakSizer =Â wx.FlexGridSizer(0,5,5,5) |
---|
938 |     for i,value in enumerate(data[0][3:]): |
---|
939 | Â Â Â Â Â Â bakVal =Â wx.TextCtrl(G2frame.dataDisplay,wx.ID_ANY,'%10.4g'%(value),style=wx.TE_PROCESS_ENTER) |
---|
940 | Â Â Â Â Â Â bakSizer.Add(bakVal,0,WACV) |
---|
941 | Â Â Â Â Â Â ValObj[bakVal.GetId()]Â =Â [i+3] |
---|
942 | Â Â Â Â Â Â bakVal.Bind(wx.EVT_TEXT_ENTER,OnBakVal) |
---|
943 | Â Â Â Â Â Â bakVal.Bind(wx.EVT_KILL_FOCUS,OnBakVal) |
---|
944 | Â Â Â Â backSizer.Add(bakSizer) |
---|
945 |     return backSizer |
---|
946 | Â Â Â Â |
---|
947 |   def DebyeSizer(): |
---|
948 | Â Â Â Â |
---|
949 |     def OnDebTerms(event): |
---|
950 | Â Â Â Â Â Â data[1]['nDebye']Â =Â int(debTerms.GetValue()) |
---|
951 | Â Â Â Â Â Â M =Â len(data[1]['debyeTerms']) |
---|
952 | Â Â Â Â Â Â N =Â data[1]['nDebye'] |
---|
953 |       if N > M:    #add terms |
---|
954 |         for i in range(M,N): |
---|
955 | Â Â Â Â Â Â Â Â Â Â data[1]['debyeTerms'].append([1.0,False,1.0,False,0.010,False]) |
---|
956 |       elif N < M:   #delete terms |
---|
957 |         for i in range(N,M): |
---|
958 | Â Â Â Â Â Â Â Â Â Â del(data[1]['debyeTerms'][-1]) |
---|
959 | Â Â Â Â Â Â #wx.CallAfter(UpdateBackground,G2frame,data) |
---|
960 | Â Â Â Â Â Â wx.CallLater(100,UpdateBackground,G2frame,data) |
---|
961 | |
---|
962 |     def KeyEditPeakGrid(event): |
---|
963 | Â Â Â Â Â Â colList =Â debyeGrid.GetSelectedCols() |
---|
964 |       if event.GetKeyCode() == wx.WXK_RETURN: |
---|
965 | Â Â Â Â Â Â Â Â event.Skip(True) |
---|
966 |       elif event.GetKeyCode() == wx.WXK_CONTROL: |
---|
967 | Â Â Â Â Â Â Â Â event.Skip(True) |
---|
968 |       elif event.GetKeyCode() == wx.WXK_SHIFT: |
---|
969 | Â Â Â Â Â Â Â Â event.Skip(True) |
---|
970 |       elif colList: |
---|
971 | Â Â Â Â Â Â Â Â debyeGrid.ClearSelection() |
---|
972 | Â Â Â Â Â Â Â Â key =Â event.GetKeyCode() |
---|
973 |         for col in colList: |
---|
974 |           if debyeTable.GetTypeName(0,col) == wg.GRID_VALUE_BOOL: |
---|
975 |             if key == 89: #'Y' |
---|
976 |               for row in range(debyeGrid.GetNumberRows()): data[1]['debyeTerms'][row][col]=True |
---|
977 |             elif key == 78: #'N' |
---|
978 |               for row in range(debyeGrid.GetNumberRows()): data[1]['debyeTerms'][row][col]=False |
---|
979 | |
---|
980 | Â Â Â Â |
---|
981 | Â Â Â Â debSizer =Â wx.BoxSizer(wx.VERTICAL) |
---|
982 | Â Â Â Â topSizer =Â wx.BoxSizer(wx.HORIZONTAL) |
---|
983 | Â Â Â Â topSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,' Debye scattering: '),0,WACV) |
---|
984 | Â Â Â Â topSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,' No. coeff.: '),0,WACV) |
---|
985 |     debTerms = wx.ComboBox(G2frame.dataDisplay,-1,value=str(data[1]['nDebye']),choices=[str(i) for i in range(12)], |
---|
986 | Â Â Â Â Â Â style=wx.CB_READONLY|wx.CB_DROPDOWN) |
---|
987 | Â Â Â Â debTerms.Bind(wx.EVT_COMBOBOX,OnDebTerms) |
---|
988 | Â Â Â Â topSizer.Add(debTerms,0,WACV) |
---|
989 | Â Â Â Â topSizer.Add((5,0),0) |
---|
990 | Â Â Â Â debSizer.Add(topSizer) |
---|
991 |     if data[1]['nDebye']: |
---|
992 | Â Â Â Â Â Â debSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,' Debye diffuse terms:'),0,WACV)Â Â Â Â |
---|
993 | Â Â Â Â Â Â rowLabels =Â [] |
---|
994 |       for i in range(len(data[1]['debyeTerms'])): rowLabels.append(str(i)) |
---|
995 | Â Â Â Â Â Â colLabels =Â ['A','refine','R','refine','U','refine'] |
---|
996 | Â Â Â Â Â Â Types =Â [wg.GRID_VALUE_FLOAT+':10,2',wg.GRID_VALUE_BOOL, |
---|
997 | Â Â Â Â Â Â wg.GRID_VALUE_FLOAT+':10,3',wg.GRID_VALUE_BOOL, |
---|
998 | Â Â Â Â Â Â wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_BOOL] |
---|
999 | Â Â Â Â Â Â debyeTable =Â G2G.Table(data[1]['debyeTerms'],rowLabels=rowLabels,colLabels=colLabels,types=Types) |
---|
1000 | Â Â Â Â Â Â debyeGrid =Â G2G.GSGrid(parent=G2frame.dataDisplay) |
---|
1001 |       debyeGrid.SetTable(debyeTable, True) |
---|
1002 |       debyeGrid.Bind(wx.EVT_KEY_DOWN, KeyEditPeakGrid) |
---|
1003 | Â Â Â Â Â Â debyeGrid.AutoSizeColumns(False) |
---|
1004 | Â Â Â Â Â Â debSizer.Add(debyeGrid)Â Â Â Â |
---|
1005 |     return debSizer |
---|
1006 | Â Â Â |
---|
1007 |   def PeaksSizer(): |
---|
1008 | |
---|
1009 |     def OnPeaks(event): |
---|
1010 | Â Â Â Â Â Â data[1]['nPeaks']Â =Â int(peaks.GetValue()) |
---|
1011 | Â Â Â Â Â Â M =Â len(data[1]['peaksList']) |
---|
1012 | Â Â Â Â Â Â N =Â data[1]['nPeaks'] |
---|
1013 |       if N > M:    #add terms |
---|
1014 |         for i in range(M,N): |
---|
1015 | Â Â Â Â Â Â Â Â Â Â data[1]['peaksList'].append([1.0,False,1.0,False,0.10,False,0.10,False]) |
---|
1016 |       elif N < M:   #delete terms |
---|
1017 |         for i in range(N,M): |
---|
1018 | Â Â Â Â Â Â Â Â Â Â del(data[1]['peaksList'][-1]) |
---|
1019 | Â Â Â Â Â Â #wx.CallAfter(UpdateBackground,G2frame,data) |
---|
1020 | Â Â Â Â Â Â wx.CallLater(100,UpdateBackground,G2frame,data) |
---|
1021 | Â Â Â Â Â Â |
---|
1022 |     def KeyEditPeakGrid(event): |
---|
1023 | Â Â Â Â Â Â colList =Â peaksGrid.GetSelectedCols() |
---|
1024 |       if event.GetKeyCode() == wx.WXK_RETURN: |
---|
1025 | Â Â Â Â Â Â Â Â event.Skip(True) |
---|
1026 |       elif event.GetKeyCode() == wx.WXK_CONTROL: |
---|
1027 | Â Â Â Â Â Â Â Â event.Skip(True) |
---|
1028 |       elif event.GetKeyCode() == wx.WXK_SHIFT: |
---|
1029 | Â Â Â Â Â Â Â Â event.Skip(True) |
---|
1030 |       elif colList: |
---|
1031 | Â Â Â Â Â Â Â Â peaksGrid.ClearSelection() |
---|
1032 | Â Â Â Â Â Â Â Â key =Â event.GetKeyCode() |
---|
1033 |         for col in colList: |
---|
1034 |           if peaksTable.GetTypeName(0,col) == wg.GRID_VALUE_BOOL: |
---|
1035 |             if key == 89: #'Y' |
---|
1036 |               for row in range(peaksGrid.GetNumberRows()): data[1]['peaksList'][row][col]=True |
---|
1037 |             elif key == 78: #'N' |
---|
1038 |               for row in range(peaksGrid.GetNumberRows()): data[1]['peaksList'][row][col]=False |
---|
1039 | |
---|
1040 | Â Â Â Â peaksSizer =Â wx.BoxSizer(wx.VERTICAL) |
---|
1041 | Â Â Â Â topSizer =Â wx.BoxSizer(wx.HORIZONTAL) |
---|
1042 | Â Â Â Â topSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,' Peaks in background: '),0,WACV) |
---|
1043 | Â Â Â Â topSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,' No. peaks: '),0,WACV) |
---|
1044 |     peaks = wx.ComboBox(G2frame.dataDisplay,-1,value=str(data[1]['nPeaks']),choices=[str(i) for i in range(30)], |
---|
1045 | Â Â Â Â Â Â style=wx.CB_READONLY|wx.CB_DROPDOWN) |
---|
1046 | Â Â Â Â peaks.Bind(wx.EVT_COMBOBOX,OnPeaks) |
---|
1047 | Â Â Â Â topSizer.Add(peaks,0,WACV) |
---|
1048 | Â Â Â Â topSizer.Add((5,0),0) |
---|
1049 | Â Â Â Â peaksSizer.Add(topSizer) |
---|
1050 |     if data[1]['nPeaks']: |
---|
1051 | Â Â Â Â Â Â peaksSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,' Peak list:'),0,WACV)Â Â Â Â |
---|
1052 | Â Â Â Â Â Â rowLabels =Â [] |
---|
1053 |       for i in range(len(data[1]['peaksList'])): rowLabels.append(str(i)) |
---|
1054 | Â Â Â Â Â Â colLabels =Â ['pos','refine','int','refine','sig','refine','gam','refine'] |
---|
1055 | Â Â Â Â Â Â Types =Â [wg.GRID_VALUE_FLOAT+':10,2',wg.GRID_VALUE_BOOL, |
---|
1056 | Â Â Â Â Â Â wg.GRID_VALUE_FLOAT+':10,3',wg.GRID_VALUE_BOOL, |
---|
1057 | Â Â Â Â Â Â wg.GRID_VALUE_FLOAT+':10,3',wg.GRID_VALUE_BOOL, |
---|
1058 | Â Â Â Â Â Â wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_BOOL] |
---|
1059 | Â Â Â Â Â Â peaksTable =Â G2G.Table(data[1]['peaksList'],rowLabels=rowLabels,colLabels=colLabels,types=Types) |
---|
1060 | Â Â Â Â Â Â peaksGrid =Â G2G.GSGrid(parent=G2frame.dataDisplay) |
---|
1061 |       peaksGrid.SetTable(peaksTable, True) |
---|
1062 |       peaksGrid.Bind(wx.EVT_KEY_DOWN, KeyEditPeakGrid) |
---|
1063 | Â Â Â Â Â Â peaksGrid.AutoSizeColumns(False) |
---|
1064 | Â Â Â Â Â Â peaksSizer.Add(peaksGrid)Â Â Â Â |
---|
1065 |     return peaksSizer |
---|
1066 | Â Â Â Â Â Â Â Â |
---|
1067 |   if G2frame.dataDisplay: |
---|
1068 | Â Â Â Â G2frame.dataFrame.DestroyChildren() |
---|
1069 | Â Â G2frame.dataDisplay =Â wx.Panel(G2frame.dataFrame) |
---|
1070 | Â Â G2gd.SetDataMenuBar(G2frame,G2frame.dataFrame.BackMenu) |
---|
1071 | Â Â G2frame.dataFrame.SetLabel('Background') |
---|
1072 |   if not G2frame.dataFrame.GetStatusBar(): |
---|
1073 | Â Â Â Â Status =Â G2frame.dataFrame.CreateStatusBar() |
---|
1074 | Â Â G2frame.Bind(wx.EVT_MENU,OnBackCopy,id=G2gd.wxID_BACKCOPY) |
---|
1075 | Â Â G2frame.Bind(wx.EVT_MENU,OnBackFlagCopy,id=G2gd.wxID_BACKFLAGCOPY) |
---|
1076 | Â Â G2frame.Bind(wx.EVT_MENU,OnPeaksMove,id=G2gd.wxID_PEAKSMOVE) |
---|
1077 | Â Â G2frame.Bind(wx.EVT_MENU,OnBkgFit,id=G2frame.dataFrame.wxID_BackPts['Fit']) |
---|
1078 | Â Â G2frame.Bind(wx.EVT_MENU,OnBkgClear,id=G2frame.dataFrame.wxID_BackPts['Clear'])Â Â |
---|
1079 |   BackId = G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId, 'Background') |
---|
1080 | Â Â Choices =Â ['chebyschev','cosine','Q^2 power series','Q^-2 powder series','lin interpolate','inv interpolate','log interpolate'] |
---|
1081 | Â Â mainSizer =Â wx.BoxSizer(wx.VERTICAL) |
---|
1082 | Â Â mainSizer.Add(BackSizer()) |
---|
1083 | Â Â mainSizer.Add((0,5),0) |
---|
1084 | Â Â mainSizer.Add(DebyeSizer()) |
---|
1085 | Â Â mainSizer.Add((0,5),0) |
---|
1086 | Â Â mainSizer.Add(PeaksSizer()) |
---|
1087 | Â Â mainSizer.Layout()Â Â |
---|
1088 | Â Â G2frame.dataDisplay.SetSizer(mainSizer) |
---|
1089 | Â Â G2frame.dataFrame.setSizePosLeft(mainSizer.Fit(G2frame.dataFrame)) |
---|
1090 | Â Â Â Â |
---|
1091 | ################################################################################ |
---|
1092 | #####Â Limits |
---|
1093 | ################################################################################Â Â Â Â Â Â |
---|
1094 | Â Â Â Â |
---|
1095 | def UpdateLimitsGrid(G2frame, data,plottype): |
---|
1096 | Â Â '''respond to selection of PWDR Limits data tree item. |
---|
1097 | Â Â ''' |
---|
1098 |   if G2frame.dataDisplay: |
---|
1099 | Â Â Â Â G2frame.dataFrame.Clear() |
---|
1100 | Â Â G2frame.ifGetExclude =Â False |
---|
1101 | Â Â Â Â |
---|
1102 |   def KeyEditPeakGrid(event): |
---|
1103 |     if event.GetKeyCode() == wx.WXK_DELETE: |
---|
1104 | Â Â Â Â Â Â row =Â G2frame.dataDisplay.GetSelectedRows()[0] |
---|
1105 |       if row > 1: #can't delete limits! |
---|
1106 | Â Â Â Â Â Â Â Â del(data[row]) |
---|
1107 | Â Â Â Â Â Â Â Â wx.CallAfter(UpdateLimitsGrid,G2frame,data,plottype) |
---|
1108 | Â Â Â Â Â Â Â Â G2plt.PlotPatterns(G2frame,plotType=plottype) |
---|
1109 | Â Â Â Â Â Â Â Â Â Â Â Â |
---|
1110 |   def RefreshLimitsGrid(event): |
---|
1111 | Â Â Â Â event.StopPropagation() |
---|
1112 | Â Â Â Â data =Â G2frame.LimitsTable.GetData() |
---|
1113 | Â Â Â Â old =Â data[0] |
---|
1114 | Â Â Â Â new =Â data[1] |
---|
1115 | Â Â Â Â new[0]Â =Â max(old[0],new[0]) |
---|
1116 | Â Â Â Â new[1]Â =Â max(new[0],min(old[1],new[1])) |
---|
1117 | Â Â Â Â excl =Â [] |
---|
1118 |     if len(data) > 2: |
---|
1119 | Â Â Â Â Â Â excl =Â data[2:] |
---|
1120 |       for item in excl: |
---|
1121 | Â Â Â Â Â Â Â Â item[0]Â =Â max(old[0],item[0]) |
---|
1122 | Â Â Â Â Â Â Â Â item[1]Â =Â max(item[0],min(old[1],item[1])) |
---|
1123 | Â Â Â Â data =Â [old,new]+excl |
---|
1124 | Â Â Â Â G2frame.LimitsTable.SetData(data) |
---|
1125 | Â Â Â Â G2plt.PlotPatterns(G2frame,plotType=plottype) |
---|
1126 | Â Â Â Â |
---|
1127 |   def OnLimitCopy(event): |
---|
1128 | Â Â Â Â hst =Â G2frame.PatternTree.GetItemText(G2frame.PatternId) |
---|
1129 | Â Â Â Â histList =Â GetHistsLikeSelected(G2frame) |
---|
1130 |     if not histList: |
---|
1131 | Â Â Â Â Â Â G2frame.ErrorDialog('No match','No histograms match '+hst,G2frame.dataFrame) |
---|
1132 | Â Â Â Â Â Â return |
---|
1133 | Â Â Â Â copyList =Â [] |
---|
1134 | Â Â Â Â dlg =Â G2G.G2MultiChoiceDialog( |
---|
1135 |       G2frame.dataFrame, |
---|
1136 | Â Â Â Â Â Â 'Copy limits from\n'+str(hst[5:])+' to...', |
---|
1137 |       'Copy limits', histList) |
---|
1138 | Â Â Â Â try: |
---|
1139 |       if dlg.ShowModal() == wx.ID_OK: |
---|
1140 |         for i in dlg.GetSelections(): |
---|
1141 | Â Â Â Â Â Â Â Â Â Â item =Â histList[i] |
---|
1142 | Â Â Â Â Â Â Â Â Â Â Id =Â G2gd.GetPatternTreeItemId(G2frame,G2frame.root,item) |
---|
1143 | Â Â Â Â Â Â Â Â Â Â G2frame.PatternTree.SetItemPyData( |
---|
1144 | Â Â Â Â Â Â Â Â Â Â Â Â G2gd.GetPatternTreeItemId(G2frame,Id,'Limits'),copy.copy(data)) |
---|
1145 | Â Â Â Â finally: |
---|
1146 | Â Â Â Â Â Â dlg.Destroy() |
---|
1147 | Â Â Â Â Â Â |
---|
1148 |   def OnAddExcl(event): |
---|
1149 | Â Â Â Â G2frame.ifGetExclude =Â True |
---|
1150 |     print 'Add excluded region' |
---|
1151 | Â Â Â Â |
---|
1152 | Â Â G2frame.LimitsTable =Â [] |
---|
1153 | Â Â colLabels =Â ['Tmin','Tmax'] |
---|
1154 | Â Â rowLabels =Â ['original','changed'] |
---|
1155 |   for i in range(len(data)-2): |
---|
1156 | Â Â Â Â rowLabels.append('exclude') |
---|
1157 | Â Â Types =Â 2*[wg.GRID_VALUE_FLOAT+':12,5',] |
---|
1158 | Â Â G2frame.LimitsTable =Â G2G.Table(data,rowLabels=rowLabels,colLabels=colLabels,types=Types) |
---|
1159 | Â Â G2frame.dataFrame.SetLabel('Limits') |
---|
1160 | Â Â G2gd.SetDataMenuBar(G2frame,G2frame.dataFrame.LimitMenu) |
---|
1161 |   if not G2frame.dataFrame.GetStatusBar(): |
---|
1162 | Â Â Â Â Status =Â G2frame.dataFrame.CreateStatusBar() |
---|
1163 | Â Â G2frame.Bind(wx.EVT_MENU,OnLimitCopy,id=G2gd.wxID_LIMITCOPY) |
---|
1164 | Â Â G2frame.Bind(wx.EVT_MENU,OnAddExcl,id=G2gd.wxID_ADDEXCLREGION)Â Â |
---|
1165 | Â Â G2frame.dataDisplay =Â G2G.GSGrid(parent=G2frame.dataFrame) |
---|
1166 |   G2frame.dataDisplay.SetTable(G2frame.LimitsTable, True)  |
---|
1167 | Â Â G2frame.dataDisplay.SetCellStyle(0,0,VERY_LIGHT_GREY,True) |
---|
1168 | Â Â G2frame.dataDisplay.SetCellStyle(0,1,VERY_LIGHT_GREY,True) |
---|
1169 |   G2frame.dataDisplay.Bind(wg.EVT_GRID_CELL_CHANGE, RefreshLimitsGrid)        |
---|
1170 |   G2frame.dataDisplay.Bind(wx.EVT_KEY_DOWN, KeyEditPeakGrid) |
---|
1171 | Â Â G2frame.dataDisplay.SetMargins(0,0) |
---|
1172 | Â Â G2frame.dataDisplay.AutoSizeColumns(False) |
---|
1173 | Â Â G2frame.dataFrame.setSizePosLeft([230,260])Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
---|
1174 | Â Â G2frame.dataFrame.SendSizeEvent() |
---|
1175 | Â Â |
---|
1176 | ################################################################################ |
---|
1177 | #####Â Instrument parameters |
---|
1178 | ################################################################################Â Â Â Â Â Â |
---|
1179 | Â Â Â Â |
---|
1180 | def UpdateInstrumentGrid(G2frame,data): |
---|
1181 | Â Â '''respond to selection of PWDR/SASD Instrument Parameters |
---|
1182 | Â Â data tree item. |
---|
1183 | Â Â ''' |
---|
1184 |   def keycheck(keys): |
---|
1185 | Â Â Â Â good =Â [] |
---|
1186 |     for key in keys: |
---|
1187 |       if key in ['Type','U','V','W','X','Y','SH/L','I(L2)/I(L1)','alpha', |
---|
1188 | Â Â Â Â Â Â Â Â 'beta-0','beta-1','beta-q','sig-0','sig-1','sig-2','sig-q','Polariz.', |
---|
1189 | Â Â Â Â Â Â Â Â 'Lam','Azimuth','2-theta','fltPath','difC','difA','difB','Zero','Lam1','Lam2']: |
---|
1190 | Â Â Â Â Â Â Â Â good.append(key) |
---|
1191 |     return good |
---|
1192 | Â Â Â Â |
---|
1193 |   def updateData(inst,ref): |
---|
1194 | Â Â Â Â data =Â G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame, |
---|
1195 | Â Â Â Â Â Â G2frame.PatternId,'Instrument Parameters'))[0] |
---|
1196 |     for item in data: |
---|
1197 | Â Â Â Â Â Â try: |
---|
1198 | Â Â Â Â Â Â Â Â data[item]Â =Â [data[item][0],inst[item],ref[item]] |
---|
1199 |       except KeyError: |
---|
1200 | Â Â Â Â Â Â Â Â try: |
---|
1201 | Â Â Â Â Â Â Â Â Â Â data[item]Â =Â [data[item][0],inst[item]] |
---|
1202 |         except KeyError: |
---|
1203 |           pass    #skip 'Polariz.' for N-data |
---|
1204 | Â Â |
---|
1205 |   def RefreshInstrumentGrid(event,doAnyway=False): |
---|
1206 |     if doAnyway or event.GetRow() == 1: |
---|
1207 |       peaks = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId, 'Peak List')) |
---|
1208 | Â Â Â Â Â Â newpeaks =Â [] |
---|
1209 |       for peak in peaks['peaks']: |
---|
1210 | Â Â Â Â Â Â Â Â newpeaks.append(G2mth.setPeakparms(data,Inst2,peak[0],peak[2])) |
---|
1211 | Â Â Â Â Â Â peaks['peaks']Â =Â newpeaks |
---|
1212 |       G2frame.PatternTree.SetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId, 'Peak List'),peaks) |
---|
1213 | Â Â Â Â Â Â |
---|
1214 |   def OnCalibrate(event): |
---|
1215 | Â Â Â Â Pattern =Â G2frame.PatternTree.GetItemPyData(G2frame.PatternId) |
---|
1216 | Â Â Â Â xye =Â ma.array(ma.getdata(Pattern[1])) |
---|
1217 | Â Â Â Â cw =Â np.diff(xye[0]) |
---|
1218 |     IndexPeaks = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId, 'Index Peak List')) |
---|
1219 |     if not len(IndexPeaks[0]): |
---|
1220 | Â Â Â Â Â Â G2frame.ErrorDialog('Can not calibrate','Index Peak List empty') |
---|
1221 | Â Â Â Â Â Â return |
---|
1222 | Â Â Â Â Ok =Â False |
---|
1223 |     for peak in IndexPeaks[0]: |
---|
1224 |       if peak[2] and peak[3]: |
---|
1225 | Â Â Â Â Â Â Â Â Ok =Â True |
---|
1226 |     if not Ok: |
---|
1227 | Â Â Â Â Â Â G2frame.ErrorDialog('Can not calibrate','Index Peak List not indexed') |
---|
1228 |       return      |
---|
1229 |     if G2pwd.DoCalibInst(IndexPeaks,data): |
---|
1230 | Â Â Â Â Â Â UpdateInstrumentGrid(G2frame,data) |
---|
1231 | Â Â Â Â Â Â XY =Â [] |
---|
1232 | Â Â Â Â Â Â Sigs =Â [] |
---|
1233 |       for ip,peak in enumerate(IndexPeaks[0]): |
---|
1234 |         if peak[2] and peak[3]: |
---|
1235 | Â Â Â Â Â Â Â Â Â Â binwid =Â cw[np.searchsorted(xye[0],peak[0])] |
---|
1236 | Â Â Â Â Â Â Â Â Â Â XY.append([peak[-1],peak[0],binwid]) |
---|
1237 | Â Â Â Â Â Â Â Â Â Â Sigs.append(IndexPeaks[1][ip]) |
---|
1238 |       if len(XY): |
---|
1239 | Â Â Â Â Â Â Â Â XY =Â np.array(XY) |
---|
1240 | Â Â Â Â Â Â Â Â G2plt.PlotCalib(G2frame,data,XY,Sigs,newPlot=True) |
---|
1241 | Â Â Â Â else: |
---|
1242 | Â Â Â Â Â Â G2frame.ErrorDialog('Can not calibrate','Nothing selected for refinement') |
---|
1243 | |
---|
1244 |   def OnLoad(event): |
---|
1245 | Â Â Â Â '''Loads instrument parameters from a G2 .instprm file |
---|
1246 | Â Â Â Â in response to the Instrument Parameters-Operations/Load Profile menu |
---|
1247 | Â Â Â Â |
---|
1248 | Â Â Â Â Note that similar code is found in ReadPowderInstprm (GSASII.py) |
---|
1249 | Â Â Â Â ''' |
---|
1250 |     dlg = wx.FileDialog(G2frame, 'Choose GSAS-II instrument parameters file', '.', '', |
---|
1251 | Â Â Â Â Â Â 'instrument parameter files (*.instprm)|*.instprm',wx.OPEN|wx.CHANGE_DIR) |
---|
1252 | Â Â Â Â try: |
---|
1253 |       if dlg.ShowModal() == wx.ID_OK: |
---|
1254 | Â Â Â Â Â Â Â Â filename =Â dlg.GetPath() |
---|
1255 | Â Â Â Â Â Â Â Â File =Â open(filename,'r') |
---|
1256 | Â Â Â Â Â Â Â Â S =Â File.readline() |
---|
1257 | Â Â Â Â Â Â Â Â newItems =Â [] |
---|
1258 | Â Â Â Â Â Â Â Â newVals =Â [] |
---|
1259 |         while S: |
---|
1260 |           if S[0] == '#': |
---|
1261 | Â Â Â Â Â Â Â Â Â Â Â Â S =Â File.readline() |
---|
1262 | Â Â Â Â Â Â Â Â Â Â Â Â continue |
---|
1263 | Â Â Â Â Â Â Â Â Â Â [item,val]Â =Â S[:-1].split(':') |
---|
1264 | Â Â Â Â Â Â Â Â Â Â newItems.append(item) |
---|
1265 | Â Â Â Â Â Â Â Â Â Â try: |
---|
1266 | Â Â Â Â Â Â Â Â Â Â Â Â newVals.append(float(val)) |
---|
1267 |           except ValueError: |
---|
1268 | Â Â Â Â Â Â Â Â Â Â Â Â newVals.append(val)Â Â Â Â Â Â Â Â Â Â Â Â |
---|
1269 | Â Â Â Â Â Â Â Â Â Â S =Â File.readline()Â Â Â Â Â Â Â Â |
---|
1270 | Â Â Â Â Â Â Â Â File.close() |
---|
1271 | Â Â Â Â Â Â Â Â Inst,Inst2 =Â G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId,'Instrument Parameters')) |
---|
1272 | Â Â Â Â Â Â Â Â data =Â G2IO.makeInstDict(newItems,newVals,len(newVals)*[False,]) |
---|
1273 | Â Â Â Â Â Â Â Â G2frame.PatternTree.SetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId,'Instrument Parameters'),[data,Inst2]) |
---|
1274 | Â Â Â Â Â Â Â Â RefreshInstrumentGrid(event,doAnyway=True)Â Â Â Â Â #to get peaks updated |
---|
1275 | Â Â Â Â Â Â Â Â UpdateInstrumentGrid(G2frame,data) |
---|
1276 | Â Â Â Â Â Â Â Â G2plt.PlotPeakWidths(G2frame) |
---|
1277 | Â Â Â Â finally: |
---|
1278 | Â Â Â Â Â Â dlg.Destroy() |
---|
1279 | Â Â Â Â |
---|
1280 |   def OnSave(event): |
---|
1281 | Â Â Â Â '''Respond to the Instrument Parameters Operations/Save Profile menu |
---|
1282 | Â Â Â Â item: writes current parameters to a .instprm file |
---|
1283 | Â Â Â Â ''' |
---|
1284 |     dlg = wx.FileDialog(G2frame, 'Choose GSAS-II instrument parameters file', '.', '', |
---|
1285 | Â Â Â Â Â Â 'instrument parameter files (*.instprm)|*.instprm',wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT|wx.CHANGE_DIR) |
---|
1286 | Â Â Â Â try: |
---|
1287 |       if dlg.ShowModal() == wx.ID_OK: |
---|
1288 | Â Â Â Â Â Â Â Â filename =Â dlg.GetPath() |
---|
1289 | Â Â Â Â Â Â Â Â # make sure extension is .instprm |
---|
1290 | Â Â Â Â Â Â Â Â filename =Â os.path.splitext(filename)[0]+'.instprm' |
---|
1291 | Â Â Â Â Â Â Â Â File =Â open(filename,'w') |
---|
1292 | Â Â Â Â Â Â Â Â File.write("#GSAS-II instrument parameter file; do not add/delete items!\n") |
---|
1293 |         for item in data: |
---|
1294 | Â Â Â Â Â Â Â Â Â Â File.write(item+':'+str(data[item][1])+'\n') |
---|
1295 | Â Â Â Â Â Â Â Â File.close() |
---|
1296 | Â Â Â Â finally: |
---|
1297 | Â Â Â Â Â Â dlg.Destroy() |
---|
1298 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
---|
1299 |   def OnReset(event): |
---|
1300 | Â Â Â Â insVal.update(insDef) |
---|
1301 | Â Â Â Â updateData(insVal,insRef) |
---|
1302 | Â Â Â Â RefreshInstrumentGrid(event,doAnyway=True)Â Â Â Â Â #to get peaks updated |
---|
1303 | Â Â Â Â UpdateInstrumentGrid(G2frame,data) |
---|
1304 | Â Â Â Â G2plt.PlotPeakWidths(G2frame) |
---|
1305 | Â Â Â Â |
---|
1306 |   def OnInstFlagCopy(event): |
---|
1307 | Â Â Â Â hst =Â G2frame.PatternTree.GetItemText(G2frame.PatternId) |
---|
1308 | Â Â Â Â histList =Â GetHistsLikeSelected(G2frame) |
---|
1309 |     if not histList: |
---|
1310 | Â Â Â Â Â Â G2frame.ErrorDialog('No match','No histograms match '+hst,G2frame.dataFrame) |
---|
1311 | Â Â Â Â Â Â return |
---|
1312 | Â Â Â Â keys =Â data.keys() |
---|
1313 | Â Â Â Â try: |
---|
1314 | Â Â Â Â Â Â keys.remove('Source') |
---|
1315 |     except ListError: |
---|
1316 | Â Â Â Â Â Â pass |
---|
1317 |     flags = dict(zip(keys,[data[key][2] for key in keys])) |
---|
1318 | Â Â Â Â instType =Â data['Type'][0] |
---|
1319 | Â Â Â Â copyList =Â [] |
---|
1320 | Â Â Â Â dlg =Â G2G.G2MultiChoiceDialog( |
---|
1321 |       G2frame.dataFrame, |
---|
1322 | Â Â Â Â Â Â 'Copy inst ref. flags from\n'+hst[5:], |
---|
1323 |       'Copy refinement flags', histList) |
---|
1324 | Â Â Â Â try: |
---|
1325 |       if dlg.ShowModal() == wx.ID_OK: |
---|
1326 |         for i in dlg.GetSelections(): |
---|
1327 | Â Â Â Â Â Â Â Â Â Â copyList.append(histList[i]) |
---|
1328 | Â Â Â Â finally: |
---|
1329 | Â Â Â Â Â Â dlg.Destroy() |
---|
1330 |     for item in copyList: |
---|
1331 | Â Â Â Â Â Â Id =Â G2gd.GetPatternTreeItemId(G2frame,G2frame.root,item) |
---|
1332 | Â Â Â Â Â Â instData =Â G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Id,'Instrument Parameters'))[0] |
---|
1333 |       if len(data) == len(instData) and instType == instData['Type'][0]:  #don't mix data types or lam & lam1/lam2 parms! |
---|
1334 |         for item in instData: |
---|
1335 |           if item not in ['Source',]: |
---|
1336 | Â Â Â Â Â Â Â Â Â Â Â Â instData[item][2]Â =Â copy.copy(flags[item]) |
---|
1337 | Â Â Â Â Â Â else: |
---|
1338 |         print item+' not copied - instrument parameters not commensurate' |
---|
1339 | Â Â Â Â |
---|
1340 |   def OnInstCopy(event): |
---|
1341 | Â Â Â Â #need fix for dictionary |
---|
1342 | Â Â Â Â hst =Â G2frame.PatternTree.GetItemText(G2frame.PatternId) |
---|
1343 | Â Â Â Â histList =Â GetHistsLikeSelected(G2frame) |
---|
1344 |     if not histList: |
---|
1345 | Â Â Â Â Â Â G2frame.ErrorDialog('No match','No histograms match '+hst,G2frame.dataFrame) |
---|
1346 | Â Â Â Â Â Â return |
---|
1347 | Â Â Â Â copyList =Â [] |
---|
1348 | Â Â Â Â instType =Â data['Type'][0] |
---|
1349 | Â Â Â Â dlg =Â G2G.G2MultiChoiceDialog( |
---|
1350 |       G2frame.dataFrame, |
---|
1351 | Â Â Â Â Â Â 'Copy inst params from\n'+hst, |
---|
1352 |       'Copy parameters', histList) |
---|
1353 | Â Â Â Â try: |
---|
1354 |       if dlg.ShowModal() == wx.ID_OK: |
---|
1355 |         for i in dlg.GetSelections(): |
---|
1356 | Â Â Â Â Â Â Â Â Â Â copyList.append(histList[i]) |
---|
1357 | Â Â Â Â finally: |
---|
1358 | Â Â Â Â Â Â dlg.Destroy() |
---|
1359 |     for item in copyList: |
---|
1360 | Â Â Â Â Â Â Id =Â G2gd.GetPatternTreeItemId(G2frame,G2frame.root,item) |
---|
1361 | Â Â Â Â Â Â instData =Â G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Id,'Instrument Parameters'))[0] |
---|
1362 |       if len(data) == len(instData) and instType == instData['Type'][0]: #don't mix data types or lam & lam1/lam2 parms! |
---|
1363 | Â Â Â Â Â Â Â Â instData.update(data) |
---|
1364 | Â Â Â Â Â Â else: |
---|
1365 |         print item+' not copied - instrument parameters not commensurate' |
---|
1366 | Â Â Â Â Â Â Â Â Â Â Â Â Â |
---|
1367 |   def AfterChange(invalid,value,tc): |
---|
1368 |     if invalid: return |
---|
1369 | Â Â Â Â updateData(insVal,insRef) |
---|
1370 | Â Â Â Â |
---|
1371 |   def OnItemRef(event): |
---|
1372 | Â Â Â Â Obj =Â event.GetEventObject() |
---|
1373 | Â Â Â Â item =Â RefObj[Obj.GetId()] |
---|
1374 | Â Â Â Â insRef[item]Â =Â Obj.GetValue() |
---|
1375 | Â Â Â Â updateData(insVal,insRef) |
---|
1376 | |
---|
1377 |   def OnCopy1Val(event): |
---|
1378 | Â Â Â Â '''Select one instrument parameter value to edit and copy to many histograms |
---|
1379 | Â Â Â Â optionally allow values to be edited in a table |
---|
1380 | Â Â Â Â ''' |
---|
1381 | Â Â Â Â updateData(insVal,insRef) |
---|
1382 | Â Â Â Â G2G.SelectEdit1Var(G2frame,data,labelLst,elemKeysLst,dspLst,refFlgElem) |
---|
1383 |     insVal.update({key:data[key][1] for key in instkeys}) |
---|
1384 |     insRef.update({key:data[key][2] for key in instkeys}) |
---|
1385 | Â Â Â Â wx.CallAfter(MakeParameterWindow) |
---|
1386 | Â Â Â Â |
---|
1387 |   def lblWdef(lbl,dec,val): |
---|
1388 | Â Â Â Â 'Label parameter showing the default value' |
---|
1389 | Â Â Â Â fmt =Â "%15."+str(dec)+"f" |
---|
1390 |     return " " + lbl + " (" + (fmt % val).strip() + "): " |
---|
1391 | |
---|
1392 |   def RefineBox(item): |
---|
1393 | Â Â Â Â 'Define a refine checkbox with binding' |
---|
1394 |     wid = wx.CheckBox(G2frame.dataDisplay,label=' Refine? ') |
---|
1395 | Â Â Â Â wid.SetValue(bool(insRef[item])) |
---|
1396 | Â Â Â Â RefObj[wid.GetId()]Â =Â item |
---|
1397 |     wid.Bind(wx.EVT_CHECKBOX, OnItemRef) |
---|
1398 |     return wid |
---|
1399 | |
---|
1400 |   def OnLamPick(event): |
---|
1401 | Â Â Â Â data['Source'][1]Â =Â lamType =Â event.GetEventObject().GetValue() |
---|
1402 |     if 'P' in insVal['Type']: |
---|
1403 | Â Â Â Â Â Â insVal['Lam1']Â =Â waves[lamType][0] |
---|
1404 | Â Â Â Â Â Â insVal['Lam2']Â =Â waves[lamType][1] |
---|
1405 |     elif 'S' in insVal['Type'] and 'synch' not in lamType: |
---|
1406 | Â Â Â Â Â Â insVal['Lam']Â =Â meanwaves[lamType] |
---|
1407 | Â Â Â Â updateData(insVal,insRef) |
---|
1408 | Â Â Â Â i,j=Â wx.__version__.split('.')[0:2] |
---|
1409 |     if int(i)+int(j)/10. > 2.8: |
---|
1410 |       pass # repaint crashes wxpython 2.9 |
---|
1411 |       wx.CallLater(100, MakeParameterWindow) |
---|
1412 | Â Â Â Â Â Â #wx.CallAfter(MakeParameterWindow) |
---|
1413 | Â Â Â Â else: |
---|
1414 | Â Â Â Â Â Â wx.CallAfter(MakeParameterWindow) |
---|
1415 | |
---|
1416 |   def MakeParameterWindow(): |
---|
1417 | Â Â Â Â 'Displays the Instrument parameters in the datadisplay frame' |
---|
1418 |     if G2frame.dataDisplay: |
---|
1419 | Â Â Â Â Â Â G2frame.dataFrame.Clear() |
---|
1420 | Â Â Â Â G2frame.dataFrame.SetLabel('Instrument Parameters') |
---|
1421 | Â Â Â Â G2frame.dataDisplay =Â wx.Panel(G2frame.dataFrame) |
---|
1422 | Â Â Â Â mainSizer =Â wx.BoxSizer(wx.VERTICAL) |
---|
1423 | Â Â Â Â instSizer =Â wx.FlexGridSizer(0,6,5,5) |
---|
1424 | Â Â Â Â subSizer =Â wx.BoxSizer(wx.HORIZONTAL) |
---|
1425 | Â Â Â Â subSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,' Histogram Type: '+insVal['Type']),0,WACV) |
---|
1426 | Â Â Â Â mainSizer.Add(subSizer) |
---|
1427 | Â Â Â Â labelLst[:],elemKeysLst[:],dspLst[:],refFlgElem[:]Â =Â [],[],[],[] |
---|
1428 |     if 'P' in insVal['Type']:          #powder data |
---|
1429 |       if 'C' in insVal['Type']:        #constant wavelength |
---|
1430 | Â Â Â Â Â Â Â Â labelLst.append('Azimuth angle') |
---|
1431 | Â Â Â Â Â Â Â Â elemKeysLst.append(['Azimuth',1]) |
---|
1432 | Â Â Â Â Â Â Â Â dspLst.append([10,2]) |
---|
1433 | Â Â Â Â Â Â Â Â refFlgElem.append(None)Â Â Â Â Â Â Â Â Â Â |
---|
1434 |         if 'Lam1' in insVal: |
---|
1435 | Â Â Â Â Â Â Â Â Â Â subSizer =Â wx.BoxSizer(wx.HORIZONTAL) |
---|
1436 | Â Â Â Â Â Â Â Â Â Â subSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,' Azimuth: '),0,WACV) |
---|
1437 | Â Â Â Â Â Â Â Â Â Â txt =Â '%7.2f'%(insVal['Azimuth']) |
---|
1438 | Â Â Â Â Â Â Â Â Â Â subSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,txt.strip()),0,WACV) |
---|
1439 | Â Â Â Â Â Â Â Â Â Â subSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,'Â Â Ka1/Ka2: '),0,WACV) |
---|
1440 | Â Â Â Â Â Â Â Â Â Â txt =Â u'Â %8.6f/%8.6f\xc5'%(insVal['Lam1'],insVal['Lam2']) |
---|
1441 | Â Â Â Â Â Â Â Â Â Â subSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,txt.strip()),0,WACV) |
---|
1442 | Â Â Â Â Â Â Â Â Â Â waveSizer =Â wx.BoxSizer(wx.HORIZONTAL) |
---|
1443 | Â Â Â Â Â Â Â Â Â Â waveSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,'Â Source type: '),0,WACV) |
---|
1444 | Â Â Â Â Â Â Â Â Â Â # PATCH?: for now at least, Source is not saved anywhere before here |
---|
1445 |           if 'Source' not in data: data['Source'] = ['CuKa','?'] |
---|
1446 | Â Â Â Â Â Â Â Â Â Â choice =Â ['TiKa','CrKa','FeKa','CoKa','CuKa','MoKa','AgKa'] |
---|
1447 | Â Â Â Â Â Â Â Â Â Â lamPick =Â wx.ComboBox(G2frame.dataDisplay,value=data['Source'][1],choices=choice,style=wx.CB_READONLY|wx.CB_DROPDOWN) |
---|
1448 |           lamPick.Bind(wx.EVT_COMBOBOX, OnLamPick) |
---|
1449 | Â Â Â Â Â Â Â Â Â Â waveSizer.Add(lamPick,0) |
---|
1450 | Â Â Â Â Â Â Â Â Â Â subSizer.Add(waveSizer,0) |
---|
1451 | Â Â Â Â Â Â Â Â Â Â mainSizer.Add(subSizer) |
---|
1452 | Â Â Â Â Â Â Â Â Â Â instSizer.Add(wx.StaticText( |
---|
1453 | Â Â Â Â Â Â Â Â Â Â Â Â G2frame.dataDisplay,-1, |
---|
1454 | Â Â Â Â Â Â Â Â Â Â Â Â lblWdef('I(L2)/I(L1)',4,insDef['I(L2)/I(L1)'])), |
---|
1455 | Â Â Â Â Â Â Â Â Â Â Â Â 0,WACV) |
---|
1456 | Â Â Â Â Â Â Â Â Â Â key =Â 'I(L2)/I(L1)' |
---|
1457 | Â Â Â Â Â Â Â Â Â Â labelLst.append(key) |
---|
1458 | Â Â Â Â Â Â Â Â Â Â elemKeysLst.append([key,1]) |
---|
1459 | Â Â Â Â Â Â Â Â Â Â dspLst.append([10,4]) |
---|
1460 | Â Â Â Â Â Â Â Â Â Â refFlgElem.append([key,2])Â Â Â Â Â Â Â Â Â Â |
---|
1461 | Â Â Â Â Â Â Â Â Â Â ratVal =Â G2G.ValidatedTxtCtrl(G2frame.dataDisplay,insVal,key,nDig=(10,4),typeHint=float,OnLeave=AfterChange) |
---|
1462 | Â Â Â Â Â Â Â Â Â Â instSizer.Add(ratVal,0) |
---|
1463 | Â Â Â Â Â Â Â Â Â Â instSizer.Add(RefineBox(key),0,WACV) |
---|
1464 | Â Â Â Â Â Â Â Â Â Â instSizer.Add((5,5),0) |
---|
1465 | Â Â Â Â Â Â Â Â Â Â instSizer.Add((5,5),0) |
---|
1466 | Â Â Â Â Â Â Â Â Â Â instSizer.Add((5,5),0)Â Â Â Â Â Â Â Â |
---|
1467 | Â Â Â Â Â Â Â Â else:Â # single wavelength |
---|
1468 | Â Â Â Â Â Â Â Â Â Â instSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,' Azimuth: '),0,WACV) |
---|
1469 | Â Â Â Â Â Â Â Â Â Â txt =Â '%7.2f'%(insVal['Azimuth']) |
---|
1470 | Â Â Â Â Â Â Â Â Â Â instSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,txt.strip()),0,WACV) |
---|
1471 | Â Â Â Â Â Â Â Â Â Â instSizer.Add((5,5),0) |
---|
1472 | Â Â Â Â Â Â Â Â Â Â key =Â 'Lam' |
---|
1473 | Â Â Â Â Â Â Â Â Â Â instSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,u' Lam (\xc5): (%10.6f)'%(insDef[key])), |
---|
1474 | Â Â Â Â Â Â Â Â Â Â Â Â 0,WACV) |
---|
1475 | Â Â Â Â Â Â Â Â Â Â waveVal =Â G2G.ValidatedTxtCtrl(G2frame.dataDisplay,insVal,key,nDig=(10,6),typeHint=float,OnLeave=AfterChange) |
---|
1476 | Â Â Â Â Â Â Â Â Â Â labelLst.append(u'Lam (\xc5)') |
---|
1477 | Â Â Â Â Â Â Â Â Â Â elemKeysLst.append([key,1]) |
---|
1478 | Â Â Â Â Â Â Â Â Â Â dspLst.append([10,6]) |
---|
1479 | Â Â Â Â Â Â Â Â Â Â instSizer.Add(waveVal,0,WACV) |
---|
1480 | Â Â Â Â Â Â Â Â Â Â refFlgElem.append([key,2])Â Â Â Â Â Â Â Â Â Â |
---|
1481 | Â Â Â Â Â Â Â Â Â Â instSizer.Add(RefineBox(key),0,WACV) |
---|
1482 | #Â Â Â Â Â Â Â Â Â Â if ifHisto: |
---|
1483 | #Â Â Â Â Â Â Â Â Â Â Â Â refFlgElem.append([key,2])Â Â Â Â Â Â Â Â Â Â |
---|
1484 | #Â Â Â Â Â Â Â Â Â Â Â Â instSizer.Add(RefineBox(key),0,WACV) |
---|
1485 | #Â Â Â Â Â Â Â Â Â Â else: |
---|
1486 | #Â Â Â Â Â Â Â Â Â Â Â Â refFlgElem.append(None)Â Â Â Â Â Â Â Â Â Â |
---|
1487 | #Â Â Â Â Â Â Â Â Â Â Â Â instSizer.Add((5,5),0) |
---|
1488 |         for item in ['Zero','Polariz.']: |
---|
1489 |           if item in insDef: |
---|
1490 | Â Â Â Â Â Â Â Â Â Â Â Â labelLst.append(item) |
---|
1491 | Â Â Â Â Â Â Â Â Â Â Â Â elemKeysLst.append([item,1]) |
---|
1492 | Â Â Â Â Â Â Â Â Â Â Â Â dspLst.append([10,4]) |
---|
1493 | Â Â Â Â Â Â Â Â Â Â Â Â instSizer.Add( |
---|
1494 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â wx.StaticText(G2frame.dataDisplay,-1,lblWdef(item,4,insDef[item])), |
---|
1495 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â 0,WACV) |
---|
1496 | Â Â Â Â Â Â Â Â Â Â Â Â itemVal =Â G2G.ValidatedTxtCtrl(G2frame.dataDisplay,insVal,item,nDig=(10,4),typeHint=float,OnLeave=AfterChange) |
---|
1497 | Â Â Â Â Â Â Â Â Â Â Â Â instSizer.Add(itemVal,0,WACV) |
---|
1498 | Â Â Â Â Â Â Â Â Â Â Â Â refFlgElem.append([item,2]) |
---|
1499 | Â Â Â Â Â Â Â Â Â Â Â Â instSizer.Add(RefineBox(item),0,WACV) |
---|
1500 | #Â Â Â Â Â Â Â Â Â Â Â Â if ifHisto: |
---|
1501 | #Â Â Â Â Â Â Â Â Â Â Â Â Â Â refFlgElem.append([item,2]) |
---|
1502 | #Â Â Â Â Â Â Â Â Â Â Â Â Â Â instSizer.Add(RefineBox(item),0,WACV) |
---|
1503 | #Â Â Â Â Â Â Â Â Â Â Â Â else: |
---|
1504 | #Â Â Â Â Â Â Â Â Â Â Â Â Â Â refFlgElem.append(None)Â Â Â Â Â Â Â Â Â Â |
---|
1505 | #Â Â Â Â Â Â Â Â Â Â Â Â Â Â instSizer.Add((5,5),0) |
---|
1506 | Â Â Â Â Â Â Â Â Â Â else:Â Â Â Â Â Â Â Â Â Â Â Â Â Â #skip Polariz. for neutrons |
---|
1507 | Â Â Â Â Â Â Â Â Â Â Â Â instSizer.Add((5,5),0) |
---|
1508 | Â Â Â Â Â Â Â Â Â Â Â Â instSizer.Add((5,5),0) |
---|
1509 | Â Â Â Â Â Â Â Â Â Â Â Â instSizer.Add((5,5),0) |
---|
1510 |         for item in ['U','V','W','','X','Y','SH/L']: |
---|
1511 |           if item == '': |
---|
1512 | Â Â Â Â Â Â Â Â Â Â Â Â instSizer.Add((5,5),0) |
---|
1513 | Â Â Â Â Â Â Â Â Â Â Â Â instSizer.Add((5,5),0) |
---|
1514 | Â Â Â Â Â Â Â Â Â Â Â Â instSizer.Add((5,5),0) |
---|
1515 | Â Â Â Â Â Â Â Â Â Â Â Â continue |
---|
1516 | Â Â Â Â Â Â Â Â Â Â nDig =Â (10,3) |
---|
1517 |           if item == 'SH/L': |
---|
1518 | Â Â Â Â Â Â Â Â Â Â Â Â nDig =Â (10,5) |
---|
1519 | Â Â Â Â Â Â Â Â Â Â labelLst.append(item) |
---|
1520 | Â Â Â Â Â Â Â Â Â Â elemKeysLst.append([item,1]) |
---|
1521 | Â Â Â Â Â Â Â Â Â Â dspLst.append(nDig) |
---|
1522 | Â Â Â Â Â Â Â Â Â Â refFlgElem.append([item,2]) |
---|
1523 | Â Â Â Â Â Â Â Â Â Â instSizer.Add( |
---|
1524 | Â Â Â Â Â Â Â Â Â Â Â Â wx.StaticText(G2frame.dataDisplay,-1,lblWdef(item,nDig[1],insDef[item])), |
---|
1525 | Â Â Â Â Â Â Â Â Â Â Â Â 0,WACV) |
---|
1526 | Â Â Â Â Â Â Â Â Â Â itemVal =Â G2G.ValidatedTxtCtrl(G2frame.dataDisplay,insVal,item,nDig=nDig,typeHint=float,OnLeave=AfterChange) |
---|
1527 | Â Â Â Â Â Â Â Â Â Â instSizer.Add(itemVal,0,WACV) |
---|
1528 | Â Â Â Â Â Â Â Â Â Â instSizer.Add(RefineBox(item),0,WACV) |
---|
1529 |       elif 'T' in insVal['Type']:                  #time of flight (neutrons) |
---|
1530 | Â Â Â Â Â Â Â Â subSizer =Â wx.BoxSizer(wx.HORIZONTAL) |
---|
1531 | Â Â Â Â Â Â Â Â subSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,' Fligth path: '),0,WACV) |
---|
1532 | Â Â Â Â Â Â Â Â txt =Â '%8.3f'%(insVal['fltPath']) |
---|
1533 | Â Â Â Â Â Â Â Â subSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,txt.strip()),0,WACV) |
---|
1534 | Â Â Â Â Â Â Â Â labelLst.append('flight path') |
---|
1535 | Â Â Â Â Â Â Â Â elemKeysLst.append(['fltpath',1]) |
---|
1536 | Â Â Â Â Â Â Â Â dspLst.append([10,2]) |
---|
1537 | Â Â Â Â Â Â Â Â refFlgElem.append(None)Â Â Â Â Â Â Â Â Â Â |
---|
1538 | Â Â Â Â Â Â Â Â subSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,'Â 2-theta: '),0,WACV) |
---|
1539 | Â Â Â Â Â Â Â Â txt =Â '%7.2f'%(insVal['2-theta']) |
---|
1540 | Â Â Â Â Â Â Â Â subSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,txt.strip()),0,WACV) |
---|
1541 | Â Â Â Â Â Â Â Â labelLst.append('2-theta') |
---|
1542 | Â Â Â Â Â Â Â Â elemKeysLst.append(['2-theta',1]) |
---|
1543 | Â Â Â Â Â Â Â Â dspLst.append([10,2]) |
---|
1544 | Â Â Â Â Â Â Â Â refFlgElem.append(None)Â Â Â Â Â Â Â Â Â Â |
---|
1545 |         if 'Pdabc' in Inst2: |
---|
1546 | Â Â Â Â Â Â Â Â Â Â Items =Â ['sig-0','sig-1','sig-2','sig-q','X','Y'] |
---|
1547 | Â Â Â Â Â Â Â Â Â Â subSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,'Â difC: '),0,WACV) |
---|
1548 | Â Â Â Â Â Â Â Â Â Â txt =Â '%8.2f'%(insVal['difC']) |
---|
1549 | Â Â Â Â Â Â Â Â Â Â subSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,txt.strip()),0,WACV) |
---|
1550 | Â Â Â Â Â Â Â Â Â Â labelLst.append('difC') |
---|
1551 | Â Â Â Â Â Â Â Â Â Â elemKeysLst.append(['difC',1]) |
---|
1552 | Â Â Â Â Â Â Â Â Â Â dspLst.append([10,2]) |
---|
1553 | Â Â Â Â Â Â Â Â Â Â refFlgElem.append(None) |
---|
1554 | Â Â Â Â Â Â Â Â Â Â subSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,'Â alpha, beta: fixed by table'),0,WACV) |
---|
1555 | Â Â Â Â Â Â Â Â else: |
---|
1556 | Â Â Â Â Â Â Â Â Â Â Items =Â ['difC','difA','difB','Zero','alpha','beta-0','beta-1','beta-q','sig-0','sig-1','sig-2','sig-q','X','Y'] |
---|
1557 | Â Â Â Â Â Â Â Â mainSizer.Add((5,5),0) |
---|
1558 | Â Â Â Â Â Â Â Â mainSizer.Add(subSizer) |
---|
1559 | Â Â Â Â Â Â Â Â mainSizer.Add((5,5),0) |
---|
1560 |         for item in Items: |
---|
1561 |           if item == '': |
---|
1562 | Â Â Â Â Â Â Â Â Â Â Â Â instSizer.Add((5,5),0) |
---|
1563 | Â Â Â Â Â Â Â Â Â Â Â Â instSizer.Add((5,5),0) |
---|
1564 | Â Â Â Â Â Â Â Â Â Â Â Â instSizer.Add((5,5),0) |
---|
1565 | Â Â Â Â Â Â Â Â Â Â Â Â continue |
---|
1566 | Â Â Â Â Â Â Â Â Â Â nDig =Â (10,3) |
---|
1567 | Â Â Â Â Â Â Â Â Â Â fmt =Â '%10.3f' |
---|
1568 |           if 'beta' in item: |
---|
1569 | Â Â Â Â Â Â Â Â Â Â Â Â fmt =Â '%12.6g' |
---|
1570 | Â Â Â Â Â Â Â Â Â Â Â Â nDig =Â (12,6) |
---|
1571 | Â Â Â Â Â Â Â Â Â Â Fmt =Â ' %s: ('+fmt+')' |
---|
1572 | Â Â Â Â Â Â Â Â Â Â instSizer.Add( |
---|
1573 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â wx.StaticText(G2frame.dataDisplay,-1,lblWdef(item,nDig[1],insDef[item])), |
---|
1574 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â 0,WACV) |
---|
1575 | Â Â Â Â Â Â Â Â Â Â itemVal =Â G2G.ValidatedTxtCtrl(G2frame.dataDisplay,insVal,item,nDig=nDig,typeHint=float,OnLeave=AfterChange) |
---|
1576 | Â Â Â Â Â Â Â Â Â Â instSizer.Add(itemVal,0,WACV) |
---|
1577 | Â Â Â Â Â Â Â Â Â Â labelLst.append(item) |
---|
1578 | Â Â Â Â Â Â Â Â Â Â elemKeysLst.append([item,1]) |
---|
1579 | Â Â Â Â Â Â Â Â Â Â dspLst.append(nDig) |
---|
1580 | Â Â Â Â Â Â Â Â Â Â refFlgElem.append([item,2]) |
---|
1581 | Â Â Â Â Â Â Â Â Â Â instSizer.Add(RefineBox(item),0,WACV) |
---|
1582 |       elif 'PKS' in insVal['Type']:  #peak positions only |
---|
1583 | Â Â Â Â Â Â Â Â key =Â 'Lam' |
---|
1584 | Â Â Â Â Â Â Â Â instSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,u' Lam (\xc5): (%10.6f)'%(insDef[key])), |
---|
1585 | Â Â Â Â Â Â Â Â Â Â 0,WACV) |
---|
1586 | Â Â Â Â Â Â Â Â waveVal =Â G2G.ValidatedTxtCtrl(G2frame.dataDisplay,insVal,key,nDig=(10,6),typeHint=float,OnLeave=AfterChange) |
---|
1587 | Â Â Â Â Â Â Â Â labelLst.append(u'Lam (\xc5)') |
---|
1588 | Â Â Â Â Â Â Â Â elemKeysLst.append([key,1]) |
---|
1589 | Â Â Â Â Â Â Â Â dspLst.append([10,6]) |
---|
1590 | Â Â Â Â Â Â Â Â instSizer.Add(waveVal,0,WACV) |
---|
1591 | Â Â Â Â Â Â Â Â refFlgElem.append([key,2])Â Â Â Â Â Â Â Â Â Â |
---|
1592 | #Â Â Â Â Â Â Â Â Â Â instSizer.Add(RefineBox(key),0,WACV) |
---|
1593 |         for item in ['Zero',]: |
---|
1594 |           if item in insDef: |
---|
1595 | Â Â Â Â Â Â Â Â Â Â Â Â labelLst.append(item) |
---|
1596 | Â Â Â Â Â Â Â Â Â Â Â Â elemKeysLst.append([item,1]) |
---|
1597 | Â Â Â Â Â Â Â Â Â Â Â Â dspLst.append([10,4]) |
---|
1598 | Â Â Â Â Â Â Â Â Â Â Â Â instSizer.Add( |
---|
1599 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â wx.StaticText(G2frame.dataDisplay,-1,lblWdef(item,4,insDef[item])), |
---|
1600 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â 0,WACV) |
---|
1601 | Â Â Â Â Â Â Â Â Â Â Â Â itemVal =Â G2G.ValidatedTxtCtrl(G2frame.dataDisplay,insVal,item,nDig=(10,4),typeHint=float,OnLeave=AfterChange) |
---|
1602 | Â Â Â Â Â Â Â Â Â Â Â Â instSizer.Add(itemVal,0,WACV) |
---|
1603 | Â Â Â Â Â Â Â Â Â Â Â Â refFlgElem.append([item,2]) |
---|
1604 | #Â Â Â Â Â Â Â Â Â Â Â Â instSizer.Add(RefineBox(item),0,WACV) |
---|
1605 | Â Â Â Â Â Â Â Â |
---|
1606 | Â Â Â Â Â Â Â Â |
---|
1607 |     elif 'S' in insVal['Type']:            #single crystal data |
---|
1608 |       if 'C' in insVal['Type']:        #constant wavelength |
---|
1609 | Â Â Â Â Â Â Â Â instSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,u' Lam (\xc5): (%10.6f)'%(insDef['Lam'])), |
---|
1610 | Â Â Â Â Â Â Â Â Â Â 0,WACV) |
---|
1611 | Â Â Â Â Â Â Â Â waveVal =Â G2G.ValidatedTxtCtrl(G2frame.dataDisplay,insVal,'Lam',nDig=(10,6),typeHint=float,OnLeave=AfterChange) |
---|
1612 | Â Â Â Â Â Â Â Â instSizer.Add(waveVal,0,WACV) |
---|
1613 | Â Â Â Â Â Â Â Â labelLst.append(u'Lam (\xc5)') |
---|
1614 | Â Â Â Â Â Â Â Â waveSizer =Â wx.BoxSizer(wx.HORIZONTAL) |
---|
1615 | Â Â Â Â Â Â Â Â waveSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,'Â Source type: '),0,WACV) |
---|
1616 | Â Â Â Â Â Â Â Â # PATCH?: for now at least, Source is not saved anywhere before here |
---|
1617 |         if 'Source' not in data: data['Source'] = ['CuKa','?'] |
---|
1618 | Â Â Â Â Â Â Â Â choice =Â ['synchrotron','TiKa','CrKa','FeKa','CoKa','CuKa','MoKa','AgKa'] |
---|
1619 | Â Â Â Â Â Â Â Â lamPick =Â wx.ComboBox(G2frame.dataDisplay,value=data['Source'][1],choices=choice,style=wx.CB_READONLY|wx.CB_DROPDOWN) |
---|
1620 |         lamPick.Bind(wx.EVT_COMBOBOX, OnLamPick) |
---|
1621 | Â Â Â Â Â Â Â Â waveSizer.Add(lamPick,0,WACV) |
---|
1622 | Â Â Â Â Â Â Â Â instSizer.Add(waveSizer,0,WACV) |
---|
1623 | Â Â Â Â Â Â Â Â elemKeysLst.append(['Lam',1]) |
---|
1624 | Â Â Â Â Â Â Â Â dspLst.append([10,6]) |
---|
1625 | Â Â Â Â Â Â Â Â refFlgElem.append(None) |
---|
1626 | Â Â Â Â Â Â else:Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #time of flight (neutrons) |
---|
1627 |         pass                #for now |
---|
1628 |     elif 'L' in insVal['Type']: |
---|
1629 |       if 'C' in insVal['Type']:    |
---|
1630 | Â Â Â Â Â Â Â Â instSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,u' Lam (\xc5): (%10.6f)'%(insDef['Lam'])), |
---|
1631 | Â Â Â Â Â Â Â Â Â Â 0,WACV) |
---|
1632 | Â Â Â Â Â Â Â Â waveVal =Â G2G.ValidatedTxtCtrl(G2frame.dataDisplay,insVal,'Lam',nDig=(10,6),typeHint=float,OnLeave=AfterChange) |
---|
1633 | Â Â Â Â Â Â Â Â instSizer.Add(waveVal,0,WACV) |
---|
1634 | Â Â Â Â Â Â Â Â labelLst.append(u'Lam (\xc5)') |
---|
1635 | Â Â Â Â Â Â Â Â elemKeysLst.append(['Lam',1]) |
---|
1636 | Â Â Â Â Â Â Â Â dspLst.append([10,6]) |
---|
1637 | Â Â Â Â Â Â Â Â refFlgElem.append(None) |
---|
1638 | Â Â Â Â Â Â Â Â instSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,'Â Azimuth: %7.2f'%(insVal['Azimuth'])),0,WACV) |
---|
1639 | Â Â Â Â Â Â Â Â labelLst.append('Azimuth angle') |
---|
1640 | Â Â Â Â Â Â Â Â elemKeysLst.append(['Azimuth',1]) |
---|
1641 | Â Â Â Â Â Â Â Â dspLst.append([10,2]) |
---|
1642 | Â Â Â Â Â Â Â Â refFlgElem.append(None)Â Â Â Â Â Â Â Â Â Â |
---|
1643 | Â Â Â Â Â Â else:Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #time of flight (neutrons) |
---|
1644 |         pass                #for now |
---|
1645 | |
---|
1646 | Â Â Â Â mainSizer.Add(instSizer,0) |
---|
1647 | Â Â Â Â mainSizer.Layout()Â Â |
---|
1648 | Â Â Â Â G2frame.dataDisplay.SetSizer(mainSizer) |
---|
1649 | Â Â Â Â G2frame.dataFrame.setSizePosLeft(mainSizer.Fit(G2frame.dataFrame)) |
---|
1650 | Â Â Â Â G2frame.dataFrame.SendSizeEvent()Â # this causes a frame repaint, even if the size does not change! |
---|
1651 | Â Â Â Â # end of MakeParameterWindow |
---|
1652 | Â Â Â Â Â Â Â Â |
---|
1653 |   # beginning of UpdateInstrumentGrid code  |
---|
1654 | Â Â #patch: make sure all parameter items are lists |
---|
1655 | Â Â patched =Â 0 |
---|
1656 |   for key in data: |
---|
1657 |     if type(data[key]) is tuple: |
---|
1658 | Â Â Â Â Â Â data[key]Â =Â list(data[key]) |
---|
1659 | Â Â Â Â Â Â patched +=Â 1 |
---|
1660 |   if patched: print patched,' instrument parameters changed from tuples' |
---|
1661 | Â Â #end of patch |
---|
1662 | Â Â labelLst,elemKeysLst,dspLst,refFlgElem =Â [],[],[],[] |
---|
1663 | Â Â instkeys =Â keycheck(data.keys()) |
---|
1664 |   if 'P' in data['Type'][0]:     #powder data |
---|
1665 |     insVal = dict(zip(instkeys,[data[key][1] for key in instkeys])) |
---|
1666 |     insDef = dict(zip(instkeys,[data[key][0] for key in instkeys])) |
---|
1667 |     insRef = dict(zip(instkeys,[data[key][2] for key in instkeys])) |
---|
1668 |     if 'NC' in data['Type'][0]: |
---|
1669 | Â Â Â Â Â Â del(insDef['Polariz.']) |
---|
1670 | Â Â Â Â Â Â del(insVal['Polariz.']) |
---|
1671 | Â Â Â Â Â Â del(insRef['Polariz.']) |
---|
1672 |   elif 'S' in data['Type'][0]:                #single crystal data |
---|
1673 |     insVal = dict(zip(instkeys,[data[key][1] for key in instkeys])) |
---|
1674 |     insDef = dict(zip(instkeys,[data[key][0] for key in instkeys])) |
---|
1675 | Â Â Â Â insRef =Â {} |
---|
1676 |   elif 'L' in data['Type'][0]:                #low angle data |
---|
1677 |     insVal = dict(zip(instkeys,[data[key][1] for key in instkeys])) |
---|
1678 |     insDef = dict(zip(instkeys,[data[key][0] for key in instkeys])) |
---|
1679 | Â Â Â Â insRef =Â {} |
---|
1680 | Â Â ValObj =Â {} |
---|
1681 | Â Â RefObj =Â {} |
---|
1682 | Â Â waves =Â {'CuKa':[1.54051,1.54433],'TiKa':[2.74841,2.75207],'CrKa':[2.28962,2.29351], |
---|
1683 | Â Â Â Â 'FeKa':[1.93597,1.93991],'CoKa':[1.78892,1.79278],'MoKa':[0.70926,0.713543], |
---|
1684 | Â Â Â Â 'AgKa':[0.559363,0.563775]} |
---|
1685 | Â Â meanwaves =Â {'CuKa':1.5418,'TiKa':2.7496,'CrKa':2.2909,'FeKa':1.9373, |
---|
1686 | Â Â Â Â 'CoKa':1.7902,'MoKa':0.7107,'AgKa':0.5608} |
---|
1687 | Â Â Inst2 =Â G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame, |
---|
1688 | Â Â Â Â Â Â G2frame.PatternId,'Instrument Parameters'))[1]Â Â Â Â |
---|
1689 | Â Â try: |
---|
1690 | Â Â Â Â histoName =Â G2frame.PatternTree.GetItemPyData(G2frame.PatternId)[-1] |
---|
1691 | Â Â Â Â ifHisto =Â IsHistogramInAnyPhase(G2frame,histoName) |
---|
1692 |   except TypeError:    #PKS data never used in a phase as data |
---|
1693 | Â Â Â Â ifhisto =Â False |
---|
1694 | Â Â G2gd.SetDataMenuBar(G2frame) |
---|
1695 | Â Â #patch |
---|
1696 |   if 'P' in insVal['Type']:          #powder data |
---|
1697 |     if 'C' in insVal['Type']:        #constant wavelength |
---|
1698 |       if 'Azimuth' not in insVal: |
---|
1699 | Â Â Â Â Â Â Â Â insVal['Azimuth']Â =Â 0.0 |
---|
1700 | Â Â Â Â Â Â Â Â insDef['Azimuth']Â =Â 0.0 |
---|
1701 | Â Â Â Â Â Â Â Â insRef['Azimuth']Â =Â False |
---|
1702 | #Â Â Â Â if 'T' in insVal['Type']: |
---|
1703 | #Â Â Â Â Â Â if 'difB' not in insVal: |
---|
1704 | #Â Â Â Â Â Â Â Â insVal['difB'] = 0.0 |
---|
1705 | #Â Â Â Â Â Â Â Â insDef['difB'] = 0.0 |
---|
1706 | #Â Â Â Â Â Â Â Â insRef['difB'] = False |
---|
1707 | Â Â #end of patch |
---|
1708 |   if 'P' in insVal['Type']:          #powder data menu commands |
---|
1709 | Â Â Â Â G2gd.SetDataMenuBar(G2frame,G2frame.dataFrame.InstMenu) |
---|
1710 |     if not G2frame.dataFrame.GetStatusBar(): |
---|
1711 | Â Â Â Â Â Â Status =Â G2frame.dataFrame.CreateStatusBar()Â Â Â Â Â Â |
---|
1712 | Â Â Â Â Â Â Status.SetStatusText('NB: Azimuth is used for polarization only') |
---|
1713 | Â Â Â Â G2frame.Bind(wx.EVT_MENU,OnCalibrate,id=G2gd.wxID_INSTCALIB) |
---|
1714 | Â Â Â Â G2frame.Bind(wx.EVT_MENU,OnLoad,id=G2gd.wxID_INSTLOAD) |
---|
1715 | Â Â Â Â G2frame.Bind(wx.EVT_MENU,OnSave,id=G2gd.wxID_INSTSAVE) |
---|
1716 | Â Â Â Â G2frame.Bind(wx.EVT_MENU,OnReset,id=G2gd.wxID_INSTPRMRESET) |
---|
1717 | Â Â Â Â G2frame.Bind(wx.EVT_MENU,OnInstCopy,id=G2gd.wxID_INSTCOPY) |
---|
1718 | Â Â Â Â G2frame.Bind(wx.EVT_MENU,OnInstFlagCopy,id=G2gd.wxID_INSTFLAGCOPY) |
---|
1719 | Â Â Â Â #G2frame.Bind(wx.EVT_MENU,OnWaveChange,id=G2gd.wxID_CHANGEWAVETYPE)Â Â Â Â |
---|
1720 | Â Â Â Â G2frame.Bind(wx.EVT_MENU,OnCopy1Val,id=G2gd.wxID_INST1VAL) |
---|
1721 |   elif 'L' in insVal['Type']:          #SASD data menu commands |
---|
1722 | Â Â Â Â G2gd.SetDataMenuBar(G2frame,G2frame.dataFrame.InstMenu) |
---|
1723 |     if not G2frame.dataFrame.GetStatusBar(): |
---|
1724 | Â Â Â Â Â Â Status =Â G2frame.dataFrame.CreateStatusBar() |
---|
1725 | Â Â Â Â G2frame.Bind(wx.EVT_MENU,OnInstCopy,id=G2gd.wxID_INSTCOPY) |
---|
1726 | Â Â MakeParameterWindow() |
---|
1727 | Â Â Â Â |
---|
1728 | Â Â |
---|
1729 | ################################################################################ |
---|
1730 | #####Â Sample parameters |
---|
1731 | ################################################################################Â Â Â Â Â Â |
---|
1732 | Â Â Â Â |
---|
1733 | def UpdateSampleGrid(G2frame,data): |
---|
1734 | Â Â '''respond to selection of PWDR/SASD Sample Parameters |
---|
1735 | Â Â data tree item. |
---|
1736 | Â Â ''' |
---|
1737 | |
---|
1738 |   def OnSampleSave(event): |
---|
1739 | Â Â Â Â '''Respond to the Sample Parameters Operations/Save menu |
---|
1740 | Â Â Â Â item: writes current parameters to a .samprm file |
---|
1741 | Â Â Â Â ''' |
---|
1742 |     dlg = wx.FileDialog(G2frame, 'Choose GSAS-II sample parameters file', '.', '', |
---|
1743 | Â Â Â Â Â Â 'sample parameter files (*.samprm)|*.samprm',wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT|wx.CHANGE_DIR) |
---|
1744 | Â Â Â Â try: |
---|
1745 |       if dlg.ShowModal() == wx.ID_OK: |
---|
1746 | Â Â Â Â Â Â Â Â filename =Â dlg.GetPath() |
---|
1747 | Â Â Â Â Â Â Â Â # make sure extension is .samprm |
---|
1748 | Â Â Â Â Â Â Â Â filename =Â os.path.splitext(filename)[0]+'.samprm' |
---|
1749 | Â Â Â Â Â Â Â Â File =Â open(filename,'w') |
---|
1750 | Â Â Â Â Â Â Â Â File.write("#GSAS-II sample parameter file\n") |
---|
1751 | Â Â Â Â Â Â Â Â File.write("'Type':'"+str(data['Type'])+"'\n") |
---|
1752 | Â Â Â Â Â Â Â Â File.write("'Gonio. radius':"+str(data['Gonio. radius'])+"\n") |
---|
1753 |         if data.get('InstrName'): |
---|
1754 | Â Â Â Â Â Â Â Â Â Â File.write("'InstrName':'"+str(data['InstrName'])+"'\n") |
---|
1755 | Â Â Â Â Â Â Â Â File.close() |
---|
1756 | Â Â Â Â finally: |
---|
1757 | Â Â Â Â Â Â dlg.Destroy() |
---|
1758 | Â Â Â Â Â Â |
---|
1759 |   def OnSampleLoad(event): |
---|
1760 | Â Â Â Â '''Loads sample parameters from a G2 .samprm file |
---|
1761 | Â Â Â Â in response to the Sample Parameters-Operations/Load menu |
---|
1762 | Â Â Â Â |
---|
1763 | Â Â Â Â Note that similar code is found in ReadPowderInstprm (GSASII.py) |
---|
1764 | Â Â Â Â ''' |
---|
1765 |     dlg = wx.FileDialog(G2frame, 'Choose GSAS-II sample parameters file', '.', '', |
---|
1766 | Â Â Â Â Â Â 'sample parameter files (*.samprm)|*.samprm',wx.OPEN|wx.CHANGE_DIR) |
---|
1767 | Â Â Â Â try: |
---|
1768 |       if dlg.ShowModal() == wx.ID_OK: |
---|
1769 | Â Â Â Â Â Â Â Â filename =Â dlg.GetPath() |
---|
1770 | Â Â Â Â Â Â Â Â File =Â open(filename,'r') |
---|
1771 | Â Â Â Â Â Â Â Â S =Â File.readline() |
---|
1772 | Â Â Â Â Â Â Â Â newItems =Â {} |
---|
1773 |         while S: |
---|
1774 |           if S[0] == '#': |
---|
1775 | Â Â Â Â Â Â Â Â Â Â Â Â S =Â File.readline() |
---|
1776 | Â Â Â Â Â Â Â Â Â Â Â Â continue |
---|
1777 | Â Â Â Â Â Â Â Â Â Â [item,val]Â =Â S[:-1].split(':') |
---|
1778 | Â Â Â Â Â Â Â Â Â Â newItems[item.strip("'")]Â =Â eval(val) |
---|
1779 | Â Â Â Â Â Â Â Â Â Â S =Â File.readline()Â Â Â Â Â Â Â Â |
---|
1780 | Â Â Â Â Â Â Â Â File.close() |
---|
1781 | Â Â Â Â Â Â Â Â data.update(newItems) |
---|
1782 | Â Â Â Â Â Â Â Â G2frame.PatternTree.SetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId,'Sample Parameters'),data) |
---|
1783 | Â Â Â Â Â Â Â Â UpdateSampleGrid(G2frame,data) |
---|
1784 | Â Â Â Â finally: |
---|
1785 | Â Â Â Â Â Â dlg.Destroy() |
---|
1786 | Â Â Â Â Â Â |
---|
1787 |   def OnAllSampleLoad(event): |
---|
1788 | Â Â Â Â filename =Â '' |
---|
1789 |     dlg = wx.FileDialog(G2frame, 'Choose multihistogram metadata text file', '.', '', |
---|
1790 | Â Â Â Â Â Â 'metadata file (*.*)|*.*',wx.OPEN|wx.CHANGE_DIR) |
---|
1791 | Â Â Â Â try: |
---|
1792 |       if dlg.ShowModal() == wx.ID_OK: |
---|
1793 | Â Â Â Â Â Â Â Â filename =Â dlg.GetPath() |
---|
1794 | Â Â Â Â Â Â Â Â File =Â open(filename,'r') |
---|
1795 | Â Â Â Â Â Â Â Â S =Â File.readline() |
---|
1796 | Â Â Â Â Â Â Â Â newItems =Â [] |
---|
1797 | Â Â Â Â Â Â Â Â itemNames =Â [] |
---|
1798 | Â Â Â Â Â Â Â Â Comments =Â [] |
---|
1799 |         while S: |
---|
1800 |           if S[0] == '#': |
---|
1801 | Â Â Â Â Â Â Â Â Â Â Â Â Comments.append(S) |
---|
1802 | Â Â Â Â Â Â Â Â Â Â Â Â S =Â File.readline() |
---|
1803 | Â Â Â Â Â Â Â Â Â Â Â Â continue |
---|
1804 | Â Â Â Â Â Â Â Â Â Â S =Â S.replace(',',' ').replace('\t',' ') |
---|
1805 | Â Â Â Â Â Â Â Â Â Â Stuff =Â S[:-1].split() |
---|
1806 | Â Â Â Â Â Â Â Â Â Â itemNames.append(Stuff[0]) |
---|
1807 | Â Â Â Â Â Â Â Â Â Â newItems.append(Stuff[1:]) |
---|
1808 | Â Â Â Â Â Â Â Â Â Â S =Â File.readline()Â Â Â Â Â Â Â Â |
---|
1809 | Â Â Â Â Â Â Â Â File.close() |
---|
1810 | Â Â Â Â finally: |
---|
1811 | Â Â Â Â Â Â dlg.Destroy() |
---|
1812 |     if not filename: |
---|
1813 | Â Â Â Â Â Â G2frame.ErrorDialog('Nothing to do','No file selected') |
---|
1814 | Â Â Â Â Â Â return |
---|
1815 | Â Â Â Â dataDict =Â dict(zip(itemNames,newItems)) |
---|
1816 | Â Â Â Â ifany =Â False |
---|
1817 | Â Â Â Â Controls =Â G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.root,'Controls')) |
---|
1818 | Â Â Â Â Names =Â [' ','Phi','Chi','Omega','Time','Temperature','Pressure'] |
---|
1819 | Â Â Â Â freeNames =Â {} |
---|
1820 |     for name in ['FreePrm1','FreePrm2','FreePrm3']: |
---|
1821 | Â Â Â Â Â Â freeNames[Controls[name]]Â =Â name |
---|
1822 | Â Â Â Â Â Â Names.append(Controls[name]) |
---|
1823 | Â Â Â Â dlg =Â G2G.G2ColumnIDDialog(Â G2frame,' Choose multihistogram metadata columns:', |
---|
1824 | Â Â Â Â Â Â 'Select columns',Comments,Names,np.array(newItems).T) |
---|
1825 | Â Â Â Â try: |
---|
1826 |       if dlg.ShowModal() == wx.ID_OK: |
---|
1827 | Â Â Â Â Â Â Â Â colNames,newData =Â dlg.GetSelection() |
---|
1828 | Â Â Â Â Â Â Â Â dataDict =Â dict(zip(itemNames,newData.T)) |
---|
1829 |         for item in colNames: |
---|
1830 |           if item != ' ': |
---|
1831 | Â Â Â Â Â Â Â Â Â Â Â Â ifany =Â True |
---|
1832 | Â Â Â Â finally: |
---|
1833 | Â Â Â Â Â Â dlg.Destroy() |
---|
1834 |     if not ifany: |
---|
1835 | Â Â Â Â Â Â G2frame.ErrorDialog('Nothing to do','No columns identified') |
---|
1836 | Â Â Â Â Â Â return |
---|
1837 | Â Â Â Â histList =Â [G2frame.PatternTree.GetItemText(G2frame.PatternId),] |
---|
1838 | Â Â Â Â histList +=Â GetHistsLikeSelected(G2frame) |
---|
1839 | Â Â Â Â colIds =Â {} |
---|
1840 |     for i,name in enumerate(colNames): |
---|
1841 |       if name != ' ': |
---|
1842 | Â Â Â Â Â Â Â Â colIds[name]Â =Â i |
---|
1843 |     for hist in histList: |
---|
1844 | Â Â Â Â Â Â name =Â hist.split()[1]Â #this is file name |
---|
1845 | Â Â Â Â Â Â newItems =Â {} |
---|
1846 |       for item in colIds: |
---|
1847 | Â Â Â Â Â Â Â Â key =Â freeNames.get(item,item) |
---|
1848 | Â Â Â Â Â Â Â Â newItems[key]Â =Â float(dataDict[name][colIds[item]]) |
---|
1849 | Â Â Â Â Â Â Id =Â G2gd.GetPatternTreeItemId(G2frame,G2frame.root,hist) |
---|
1850 | Â Â Â Â Â Â sampleData =Â G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Id,'Sample Parameters')) |
---|
1851 | Â Â Â Â Â Â sampleData.update(newItems)Â Â Â Â |
---|
1852 | Â Â Â Â UpdateSampleGrid(G2frame,data)Â Â Â Â |
---|
1853 | Â Â |
---|
1854 |   def OnSetScale(event): |
---|
1855 | Â Â Â Â histList =Â [] |
---|
1856 |     item, cookie = G2frame.PatternTree.GetFirstChild(G2frame.root) |
---|
1857 |     while item: |
---|
1858 | Â Â Â Â Â Â name =Â G2frame.PatternTree.GetItemText(item) |
---|
1859 |       if 'SASD' in name and name != histName: |
---|
1860 | Â Â Â Â Â Â Â Â histList.append(name) |
---|
1861 |       item, cookie = G2frame.PatternTree.GetNextChild(G2frame.root, cookie) |
---|
1862 |     if not len(histList):   #nothing to copy to! |
---|
1863 | Â Â Â Â Â Â return |
---|
1864 | Â Â Â Â dlg =Â wx.SingleChoiceDialog(G2frame,'Select reference histogram for scaling', |
---|
1865 | Â Â Â Â Â Â 'Reference histogram',histList) |
---|
1866 | Â Â Â Â try: |
---|
1867 |       if dlg.ShowModal() == wx.ID_OK: |
---|
1868 | Â Â Â Â Â Â Â Â sel =Â dlg.GetSelection() |
---|
1869 | Â Â Â Â Â Â Â Â refHist =Â histList[sel] |
---|
1870 | Â Â Â Â finally: |
---|
1871 | Â Â Â Â Â Â dlg.Destroy() |
---|
1872 |     Limits = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId, 'Limits')) |
---|
1873 | Â Â Â Â Profile =Â G2frame.PatternTree.GetItemPyData(G2frame.PatternId)[1] |
---|
1874 | Â Â Â Â Data =Â [Profile,Limits,data] |
---|
1875 | Â Â Â Â refId =Â G2gd.GetPatternTreeItemId(G2frame,G2frame.root,refHist) |
---|
1876 |     refSample = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,refId, 'Sample Parameters')) |
---|
1877 |     refLimits = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,refId, 'Limits')) |
---|
1878 | Â Â Â Â refProfile =Â G2frame.PatternTree.GetItemPyData(refId)[1] |
---|
1879 | Â Â Â Â refData =Â [refProfile,refLimits,refSample] |
---|
1880 | Â Â Â Â G2sasd.SetScale(Data,refData) |
---|
1881 | Â Â Â Â G2plt.PlotPatterns(G2frame,plotType='SASD',newPlot=True) |
---|
1882 | Â Â Â Â UpdateSampleGrid(G2frame,data)Â Â Â Â |
---|
1883 | Â Â Â Â |
---|
1884 |   def OnSampleCopy(event): |
---|
1885 | Â Â Â Â histType,copyNames =Â SetCopyNames(histName,data['Type'], |
---|
1886 | Â Â Â Â Â Â addNames =Â ['Omega','Chi','Phi','Gonio. radius','InstrName']) |
---|
1887 | Â Â Â Â copyDict =Â {} |
---|
1888 |     for parm in copyNames: |
---|
1889 | Â Â Â Â Â Â copyDict[parm]Â =Â data[parm] |
---|
1890 | Â Â Â Â hst =Â G2frame.PatternTree.GetItemText(G2frame.PatternId) |
---|
1891 | Â Â Â Â histList =Â GetHistsLikeSelected(G2frame) |
---|
1892 |     if not histList: |
---|
1893 | Â Â Â Â Â Â G2frame.ErrorDialog('No match','No histograms match '+hst,G2frame.dataFrame) |
---|
1894 | Â Â Â Â Â Â return |
---|
1895 | Â Â Â Â dlg =Â G2G.G2MultiChoiceDialog( |
---|
1896 | Â Â Â Â Â Â G2frame.dataFrame, |
---|
1897 | Â Â Â Â Â Â 'Copy sample params from\n'+str(hst[5:])+' to...', |
---|
1898 |       'Copy sample parameters', histList) |
---|
1899 | Â Â Â Â try: |
---|
1900 |       if dlg.ShowModal() == wx.ID_OK: |
---|
1901 | Â Â Â Â Â Â Â Â result =Â dlg.GetSelections() |
---|
1902 |         for i in result: |
---|
1903 | Â Â Â Â Â Â Â Â Â Â item =Â histList[i] |
---|
1904 | Â Â Â Â Â Â Â Â Â Â Id =Â G2gd.GetPatternTreeItemId(G2frame,G2frame.root,item) |
---|
1905 | Â Â Â Â Â Â Â Â Â Â sampleData =Â G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Id,'Sample Parameters')) |
---|
1906 | Â Â Â Â Â Â Â Â Â Â sampleData.update(copy.deepcopy(copyDict)) |
---|
1907 | Â Â Â Â finally: |
---|
1908 | Â Â Â Â Â Â dlg.Destroy() |
---|
1909 | |
---|
1910 |   def OnSampleCopySelected(event): |
---|
1911 | Â Â Â Â hst =Â G2frame.PatternTree.GetItemText(G2frame.PatternId) |
---|
1912 | Â Â Â Â Controls =Â G2frame.PatternTree.GetItemPyData( |
---|
1913 |       G2gd.GetPatternTreeItemId(G2frame,G2frame.root, 'Controls')) |
---|
1914 | Â Â Â Â histList =Â GetHistsLikeSelected(G2frame) |
---|
1915 |     if not histList: |
---|
1916 | Â Â Â Â Â Â G2frame.ErrorDialog('No match','No histograms match '+hst,G2frame.dataFrame) |
---|
1917 | Â Â Â Â Â Â return |
---|
1918 | Â Â Â Â # Assemble a list of item labels |
---|
1919 |     TextTable = {key:label for key,label,dig in |
---|
1920 | Â Â Â Â Â Â Â Â Â Â Â SetupSampleLabels(hst,data.get('Type'),Inst['Type'][0]) |
---|
1921 | Â Â Â Â Â Â Â Â Â Â Â } |
---|
1922 | Â Â Â Â # get flexible labels |
---|
1923 | Â Â Â Â TextTable.update({ |
---|
1924 |       key:Controls[key] for key in Controls if key.startswith('FreePrm') |
---|
1925 | Â Â Â Â Â Â }) |
---|
1926 | Â Â Â Â # add a few extra |
---|
1927 | Â Â Â Â TextTable.update({ |
---|
1928 | Â Â Â Â Â Â 'Type':'Diffractometer type', |
---|
1929 | Â Â Â Â Â Â 'InstrName':'Instrument Name', |
---|
1930 | Â Â Â Â Â Â }) |
---|
1931 | Â Â Â Â # Assemble a list of dict entries that would be labeled in the Sample |
---|
1932 | Â Â Â Â # params data window (drop ranId and items not used). |
---|
1933 |     keyList = [i for i in data.keys() if i in TextTable] |
---|
1934 |     keyText = [TextTable[i] for i in keyList] |
---|
1935 | Â Â Â Â # sort both lists together, ordered by keyText |
---|
1936 |     keyText, keyList = zip(*sorted(zip(keyText,keyList))) # sort lists |
---|
1937 | Â Â Â Â selectedKeys =Â [] |
---|
1938 | Â Â Â Â dlg =Â G2G.G2MultiChoiceDialog( |
---|
1939 | Â Â Â Â Â Â G2frame.dataFrame, |
---|
1940 | Â Â Â Â Â Â 'Select which sample parameters\nto copy', |
---|
1941 |       'Select sample parameters', keyText) |
---|
1942 | Â Â Â Â try: |
---|
1943 |       if dlg.ShowModal() == wx.ID_OK: |
---|
1944 |         selectedKeys = [keyList[i] for i in dlg.GetSelections()] |
---|
1945 | Â Â Â Â finally: |
---|
1946 | Â Â Â Â Â Â dlg.Destroy() |
---|
1947 |     if not selectedKeys: return # nothing to copy |
---|
1948 | Â Â Â Â copyDict =Â {} |
---|
1949 |     for parm in selectedKeys: |
---|
1950 | Â Â Â Â Â Â copyDict[parm]Â =Â data[parm] |
---|
1951 | Â Â Â Â dlg =Â G2G.G2MultiChoiceDialog( |
---|
1952 | Â Â Â Â Â Â G2frame.dataFrame, |
---|
1953 | Â Â Â Â Â Â 'Copy sample params from\n'+str(hst[5:])+' to...', |
---|
1954 |       'Copy sample parameters', histList) |
---|
1955 | Â Â Â Â try: |
---|
1956 |       if dlg.ShowModal() == wx.ID_OK: |
---|
1957 | Â Â Â Â Â Â Â Â result =Â dlg.GetSelections() |
---|
1958 |         for i in result: |
---|
1959 | Â Â Â Â Â Â Â Â Â Â item =Â histList[i] |
---|
1960 | Â Â Â Â Â Â Â Â Â Â Id =Â G2gd.GetPatternTreeItemId(G2frame,G2frame.root,item) |
---|
1961 | Â Â Â Â Â Â Â Â Â Â sampleData =Â G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Id,'Sample Parameters')) |
---|
1962 | Â Â Â Â Â Â Â Â Â Â sampleData.update(copy.deepcopy(copyDict)) |
---|
1963 | Â Â Â Â finally: |
---|
1964 | Â Â Â Â Â Â dlg.Destroy()Â Â Â Â Â Â |
---|
1965 | Â Â Â Â G2plt.PlotPatterns(G2frame,plotType=hst[:4],newPlot=False) |
---|
1966 | |
---|
1967 |   def OnSampleFlagCopy(event): |
---|
1968 | Â Â Â Â histType,copyNames =Â SetCopyNames(histName,data['Type']) |
---|
1969 | Â Â Â Â flagDict =Â {} |
---|
1970 |     for parm in copyNames: |
---|
1971 | Â Â Â Â Â Â flagDict[parm]Â =Â data[parm][1] |
---|
1972 | Â Â Â Â hst =Â G2frame.PatternTree.GetItemText(G2frame.PatternId) |
---|
1973 | Â Â Â Â histList =Â GetHistsLikeSelected(G2frame) |
---|
1974 |     if not histList: |
---|
1975 | Â Â Â Â Â Â G2frame.ErrorDialog('No match','No histograms match '+hst,G2frame.dataFrame) |
---|
1976 | Â Â Â Â Â Â return |
---|
1977 | Â Â Â Â dlg =Â G2G.G2MultiChoiceDialog( |
---|
1978 |       G2frame.dataFrame, |
---|
1979 | Â Â Â Â Â Â 'Copy sample ref. flags from\n'+str(hst[5:])+' to...', |
---|
1980 |       'Copy sample flags', histList) |
---|
1981 | Â Â Â Â try: |
---|
1982 |       if dlg.ShowModal() == wx.ID_OK: |
---|
1983 | Â Â Â Â Â Â Â Â result =Â dlg.GetSelections() |
---|
1984 |         for i in result: |
---|
1985 | Â Â Â Â Â Â Â Â Â Â item =Â histList[i] |
---|
1986 | Â Â Â Â Â Â Â Â Â Â Id =Â G2gd.GetPatternTreeItemId(G2frame,G2frame.root,item) |
---|
1987 | Â Â Â Â Â Â Â Â Â Â sampleData =Â G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Id,'Sample Parameters')) |
---|
1988 |           for name in copyNames: |
---|
1989 | Â Â Â Â Â Â Â Â Â Â Â Â sampleData[name][1]Â =Â copy.copy(flagDict[name]) |
---|
1990 | Â Â Â Â finally: |
---|
1991 | Â Â Â Â Â Â dlg.Destroy() |
---|
1992 | |
---|
1993 |   def OnHistoChange(): |
---|
1994 | Â Â Â Â '''Called when the histogram type is changed to refresh the window |
---|
1995 | Â Â Â Â ''' |
---|
1996 | Â Â Â Â wx.CallAfter(UpdateSampleGrid,G2frame,data) |
---|
1997 | Â Â Â Â |
---|
1998 |   def SetNameVal(): |
---|
1999 | Â Â Â Â inst =Â instNameVal.GetValue() |
---|
2000 | Â Â Â Â data['InstrName']Â =Â inst.strip() |
---|
2001 | |
---|
2002 |   def OnNameVal(event): |
---|
2003 | Â Â Â Â event.Skip() |
---|
2004 | Â Â Â Â wx.CallAfter(SetNameVal) |
---|
2005 | Â Â Â Â |
---|
2006 |   def AfterChange(invalid,value,tc): |
---|
2007 |     if invalid: |
---|
2008 | Â Â Â Â Â Â return |
---|
2009 |     if tc.key == 0 and 'SASD' in histName:     #a kluge for Scale! |
---|
2010 | Â Â Â Â Â Â G2plt.PlotPatterns(G2frame,plotType='SASD',newPlot=True) |
---|
2011 |     elif tc.key == 'Thick': |
---|
2012 | Â Â Â Â Â Â wx.CallAfter(UpdateSampleGrid,G2frame,data)Â Â Â Â Â Â |
---|
2013 | Â Â Â Â Â Â |
---|
2014 |   def OnMaterial(event): |
---|
2015 | Â Â Â Â Obj =Â event.GetEventObject() |
---|
2016 | Â Â Â Â id,key =Â Info[Obj.GetId()] |
---|
2017 |     if key == 'Name': |
---|
2018 | Â Â Â Â Â Â data['Materials'][id][key]Â =Â Obj.GetValue() |
---|
2019 |     elif key == 'VolFrac': |
---|
2020 | Â Â Â Â Â Â try: |
---|
2021 | Â Â Â Â Â Â Â Â value =Â min(max(0.,float(Obj.GetValue())),1.) |
---|
2022 |       except ValueError: |
---|
2023 | Â Â Â Â Â Â Â Â value =Â data['Materials'][id][key] |
---|
2024 | Â Â Â Â Â Â data['Materials'][id][key]Â =Â value |
---|
2025 |       data['Materials'][not id][key] = 1.-value |
---|
2026 | Â Â Â Â wx.CallAfter(UpdateSampleGrid,G2frame,data) |
---|
2027 | |
---|
2028 |   def OnCopy1Val(event): |
---|
2029 | Â Â Â Â 'Select one value to copy to many histograms and optionally allow values to be edited in a table' |
---|
2030 | Â Â Â Â G2G.SelectEdit1Var(G2frame,data,labelLst,elemKeysLst,dspLst,refFlgElem) |
---|
2031 | Â Â Â Â wx.CallAfter(UpdateSampleGrid,G2frame,data) |
---|
2032 | Â Â Â Â |
---|
2033 | Â Â ######## DEBUG ####################################################### |
---|
2034 | Â Â #import GSASIIpwdGUI |
---|
2035 | Â Â #reload(GSASIIpwdGUI) |
---|
2036 | Â Â #reload(G2gd) |
---|
2037 | Â Â ###################################################################### |
---|
2038 | Â Â Inst =Â G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId( |
---|
2039 |       G2frame,G2frame.PatternId, 'Instrument Parameters'))[0] |
---|
2040 | Â Â histName =Â G2frame.PatternTree.GetItemText(G2frame.PatternId) |
---|
2041 |   if G2frame.dataDisplay: |
---|
2042 | Â Â Â Â G2frame.dataFrame.Clear() |
---|
2043 | Â Â G2gd.SetDataMenuBar(G2frame,G2frame.dataFrame.SampleMenu) |
---|
2044 | Â Â G2frame.dataFrame.SetLabel('Sample Parameters') |
---|
2045 |   G2frame.Bind(wx.EVT_MENU, OnSetScale, id=G2gd.wxID_SETSCALE) |
---|
2046 |   G2frame.Bind(wx.EVT_MENU, OnSampleCopy, id=G2gd.wxID_SAMPLECOPY) |
---|
2047 |   G2frame.Bind(wx.EVT_MENU, OnSampleCopySelected, id=G2gd.wxID_SAMPLECOPYSOME) |
---|
2048 |   G2frame.Bind(wx.EVT_MENU, OnSampleFlagCopy, id=G2gd.wxID_SAMPLEFLAGCOPY) |
---|
2049 |   G2frame.Bind(wx.EVT_MENU, OnSampleSave, id=G2gd.wxID_SAMPLESAVE) |
---|
2050 |   G2frame.Bind(wx.EVT_MENU, OnSampleLoad, id=G2gd.wxID_SAMPLELOAD) |
---|
2051 |   G2frame.Bind(wx.EVT_MENU, OnCopy1Val, id=G2gd.wxID_SAMPLE1VAL) |
---|
2052 |   G2frame.Bind(wx.EVT_MENU, OnAllSampleLoad, id=G2gd.wxID_ALLSAMPLELOAD) |
---|
2053 |   if 'SASD' in histName: |
---|
2054 | Â Â Â Â G2frame.dataFrame.SetScale.Enable(True) |
---|
2055 |   if not G2frame.dataFrame.GetStatusBar(): |
---|
2056 | Â Â Â Â Status =Â G2frame.dataFrame.CreateStatusBar()Â Â |
---|
2057 | Â Â G2frame.dataDisplay =Â wx.Panel(G2frame.dataFrame) |
---|
2058 | Â Â Controls =Â G2frame.PatternTree.GetItemPyData( |
---|
2059 |     G2gd.GetPatternTreeItemId(G2frame,G2frame.root, 'Controls')) |
---|
2060 | #patch |
---|
2061 |   if 'ranId' not in data: |
---|
2062 | Â Â Â Â data['ranId']Â =Â ran.randint(0,sys.maxint) |
---|
2063 |   if not 'Gonio. radius' in data: |
---|
2064 | Â Â Â Â data['Gonio. radius']Â =Â 200.0 |
---|
2065 |   if not 'Omega' in data: |
---|
2066 | Â Â Â Â data.update({'Omega':0.0,'Chi':0.0,'Phi':0.0}) |
---|
2067 |   if 'Azimuth' not in data: |
---|
2068 | Â Â Â Â data['Azimuth']Â =Â 0.0 |
---|
2069 |   if type(data['Temperature']) is int: |
---|
2070 | Â Â Â Â data['Temperature']Â =Â float(data['Temperature']) |
---|
2071 |   if 'Time' not in data: |
---|
2072 | Â Â Â Â data['Time']Â =Â 0.0 |
---|
2073 |   if 'FreePrm1' not in Controls: |
---|
2074 | Â Â Â Â Controls['FreePrm1']Â =Â 'Sample humidity (%)' |
---|
2075 |   if 'FreePrm2' not in Controls: |
---|
2076 | Â Â Â Â Controls['FreePrm2']Â =Â 'Sample voltage (V)' |
---|
2077 |   if 'FreePrm3' not in Controls: |
---|
2078 | Â Â Â Â Controls['FreePrm3']Â =Â 'Applied load (MN)' |
---|
2079 |   if 'FreePrm1' not in data: |
---|
2080 | Â Â Â Â data['FreePrm1']Â =Â 0. |
---|
2081 |   if 'FreePrm2' not in data: |
---|
2082 | Â Â Â Â data['FreePrm2']Â =Â 0. |
---|
2083 |   if 'FreePrm3' not in data: |
---|
2084 | Â Â Â Â data['FreePrm3']Â =Â 0. |
---|
2085 |   if 'SurfRoughA' not in data and 'PWDR' in histName: |
---|
2086 | Â Â Â Â data['SurfRoughA']Â =Â [0.,False] |
---|
2087 | Â Â Â Â data['SurfRoughB']Â =Â [0.,False] |
---|
2088 |   if 'Trans' not in data and 'SASD' in histName: |
---|
2089 | Â Â Â Â data['Trans']Â =Â 1.0 |
---|
2090 |   if 'SlitLen' not in data and 'SASD' in histName: |
---|
2091 | Â Â Â Â data['SlitLen']Â =Â 0.0 |
---|
2092 |   if 'Shift' not in data: |
---|
2093 | Â Â Â Â data['Shift']Â =Â [0.0,False] |
---|
2094 |   if 'Transparency' not in data: |
---|
2095 | Â Â Â Â data['Transparency']Â =Â [0.0,False] |
---|
2096 | Â Â data['InstrName']Â =Â data.get('InstrName','') |
---|
2097 | #patch end |
---|
2098 | Â Â labelLst,elemKeysLst,dspLst,refFlgElem =Â [],[],[],[] |
---|
2099 | Â Â parms =Â SetupSampleLabels(histName,data.get('Type'),Inst['Type'][0]) |
---|
2100 | Â Â mainSizer =Â wx.BoxSizer(wx.VERTICAL) |
---|
2101 | Â Â topSizer =Â wx.BoxSizer(wx.HORIZONTAL) |
---|
2102 | Â Â topSizer.Add((-1,-1),1,wx.EXPAND,1) |
---|
2103 | Â Â topSizer.Add(wx.StaticText(G2frame.dataDisplay,label='Sample and Experimental Parameters')) |
---|
2104 | Â Â topSizer.Add((-1,-1),1,wx.EXPAND,1) |
---|
2105 | Â Â mainSizer.Add(topSizer,0,wx.EXPAND,1) |
---|
2106 | Â Â nameSizer =Â wx.BoxSizer(wx.HORIZONTAL) |
---|
2107 | Â Â nameSizer.Add(wx.StaticText(G2frame.dataDisplay,wx.ID_ANY,' Instrument Name'), |
---|
2108 | Â Â Â Â Â Â Â Â 0,WACV) |
---|
2109 | Â Â nameSizer.Add((-1,-1),1,wx.EXPAND,1) |
---|
2110 | Â Â instNameVal =Â wx.TextCtrl(G2frame.dataDisplay,wx.ID_ANY,data['InstrName'], |
---|
2111 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â size=(200,-1),style=wx.TE_PROCESS_ENTER)Â Â Â Â |
---|
2112 | Â Â nameSizer.Add(instNameVal) |
---|
2113 | Â Â instNameVal.Bind(wx.EVT_CHAR,OnNameVal) |
---|
2114 | Â Â mainSizer.Add(nameSizer,0,wx.EXPAND,1) |
---|
2115 | Â Â mainSizer.Add((5,5),0) |
---|
2116 | Â Â labelLst.append('Instrument Name') |
---|
2117 | Â Â elemKeysLst.append(['InstrName']) |
---|
2118 | Â Â dspLst.append(None) |
---|
2119 | Â Â refFlgElem.append(None) |
---|
2120 | |
---|
2121 |   if 'PWDR' in histName: |
---|
2122 | Â Â Â Â nameSizer =Â wx.BoxSizer(wx.HORIZONTAL) |
---|
2123 | Â Â Â Â nameSizer.Add(wx.StaticText(G2frame.dataDisplay,wx.ID_ANY,' Diffractometer type: '), |
---|
2124 | Â Â Â Â Â Â Â Â Â Â 0,WACV) |
---|
2125 |     if 'T' in Inst['Type'][0]: |
---|
2126 | Â Â Â Â Â Â choices =Â ['Debye-Scherrer',] |
---|
2127 | Â Â Â Â else: |
---|
2128 | Â Â Â Â Â Â choices =Â ['Debye-Scherrer','Bragg-Brentano',] |
---|
2129 | Â Â Â Â histoType =Â G2G.G2ChoiceButton(G2frame.dataDisplay,choices, |
---|
2130 | Â Â Â Â Â Â Â Â Â Â strLoc=data,strKey='Type', |
---|
2131 | Â Â Â Â Â Â Â Â Â Â onChoice=OnHistoChange) |
---|
2132 | Â Â Â Â nameSizer.Add(histoType) |
---|
2133 | Â Â Â Â mainSizer.Add(nameSizer,0,wx.EXPAND,1) |
---|
2134 | Â Â Â Â mainSizer.Add((5,5),0) |
---|
2135 | |
---|
2136 | Â Â parmSizer =Â wx.FlexGridSizer(0,2,5,0) |
---|
2137 |   for key,lbl,nDig in parms: |
---|
2138 | Â Â Â Â labelLst.append(lbl.strip().strip(':').strip()) |
---|
2139 | Â Â Â Â dspLst.append(nDig) |
---|
2140 |     if 'list' in str(type(data[key])): |
---|
2141 | Â Â Â Â Â Â parmRef =Â G2G.G2CheckBox(G2frame.dataDisplay,' '+lbl,data[key],1) |
---|
2142 | Â Â Â Â Â Â parmSizer.Add(parmRef,0,WACV|wx.EXPAND) |
---|
2143 | Â Â Â Â Â Â parmVal =Â G2G.ValidatedTxtCtrl(G2frame.dataDisplay,data[key],0, |
---|
2144 | Â Â Â Â Â Â Â Â nDig=nDig,typeHint=float,OnLeave=AfterChange) |
---|
2145 | Â Â Â Â Â Â elemKeysLst.append([key,0]) |
---|
2146 | Â Â Â Â Â Â refFlgElem.append([key,1]) |
---|
2147 | Â Â Â Â else: |
---|
2148 | Â Â Â Â Â Â parmSizer.Add(wx.StaticText(G2frame.dataDisplay,label=' '+lbl), |
---|
2149 | Â Â Â Â Â Â Â Â 0,WACV|wx.EXPAND) |
---|
2150 | Â Â Â Â Â Â parmVal =Â G2G.ValidatedTxtCtrl(G2frame.dataDisplay,data,key, |
---|
2151 | Â Â Â Â Â Â Â Â typeHint=float,OnLeave=AfterChange) |
---|
2152 | Â Â Â Â Â Â elemKeysLst.append([key]) |
---|
2153 | Â Â Â Â Â Â refFlgElem.append(None) |
---|
2154 | Â Â Â Â parmSizer.Add(parmVal,1,wx.EXPAND) |
---|
2155 | Â Â Info =Â {} |
---|
2156 | Â Â Â Â |
---|
2157 |   for key in ('FreePrm1','FreePrm2','FreePrm3'): |
---|
2158 | Â Â Â Â parmVal =Â G2G.ValidatedTxtCtrl(G2frame.dataDisplay,Controls,key,typeHint=str, |
---|
2159 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â notBlank=False) |
---|
2160 | Â Â Â Â parmSizer.Add(parmVal,1,wx.EXPAND) |
---|
2161 | Â Â Â Â parmVal =Â G2G.ValidatedTxtCtrl(G2frame.dataDisplay,data,key,typeHint=float) |
---|
2162 | Â Â Â Â parmSizer.Add(parmVal,1,wx.EXPAND) |
---|
2163 | Â Â Â Â labelLst.append(Controls[key]) |
---|
2164 | Â Â Â Â dspLst.append(None) |
---|
2165 | Â Â Â Â elemKeysLst.append([key]) |
---|
2166 | Â Â Â Â refFlgElem.append(None) |
---|
2167 | Â Â Â Â |
---|
2168 | Â Â mainSizer.Add(parmSizer,1,wx.EXPAND) |
---|
2169 | Â Â mainSizer.Add((0,5),0)Â Â |
---|
2170 |   if 'SASD' in histName: |
---|
2171 | Â Â Â Â rho =Â [0.,0.] |
---|
2172 | Â Â Â Â anomrho =Â [0.,0.] |
---|
2173 | Â Â Â Â mu =Â 0. |
---|
2174 | Â Â Â Â subSizer =Â wx.FlexGridSizer(0,4,5,5) |
---|
2175 | Â Â Â Â Substances =Â G2frame.PatternTree.GetItemPyData( |
---|
2176 |       G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId, 'Substances')) |
---|
2177 |     for id,item in enumerate(data['Materials']): |
---|
2178 | Â Â Â Â Â Â subSizer.Add(wx.StaticText(G2frame.dataDisplay,label=' Material: '),0,WACV) |
---|
2179 | Â Â Â Â Â Â matsel =Â wx.ComboBox(G2frame.dataDisplay,value=item['Name'],choices=Substances['Substances'].keys(), |
---|
2180 | Â Â Â Â Â Â Â Â style=wx.CB_READONLY|wx.CB_DROPDOWN) |
---|
2181 | Â Â Â Â Â Â Info[matsel.GetId()]Â =Â [id,'Name'] |
---|
2182 | Â Â Â Â Â Â matsel.Bind(wx.EVT_COMBOBOX,OnMaterial)Â Â Â Â |
---|
2183 | Â Â Â Â Â Â subSizer.Add(matsel,0,WACV) |
---|
2184 | Â Â Â Â Â Â subSizer.Add(wx.StaticText(G2frame.dataDisplay,label=' Volume fraction: '),0,WACV) |
---|
2185 | Â Â Â Â Â Â volfrac =Â wx.TextCtrl(G2frame.dataDisplay,value=str('%.3f'%(item['VolFrac'])),style=wx.TE_PROCESS_ENTER) |
---|
2186 | Â Â Â Â Â Â Info[volfrac.GetId()]Â =Â [id,'VolFrac'] |
---|
2187 | Â Â Â Â Â Â volfrac.Bind(wx.EVT_TEXT_ENTER,OnMaterial) |
---|
2188 | Â Â Â Â Â Â volfrac.Bind(wx.EVT_KILL_FOCUS,OnMaterial) |
---|
2189 | Â Â Â Â Â Â subSizer.Add(volfrac,0,WACV) |
---|
2190 | Â Â Â Â Â Â material =Â Substances['Substances'][item['Name']] |
---|
2191 | Â Â Â Â Â Â mu +=Â item['VolFrac']*material.get('XAbsorption',0.) |
---|
2192 | Â Â Â Â Â Â rho[id]Â =Â material['Scatt density'] |
---|
2193 | Â Â Â Â Â Â anomrho[id]Â =Â material.get('XAnom density',0.) |
---|
2194 | Â Â Â Â data['Contrast']Â =Â [(rho[1]-rho[0])**2,(anomrho[1]-anomrho[0])**2] |
---|
2195 | Â Â Â Â mainSizer.Add(subSizer,0) |
---|
2196 | Â Â Â Â conSizer =Â wx.BoxSizer(wx.HORIZONTAL) |
---|
2197 |     conSizer.Add(wx.StaticText(G2frame.dataDisplay,label=' Contrast: %10.2f '%(data['Contrast'][0])),0,WACV) |
---|
2198 |     conSizer.Add(wx.StaticText(G2frame.dataDisplay,label=' Anom. Contrast: %10.2f '%(data['Contrast'][1])),0,WACV) |
---|
2199 | Â Â Â Â mut =Â mu*data['Thick'] |
---|
2200 |     conSizer.Add(wx.StaticText(G2frame.dataDisplay,label=' Transmission (calc): %10.3f '%(np.exp(-mut))),0,WACV) |
---|
2201 | Â Â Â Â mainSizer.Add(conSizer,0) |
---|
2202 | Â Â |
---|
2203 | Â Â mainSizer.Layout()Â Â |
---|
2204 | Â Â G2frame.dataDisplay.SetSizer(mainSizer) |
---|
2205 | Â Â Size =Â mainSizer.Fit(G2frame.dataFrame) |
---|
2206 | Â Â G2frame.dataDisplay.SetSize(Size) |
---|
2207 | Â Â G2frame.dataFrame.setSizePosLeft(Size) |
---|
2208 | Â Â Â Â Â Â Â Â |
---|
2209 | ################################################################################ |
---|
2210 | #####Â Indexing Peaks |
---|
2211 | ################################################################################Â Â Â Â Â Â |
---|
2212 | Â Â Â Â |
---|
2213 | def UpdateIndexPeaksGrid(G2frame, data): |
---|
2214 | Â Â '''respond to selection of PWDR Index Peak List data |
---|
2215 | Â Â tree item. |
---|
2216 | Â Â ''' |
---|
2217 | Â Â bravaisSymb =Â ['Fm3m','Im3m','Pm3m','R3-H','P6/mmm','I4/mmm', |
---|
2218 | Â Â Â Â 'P4/mmm','Fmmm','Immm','Cmmm','Pmmm','C2/m','P2/m','P1'] |
---|
2219 |   IndexId = G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId, 'Index Peak List') |
---|
2220 |   Inst = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId, 'Instrument Parameters'))[0] |
---|
2221 | |
---|
2222 |   def RefreshIndexPeaksGrid(event): |
---|
2223 | Â Â Â Â r,c =Â event.GetRow(),event.GetCol() |
---|
2224 | Â Â Â Â peaks =Â G2frame.IndexPeaksTable.GetData() |
---|
2225 |     if c == 2: |
---|
2226 |       if peaks[r][c]: |
---|
2227 | Â Â Â Â Â Â Â Â peaks[r][c]Â =Â False |
---|
2228 | Â Â Â Â Â Â else: |
---|
2229 | Â Â Â Â Â Â Â Â peaks[r][c]Â =Â True |
---|
2230 | Â Â Â Â Â Â G2frame.IndexPeaksTable.SetData(peaks) |
---|
2231 | Â Â Â Â Â Â G2frame.PatternTree.SetItemPyData(IndexId,[peaks,data[1]]) |
---|
2232 | Â Â Â Â Â Â G2frame.dataDisplay.ForceRefresh() |
---|
2233 |       if 'PKS' in G2frame.PatternTree.GetItemText(G2frame.PatternId): |
---|
2234 | Â Â Â Â Â Â Â Â G2plt.PlotPowderLines(G2frame) |
---|
2235 | Â Â Â Â Â Â else: |
---|
2236 | Â Â Â Â Â Â Â Â G2plt.PlotPatterns(G2frame,plotType='PWDR') |
---|
2237 | Â Â Â Â Â Â |
---|
2238 |   def OnReload(event): |
---|
2239 | Â Â Â Â peaks =Â [] |
---|
2240 | Â Â Â Â sigs =Â [] |
---|
2241 |     Peaks = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId, 'Peak List')) |
---|
2242 |     for ip,peak in enumerate(Peaks['peaks']): |
---|
2243 | Â Â Â Â Â Â dsp =Â G2lat.Pos2dsp(Inst,peak[0]) |
---|
2244 | Â Â Â Â Â Â peaks.append([peak[0],peak[2],True,False,0,0,0,dsp,0.0])Â Â #SS? |
---|
2245 | Â Â Â Â Â Â try: |
---|
2246 | Â Â Â Â Â Â Â Â sig =Â Peaks['sigDict']['pos'+str(ip)] |
---|
2247 |       except KeyError: |
---|
2248 | Â Â Â Â Â Â Â Â sig =Â 0. |
---|
2249 | Â Â Â Â Â Â sigs.append(sig) |
---|
2250 | Â Â Â Â data =Â [peaks,sigs] |
---|
2251 | Â Â Â Â G2frame.PatternTree.SetItemPyData(IndexId,data) |
---|
2252 | Â Â Â Â UpdateIndexPeaksGrid(G2frame,data) |
---|
2253 | Â Â Â Â |
---|
2254 |   def KeyEditPickGrid(event): |
---|
2255 | Â Â Â Â colList =Â G2frame.dataDisplay.GetSelectedCols() |
---|
2256 | Â Â Â Â rowList =Â G2frame.dataDisplay.GetSelectedRows() |
---|
2257 | Â Â Â Â data =Â G2frame.PatternTree.GetItemPyData(IndexId) |
---|
2258 |     if event.GetKeyCode() == wx.WXK_RETURN: |
---|
2259 | Â Â Â Â Â Â event.Skip(True) |
---|
2260 |     elif event.GetKeyCode() == wx.WXK_CONTROL: |
---|
2261 | Â Â Â Â Â Â event.Skip(True) |
---|
2262 |     elif event.GetKeyCode() == wx.WXK_SHIFT: |
---|
2263 | Â Â Â Â Â Â event.Skip(True) |
---|
2264 |     elif colList: |
---|
2265 | Â Â Â Â Â Â G2frame.dataDisplay.ClearSelection() |
---|
2266 | Â Â Â Â Â Â key =Â event.GetKeyCode() |
---|
2267 |       for col in colList: |
---|
2268 |         if G2frame.IndexPeaksTable.GetColLabelValue(col) in ['use',]: |
---|
2269 |           if key == 89: #'Y' |
---|
2270 |             for row in range(G2frame.IndexPeaksTable.GetNumberRows()): data[0][row][col]=True |
---|
2271 |           elif key == 78: #'N' |
---|
2272 |             for row in range(G2frame.IndexPeaksTable.GetNumberRows()): data[0][row][col]=False |
---|
2273 | Â Â Â Â Â Â |
---|
2274 |   if G2frame.dataDisplay: |
---|
2275 | Â Â Â Â G2frame.dataFrame.Clear() |
---|
2276 |   if not G2frame.dataFrame.GetStatusBar(): |
---|
2277 | Â Â Â Â Status =Â G2frame.dataFrame.CreateStatusBar() |
---|
2278 |   if 'PWD' in G2frame.PatternTree.GetItemText(G2frame.PatternId): |
---|
2279 | Â Â Â Â G2gd.SetDataMenuBar(G2frame,G2frame.dataFrame.IndPeaksMenu) |
---|
2280 |     G2frame.Bind(wx.EVT_MENU, OnReload, id=G2gd.wxID_INDXRELOAD) |
---|
2281 | Â Â G2frame.dataFrame.IndexPeaks.Enable(False) |
---|
2282 | Â Â G2frame.IndexPeaksTable =Â [] |
---|
2283 |   if len(data[0]): |
---|
2284 | Â Â Â Â G2frame.dataFrame.IndexPeaks.Enable(True) |
---|
2285 |     Unit = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId, 'Unit Cells List')) |
---|
2286 |     if Unit: |
---|
2287 |       if len(Unit) == 4: #patch |
---|
2288 | Â Â Â Â Â Â Â Â Unit.append({}) |
---|
2289 | Â Â Â Â Â Â controls,bravais,cellist,dmin,ssopt =Â Unit |
---|
2290 | Â Â Â Â Â Â G2frame.HKL =Â [] |
---|
2291 |       if ssopt.get('Use',False): |
---|
2292 | Â Â Â Â Â Â Â Â cell =Â controls[6:12] |
---|
2293 | Â Â Â Â Â Â Â Â A =Â G2lat.cell2A(cell) |
---|
2294 | Â Â Â Â Â Â Â Â ibrav =Â bravaisSymb.index(controls[5]) |
---|
2295 | Â Â Â Â Â Â Â Â spc =Â controls[13] |
---|
2296 | Â Â Â Â Â Â Â Â SGData =Â G2spc.SpcGroup(spc)[1] |
---|
2297 | Â Â Â Â Â Â Â Â SSGData =Â G2spc.SSpcGroup(SGData,ssopt['ssSymb'])[1] |
---|
2298 | Â Â Â Â Â Â Â Â Vec =Â ssopt['ModVec'] |
---|
2299 | Â Â Â Â Â Â Â Â maxH =Â ssopt['maxH'] |
---|
2300 | Â Â Â Â Â Â Â Â G2frame.HKL =Â G2pwd.getHKLMpeak(dmin,Inst,SGData,SSGData,Vec,maxH,A) |
---|
2301 | Â Â Â Â Â Â Â Â data[0]Â =Â G2indx.IndexSSPeaks(data[0],G2frame.HKL)[1] |
---|
2302 | Â Â Â Â Â Â else:Â Â Â Â #select cell from table - no SS |
---|
2303 |         for i,cell in enumerate(cellist): |
---|
2304 |           if cell[-2]: |
---|
2305 | Â Â Â Â Â Â Â Â Â Â Â Â ibrav =Â cell[2] |
---|
2306 | Â Â Â Â Â Â Â Â Â Â Â Â A =Â G2lat.cell2A(cell[3:9]) |
---|
2307 | Â Â Â Â Â Â Â Â Â Â Â Â G2frame.HKL =Â G2lat.GenHBravais(dmin,ibrav,A) |
---|
2308 |             for hkl in G2frame.HKL: |
---|
2309 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â hkl.insert(4,G2lat.Dsp2pos(Inst,hkl[3])) |
---|
2310 | Â Â Â Â Â Â Â Â Â Â Â Â data[0]Â =Â G2indx.IndexPeaks(data[0],G2frame.HKL)[1] |
---|
2311 | Â Â Â Â Â Â Â Â Â Â Â Â break |
---|
2312 | Â Â rowLabels =Â [] |
---|
2313 |   for i in range(len(data[0])): rowLabels.append(str(i+1)) |
---|
2314 | Â Â colLabels =Â ['position','intensity','use','indexed','h','k','l','d-obs','d-calc'] |
---|
2315 | Â Â Types =Â [wg.GRID_VALUE_FLOAT+':10,4',wg.GRID_VALUE_FLOAT+':10,1',]+2*[wg.GRID_VALUE_BOOL,]+Â \ |
---|
2316 | Â Â Â Â 3*[wg.GRID_VALUE_LONG,]+2*[wg.GRID_VALUE_FLOAT+':10,5',] |
---|
2317 |   if len(data[0]) and len(data[0][0]) > 9: |
---|
2318 | Â Â Â Â colLabels =Â ['position','intensity','use','indexed','h','k','l','m','d-obs','d-calc'] |
---|
2319 | Â Â Â Â Types =Â [wg.GRID_VALUE_FLOAT+':10,4',wg.GRID_VALUE_FLOAT+':10,1',]+2*[wg.GRID_VALUE_BOOL,]+Â \ |
---|
2320 | Â Â Â Â Â Â 4*[wg.GRID_VALUE_LONG,]+2*[wg.GRID_VALUE_FLOAT+':10,5',] |
---|
2321 | Â Â G2frame.PatternTree.SetItemPyData(IndexId,data) |
---|
2322 | Â Â G2frame.IndexPeaksTable =Â G2G.Table(data[0],rowLabels=rowLabels,colLabels=colLabels,types=Types) |
---|
2323 | Â Â G2frame.dataFrame.SetLabel('Index Peak List') |
---|
2324 | Â Â G2frame.dataDisplay =Â G2G.GSGrid(parent=G2frame.dataFrame)Â Â Â Â Â Â Â Â |
---|
2325 |   G2frame.dataDisplay.SetTable(G2frame.IndexPeaksTable, True) |
---|
2326 | Â Â XY =Â [] |
---|
2327 | Â Â Sigs =Â [] |
---|
2328 |   for r in range(G2frame.dataDisplay.GetNumberRows()): |
---|
2329 |     for c in range(G2frame.dataDisplay.GetNumberCols()): |
---|
2330 |       if c == 2: |
---|
2331 | Â Â Â Â Â Â Â Â G2frame.dataDisplay.SetReadOnly(r,c,isReadOnly=False) |
---|
2332 | Â Â Â Â Â Â else: |
---|
2333 | Â Â Â Â Â Â Â Â G2frame.dataDisplay.SetReadOnly(r,c,isReadOnly=True) |
---|
2334 |     if data[0][r][2] and data[0][r][3]: |
---|
2335 | Â Â Â Â Â Â XY.append([data[0][r][-1],data[0][r][0]]) |
---|
2336 | Â Â Â Â Â Â try: |
---|
2337 | Â Â Â Â Â Â Â Â sig =Â data[1][r] |
---|
2338 |       except IndexError: |
---|
2339 | Â Â Â Â Â Â Â Â sig =Â 0. |
---|
2340 | Â Â Â Â Â Â Sigs.append(sig) |
---|
2341 |   G2frame.dataDisplay.Bind(wg.EVT_GRID_CELL_LEFT_CLICK, RefreshIndexPeaksGrid) |
---|
2342 |   G2frame.dataDisplay.Bind(wx.EVT_KEY_DOWN, KeyEditPickGrid)         |
---|
2343 | Â Â G2frame.dataDisplay.SetMargins(0,0) |
---|
2344 | Â Â G2frame.dataDisplay.AutoSizeColumns(False) |
---|
2345 | Â Â G2frame.dataFrame.setSizePosLeft([490,300]) |
---|
2346 |   if len(XY): |
---|
2347 | Â Â Â Â XY =Â np.array(XY) |
---|
2348 | Â Â Â Â G2plt.PlotCalib(G2frame,Inst,XY,Sigs,newPlot=True) |
---|
2349 | Â Â G2frame.dataFrame.SendSizeEvent() |
---|
2350 | Â Â Â |
---|
2351 | ################################################################################ |
---|
2352 | #####Â Unit cells |
---|
2353 | ################################################################################Â Â Â Â Â Â |
---|
2354 | Â Â Â Â |
---|
2355 | def UpdateUnitCellsGrid(G2frame, data): |
---|
2356 | Â Â '''respond to selection of PWDR Unit Cells data tree item. |
---|
2357 | Â Â ''' |
---|
2358 |   UnitCellsId = G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId, 'Unit Cells List') |
---|
2359 | Â Â SPGlist =Â G2spc.spglist |
---|
2360 | Â Â bravaisSymb =Â ['Fm3m','Im3m','Pm3m','R3-H','P6/mmm','I4/mmm', |
---|
2361 | Â Â Â Â 'P4/mmm','Fmmm','Immm','Cmmm','Pmmm','C2/m','P2/m','P1'] |
---|
2362 | Â Â spaceGroups =Â ['F m 3 m','I m 3 m','P m 3 m','R 3 m','P 6/m m m','I 4/m m m', |
---|
2363 | Â Â Â Â 'P 4/m m m','F m m m','I m m m','C m m m','P m m m','C 2/m','P 2/m','P -1'] |
---|
2364 |   Inst = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId, 'Instrument Parameters'))[0] |
---|
2365 |   if 'C' in Inst['Type'][0] or 'PKS' in Inst['Type'][0]: |
---|
2366 | Â Â Â Â wave =Â G2mth.getWave(Inst) |
---|
2367 | Â Â else: |
---|
2368 | Â Â Â Â difC =Â Inst['difC'][1] |
---|
2369 | Â Â |
---|
2370 |   def SetLattice(controls): |
---|
2371 | Â Â Â Â ibrav =Â bravaisSymb.index(controls[5]) |
---|
2372 |     if ibrav in [0,1,2]: |
---|
2373 | Â Â Â Â Â Â controls[7]Â =Â controls[8]Â =Â controls[6] |
---|
2374 | Â Â Â Â Â Â controls[9]Â =Â controls[10]Â =Â controls[11]Â =Â 90. |
---|
2375 |     elif ibrav in [3,4,5,6]: |
---|
2376 | Â Â Â Â Â Â controls[7]Â =Â controls[6] |
---|
2377 | Â Â Â Â Â Â controls[9]Â =Â controls[10]Â =Â controls[11]Â =Â 90. |
---|
2378 |       if ibrav in [3,4]: |
---|
2379 | Â Â Â Â Â Â Â Â controls[11]Â =Â 120. |
---|
2380 |     elif ibrav in [7,8,9,10]: |
---|
2381 | Â Â Â Â Â Â controls[9]Â =Â controls[10]Â =Â controls[11]Â =Â 90. |
---|
2382 |     elif ibrav in [11,12]: |
---|
2383 |       controls[9] = controls[11] = 90. # b unique |
---|
2384 |     if len(controls) < 13: controls.append(0) |
---|
2385 | Â Â Â Â controls[12]Â =Â G2lat.calc_V(G2lat.cell2A(controls[6:12])) |
---|
2386 |     return ibrav |
---|
2387 | Â Â Â Â |
---|
2388 |   def OnNcNo(event): |
---|
2389 | Â Â Â Â controls[2]Â =Â NcNo.GetValue() |
---|
2390 | Â Â Â Â |
---|
2391 |   def OnIfX20(event): |
---|
2392 | Â Â Â Â G2frame.ifX20 =Â x20.GetValue() |
---|
2393 | Â Â Â Â |
---|
2394 |   def OnStartVol(event): |
---|
2395 | Â Â Â Â try: |
---|
2396 | Â Â Â Â Â Â stVol =Â int(float(startVol.GetValue())) |
---|
2397 |       if stVol < 25: |
---|
2398 |         raise ValueError |
---|
2399 |     except ValueError: |
---|
2400 | Â Â Â Â Â Â stVol =Â 25 |
---|
2401 | Â Â Â Â controls[3]Â =Â stVol |
---|
2402 | Â Â Â Â startVol.SetValue("%d"%(stVol)) |
---|
2403 | Â Â Â Â |
---|
2404 |   def OnBravais(event): |
---|
2405 | Â Â Â Â Obj =Â event.GetEventObject() |
---|
2406 | Â Â Â Â bravais[bravList.index(Obj.GetId())]Â =Â Obj.GetValue() |
---|
2407 | Â Â Â Â |
---|
2408 |   def OnZero(event): |
---|
2409 | Â Â Â Â try: |
---|
2410 | Â Â Â Â Â Â Zero =Â min(5.0,max(-5.0,float(zero.GetValue()))) |
---|
2411 |     except ValueError: |
---|
2412 | Â Â Â Â Â Â Zero =Â 0.0 |
---|
2413 | Â Â Â Â controls[1]Â =Â Zero |
---|
2414 | Â Â Â Â zero.SetValue("%.4f"%(Zero)) |
---|
2415 | Â Â Â Â |
---|
2416 |   def OnZeroVar(event): |
---|
2417 | Â Â Â Â controls[0]Â =Â zeroVar.GetValue() |
---|
2418 | Â Â Â Â |
---|
2419 |   def OnSSopt(event): |
---|
2420 |     if controls[5] in ['Fm3m','Im3m','Pm3m']: |
---|
2421 | Â Â Â Â Â Â SSopt.SetValue(False) |
---|
2422 |       G2frame.ErrorDialog('Cubic lattice', 'Superlattice not allowed for a cubic lattice') |
---|
2423 | Â Â Â Â Â Â return |
---|
2424 | Â Â Â Â ssopt['Use']Â =Â SSopt.GetValue() |
---|
2425 |     if 'ssSymb' not in ssopt: |
---|
2426 | Â Â Â Â Â Â ssopt.update({'ssSymb':'(abg)','ModVec':[0.1,0.1,0.1],'maxH':1}) |
---|
2427 | Â Â Â Â wx.CallAfter(UpdateUnitCellsGrid,G2frame,data) |
---|
2428 | Â Â Â Â |
---|
2429 |   def OnSelMG(event): |
---|
2430 | Â Â Â Â ssopt['ssSymb']Â =Â selMG.GetValue() |
---|
2431 | Â Â Â Â Vec =Â ssopt['ModVec'] |
---|
2432 | Â Â Â Â modS =Â G2spc.splitSSsym(ssopt['ssSymb'])[0] |
---|
2433 | Â Â Â Â ssopt['ModVec']Â =Â G2spc.SSGModCheck(Vec,modS)[0] |
---|
2434 |     print ' Selecting: ',controls[13],ssopt['ssSymb'], 'maxH:',ssopt['maxH'] |
---|
2435 | Â Â Â Â OnHklShow(event) |
---|
2436 | Â Â Â Â wx.CallAfter(UpdateUnitCellsGrid,G2frame,data) |
---|
2437 | Â Â Â Â |
---|
2438 |   def OnModVal(event): |
---|
2439 | Â Â Â Â Obj =Â event.GetEventObject() |
---|
2440 | Â Â Â Â ObjId =Â Obj.GetId() |
---|
2441 | Â Â Â Â Id =Â Indx[ObjId] |
---|
2442 | Â Â Â Â try: |
---|
2443 | Â Â Â Â Â Â value =Â min(1.0,max(0.,float(Obj.GetValue()))) |
---|
2444 |     except ValueError: |
---|
2445 | Â Â Â Â Â Â value =Â ssopt['ModVec'][Id] |
---|
2446 | Â Â Â Â Obj.SetValue('%.4f'%(value)) |
---|
2447 | Â Â Â Â ssopt['ModVec'][Id]Â =Â value |
---|
2448 | Â Â Â Â OnHklShow(event) |
---|
2449 | Â Â Â Â |
---|
2450 |   def OnMoveMod(event): |
---|
2451 | Â Â Â Â Obj =Â event.GetEventObject() |
---|
2452 | Â Â Â Â ObjId =Â Obj.GetId() |
---|
2453 | Â Â Â Â Id,valObj =Â Indx[ObjId] |
---|
2454 | Â Â Â Â move =Â Obj.GetValue()*0.0005 |
---|
2455 | Â Â Â Â Obj.SetValue(0) |
---|
2456 | Â Â Â Â value =Â min(1.0,max(.0,float(valObj.GetValue())+move)) |
---|
2457 | Â Â Â Â valObj.SetValue('%.4f'%(value))Â |
---|
2458 | Â Â Â Â ssopt['ModVec'][Id]Â =Â value |
---|
2459 | Â Â Â Â OnHklShow(event) |
---|
2460 | Â Â Â Â |
---|
2461 |   def OnMaxMH(event): |
---|
2462 | Â Â Â Â ssopt['maxH']Â =Â int(maxMH.GetValue()) |
---|
2463 |     print ' Selecting: ',controls[13],ssopt['ssSymb'], 'maxH:',ssopt['maxH'] |
---|
2464 | Â Â Â Â OnHklShow(event) |
---|
2465 | Â Â Â Â |
---|
2466 |   def OnFindMV(event): |
---|
2467 | Â Â Â Â Peaks =Â np.copy(peaks[0]) |
---|
2468 |     print ' Trying: ',controls[13],ssopt['ssSymb'], 'maxH:',ssopt['maxH'] |
---|
2469 | Â Â Â Â dlg =Â wx.ProgressDialog('Elapsed time','Modulation vector search', |
---|
2470 | Â Â Â Â Â Â style =Â wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE) |
---|
2471 | Â Â Â Â try: |
---|
2472 | Â Â Â Â Â Â ssopt['ModVec']Â =Â G2indx.findMV(Peaks,controls,ssopt,Inst,dlg) |
---|
2473 | Â Â Â Â finally: |
---|
2474 | Â Â Â Â Â Â dlg.Destroy() |
---|
2475 | Â Â Â Â OnHklShow(event) |
---|
2476 | Â Â Â Â wx.CallAfter(UpdateUnitCellsGrid,G2frame,data) |
---|
2477 | Â Â Â Â |
---|
2478 |   def OnBravSel(event): |
---|
2479 | Â Â Â Â brav =Â bravSel.GetString(bravSel.GetSelection()) |
---|
2480 | Â Â Â Â controls[5]Â =Â brav |
---|
2481 | Â Â Â Â controls[13]Â =Â SPGlist[brav][0]Â Â Â Â |
---|
2482 | Â Â Â Â wx.CallAfter(UpdateUnitCellsGrid,G2frame,data) |
---|
2483 | Â Â Â Â |
---|
2484 |   def OnSpcSel(event): |
---|
2485 | Â Â Â Â controls[13]Â =Â spcSel.GetString(spcSel.GetSelection()) |
---|
2486 | Â Â Â Â G2frame.dataFrame.RefineCell.Enable(True) |
---|
2487 | Â Â Â Â OnHklShow(event) |
---|
2488 | Â Â Â Â |
---|
2489 |   def SetCellValue(Obj,ObjId,value): |
---|
2490 | Â Â Â Â ibrav =Â bravaisSymb.index(controls[5]) |
---|
2491 |     if ibrav in [0,1,2]: |
---|
2492 | Â Â Â Â Â Â controls[6]Â =Â controls[7]Â =Â controls[8]Â =Â value |
---|
2493 | Â Â Â Â Â Â controls[9]Â =Â controls[10]Â =Â controls[11]Â =Â 90.0 |
---|
2494 | Â Â Â Â Â Â Obj.SetValue("%.5f"%(controls[6])) |
---|
2495 |     elif ibrav in [3,4,5,6]: |
---|
2496 |       if ObjId == 0: |
---|
2497 | Â Â Â Â Â Â Â Â controls[6]Â =Â controls[7]Â =Â value |
---|
2498 | Â Â Â Â Â Â Â Â Obj.SetValue("%.5f"%(controls[6])) |
---|
2499 | Â Â Â Â Â Â else: |
---|
2500 | Â Â Â Â Â Â Â Â controls[8]Â =Â value |
---|
2501 | Â Â Â Â Â Â Â Â Obj.SetValue("%.5f"%(controls[8])) |
---|
2502 | Â Â Â Â Â Â controls[9]Â =Â controls[10]Â =Â controls[11]Â =Â 90.0 |
---|
2503 |       if ibrav in [3,4]: |
---|
2504 | Â Â Â Â Â Â Â Â controls[11]Â =Â 120. |
---|
2505 |     elif ibrav in [7,8,9,10]: |
---|
2506 | Â Â Â Â Â Â controls[6+ObjId]Â =Â value |
---|
2507 | Â Â Â Â Â Â Obj.SetValue("%.5f"%(controls[6+ObjId])) |
---|
2508 | Â Â Â Â Â Â controls[9]Â =Â controls[10]Â =Â controls[11]Â =Â 90.0 |
---|
2509 |     elif ibrav in [11,12]: |
---|
2510 | Â Â Â Â Â Â controls[9]Â =Â controls[11]Â =Â 90.0 |
---|
2511 |       if ObjId != 3: |
---|
2512 | Â Â Â Â Â Â Â Â controls[6+ObjId]Â =Â value |
---|
2513 | Â Â Â Â Â Â Â Â Obj.SetValue("%.5f"%(controls[6+ObjId])) |
---|
2514 | Â Â Â Â Â Â else: |
---|
2515 | Â Â Â Â Â Â Â Â controls[10]Â =Â value |
---|
2516 | Â Â Â Â Â Â Â Â Obj.SetValue("%.3f"%(controls[10])) |
---|
2517 | Â Â Â Â else: |
---|
2518 | Â Â Â Â Â Â controls[6+ObjId]Â =Â value |
---|
2519 |       if ObjId < 3: |
---|
2520 | Â Â Â Â Â Â Â Â Obj.SetValue("%.5f"%(controls[6+ObjId])) |
---|
2521 | Â Â Â Â Â Â else: |
---|
2522 | Â Â Â Â Â Â Â Â Obj.SetValue("%.3f"%(controls[6+ObjId])) |
---|
2523 | Â Â Â Â controls[12]Â =Â G2lat.calc_V(G2lat.cell2A(controls[6:12])) |
---|
2524 | Â Â Â Â volVal.SetValue("%.3f"%(controls[12])) |
---|
2525 | Â Â Â Â |
---|
2526 |   def OnMoveCell(event): |
---|
2527 | Â Â Â Â Obj =Â event.GetEventObject() |
---|
2528 | Â Â Â Â ObjId =Â cellList.index(Obj.GetId()) |
---|
2529 | Â Â Â Â valObj =Â valDict[Obj.GetId()] |
---|
2530 |     if ObjId/2 < 3: |
---|
2531 | Â Â Â Â Â Â move =Â Obj.GetValue()*0.01 |
---|
2532 | Â Â Â Â else: |
---|
2533 | Â Â Â Â Â Â move =Â Obj.GetValue()*0.1 |
---|
2534 | Â Â Â Â Obj.SetValue(0) |
---|
2535 |     value = float(valObj.GetValue())+move |
---|
2536 | Â Â Â Â SetCellValue(valObj,ObjId/2,value) |
---|
2537 | Â Â Â Â OnHklShow(event) |
---|
2538 | Â Â Â Â |
---|
2539 |   def OnExportCells(event): |
---|
2540 |     dlg = wx.FileDialog(G2frame, 'Choose Indexing Result csv file', '.', '', |
---|
2541 | Â Â Â Â Â Â 'indexing result file (*.csv)|*.csv',wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT|wx.CHANGE_DIR) |
---|
2542 | Â Â Â Â try: |
---|
2543 |       if dlg.ShowModal() == wx.ID_OK: |
---|
2544 | Â Â Â Â Â Â Â Â filename =Â dlg.GetPath() |
---|
2545 | Â Â Â Â Â Â Â Â filename =Â os.path.splitext(filename)[0]+'.csv' |
---|
2546 | Â Â Â Â Â Â Â Â File =Â open(filename,'w') |
---|
2547 | Â Â Â Â Â Â Â Â names =Â 'M20,X20,Bravais,a,b,c,alpha,beta,gamma,volume\n' |
---|
2548 | Â Â Â Â Â Â Â Â File.write(names) |
---|
2549 | Â Â Â Â Â Â Â Â fmt =Â '%.2f,%d,%s,%.4f,%.4f,%.4f,%.2f,%.2f,%.2f,%.3f\n' |
---|
2550 |         for cell in cells: |
---|
2551 |           File.write(fmt%(cell[0],cell[1],bravaisSymb[cell[2]], cell[3],cell[4],cell[5], cell[6],cell[7],cell[8],cell[9])) |
---|
2552 | Â Â Â Â Â Â Â Â File.close() |
---|
2553 | Â Â Â Â finally: |
---|
2554 | Â Â Â Â Â Â dlg.Destroy() |
---|
2555 | Â Â Â Â |
---|
2556 |   def OnCellChange(event): |
---|
2557 | Â Â Â Â Obj =Â event.GetEventObject() |
---|
2558 | Â Â Â Â ObjId =Â cellList.index(Obj.GetId()) |
---|
2559 | Â Â Â Â try: |
---|
2560 | Â Â Â Â Â Â value =Â max(1.0,float(Obj.GetValue())) |
---|
2561 |     except ValueError: |
---|
2562 |       if ObjId/2 < 3:        #bad cell edge - reset |
---|
2563 | Â Â Â Â Â Â Â Â value =Â controls[6+ObjId/2] |
---|
2564 | Â Â Â Â Â Â else:Â Â Â Â Â Â Â Â Â Â Â Â #bad angle |
---|
2565 | Â Â Â Â Â Â Â Â value =Â 90. |
---|
2566 | Â Â Â Â SetCellValue(Obj,ObjId/2,value) |
---|
2567 | Â Â Â Â |
---|
2568 |   def OnHklShow(event): |
---|
2569 | Â Â Â Â PatternId =Â G2frame.PatternId |
---|
2570 |     PickId = G2frame.PickId  |
---|
2571 |     peaks = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Index Peak List')) |
---|
2572 |     limits = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Limits'))[1] |
---|
2573 |     controls,bravais,cells,dmin,ssopt = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Unit Cells List')) |
---|
2574 | Â Â Â Â cell =Â controls[6:12] |
---|
2575 | Â Â Â Â A =Â G2lat.cell2A(cell) |
---|
2576 | Â Â Â Â ibrav =Â bravaisSymb.index(controls[5]) |
---|
2577 | Â Â Â Â spc =Â controls[13] |
---|
2578 | Â Â Â Â SGData =Â G2spc.SpcGroup(spc)[1] |
---|
2579 |     if 'C' in Inst['Type'][0]: |
---|
2580 | Â Â Â Â Â Â dmin =Â G2lat.Pos2dsp(Inst,limits[1]) |
---|
2581 | Â Â Â Â else:Â Â #TOF - use other limit! |
---|
2582 | Â Â Â Â Â Â dmin =Â G2lat.Pos2dsp(Inst,limits[0]) |
---|
2583 |     if ssopt.get('Use',False): |
---|
2584 | Â Â Â Â Â Â dmin =Â peaks[0][-1][8] |
---|
2585 | Â Â Â Â Â Â SSGData =Â G2spc.SSpcGroup(SGData,ssopt['ssSymb'])[1] |
---|
2586 | Â Â Â Â Â Â Vec =Â ssopt['ModVec'] |
---|
2587 | Â Â Â Â Â Â maxH =Â ssopt['maxH'] |
---|
2588 | Â Â Â Â Â Â G2frame.HKL =Â G2pwd.getHKLMpeak(dmin,Inst,SGData,SSGData,Vec,maxH,A) |
---|
2589 | Â Â Â Â Â Â peaks =Â [G2indx.IndexSSPeaks(peaks[0],G2frame.HKL)[1],peaks[1]]Â Â #keep esds from peak fit |
---|
2590 | Â Â Â Â Â Â M20,X20 =Â G2indx.calc_M20SS(peaks[0],G2frame.HKL) |
---|
2591 | Â Â Â Â else: |
---|
2592 |       if len(peaks[0]): |
---|
2593 | Â Â Â Â Â Â Â Â dmin =Â peaks[0][-1][7] |
---|
2594 | Â Â Â Â Â Â Â Â G2frame.HKL =Â G2pwd.getHKLpeak(dmin,SGData,A,Inst) |
---|
2595 | Â Â Â Â Â Â Â Â peaks =Â [G2indx.IndexPeaks(peaks[0],G2frame.HKL)[1],peaks[1]]Â Â #keep esds from peak fit |
---|
2596 | Â Â Â Â Â Â Â Â M20,X20 =Â G2indx.calc_M20(peaks[0],G2frame.HKL) |
---|
2597 | Â Â Â Â Â Â else: |
---|
2598 | Â Â Â Â Â Â Â Â M20 =Â X20 =Â 0. |
---|
2599 | Â Â Â Â Â Â Â Â G2frame.HKL =Â G2pwd.getHKLpeak(dmin,SGData,A,Inst) |
---|
2600 |     if len(G2frame.HKL): |
---|
2601 |       print ' new M20,X20: %.2f %d fraction found: %.3f'%(M20,X20,float(len(peaks[0]))/len(G2frame.HKL)) |
---|
2602 |     G2frame.PatternTree.SetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Index Peak List'),peaks) |
---|
2603 |     if 'PKS' in G2frame.PatternTree.GetItemText(G2frame.PatternId): |
---|
2604 | Â Â Â Â Â Â G2plt.PlotPowderLines(G2frame) |
---|
2605 | Â Â Â Â else: |
---|
2606 | Â Â Â Â Â Â G2plt.PlotPatterns(G2frame) |
---|
2607 | Â Â Â Â Â Â |
---|
2608 |   def OnSortCells(event): |
---|
2609 | Â Â Â Â controls,bravais,cells,dmin,ssopt =Â G2frame.PatternTree.GetItemPyData(UnitCellsId) |
---|
2610 | Â Â Â Â c =Â event.GetCol() |
---|
2611 |     if colLabels[c] == 'M20': |
---|
2612 | Â Â Â Â Â Â cells =Â G2indx.sortM20(cells) |
---|
2613 |     elif colLabels[c] in ['X20','Bravais','a','b','c','alpha','beta','gamma','Volume']: |
---|
2614 |       if c == 1: |
---|
2615 | Â Â Â Â Â Â Â Â c +=Â 1Â #X20 before Use |
---|
2616 | Â Â Â Â Â Â cells =Â G2indx.sortCells(cells,c-1)Â Â Â #an extra column (Use) not in cells |
---|
2617 | Â Â Â Â else: |
---|
2618 | Â Â Â Â Â Â return |
---|
2619 | Â Â Â Â data =Â [controls,bravais,cells,dmin,ssopt] |
---|
2620 | Â Â Â Â G2frame.PatternTree.SetItemPyData(UnitCellsId,data) |
---|
2621 | Â Â Â Â wx.CallAfter(UpdateUnitCellsGrid,G2frame,data) |
---|
2622 | Â Â Â Â |
---|
2623 |   def CopyUnitCell(event): |
---|
2624 | Â Â Â Â controls,bravais,cells,dmin,ssopt =Â G2frame.PatternTree.GetItemPyData(UnitCellsId) |
---|
2625 |     for Cell in cells: |
---|
2626 |       if Cell[-2]: |
---|
2627 | Â Â Â Â Â Â Â Â break |
---|
2628 | Â Â Â Â cell =Â Cell[2:9] |
---|
2629 | Â Â Â Â controls[4]Â =Â 1 |
---|
2630 | Â Â Â Â controls[5]Â =Â bravaisSymb[cell[0]] |
---|
2631 | Â Â Â Â controls[6:12]Â =Â cell[1:8] |
---|
2632 | Â Â Â Â controls[12]Â =Â G2lat.calc_V(G2lat.cell2A(controls[6:12])) |
---|
2633 | Â Â Â Â controls[13]Â =Â spaceGroups[bravaisSymb.index(controls[5])] |
---|
2634 | Â Â Â Â G2frame.PatternTree.SetItemPyData(UnitCellsId,[controls,bravais,cells,dmin,ssopt]) |
---|
2635 | Â Â Â Â G2frame.dataFrame.RefineCell.Enable(True) |
---|
2636 | Â Â Â Â wx.CallAfter(UpdateUnitCellsGrid,G2frame,data)Â Â Â Â |
---|
2637 | Â Â Â Â Â Â Â Â |
---|
2638 |   def RefineCell(event): |
---|
2639 | Â Â Â Â |
---|
2640 |     def cellPrint(ibrav,A): |
---|
2641 | Â Â Â Â Â Â cell =Â G2lat.A2cell(A) |
---|
2642 | Â Â Â Â Â Â Vol =Â G2lat.calc_V(A) |
---|
2643 |       if ibrav in [0,1,2]: |
---|
2644 |         print " %s%10.6f" % ('a =',cell[0]) |
---|
2645 |       elif ibrav in [3,4,5,6]: |
---|
2646 |         print " %s%10.6f %s%10.6f %s%12.3f" % ('a =',cell[0],' c =',cell[2],' volume =',Vol) |
---|
2647 |       elif ibrav in [7,8,9,10]: |
---|
2648 |         print " %s%10.6f %s%10.6f %s%10.6f %s%12.3f" % ('a =',cell[0],'b =',cell[1],'c =',cell[2],' volume =',Vol) |
---|
2649 |       elif ibrav in [11,12]: |
---|
2650 |         print " %s%10.6f %s%10.6f %s%10.6f %s%8.3f %s%12.3f" % ('a =',cell[0],'b =',cell[1],'c =',cell[2],'beta =',cell[4],' volume =',Vol) |
---|
2651 | Â Â Â Â Â Â else: |
---|
2652 |         print " %s%10.6f %s%10.6f %s%10.6f" % ('a =',cell[0],'b =',cell[1],'c =',cell[2]) |
---|
2653 |         print " %s%8.3f %s%8.3f %s%8.3f %s%12.3f" % ('alpha =',cell[3],'beta =',cell[4],'gamma =',cell[5],' volume =',Vol) |
---|
2654 | Â Â Â Â Â Â Â Â |
---|
2655 |     def vecPrint(Vec): |
---|
2656 |       print ' %s %10.5f %10.5f %10.5f'%('Modulation vector:',Vec[0],Vec[1],Vec[2]) |
---|
2657 | Â Â Â Â Â Â Â |
---|
2658 | Â Â Â Â PatternId =Â G2frame.PatternId |
---|
2659 |     PickId = G2frame.PickId  |
---|
2660 |     peaks = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Index Peak List')) |
---|
2661 |     if not len(peaks[0]): |
---|
2662 |       G2frame.ErrorDialog('No peaks!', 'Nothing to refine!') |
---|
2663 |       return    |
---|
2664 |     print ' Refine cell' |
---|
2665 |     controls,bravais,cells,dmin,ssopt = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Unit Cells List')) |
---|
2666 | Â Â Â Â cell =Â controls[6:12] |
---|
2667 | Â Â Â Â A =Â G2lat.cell2A(cell) |
---|
2668 | Â Â Â Â ibrav =Â bravaisSymb.index(controls[5]) |
---|
2669 | Â Â Â Â SGData =Â G2spc.SpcGroup(controls[13])[1] |
---|
2670 | Â Â Â Â dmin =Â G2indx.getDmin(peaks[0])-0.005 |
---|
2671 |     if 'C' in Inst['Type'][0]: |
---|
2672 |       if ssopt.get('Use',False): |
---|
2673 |         vecFlags = [True if x in ssopt['ssSymb'] else False for x in ['a','b','g']] |
---|
2674 | Â Â Â Â Â Â Â Â SSGData =Â G2spc.SSpcGroup(SGData,ssopt['ssSymb'])[1] |
---|
2675 | Â Â Â Â Â Â Â Â G2frame.HKL =Â G2pwd.getHKLMpeak(dmin,Inst,SGData,SSGData,ssopt['ModVec'],ssopt['maxH'],A) |
---|
2676 | Â Â Â Â Â Â Â Â peaks =Â [G2indx.IndexSSPeaks(peaks[0],G2frame.HKL)[1],peaks[1]]Â Â #put peak fit esds back in peaks |
---|
2677 | Â Â Â Â Â Â Â Â Lhkl,M20,X20,Aref,Vec,Zero =Â \ |
---|
2678 | Â Â Â Â Â Â Â Â Â Â G2indx.refinePeaksZSS(peaks[0],wave,Inst,SGData,SSGData,ssopt['maxH'],ibrav,A,ssopt['ModVec'],vecFlags,controls[1],controls[0]) |
---|
2679 | Â Â Â Â Â Â else: |
---|
2680 | Â Â Â Â Â Â Â Â G2frame.HKL =Â G2pwd.getHKLpeak(dmin,SGData,A,Inst) |
---|
2681 | Â Â Â Â Â Â Â Â peaks =Â [G2indx.IndexPeaks(peaks[0],G2frame.HKL)[1],peaks[1]]Â Â #put peak fit esds back in peaks |
---|
2682 | Â Â Â Â Â Â Â Â Lhkl,M20,X20,Aref,Zero =Â G2indx.refinePeaksZ(peaks[0],wave,ibrav,A,controls[1],controls[0]) |
---|
2683 | Â Â Â Â else:Â Â #'T'OF - doesn't seem to work |
---|
2684 | Â Â Â Â Â Â G2frame.HKL =Â G2pwd.getHKLpeak(dmin,SGData,A,Inst) |
---|
2685 | Â Â Â Â Â Â peaks =Â [G2indx.IndexPeaks(peaks[0],G2frame.HKL)[1],peaks[1]]Â Â #put peak fit esds back in peaks |
---|
2686 | Â Â Â Â Â Â Lhkl,M20,X20,Aref,Zero =Â G2indx.refinePeaksT(peaks[0],difC,ibrav,A,controls[1],controls[0])Â Â Â Â Â Â |
---|
2687 | Â Â Â Â controls[1]Â =Â Zero |
---|
2688 | Â Â Â Â controls[6:12]Â =Â G2lat.A2cell(Aref) |
---|
2689 | Â Â Â Â controls[12]Â =Â G2lat.calc_V(Aref) |
---|
2690 | Â Â Â Â cells =Â G2frame.PatternTree.GetItemPyData(UnitCellsId)[2] |
---|
2691 |     for cell in cells: |
---|
2692 | Â Â Â Â Â Â cell[-2]Â =Â False |
---|
2693 | Â Â Â Â cells.insert(0,[M20,X20,ibrav]+controls[6:13]+[True,False]) |
---|
2694 |     if ssopt.get('Use',False): |
---|
2695 | Â Â Â Â Â Â ssopt['ModVec']Â =Â Vec |
---|
2696 | Â Â Â Â Â Â G2frame.HKL =Â G2pwd.getHKLMpeak(dmin,Inst,SGData,SSGData,ssopt['ModVec'],ssopt['maxH'],A) |
---|
2697 | Â Â Â Â else: |
---|
2698 | Â Â Â Â Â Â G2frame.HKL =Â G2pwd.getHKLpeak(dmin,SGData,A,Inst) |
---|
2699 | Â Â Â Â data =Â [controls,bravais,cells,dmin,ssopt] |
---|
2700 |     G2frame.PatternTree.SetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Unit Cells List'),data) |
---|
2701 |     print " %s%10.3f" % ('refinement M20 = ',M20) |
---|
2702 |     print ' unindexed lines = ',X20 |
---|
2703 | Â Â Â Â cellPrint(ibrav,Aref) |
---|
2704 | Â Â Â Â ip =Â 4 |
---|
2705 |     if ssopt.get('Use',False): |
---|
2706 | Â Â Â Â Â Â vecPrint(Vec) |
---|
2707 | Â Â Â Â Â Â ip =Â 5 |
---|
2708 |     for hkl in G2frame.HKL: |
---|
2709 | Â Â Â Â Â Â hkl[ip]Â =Â G2lat.Dsp2pos(Inst,hkl[ip-1])+controls[1] |
---|
2710 |     if 'PKS' in G2frame.PatternTree.GetItemText(G2frame.PatternId): |
---|
2711 | Â Â Â Â Â Â G2plt.PlotPowderLines(G2frame) |
---|
2712 | Â Â Â Â else: |
---|
2713 | Â Â Â Â Â Â G2plt.PlotPatterns(G2frame) |
---|
2714 | Â Â Â Â wx.CallAfter(UpdateUnitCellsGrid,G2frame,data) |
---|
2715 | Â Â Â Â |
---|
2716 |   def IndexPeaks(event): |
---|
2717 |     PatternId = G2frame.PatternId  |
---|
2718 |     print 'Peak Indexing' |
---|
2719 | Â Â Â Â keepcells =Â [] |
---|
2720 | Â Â Â Â try: |
---|
2721 |       controls,bravais,cells,dmin,ssopt = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Unit Cells List')) |
---|
2722 |       for cell in cells: |
---|
2723 |         if cell[11]: |
---|
2724 |           cell[10] = False  #clear selection flag on keepers |
---|
2725 | Â Â Â Â Â Â Â Â Â Â keepcells.append(cell) |
---|
2726 |     except IndexError: |
---|
2727 | Â Â Â Â Â Â pass |
---|
2728 |     except ValueError: |
---|
2729 | Â Â Â Â Â Â G2frame.ErrorDialog('Error','Need to set controls in Unit Cell List first') |
---|
2730 | Â Â Â Â Â Â return |
---|
2731 |     if ssopt.get('Use',False): |
---|
2732 | Â Â Â Â Â Â G2frame.ErrorDialog('Super lattice error','Indexing not available for super lattices') |
---|
2733 | Â Â Â Â Â Â return |
---|
2734 |     if True not in bravais: |
---|
2735 | Â Â Â Â Â Â G2frame.ErrorDialog('Error','No Bravais lattices selected') |
---|
2736 | Â Â Â Â Â Â return |
---|
2737 |     if not len(peaks[0]): |
---|
2738 | Â Â Â Â Â Â G2frame.ErrorDialog('Error','Index Peak List is empty') |
---|
2739 | Â Â Â Â Â Â return |
---|
2740 |     if len(peaks[0][0]) > 9: |
---|
2741 | Â Â Â Â Â Â G2frame.ErrorDialog('Error','You need to reload Index Peaks List first') |
---|
2742 | Â Â Â Â Â Â return |
---|
2743 | Â Â Â Â G2frame.dataFrame.CopyCell.Enable(False) |
---|
2744 | Â Â Â Â G2frame.dataFrame.RefineCell.Enable(False) |
---|
2745 | Â Â Â Â OK,dmin,newcells =Â G2indx.DoIndexPeaks(peaks[0],controls,bravais,G2frame.ifX20) |
---|
2746 | Â Â Â Â cells =Â keepcells+newcells |
---|
2747 | Â Â Â Â cells =Â G2indx.sortM20(cells) |
---|
2748 |     if OK: |
---|
2749 |       cells[0][10] = True     #select best M20 |
---|
2750 | Â Â Â Â Â Â data =Â [controls,bravais,cells,dmin,ssopt] |
---|
2751 |       G2frame.PatternTree.SetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Unit Cells List'),data) |
---|
2752 | Â Â Â Â Â Â bestCell =Â cells[0] |
---|
2753 |       if bestCell[0] > 10.: |
---|
2754 | Â Â Â Â Â Â Â Â G2frame.HKL =Â G2lat.GenHBravais(dmin,bestCell[2],G2lat.cell2A(bestCell[3:9])) |
---|
2755 |         for hkl in G2frame.HKL: |
---|
2756 | Â Â Â Â Â Â Â Â Â Â hkl.insert(4,G2lat.Dsp2pos(Inst,hkl[3])+controls[1]) |
---|
2757 |         if 'PKS' in G2frame.PatternTree.GetItemText(G2frame.PatternId): |
---|
2758 | Â Â Â Â Â Â Â Â Â Â G2plt.PlotPowderLines(G2frame) |
---|
2759 | Â Â Â Â Â Â Â Â else: |
---|
2760 | Â Â Â Â Â Â Â Â Â Â G2plt.PlotPatterns(G2frame) |
---|
2761 | Â Â Â Â Â Â G2frame.dataFrame.CopyCell.Enable(True) |
---|
2762 | Â Â Â Â Â Â G2frame.dataFrame.IndexPeaks.Enable(True) |
---|
2763 | Â Â Â Â Â Â G2frame.dataFrame.MakeNewPhase.Enable(True) |
---|
2764 | Â Â Â Â Â Â G2frame.ifX20 =Â True |
---|
2765 | Â Â Â Â Â Â wx.CallAfter(UpdateUnitCellsGrid,G2frame,data) |
---|
2766 | Â Â Â Â Â Â Â Â |
---|
2767 |   def RefreshUnitCellsGrid(event): |
---|
2768 | Â Â Â Â data =Â G2frame.PatternTree.GetItemPyData(UnitCellsId) |
---|
2769 | Â Â Â Â cells,dmin =Â data[2:4] |
---|
2770 | Â Â Â Â r,c =Â event.GetRow(),event.GetCol() |
---|
2771 |     if cells: |
---|
2772 |       if c == 2: |
---|
2773 |         for i in range(len(cells)): |
---|
2774 | Â Â Â Â Â Â Â Â Â Â cells[i][-2]Â =Â False |
---|
2775 | Â Â Â Â Â Â Â Â Â Â UnitCellsTable.SetValue(i,c,False) |
---|
2776 | Â Â Â Â Â Â Â Â UnitCellsTable.SetValue(r,c,True) |
---|
2777 | Â Â Â Â Â Â Â Â gridDisplay.Refresh() |
---|
2778 | Â Â Â Â Â Â Â Â cells[r][-2]Â =Â True |
---|
2779 | Â Â Â Â Â Â Â Â ibrav =Â cells[r][2] |
---|
2780 | Â Â Â Â Â Â Â Â A =Â G2lat.cell2A(cells[r][3:9]) |
---|
2781 | Â Â Â Â Â Â Â Â G2frame.HKL =Â G2lat.GenHBravais(dmin,ibrav,A) |
---|
2782 |         for hkl in G2frame.HKL: |
---|
2783 | Â Â Â Â Â Â Â Â Â Â hkl.insert(4,G2lat.Dsp2pos(Inst,hkl[3])+controls[1]) |
---|
2784 |         if 'PKS' in G2frame.PatternTree.GetItemText(G2frame.PatternId): |
---|
2785 | Â Â Â Â Â Â Â Â Â Â G2plt.PlotPowderLines(G2frame) |
---|
2786 | Â Â Â Â Â Â Â Â else: |
---|
2787 | Â Â Â Â Â Â Â Â Â Â G2plt.PlotPatterns(G2frame) |
---|
2788 |       elif c == 11: |
---|
2789 |         if UnitCellsTable.GetValue(r,c): |
---|
2790 | Â Â Â Â Â Â Â Â Â Â UnitCellsTable.SetValue(r,c,False) |
---|
2791 | Â Â Â Â Â Â Â Â Â Â cells[r][c]Â =Â False |
---|
2792 | Â Â Â Â Â Â Â Â else: |
---|
2793 | Â Â Â Â Â Â Â Â Â Â cells[r][c]Â =Â True |
---|
2794 | Â Â Â Â Â Â Â Â Â Â UnitCellsTable.SetValue(r,c,True) |
---|
2795 | Â Â Â Â Â Â Â Â gridDisplay.ForceRefresh() |
---|
2796 | Â Â Â Â Â Â G2frame.PatternTree.SetItemPyData(UnitCellsId,data) |
---|
2797 | Â Â Â Â |
---|
2798 |   def MakeNewPhase(event): |
---|
2799 |     if not G2gd.GetPatternTreeItemId(G2frame,G2frame.root,'Phases'): |
---|
2800 | Â Â Â Â Â Â sub =Â G2frame.PatternTree.AppendItem(parent=G2frame.root,text='Phases') |
---|
2801 | Â Â Â Â else: |
---|
2802 | Â Â Â Â Â Â sub =Â G2gd.GetPatternTreeItemId(G2frame,G2frame.root,'Phases') |
---|
2803 | Â Â Â Â PhaseName =Â '' |
---|
2804 | Â Â Â Â dlg =Â wx.TextEntryDialog(None,'Enter a name for this phase','Phase Name Entry','New phase', |
---|
2805 | Â Â Â Â Â Â style=wx.OK) |
---|
2806 | Â Â Â Â try: |
---|
2807 |       if dlg.ShowModal() == wx.ID_OK: |
---|
2808 | Â Â Â Â Â Â Â Â PhaseName =Â dlg.GetValue() |
---|
2809 | Â Â Â Â Â Â Â Â cells =Â G2frame.PatternTree.GetItemPyData(UnitCellsId)[2] |
---|
2810 |         for Cell in cells: |
---|
2811 |           if Cell[-2]: |
---|
2812 | Â Â Â Â Â Â Â Â Â Â Â Â break |
---|
2813 | Â Â Â Â Â Â Â Â cell =Â Cell[2:10]Â Â Â Â |
---|
2814 | Â Â Â Â Â Â Â Â sub =Â G2frame.PatternTree.AppendItem(parent=sub,text=PhaseName) |
---|
2815 | Â Â Â Â Â Â Â Â E,SGData =Â G2spc.SpcGroup(controls[13]) |
---|
2816 |         G2frame.PatternTree.SetItemPyData(sub, \ |
---|
2817 | Â Â Â Â Â Â Â Â Â Â G2IO.SetNewPhase(Name=PhaseName,SGData=SGData,cell=cell[1:],Super=ssopt)) |
---|
2818 | Â Â Â Â Â Â Â Â Status.SetStatusText('Change space group from '+str(controls[13])+' if needed') |
---|
2819 | Â Â Â Â finally: |
---|
2820 | Â Â Â Â Â Â dlg.Destroy() |
---|
2821 | Â Â Â Â Â Â |
---|
2822 |   if G2frame.dataDisplay: |
---|
2823 | Â Â Â Â G2frame.dataFrame.DestroyChildren() |
---|
2824 | Â Â G2frame.dataDisplay =Â wxscroll.ScrolledPanel(G2frame.dataFrame) |
---|
2825 | Â Â G2gd.SetDataMenuBar(G2frame,G2frame.dataFrame.IndexMenu) |
---|
2826 |   if not G2frame.dataFrame.GetStatusBar(): |
---|
2827 | Â Â Â Â Status =Â G2frame.dataFrame.CreateStatusBar() |
---|
2828 |   G2frame.Bind(wx.EVT_MENU, IndexPeaks, id=G2gd.wxID_INDEXPEAKS) |
---|
2829 |   G2frame.Bind(wx.EVT_MENU, CopyUnitCell, id=G2gd.wxID_COPYCELL) |
---|
2830 |   G2frame.Bind(wx.EVT_MENU, RefineCell, id=G2gd.wxID_REFINECELL) |
---|
2831 |   G2frame.Bind(wx.EVT_MENU, MakeNewPhase, id=G2gd.wxID_MAKENEWPHASE) |
---|
2832 |   G2frame.Bind(wx.EVT_MENU, OnExportCells, id=G2gd.wxID_EXPORTCELLS) |
---|
2833 | Â Â Â Â |
---|
2834 | Â Â controls,bravais,cells,dmin,ssopt =Â data |
---|
2835 |   if len(controls) < 13:       #add cell volume if missing |
---|
2836 | Â Â Â Â controls.append(G2lat.calc_V(G2lat.cell2A(controls[6:12]))) |
---|
2837 |   if len(controls) < 14:       #add space gropu used in indexing |
---|
2838 | Â Â Â Â controls.append(spaceGroups[bravaisSymb.index(controls[5])]) |
---|
2839 | Â Â G2frame.PatternTree.SetItemPyData(UnitCellsId,data)Â Â Â Â Â Â #update with volume |
---|
2840 | Â Â bravaisNames =Â ['Cubic-F','Cubic-I','Cubic-P','Trigonal-R','Trigonal/Hexagonal-P', |
---|
2841 | Â Â Â Â 'Tetragonal-I','Tetragonal-P','Orthorhombic-F','Orthorhombic-I','Orthorhombic-C', |
---|
2842 | Â Â Â Â 'Orthorhombic-P','Monoclinic-C','Monoclinic-P','Triclinic'] |
---|
2843 | Â Â cellGUIlist =Â [[[0,1,2],4,zip([" Unit cell: a = "," Vol = "],["%.5f","%.3f"],[True,False],[0,0])], |
---|
2844 | Â Â [[3,4,5,6],6,zip([" Unit cell: a = "," c = "," Vol = "],["%.5f","%.5f","%.3f"],[True,True,False],[0,2,0])], |
---|
2845 | Â Â [[7,8,9,10],8,zip([" Unit cell: a = "," b = "," c = "," Vol = "],["%.5f","%.5f","%.5f","%.3f"], |
---|
2846 | Â Â Â Â [True,True,True,False],[0,1,2,0])], |
---|
2847 | Â Â [[11,12],10,zip([" Unit cell: a = "," b = "," c = "," beta = "," Vol = "], |
---|
2848 | Â Â Â Â ["%.5f","%.5f","%.5f","%.3f","%.3f"],[True,True,True,True,False],[0,1,2,4,0])], |
---|
2849 | Â Â [[13,],8,zip([" Unit cell: a = "," b = "," c = "," Vol = "," alpha = "," beta = "," gamma = "], |
---|
2850 | Â Â Â Â ["%.5f","%.5f","%.5f","%.3f","%.3f","%.3f","%.3f"], |
---|
2851 | Â Â Â Â [True,True,True,False,True,True,True],[0,1,2,0,3,4,5])]] |
---|
2852 | Â Â |
---|
2853 | Â Â G2frame.dataFrame.SetLabel('Unit Cells List') |
---|
2854 | Â Â G2frame.dataFrame.IndexPeaks.Enable(False) |
---|
2855 |   peaks = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId, 'Index Peak List')) |
---|
2856 |   if peaks: |
---|
2857 | Â Â Â Â G2frame.dataFrame.IndexPeaks.Enable(True) |
---|
2858 | Â Â G2frame.dataFrame.RefineCell.Enable(False) |
---|
2859 |   if controls[12] > 1.0:                #if a "real" volume (i.e. not default) |
---|
2860 | Â Â Â Â G2frame.dataFrame.RefineCell.Enable(True)Â Â |
---|
2861 | Â Â G2frame.dataFrame.CopyCell.Enable(False) |
---|
2862 | Â Â G2frame.dataFrame.MakeNewPhase.Enable(False)Â Â Â Â |
---|
2863 | Â Â G2frame.dataFrame.ExportCells.Enable(False) |
---|
2864 |   if cells: |
---|
2865 | Â Â Â Â G2frame.dataFrame.CopyCell.Enable(True) |
---|
2866 | Â Â Â Â G2frame.dataFrame.MakeNewPhase.Enable(True) |
---|
2867 | Â Â Â Â G2frame.dataFrame.ExportCells.Enable(True) |
---|
2868 | Â Â mainSizer =Â wx.BoxSizer(wx.VERTICAL) |
---|
2869 | Â Â mainSizer.Add(wx.StaticText(parent=G2frame.dataDisplay,label=' Indexing controls: '),0,WACV) |
---|
2870 | Â Â mainSizer.Add((5,5),0) |
---|
2871 | Â Â littleSizer =Â wx.FlexGridSizer(0,5,5,5) |
---|
2872 | Â Â littleSizer.Add(wx.StaticText(parent=G2frame.dataDisplay,label=' Max Nc/Nobs '),0,WACV) |
---|
2873 | Â Â NcNo =Â wx.SpinCtrl(G2frame.dataDisplay) |
---|
2874 | Â Â NcNo.SetRange(2,6) |
---|
2875 | Â Â NcNo.SetValue(controls[2]) |
---|
2876 | Â Â NcNo.Bind(wx.EVT_SPINCTRL,OnNcNo) |
---|
2877 | Â Â littleSizer.Add(NcNo,0,WACV) |
---|
2878 | Â Â littleSizer.Add(wx.StaticText(parent=G2frame.dataDisplay,label=' Start Volume '),0,WACV) |
---|
2879 | Â Â startVol =Â wx.TextCtrl(G2frame.dataDisplay,value=str('%d'%(controls[3])),style=wx.TE_PROCESS_ENTER) |
---|
2880 | Â Â startVol.Bind(wx.EVT_TEXT_ENTER,OnStartVol) |
---|
2881 | Â Â startVol.Bind(wx.EVT_KILL_FOCUS,OnStartVol) |
---|
2882 | Â Â littleSizer.Add(startVol,0,WACV) |
---|
2883 | Â Â x20 =Â wx.CheckBox(G2frame.dataDisplay,label='Use M20/(X20+1)?') |
---|
2884 | Â Â x20.SetValue(G2frame.ifX20) |
---|
2885 | Â Â x20.Bind(wx.EVT_CHECKBOX,OnIfX20) |
---|
2886 | Â Â littleSizer.Add(x20,0,WACV) |
---|
2887 | Â Â mainSizer.Add(littleSizer,0) |
---|
2888 | Â Â mainSizer.Add((5,5),0) |
---|
2889 | Â Â mainSizer.Add(wx.StaticText(G2frame.dataDisplay,label=' Select Bravais Lattices for indexing: '), |
---|
2890 | Â Â Â Â 0,WACV) |
---|
2891 | Â Â mainSizer.Add((5,5),0) |
---|
2892 | Â Â littleSizer =Â wx.FlexGridSizer(0,7,5,5) |
---|
2893 | Â Â bravList =Â [] |
---|
2894 | Â Â bravs =Â zip(bravais,bravaisNames) |
---|
2895 |   for brav,bravName in bravs: |
---|
2896 | Â Â Â Â bravCk =Â wx.CheckBox(G2frame.dataDisplay,label=bravName) |
---|
2897 | Â Â Â Â bravList.append(bravCk.GetId()) |
---|
2898 | Â Â Â Â bravCk.SetValue(brav) |
---|
2899 | Â Â Â Â bravCk.Bind(wx.EVT_CHECKBOX,OnBravais) |
---|
2900 | Â Â Â Â littleSizer.Add(bravCk,0,WACV) |
---|
2901 | Â Â mainSizer.Add(littleSizer,0) |
---|
2902 | Â Â mainSizer.Add((5,5),0) |
---|
2903 | Â Â |
---|
2904 | Â Â mainSizer.Add(wx.StaticText(parent=G2frame.dataDisplay,label=' Cell Refinement: '),0,WACV) |
---|
2905 | Â Â mainSizer.Add((5,5),0) |
---|
2906 | Â Â littleSizer =Â wx.BoxSizer(wx.HORIZONTAL) |
---|
2907 | Â Â littleSizer.Add(wx.StaticText(G2frame.dataDisplay,label=" Bravais lattice "),0,WACV) |
---|
2908 | Â Â bravSel =Â wx.Choice(G2frame.dataDisplay,choices=bravaisSymb) |
---|
2909 | Â Â bravSel.SetSelection(bravaisSymb.index(controls[5])) |
---|
2910 | Â Â bravSel.Bind(wx.EVT_CHOICE,OnBravSel) |
---|
2911 | Â Â littleSizer.Add(bravSel,0,WACV) |
---|
2912 | Â Â littleSizer.Add(wx.StaticText(G2frame.dataDisplay,label=" Space group "),0,WACV) |
---|
2913 | Â Â spcSel =Â wx.Choice(G2frame.dataDisplay,choices=SPGlist[controls[5]]) |
---|
2914 | Â Â spcSel.SetSelection(SPGlist[controls[5]].index(controls[13])) |
---|
2915 | Â Â spcSel.Bind(wx.EVT_CHOICE,OnSpcSel) |
---|
2916 | Â Â littleSizer.Add(spcSel,0,WACV) |
---|
2917 |   if ssopt.get('Use',False):    #zero for super lattice doesn't work! |
---|
2918 | Â Â Â Â controls[0]Â =Â False |
---|
2919 | Â Â else: |
---|
2920 | Â Â Â Â littleSizer.Add(wx.StaticText(G2frame.dataDisplay,label=" Zero offset"),0,WACV) |
---|
2921 | Â Â Â Â zero =Â wx.TextCtrl(G2frame.dataDisplay,value="%.4f"%(controls[1]),style=wx.TE_PROCESS_ENTER) |
---|
2922 | Â Â Â Â zero.Bind(wx.EVT_TEXT_ENTER,OnZero) |
---|
2923 | Â Â Â Â zero.Bind(wx.EVT_KILL_FOCUS,OnZero) |
---|
2924 | Â Â Â Â littleSizer.Add(zero,0,WACV) |
---|
2925 | Â Â Â Â zeroVar =Â wx.CheckBox(G2frame.dataDisplay,label="Refine?") |
---|
2926 | Â Â Â Â zeroVar.SetValue(controls[0]) |
---|
2927 | Â Â Â Â zeroVar.Bind(wx.EVT_CHECKBOX,OnZeroVar) |
---|
2928 | Â Â Â Â littleSizer.Add(zeroVar,0,WACV) |
---|
2929 | Â Â SSopt =Â wx.CheckBox(G2frame.dataDisplay,label="Super lattice?") |
---|
2930 | Â Â SSopt.SetValue(ssopt.get('Use',False)) |
---|
2931 | Â Â SSopt.Bind(wx.EVT_CHECKBOX,OnSSopt) |
---|
2932 | Â Â littleSizer.Add(SSopt,0,WACV) |
---|
2933 | Â Â hklShow =Â wx.Button(G2frame.dataDisplay,label="Show hkl positions") |
---|
2934 | Â Â hklShow.Bind(wx.EVT_BUTTON,OnHklShow) |
---|
2935 | Â Â littleSizer.Add(hklShow,0,WACV) |
---|
2936 | Â Â mainSizer.Add(littleSizer,0) |
---|
2937 | Â Â |
---|
2938 | Â Â mainSizer.Add((5,5),0) |
---|
2939 | Â Â ibrav =Â SetLattice(controls) |
---|
2940 |   for cellGUI in cellGUIlist: |
---|
2941 |     if ibrav in cellGUI[0]: |
---|
2942 | Â Â Â Â Â Â useGUI =Â cellGUI |
---|
2943 | Â Â cellList =Â [] |
---|
2944 | Â Â valDict =Â {} |
---|
2945 | Â Â littleSizer =Â wx.FlexGridSizer(0,useGUI[1],5,5) |
---|
2946 |   for txt,fmt,ifEdit,Id in useGUI[2]: |
---|
2947 | Â Â Â Â littleSizer.Add(wx.StaticText(G2frame.dataDisplay,label=txt),0,WACV) |
---|
2948 |     if ifEdit:     #a,b,c,etc. |
---|
2949 | Â Â Â Â Â Â cellVal =Â wx.TextCtrl(G2frame.dataDisplay,value=(fmt%(controls[6+Id])),style=wx.TE_PROCESS_ENTER) |
---|
2950 | Â Â Â Â Â Â cellVal.Bind(wx.EVT_TEXT_ENTER,OnCellChange)Â Â Â Â |
---|
2951 | Â Â Â Â Â Â cellVal.Bind(wx.EVT_KILL_FOCUS,OnCellChange) |
---|
2952 | Â Â Â Â Â Â valSizer =Â wx.BoxSizer(wx.HORIZONTAL) |
---|
2953 | Â Â Â Â Â Â valSizer.Add(cellVal,0,WACV) |
---|
2954 | Â Â Â Â Â Â cellSpin =Â wx.SpinButton(G2frame.dataDisplay,style=wx.SP_VERTICAL,size=wx.Size(20,20)) |
---|
2955 | Â Â Â Â Â Â cellSpin.SetValue(0) |
---|
2956 | Â Â Â Â Â Â cellSpin.SetRange(-1,1) |
---|
2957 |       cellSpin.Bind(wx.EVT_SPIN, OnMoveCell) |
---|
2958 | Â Â Â Â Â Â valSizer.Add(cellSpin,0,WACV) |
---|
2959 | Â Â Â Â Â Â littleSizer.Add(valSizer,0,WACV) |
---|
2960 | Â Â Â Â Â Â cellList.append(cellVal.GetId()) |
---|
2961 | Â Â Â Â Â Â cellList.append(cellSpin.GetId()) |
---|
2962 | Â Â Â Â Â Â valDict[cellSpin.GetId()]Â =Â cellVal |
---|
2963 | Â Â Â Â else:Â Â Â Â Â Â Â Â #volume |
---|
2964 | Â Â Â Â Â Â volVal =Â wx.TextCtrl(G2frame.dataDisplay,value=(fmt%(controls[12])),style=wx.TE_READONLY) |
---|
2965 | Â Â Â Â Â Â volVal.SetBackgroundColour(VERY_LIGHT_GREY) |
---|
2966 | Â Â Â Â Â Â littleSizer.Add(volVal,0,WACV) |
---|
2967 | Â Â mainSizer.Add(littleSizer,0) |
---|
2968 |   if ssopt.get('Use',False):    #super lattice display |
---|
2969 | Â Â Â Â indChoice =Â ['1','2','3','4',] |
---|
2970 | Â Â Â Â SpSg =Â controls[13] |
---|
2971 | Â Â Â Â ssChoice =Â G2spc.ssdict[SpSg] |
---|
2972 |     if ssopt['ssSymb'] not in ssChoice: |
---|
2973 | Â Â Â Â Â Â ssopt['ssSymb']Â =Â ssChoice[0] |
---|
2974 | Â Â Â Â ssSizer =Â wx.BoxSizer(wx.HORIZONTAL) |
---|
2975 | Â Â Â Â ssSizer.Add(wx.StaticText(G2frame.dataDisplay,label=' Supersymmetry space group: '+SpSg+' '),0,WACV) |
---|
2976 | Â Â Â Â selMG =Â wx.ComboBox(G2frame.dataDisplay,value=ssopt['ssSymb'], |
---|
2977 | Â Â Â Â Â Â Â Â choices=ssChoice,style=wx.CB_READONLY|wx.CB_DROPDOWN) |
---|
2978 |     selMG.Bind(wx.EVT_COMBOBOX, OnSelMG) |
---|
2979 | Â Â Â Â ssSizer.Add(selMG,0,WACV) |
---|
2980 | Â Â Â Â ssSizer.Add(wx.StaticText(G2frame.dataDisplay,label=' Mod. vector: '),0,WACV) |
---|
2981 | Â Â Â Â modS =Â G2spc.splitSSsym(ssopt['ssSymb'])[0] |
---|
2982 | Â Â Â Â ssopt['ModVec'],ifShow =Â G2spc.SSGModCheck(ssopt['ModVec'],modS) |
---|
2983 | Â Â Â Â Indx =Â {} |
---|
2984 |     for i,[val,show] in enumerate(zip(ssopt['ModVec'],ifShow)): |
---|
2985 |       if show: |
---|
2986 | Â Â Â Â Â Â Â Â valSizer =Â wx.BoxSizer(wx.HORIZONTAL) |
---|
2987 | Â Â Â Â Â Â Â Â modVal =Â wx.TextCtrl(G2frame.dataDisplay,value=('%.4f'%(val)), |
---|
2988 | Â Â Â Â Â Â Â Â Â Â size=wx.Size(50,20),style=wx.TE_PROCESS_ENTER) |
---|
2989 | Â Â Â Â Â Â Â Â modVal.Bind(wx.EVT_TEXT_ENTER,OnModVal)Â Â Â Â |
---|
2990 | Â Â Â Â Â Â Â Â modVal.Bind(wx.EVT_KILL_FOCUS,OnModVal) |
---|
2991 | Â Â Â Â Â Â Â Â valSizer.Add(modVal,0,WACV) |
---|
2992 | Â Â Â Â Â Â Â Â modSpin =Â wx.SpinButton(G2frame.dataDisplay,style=wx.SP_VERTICAL,size=wx.Size(20,20)) |
---|
2993 | Â Â Â Â Â Â Â Â modSpin.SetValue(0) |
---|
2994 | Â Â Â Â Â Â Â Â modSpin.SetRange(-1,1) |
---|
2995 |         modSpin.Bind(wx.EVT_SPIN, OnMoveMod) |
---|
2996 | Â Â Â Â Â Â Â Â valSizer.Add(modSpin,0,WACV) |
---|
2997 | Â Â Â Â Â Â Â Â ssSizer.Add(valSizer,0,WACV) |
---|
2998 | Â Â Â Â Â Â Â Â Indx[modVal.GetId()]Â =Â i |
---|
2999 | Â Â Â Â Â Â Â Â Indx[modSpin.GetId()]Â =Â [i,modVal] |
---|
3000 | Â Â Â Â Â Â else: |
---|
3001 | Â Â Â Â Â Â Â Â modVal =Â wx.TextCtrl(G2frame.dataDisplay,value=('%.3f'%(val)), |
---|
3002 | Â Â Â Â Â Â Â Â Â Â size=wx.Size(50,20),style=wx.TE_READONLY) |
---|
3003 | Â Â Â Â Â Â Â Â modVal.SetBackgroundColour(VERY_LIGHT_GREY) |
---|
3004 | Â Â Â Â Â Â Â Â ssSizer.Add(modVal,0,WACV) |
---|
3005 | Â Â Â Â ssSizer.Add(wx.StaticText(G2frame.dataDisplay,label=' Max. M: '),0,WACV) |
---|
3006 | Â Â Â Â maxMH =Â wx.ComboBox(G2frame.dataDisplay,value=str(ssopt['maxH']), |
---|
3007 | Â Â Â Â Â Â choices=indChoice,style=wx.CB_READONLY|wx.CB_DROPDOWN) |
---|
3008 |     maxMH.Bind(wx.EVT_COMBOBOX, OnMaxMH) |
---|
3009 | Â Â Â Â ssSizer.Add(maxMH,0,WACV) |
---|
3010 | Â Â Â Â findMV =Â wx.wx.Button(G2frame.dataDisplay,label="Find mod. vec.?") |
---|
3011 | Â Â Â Â findMV.Bind(wx.EVT_BUTTON,OnFindMV) |
---|
3012 | Â Â Â Â ssSizer.Add(findMV,0,WACV) |
---|
3013 | Â Â Â Â mainSizer.Add(ssSizer,0) |
---|
3014 | |
---|
3015 |   if cells: |
---|
3016 |     mainSizer.Add(wx.StaticText(parent=G2frame.dataDisplay,label='\n Indexing Result:'),0,WACV) |
---|
3017 | Â Â Â Â rowLabels =Â [] |
---|
3018 | Â Â Â Â colLabels =Â ['M20','X20','use','Bravais','a','b','c','alpha','beta','gamma','Volume','Keep'] |
---|
3019 | Â Â Â Â Types =Â [wg.GRID_VALUE_FLOAT+':10,2',wg.GRID_VALUE_NUMBER,wg.GRID_VALUE_BOOL,wg.GRID_VALUE_STRING,]+Â \ |
---|
3020 | Â Â Â Â Â Â 3*[wg.GRID_VALUE_FLOAT+':10,5',]+3*[wg.GRID_VALUE_FLOAT+':10,3',]+Â \ |
---|
3021 | Â Â Â Â Â Â [wg.GRID_VALUE_FLOAT+':10,2',wg.GRID_VALUE_BOOL] |
---|
3022 | Â Â Â Â numRows =Â len(cells) |
---|
3023 | Â Â Â Â table =Â [] |
---|
3024 |     for cell in cells: |
---|
3025 | Â Â Â Â Â Â rowLabels.append('') |
---|
3026 | Â Â Â Â Â Â row =Â cell[0:2]+[cell[-2]]+[bravaisSymb[cell[2]]]+cell[3:10]+[cell[11],] |
---|
3027 |       if cell[-2]: |
---|
3028 | Â Â Â Â Â Â Â Â A =Â G2lat.cell2A(cell[3:9]) |
---|
3029 | Â Â Â Â Â Â Â Â G2frame.HKL =Â G2lat.GenHBravais(dmin,cell[2],A) |
---|
3030 |         for hkl in G2frame.HKL: |
---|
3031 | Â Â Â Â Â Â Â Â Â Â hkl.insert(4,G2lat.Dsp2pos(Inst,hkl[3])+controls[1]) |
---|
3032 | Â Â Â Â Â Â table.append(row) |
---|
3033 | Â Â Â Â UnitCellsTable =Â G2G.Table(table,rowLabels=rowLabels,colLabels=colLabels,types=Types) |
---|
3034 | Â Â Â Â gridDisplay =Â G2G.GSGrid(G2frame.dataDisplay) |
---|
3035 |     gridDisplay.SetTable(UnitCellsTable, True) |
---|
3036 | Â Â Â Â G2frame.dataFrame.CopyCell.Enable(True) |
---|
3037 | Â Â Â Â gridDisplay.Bind(wg.EVT_GRID_CELL_LEFT_CLICK,RefreshUnitCellsGrid) |
---|
3038 | Â Â Â Â gridDisplay.Bind(wg.EVT_GRID_LABEL_LEFT_DCLICK,OnSortCells) |
---|
3039 | Â Â Â Â gridDisplay.SetMargins(0,0) |
---|
3040 | Â Â Â Â gridDisplay.SetRowLabelSize(0) |
---|
3041 | Â Â Â Â gridDisplay.AutoSizeColumns(False) |
---|
3042 |     for r in range(gridDisplay.GetNumberRows()): |
---|
3043 |       for c in range(gridDisplay.GetNumberCols()): |
---|
3044 |         if c == 2: |
---|
3045 | Â Â Â Â Â Â Â Â Â Â gridDisplay.SetReadOnly(r,c,isReadOnly=False) |
---|
3046 | Â Â Â Â Â Â Â Â else: |
---|
3047 | Â Â Â Â Â Â Â Â Â Â gridDisplay.SetReadOnly(r,c,isReadOnly=True) |
---|
3048 | Â Â Â Â mainSizer.Add(gridDisplay,0,WACV) |
---|
3049 | Â Â mainSizer.Layout()Â Â |
---|
3050 | Â Â G2frame.dataDisplay.SetSizer(mainSizer) |
---|
3051 | Â Â G2frame.dataDisplay.SetAutoLayout(1) |
---|
3052 | Â Â G2frame.dataDisplay.SetupScrolling() |
---|
3053 | Â Â Size =Â mainSizer.Fit(G2frame.dataFrame) |
---|
3054 | Â Â Size[0]Â +=Â 25 |
---|
3055 | Â Â G2frame.dataDisplay.SetSize(Size) |
---|
3056 | Â Â G2frame.dataFrame.setSizePosLeft(Size)Â Â |
---|
3057 | Â Â |
---|
3058 | ################################################################################ |
---|
3059 | #####Â Reflection list |
---|
3060 | ################################################################################Â Â Â Â Â Â |
---|
3061 | Â Â Â Â |
---|
3062 | def UpdateReflectionGrid(G2frame,data,HKLF=False,Name=''): |
---|
3063 | Â Â '''respond to selection of PWDR Reflections data tree item by displaying |
---|
3064 | Â Â a table of reflections in the data window. |
---|
3065 | Â Â ''' |
---|
3066 |   def OnPlotHKL(event): |
---|
3067 | Â Â Â Â '''Plots a layer of reflections |
---|
3068 | Â Â Â Â ''' |
---|
3069 | Â Â Â Â phaseName =Â G2frame.RefList |
---|
3070 | Â Â Â Â pId =Â G2gd.GetPatternTreeItemId(G2frame,G2frame.root,'Phases') |
---|
3071 | Â Â Â Â phaseId =Â G2gd.GetPatternTreeItemId(G2frame,pId,phaseName) |
---|
3072 | Â Â Â Â General =Â G2frame.PatternTree.GetItemPyData(phaseId)['General'] |
---|
3073 | Â Â Â Â Super =Â General.get('Super',0) |
---|
3074 | Â Â Â Â SuperVec =Â General.get('SuperVec',[]) |
---|
3075 |     if 'list' in str(type(data)):  #single crystal data is 2 dict in list |
---|
3076 | Â Â Â Â Â Â refList =Â data[1]['RefList'] |
---|
3077 | Â Â Â Â else:Â Â Â Â Â Â Â Â Â Â Â Â Â Â #powder data is a dict of dicts; each same structure as SC 2nd dict |
---|
3078 | Â Â Â Â Â Â refList =Â np.array(data[phaseName]['RefList']) |
---|
3079 | Â Â Â Â FoMax =Â np.max(refList.T[8+Super]) |
---|
3080 | Â Â Â Â Hmin =Â np.array([int(np.min(refList.T[0])),int(np.min(refList.T[1])),int(np.min(refList.T[2]))]) |
---|
3081 | Â Â Â Â Hmax =Â np.array([int(np.max(refList.T[0])),int(np.max(refList.T[1])),int(np.max(refList.T[2]))]) |
---|
3082 | Â Â Â Â controls =Â {'Type'Â :Â 'Fo','ifFc'Â :Â True,'HKLmax'Â :Â Hmax,'HKLmin'Â :Â Hmin, |
---|
3083 | Â Â Â Â Â Â 'FoMax'Â :Â FoMax,'Zone'Â :Â '001','Layer'Â :Â 0,'Scale'Â :Â 1.0,'Super':Super,'SuperVec':SuperVec} |
---|
3084 | Â Â Â Â G2plt.PlotSngl(G2frame,newPlot=True,Data=controls,hklRef=refList,Title=phaseName) |
---|
3085 | Â Â Â Â |
---|
3086 |   def OnPlot3DHKL(event): |
---|
3087 | Â Â Â Â '''Plots the reflections in 3D |
---|
3088 | Â Â Â Â ''' |
---|
3089 | Â Â Â Â phaseName =Â G2frame.RefList |
---|
3090 | Â Â Â Â pId =Â G2gd.GetPatternTreeItemId(G2frame,G2frame.root,'Phases') |
---|
3091 | Â Â Â Â phaseId =Â G2gd.GetPatternTreeItemId(G2frame,pId,phaseName) |
---|
3092 | Â Â Â Â General =Â G2frame.PatternTree.GetItemPyData(phaseId)['General'] |
---|
3093 | Â Â Â Â Super =Â General.get('Super',0) |
---|
3094 | Â Â Â Â SuperVec =Â General.get('SuperVec',[]) |
---|
3095 |     if 'list' in str(type(data)):  #single crystal data is 2 dict in list |
---|
3096 | Â Â Â Â Â Â refList =Â data[1]['RefList'] |
---|
3097 | Â Â Â Â else:Â Â Â Â Â Â Â Â Â Â Â Â Â Â #powder data is a dict of dicts; each same structure as SC 2nd dict |
---|
3098 | Â Â Â Â Â Â refList =Â np.array(data[phaseName]['RefList']) |
---|
3099 | Â Â Â Â FoMax =Â np.max(refList.T[8+Super]) |
---|
3100 | Â Â Â Â Hmin =Â np.array([int(np.min(refList.T[0])),int(np.min(refList.T[1])),int(np.min(refList.T[2]))]) |
---|
3101 | Â Â Â Â Hmax =Â np.array([int(np.max(refList.T[0])),int(np.max(refList.T[1])),int(np.max(refList.T[2]))]) |
---|
3102 | Â Â Â Â Vpoint =Â [int(np.mean(refList.T[0])),int(np.mean(refList.T[1])),int(np.mean(refList.T[2]))] |
---|
3103 | Â Â Â Â controls =Â {'Type':'Fosq','Iscale':False,'HKLmax':Hmax,'HKLmin':Hmin, |
---|
3104 | Â Â Â Â Â Â 'FoMax'Â :Â FoMax,'Scale'Â :Â 1.0,'Drawing':{'viewPoint':[Vpoint,[]],'default':Vpoint[:], |
---|
3105 | Â Â Â Â Â Â 'backColor':[0,0,0],'depthFog':False,'Zclip':10.0,'cameraPos':10.,'Zstep':0.05, |
---|
3106 | Â Â Â Â Â Â 'Scale':1.0,'oldxy':[],'viewDir':[1,0,0]},'Super':Super,'SuperVec':SuperVec} |
---|
3107 | Â Â Â Â G2plt.Plot3DSngl(G2frame,newPlot=True,Data=controls,hklRef=refList,Title=phaseName) |
---|
3108 | Â Â Â Â |
---|
3109 |   def MakeReflectionTable(phaseName): |
---|
3110 | Â Â Â Â '''Returns a wx.grid table (G2G.Table) containing a list of all reflections |
---|
3111 |     for a phase.    |
---|
3112 | Â Â Â Â ''' |
---|
3113 |     if phaseName: |
---|
3114 | Â Â Â Â Â Â pId =Â G2gd.GetPatternTreeItemId(G2frame,G2frame.root,'Phases') |
---|
3115 | Â Â Â Â Â Â phaseId =Â G2gd.GetPatternTreeItemId(G2frame,pId,phaseName) |
---|
3116 | Â Â Â Â Â Â General =Â G2frame.PatternTree.GetItemPyData(phaseId)['General'] |
---|
3117 | Â Â Â Â Â Â Super =Â General.get('Super',0) |
---|
3118 | Â Â Â Â Â Â SuperVec =Â General.get('SuperVec',[]) |
---|
3119 | Â Â Â Â else: |
---|
3120 | Â Â Â Â Â Â Super =Â 0 |
---|
3121 | Â Â Â Â Â Â SuperVec =Â []Â Â Â Â |
---|
3122 | Â Â Â Â rowLabels =Â [] |
---|
3123 |     if HKLF: |
---|
3124 | Â Â Â Â Â Â refList =Â data[1]['RefList'] |
---|
3125 | Â Â Â Â Â Â refs =Â refList |
---|
3126 | Â Â Â Â else: |
---|
3127 |       if len(data) > 1: |
---|
3128 | Â Â Â Â Â Â Â Â G2frame.dataFrame.SelectPhase.Enable(True) |
---|
3129 | Â Â Â Â Â Â try:Â Â Â Â Â Â #patch for old reflection lists |
---|
3130 |         if not len(data[phaseName]): |
---|
3131 |           return None |
---|
3132 | Â Â Â Â Â Â Â Â refList =Â np.array(data[phaseName]['RefList']) |
---|
3133 | Â Â Â Â Â Â Â Â I100 =Â refList.T[8+Super]*refList.T[11+Super] |
---|
3134 |       except TypeError: |
---|
3135 |         refList = np.array([refl[:11+Super] for refl in data[phaseName]]) |
---|
3136 |         I100 = refList.T[8+Super]*np.array([refl[11+Super] for refl in data[phaseName]]) |
---|
3137 | Â Â Â Â Â Â Imax =Â np.max(I100) |
---|
3138 |       if Imax: |
---|
3139 | Â Â Â Â Â Â Â Â I100 *=Â 100.0/Imax |
---|
3140 |       if 'C' in Inst['Type'][0]: |
---|
3141 | Â Â Â Â Â Â Â Â refs =Â np.vstack((refList.T[:15+Super],I100)).T |
---|
3142 |       elif 'T' in Inst['Type'][0]: |
---|
3143 | Â Â Â Â Â Â Â Â refs =Â np.vstack((refList.T[:18+Super],I100)).T |
---|
3144 |     for i in range(len(refs)): rowLabels.append(str(i)) |
---|
3145 | Â Â Â Â Types =Â (4+Super)*[wg.GRID_VALUE_LONG,]+4*[wg.GRID_VALUE_FLOAT+':10,4',]+Â \ |
---|
3146 | Â Â Â Â Â Â 2*[wg.GRID_VALUE_FLOAT+':10,2',]+[wg.GRID_VALUE_FLOAT+':10,3',]+Â \ |
---|
3147 | Â Â Â Â Â Â [wg.GRID_VALUE_FLOAT+':10,3',] |
---|
3148 |     if HKLF: |
---|
3149 | Â Â Â Â Â Â colLabels =Â ['H','K','L','mul','d','Fosq','sig','Fcsq','FoTsq','FcTsq','phase','ExtC',] |
---|
3150 |       if 'T' in Inst['Type'][0]: |
---|
3151 | Â Â Â Â Â Â Â Â colLabels =Â ['H','K','L','mul','d','Fosq','sig','Fcsq','FoTsq','FcTsq','phase','ExtC','wave','tbar'] |
---|
3152 | Â Â Â Â Â Â Â Â Types +=Â 2*[wg.GRID_VALUE_FLOAT+':10,3',] |
---|
3153 |       if Super: |
---|
3154 | Â Â Â Â Â Â Â Â colLabels.insert(3,'M') |
---|
3155 | Â Â Â Â else: |
---|
3156 |       if 'C' in Inst['Type'][0]: |
---|
3157 | Â Â Â Â Â Â Â Â colLabels =Â ['H','K','L','mul','d','pos','sig','gam','Fosq','Fcsq','phase','Icorr','Prfo','Trans','ExtP','I100'] |
---|
3158 | Â Â Â Â Â Â Â Â Types +=Â 4*[wg.GRID_VALUE_FLOAT+':10,3',] |
---|
3159 |       elif 'T' in Inst['Type'][0]: |
---|
3160 | Â Â Â Â Â Â Â Â colLabels =Â ['H','K','L','mul','d','pos','sig','gam','Fosq','Fcsq','phase','Icorr','alp','bet','wave','Prfo','Abs','Ext','I100'] |
---|
3161 | Â Â Â Â Â Â Â Â Types +=Â 7*[wg.GRID_VALUE_FLOAT+':10,3',] |
---|
3162 |       if Super: |
---|
3163 | Â Â Â Â Â Â Â Â colLabels.insert(3,'M') |
---|
3164 |     return G2G.Table(refs,rowLabels=rowLabels,colLabels=colLabels,types=Types) |
---|
3165 | |
---|
3166 |   def ShowReflTable(phaseName): |
---|
3167 | Â Â Â Â '''Posts a table of reflections for a phase, creating the table |
---|
3168 | Â Â Â Â if needed using MakeReflectionTable |
---|
3169 | Â Â Â Â ''' |
---|
3170 |     def setBackgroundColors(im,it): |
---|
3171 |       for r in range(G2frame.refTable[phaseName].GetNumberRows()): |
---|
3172 |         if HKLF: |
---|
3173 |           if float(G2frame.refTable[phaseName].GetCellValue(r,3+im)) <= 0.: |
---|
3174 | Â Â Â Â Â Â Â Â Â Â Â Â G2frame.refTable[phaseName].SetCellBackgroundColour(r,3+im,wx.RED) |
---|
3175 | Â Â Â Â Â Â Â Â Â Â Fosq =Â float(G2frame.refTable[phaseName].GetCellValue(r,5+im)) |
---|
3176 | Â Â Â Â Â Â Â Â Â Â Fcsq =Â float(G2frame.refTable[phaseName].GetCellValue(r,7+im)) |
---|
3177 | Â Â Â Â Â Â Â Â Â Â sig =Â float(G2frame.refTable[phaseName].GetCellValue(r,6+im)) |
---|
3178 | Â Â Â Â Â Â Â Â Â Â rat =Â abs(Fosq-Fcsq)/sig |
---|
3179 |           if rat > 10.: |
---|
3180 | Â Â Â Â Â Â Â Â Â Â Â Â G2frame.refTable[phaseName].SetCellBackgroundColour(r,7+im,wx.RED) |
---|
3181 |           elif rat > 3.0: |
---|
3182 | Â Â Â Â Â Â Â Â Â Â Â Â G2frame.refTable[phaseName].SetCellBackgroundColour(r,7+im,wx.Colour(255,255,0)) |
---|
3183 | #Â Â Â Â Â Â Â Â Â Â else: |
---|
3184 | #Â Â Â Â Â Â Â Â Â Â Â Â G2frame.refTable[phaseName].SetCellBackgroundColour(r,7+im,wx.WHITE) |
---|
3185 | Â Â Â Â Â Â Â Â else:Â Â #PWDR |
---|
3186 |           if float(G2frame.refTable[phaseName].GetCellValue(r,12+im+it)) < 0.: |
---|
3187 | Â Â Â Â Â Â Â Â Â Â Â Â G2frame.refTable[phaseName].SetCellBackgroundColour(r,12+im+it,wx.RED) |
---|
3188 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
---|
3189 | Â Â Â Â G2frame.RefList =Â phaseName |
---|
3190 | Â Â Â Â G2frame.dataFrame.SetLabel('Reflection List for '+phaseName) |
---|
3191 |     if HKLF: |
---|
3192 | Â Â Â Â Â Â Status.SetStatusText('abs(DF)/sig > 10 red; > 3 yellow; mul < 0 (user rejected) red; mul=0 (sp. gp. absent) red') |
---|
3193 | Â Â Â Â else: |
---|
3194 | Â Â Â Â Â Â Status.SetStatusText('Prfo < 0. in red') |
---|
3195 | Â Â Â Â it =Â 0 |
---|
3196 |     if HKLF: |
---|
3197 | Â Â Â Â Â Â im =Â data[1].get('Super',0) |
---|
3198 | Â Â Â Â else: |
---|
3199 |       if 'T' in data[phaseName]['Type']: |
---|
3200 | Â Â Â Â Â Â Â Â it =Â 3 |
---|
3201 | Â Â Â Â Â Â im =Â data[phaseName].get('Super',0) |
---|
3202 | Â Â Â Â # has this table already been displayed? |
---|
3203 |     if G2frame.refTable[phaseName].GetTable() is None: |
---|
3204 | Â Â Â Â Â Â PeakTable =Â MakeReflectionTable(phaseName) |
---|
3205 |       G2frame.refTable[phaseName].SetTable(PeakTable, True) |
---|
3206 | Â Â Â Â Â Â G2frame.refTable[phaseName].EnableEditing(False) |
---|
3207 | Â Â Â Â Â Â G2frame.refTable[phaseName].SetMargins(0,0) |
---|
3208 | Â Â Â Â Â Â G2frame.refTable[phaseName].AutoSizeColumns(False) |
---|
3209 | Â Â Â Â Â Â setBackgroundColors(im,it) |
---|
3210 | Â Â Â Â # raise the tab (needed for 1st use and from OnSelectPhase) |
---|
3211 |     for PageNum in range(G2frame.dataDisplay.GetPageCount()): |
---|
3212 |       if phaseName == G2frame.dataDisplay.GetPageText(PageNum): |
---|
3213 | Â Â Â Â Â Â Â Â G2frame.dataDisplay.SetSelection(PageNum) |
---|
3214 | Â Â Â Â Â Â Â Â break |
---|
3215 | Â Â Â Â else: |
---|
3216 |       print phaseName |
---|
3217 |       print phases |
---|
3218 |       raise Exception("how did we not find a phase name?") |
---|
3219 | Â Â Â Â |
---|
3220 |   def OnPageChanged(event): |
---|
3221 | Â Â Â Â '''Respond to a press on a phase tab by displaying the reflections. This |
---|
3222 | Â Â Â Â routine is needed because the reflection table may not have been created yet. |
---|
3223 | Â Â Â Â ''' |
---|
3224 | Â Â Â Â page =Â event.GetSelection() |
---|
3225 | Â Â Â Â phaseName =Â G2frame.dataDisplay.GetPageText(page) |
---|
3226 | Â Â Â Â ShowReflTable(phaseName) |
---|
3227 | |
---|
3228 |   def OnSelectPhase(event): |
---|
3229 | Â Â Â Â '''For PWDR, selects a phase with a selection box. Called from menu. |
---|
3230 | Â Â Â Â ''' |
---|
3231 |     if len(phases) < 2: return |
---|
3232 | Â Â Â Â dlg =Â wx.SingleChoiceDialog(G2frame,'Select','Phase',phases) |
---|
3233 | Â Â Â Â try: |
---|
3234 |       if dlg.ShowModal() == wx.ID_OK: |
---|
3235 | Â Â Â Â Â Â Â Â sel =Â dlg.GetSelection() |
---|
3236 | Â Â Â Â Â Â Â Â ShowReflTable(phases[sel]) |
---|
3237 | Â Â Â Â finally: |
---|
3238 | Â Â Â Â Â Â dlg.Destroy() |
---|
3239 | Â Â Â Â Â Â |
---|
3240 |   if not data: |
---|
3241 |     print 'No phases, no reflections' |
---|
3242 | Â Â Â Â return |
---|
3243 |   if HKLF: |
---|
3244 | Â Â Â Â G2frame.RefList =Â 1 |
---|
3245 | Â Â Â Â phaseName =Â IsHistogramInAnyPhase(G2frame,Name) |
---|
3246 | Â Â Â Â phases =Â [phaseName] |
---|
3247 | Â Â else: |
---|
3248 | Â Â Â Â phaseName =Â G2frame.RefList |
---|
3249 | Â Â Â Â phases =Â data.keys() |
---|
3250 |   if G2frame.dataDisplay: |
---|
3251 | Â Â Â Â G2frame.dataFrame.Clear() |
---|
3252 |   Inst = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId, 'Instrument Parameters'))[0] |
---|
3253 |   if HKLF: |
---|
3254 | Â Â Â Â G2gd.SetDataMenuBar(G2frame) |
---|
3255 | Â Â Â Â G2gd.SetDataMenuBar(G2frame,G2frame.dataFrame.ReflMenu) |
---|
3256 |     if not G2frame.dataFrame.GetStatusBar(): |
---|
3257 | Â Â Â Â Â Â Status =Â G2frame.dataFrame.CreateStatusBar()Â Â |
---|
3258 |     G2frame.Bind(wx.EVT_MENU, OnPlotHKL, id=G2gd.wxID_PWDHKLPLOT) |
---|
3259 |     G2frame.Bind(wx.EVT_MENU, OnPlot3DHKL, id=G2gd.wxID_PWD3DHKLPLOT) |
---|
3260 | Â Â Â Â G2frame.dataFrame.SelectPhase.Enable(False) |
---|
3261 | Â Â else: |
---|
3262 | Â Â Â Â G2gd.SetDataMenuBar(G2frame,G2frame.dataFrame.ReflMenu) |
---|
3263 |     if not G2frame.dataFrame.GetStatusBar(): |
---|
3264 | Â Â Â Â Â Â Status =Â G2frame.dataFrame.CreateStatusBar()Â Â |
---|
3265 |     G2frame.Bind(wx.EVT_MENU, OnSelectPhase, id=G2gd.wxID_SELECTPHASE) |
---|
3266 |     G2frame.Bind(wx.EVT_MENU, OnPlotHKL, id=G2gd.wxID_PWDHKLPLOT) |
---|
3267 |     G2frame.Bind(wx.EVT_MENU, OnPlot3DHKL, id=G2gd.wxID_PWD3DHKLPLOT) |
---|
3268 | Â Â Â Â G2frame.dataFrame.SelectPhase.Enable(False) |
---|
3269 | Â Â Â Â Â Â |
---|
3270 | Â Â G2frame.dataDisplay =Â G2G.GSNoteBook(parent=G2frame.dataFrame,size=G2frame.dataFrame.GetClientSize()) |
---|
3271 | Â Â G2frame.refTable =Â {} |
---|
3272 |   for tabnum,phase in enumerate(phases): |
---|
3273 | Â Â Â Â G2frame.refTable[phase]Â =Â G2G.GSGrid(parent=G2frame.dataDisplay) |
---|
3274 | Â Â Â Â G2frame.dataDisplay.AddPage(G2frame.refTable[phase],phase) |
---|
3275 |   if phaseName not in G2frame.refTable: |
---|
3276 |     print phaseName |
---|
3277 |     print phases |
---|
3278 |     raise Exception("how did we get a invalid phase name?")  |
---|
3279 | Â Â ShowReflTable(phaseName) |
---|
3280 | Â Â G2frame.refTable[phaseName].Fit() |
---|
3281 | Â Â size =Â G2frame.refTable[phaseName].GetSize() |
---|
3282 | Â Â G2frame.dataFrame.setSizePosLeft([size[0]+32,350])Â Â Â Â |
---|
3283 |   G2frame.dataDisplay.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGED, OnPageChanged) |
---|
3284 | Â Â |
---|
3285 | ################################################################################ |
---|
3286 | #####Â SASD Substances |
---|
3287 | ################################################################################ |
---|
3288 | Â Â Â Â Â Â |
---|
3289 | def UpdateSubstanceGrid(G2frame,data): |
---|
3290 | Â Â '''respond to selection of SASD Substance data tree item. |
---|
3291 | Â Â ''' |
---|
3292 |   import Substances as substFile |
---|
3293 | Â Â |
---|
3294 |   def OnLoadSubstance(event): |
---|
3295 | Â Â Â Â names =Â substFile.Substances.keys() |
---|
3296 | Â Â Â Â names.sort() |
---|
3297 |     dlg = wx.SingleChoiceDialog(G2frame, 'Which substance?', 'Select substance', names, wx.CHOICEDLG_STYLE) |
---|
3298 | Â Â Â Â try: |
---|
3299 |       if dlg.ShowModal() == wx.ID_OK: |
---|
3300 | Â Â Â Â Â Â Â Â name =Â names[dlg.GetSelection()] |
---|
3301 | Â Â Â Â Â Â else: |
---|
3302 | Â Â Â Â Â Â Â Â return |
---|
3303 | Â Â Â Â finally: |
---|
3304 | Â Â Â Â Â Â dlg.Destroy() |
---|
3305 | Â Â Â Â data['Substances'][name]Â =Â {'Elements':{},'Volume':1.0,'Density':1.0, |
---|
3306 | Â Â Â Â Â Â 'Scatt density':0.0,'XAnom density':0.0,'XAbsorption':0.0} |
---|
3307 | Â Â Â Â subst =Â substFile.Substances[name] |
---|
3308 | Â Â Â Â ElList =Â subst['Elements'].keys() |
---|
3309 |     for El in ElList: |
---|
3310 | Â Â Â Â Â Â Info =Â G2elem.GetAtomInfo(El.strip().capitalize()) |
---|
3311 | Â Â Â Â Â Â Info.update(subst['Elements'][El]) |
---|
3312 | Â Â Â Â Â Â data['Substances'][name]['Elements'][El]Â =Â Info |
---|
3313 |       if 'Volume' in subst: |
---|
3314 | Â Â Â Â Â Â Â Â data['Substances'][name]['Volume']Â =Â subst['Volume'] |
---|
3315 | Â Â Â Â Â Â Â Â data['Substances'][name]['Density']Â =Â \ |
---|
3316 | Â Â Â Â Â Â Â Â Â Â G2mth.Vol2Den(data['Substances'][name]['Elements'],data['Substances'][name]['Volume']) |
---|
3317 |       elif 'Density' in subst: |
---|
3318 | Â Â Â Â Â Â Â Â data['Substances'][name]['Density']Â =Â subst['Density'] |
---|
3319 | Â Â Â Â Â Â Â Â data['Substances'][name]['Volume']Â =Â \ |
---|
3320 | Â Â Â Â Â Â Â Â Â Â G2mth.Den2Vol(data['Substances'][name]['Elements'],data['Substances'][name]['Density']) |
---|
3321 | Â Â Â Â Â Â else: |
---|
3322 | Â Â Â Â Â Â Â Â data['Substances'][name]['Volume']Â =Â G2mth.El2EstVol(data['Substances'][name]['Elements']) |
---|
3323 | Â Â Â Â Â Â Â Â data['Substances'][name]['Density']Â =Â \ |
---|
3324 | Â Â Â Â Â Â Â Â Â Â G2mth.Vol2Den(data['Substances'][name]['Elements'],data['Substances'][name]['Volume']) |
---|
3325 | Â Â Â Â Â Â data['Substances'][name]['Scatt density']Â =Â \ |
---|
3326 | Â Â Â Â Â Â Â Â G2mth.XScattDen(data['Substances'][name]['Elements'],data['Substances'][name]['Volume'])[0] |
---|
3327 | Â Â Â Â Â Â contrst,absorb =Â G2mth.XScattDen(data['Substances'][name]['Elements'],data['Substances'][name]['Volume'],wave)Â Â Â Â Â |
---|
3328 | Â Â Â Â Â Â data['Substances'][name]['XAnom density']Â =Â contrst |
---|
3329 | Â Â Â Â Â Â data['Substances'][name]['XAbsorption']Â =Â absorb |
---|
3330 | Â Â Â Â Â Â Â Â Â Â Â Â Â |
---|
3331 | Â Â Â Â UpdateSubstanceGrid(G2frame,data) |
---|
3332 | Â Â Â Â |
---|
3333 |   def OnCopySubstance(event): |
---|
3334 | Â Â Â Â hst =Â G2frame.PatternTree.GetItemText(G2frame.PatternId) |
---|
3335 | Â Â Â Â histList =Â GetHistsLikeSelected(G2frame) |
---|
3336 |     if not histList: |
---|
3337 | Â Â Â Â Â Â G2frame.ErrorDialog('No match','No histograms match '+hst,G2frame.dataFrame) |
---|
3338 | Â Â Â Â Â Â return |
---|
3339 | Â Â Â Â copyList =Â [] |
---|
3340 | Â Â Â Â dlg =Â G2G.G2MultiChoiceDialog( |
---|
3341 |       G2frame.dataFrame, |
---|
3342 | Â Â Â Â Â Â 'Copy substances from\n'+hst[5:]+' to...', |
---|
3343 |       'Copy substances', histList) |
---|
3344 | Â Â Â Â try: |
---|
3345 |       if dlg.ShowModal() == wx.ID_OK: |
---|
3346 |         for i in dlg.GetSelections(): |
---|
3347 | Â Â Â Â Â Â Â Â Â Â copyList.append(histList[i]) |
---|
3348 | Â Â Â Â finally: |
---|
3349 | Â Â Â Â Â Â dlg.Destroy()Â Â Â Â |
---|
3350 |     for item in copyList: |
---|
3351 | Â Â Â Â Â Â Id =Â G2gd.GetPatternTreeItemId(G2frame,G2frame.root,item) |
---|
3352 | Â Â Â Â Â Â G2frame.PatternTree.SetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Id,'Substances'), |
---|
3353 | Â Â Â Â Â Â Â Â copy.copy(data)) |
---|
3354 | Â Â |
---|
3355 |   def OnAddSubstance(event): |
---|
3356 | Â Â Â Â dlg =Â wx.TextEntryDialog(None,'Enter a name for this substance','Substance Name Entry','New substance', |
---|
3357 | Â Â Â Â Â Â style=wx.OK) |
---|
3358 |     if dlg.ShowModal() == wx.ID_OK: |
---|
3359 | Â Â Â Â Â Â Name =Â dlg.GetValue() |
---|
3360 | Â Â Â Â Â Â data['Substances'][Name]Â =Â {'Elements':{},'Volume':1.0,'Density':1.0, |
---|
3361 | Â Â Â Â Â Â Â Â 'Scatt density':0.0,'XAnom density':0.,'XAbsorption':0.} |
---|
3362 | Â Â Â Â dlg.Destroy() |
---|
3363 | Â Â Â Â AddElement(Name) |
---|
3364 | Â Â Â Â UpdateSubstanceGrid(G2frame,data) |
---|
3365 | Â Â Â Â |
---|
3366 |   def OnDeleteSubstance(event): |
---|
3367 | Â Â Â Â TextList =Â [] |
---|
3368 |     for name in data['Substances']: |
---|
3369 |       if name != 'vacuum': |
---|
3370 | Â Â Â Â Â Â Â Â TextList +=Â [name,] |
---|
3371 |     if not TextList: |
---|
3372 | Â Â Â Â Â Â return |
---|
3373 |     dlg = wx.SingleChoiceDialog(G2frame, 'Which substance?', 'Select substance to delete', TextList, wx.CHOICEDLG_STYLE) |
---|
3374 | Â Â Â Â try: |
---|
3375 |       if dlg.ShowModal() == wx.ID_OK: |
---|
3376 | Â Â Â Â Â Â Â Â name =Â TextList[dlg.GetSelection()] |
---|
3377 | Â Â Â Â Â Â else: |
---|
3378 | Â Â Â Â Â Â Â Â return |
---|
3379 | Â Â Â Â finally: |
---|
3380 | Â Â Â Â Â Â dlg.Destroy() |
---|
3381 | Â Â Â Â del(data['Substances'][name]) |
---|
3382 | Â Â Â Â UpdateSubstanceGrid(G2frame,data)Â Â Â Â |
---|
3383 | Â Â Â Â Â Â Â Â |
---|
3384 |   def OnAddElement(event):    |
---|
3385 | Â Â Â Â TextList =Â [] |
---|
3386 |     for name in data['Substances']: |
---|
3387 |       if name != 'vacuum': |
---|
3388 | Â Â Â Â Â Â Â Â TextList +=Â [name,] |
---|
3389 |     if not TextList: |
---|
3390 | Â Â Â Â Â Â return |
---|
3391 |     dlg = wx.SingleChoiceDialog(G2frame, 'Which substance?', 'Select substance', TextList, wx.CHOICEDLG_STYLE) |
---|
3392 | Â Â Â Â try: |
---|
3393 |       if dlg.ShowModal() == wx.ID_OK: |
---|
3394 | Â Â Â Â Â Â Â Â name =Â TextList[dlg.GetSelection()] |
---|
3395 | Â Â Â Â Â Â else: |
---|
3396 | Â Â Â Â Â Â Â Â return |
---|
3397 | Â Â Â Â finally: |
---|
3398 | Â Â Â Â Â Â dlg.Destroy() |
---|
3399 | Â Â Â Â AddElement(name) |
---|
3400 | Â Â Â Â UpdateSubstanceGrid(G2frame,data) |
---|
3401 | Â Â Â Â |
---|
3402 |   def AddElement(name): |
---|
3403 | Â Â Â Â ElList =Â data['Substances'][name]['Elements'].keys() |
---|
3404 | Â Â Â Â dlg =Â G2elemGUI.PickElements(G2frame,ElList) |
---|
3405 |     if dlg.ShowModal() == wx.ID_OK: |
---|
3406 |       for El in dlg.Elem: |
---|
3407 | Â Â Â Â Â Â Â Â El =Â El.strip().capitalize() |
---|
3408 | Â Â Â Â Â Â Â Â Info =Â G2elem.GetAtomInfo(El) |
---|
3409 | Â Â Â Â Â Â Â Â Info.update({'Num':1}) |
---|
3410 | Â Â Â Â Â Â Â Â data['Substances'][name]['Elements'][El]Â =Â Info |
---|
3411 | Â Â Â Â Â Â Â Â data['Substances'][name]['Volume']Â =Â G2mth.El2EstVol(data['Substances'][name]['Elements']) |
---|
3412 | Â Â Â Â Â Â Â Â data['Substances'][name]['Density']Â =Â \ |
---|
3413 | Â Â Â Â Â Â Â Â Â Â G2mth.Vol2Den(data['Substances'][name]['Elements'],data['Substances'][name]['Volume']) |
---|
3414 | Â Â Â Â Â Â Â Â data['Substances'][name]['Scatt density']Â =Â \ |
---|
3415 | Â Â Â Â Â Â Â Â Â Â G2mth.XScattDen(data['Substances'][name]['Elements'],data['Substances'][name]['Volume'])[0] |
---|
3416 | Â Â Â Â Â Â Â Â contrst,absorb =Â G2mth.XScattDen(data['Substances'][name]['Elements'],data['Substances'][name]['Volume'],wave)Â Â Â Â Â |
---|
3417 | Â Â Â Â Â Â Â Â data['Substances'][name]['XAnom density']Â =Â contrst |
---|
3418 | Â Â Â Â Â Â Â Â data['Substances'][name]['XAbsorption']Â =Â absorb |
---|
3419 | Â Â Â Â dlg.Destroy() |
---|
3420 | Â Â Â Â |
---|
3421 |   def OnDeleteElement(event): |
---|
3422 | Â Â Â Â TextList =Â [] |
---|
3423 |     for name in data['Substances']: |
---|
3424 |       if name != 'vacuum': |
---|
3425 | Â Â Â Â Â Â Â Â TextList +=Â [name,] |
---|
3426 |     if not TextList: |
---|
3427 | Â Â Â Â Â Â return |
---|
3428 |     dlg = wx.SingleChoiceDialog(G2frame, 'Which substance?', 'Select substance', TextList, wx.CHOICEDLG_STYLE) |
---|
3429 | Â Â Â Â try: |
---|
3430 |       if dlg.ShowModal() == wx.ID_OK: |
---|
3431 | Â Â Â Â Â Â Â Â name =Â TextList[dlg.GetSelection()] |
---|
3432 | Â Â Â Â Â Â else: |
---|
3433 | Â Â Â Â Â Â Â Â return |
---|
3434 | Â Â Â Â finally: |
---|
3435 | Â Â Â Â Â Â dlg.Destroy() |
---|
3436 | Â Â Â Â ElList =Â data['Substances'][name]['Elements'].keys() |
---|
3437 |     if len(ElList): |
---|
3438 | Â Â Â Â Â Â DE =Â G2elemGUI.DeleteElement(G2frame,ElList) |
---|
3439 |       if DE.ShowModal() == wx.ID_OK: |
---|
3440 | Â Â Â Â Â Â Â Â El =Â DE.GetDeleteElement().strip().upper() |
---|
3441 | Â Â Â Â Â Â Â Â del(data['Substances'][name]['Elements'][El]) |
---|
3442 | Â Â Â Â Â Â Â Â data['Substances'][name]['Volume']Â =Â G2mth.El2EstVol(data['Substances'][name]['Elements']) |
---|
3443 | Â Â Â Â Â Â Â Â data['Substances'][name]['Density']Â =Â \ |
---|
3444 | Â Â Â Â Â Â Â Â Â Â G2mth.Vol2Den(data['Substances'][name]['Elements'],data['Substances'][name]['Volume']) |
---|
3445 | Â Â Â Â Â Â Â Â data['Substances'][name]['Scatt density']Â =Â \ |
---|
3446 | Â Â Â Â Â Â Â Â Â Â G2mth.XScattDen(data['Substances'][name]['Elements'],data['Substances'][name]['Volume'])[0] |
---|
3447 | Â Â Â Â Â Â Â Â contrst,absorb =Â G2mth.XScattDen(data['Substances'][name]['Elements'],data['Substances'][name]['Volume'],wave)Â Â Â Â Â |
---|
3448 | Â Â Â Â Â Â Â Â data['Substances'][name]['XAnom density']Â =Â contrst |
---|
3449 | Â Â Â Â Â Â Â Â data['Substances'][name]['XAbsorption']Â =Â absorb |
---|
3450 | Â Â Â Â UpdateSubstanceGrid(G2frame,data) |
---|
3451 | Â Â Â Â Â Â Â Â |
---|
3452 |   def SubstSizer(): |
---|
3453 | Â Â Â Â |
---|
3454 |     def OnValueChange(event): |
---|
3455 | Â Â Â Â Â Â Obj =Â event.GetEventObject() |
---|
3456 |       if len(Indx[Obj.GetId()]) == 3: |
---|
3457 | Â Â Â Â Â Â Â Â name,El,keyId =Â Indx[Obj.GetId()] |
---|
3458 | Â Â Â Â Â Â Â Â try: |
---|
3459 | Â Â Â Â Â Â Â Â Â Â value =Â max(0,float(Obj.GetValue())) |
---|
3460 |         except ValueError: |
---|
3461 | Â Â Â Â Â Â Â Â Â Â value =Â 0 |
---|
3462 | Â Â Â Â Â Â Â Â Â Â Obj.SetValue('%.2f'%(value)) |
---|
3463 | Â Â Â Â Â Â Â Â data['Substances'][name]['Elements'][El][keyId]Â =Â value |
---|
3464 | Â Â Â Â Â Â Â Â data['Substances'][name]['Volume']Â =Â G2mth.El2EstVol(data['Substances'][name]['Elements']) |
---|
3465 | Â Â Â Â Â Â Â Â data['Substances'][name]['Density']Â =Â \ |
---|
3466 | Â Â Â Â Â Â Â Â Â Â G2mth.Vol2Den(data['Substances'][name]['Elements'],data['Substances'][name]['Volume']) |
---|
3467 | Â Â Â Â Â Â else: |
---|
3468 | Â Â Â Â Â Â Â Â name,keyId =Â Indx[Obj.GetId()] |
---|
3469 | Â Â Â Â Â Â Â Â try: |
---|
3470 | Â Â Â Â Â Â Â Â Â Â value =Â max(0,float(Obj.GetValue())) |
---|
3471 |         except ValueError: |
---|
3472 | Â Â Â Â Â Â Â Â Â Â value =Â 1.0 |
---|
3473 | Â Â Â Â Â Â Â Â data['Substances'][name][keyId]Â =Â value |
---|
3474 |         if keyId in 'Volume': |
---|
3475 | Â Â Â Â Â Â Â Â Â Â data['Substances'][name]['Density']Â =Â \ |
---|
3476 | Â Â Â Â Â Â Â Â Â Â Â Â G2mth.Vol2Den(data['Substances'][name]['Elements'],value) |
---|
3477 |         elif keyId in 'Density': |
---|
3478 | Â Â Â Â Â Â Â Â Â Â data['Substances'][name]['Volume']Â =Â \ |
---|
3479 | Â Â Â Â Â Â Â Â Â Â Â Â G2mth.Den2Vol(data['Substances'][name]['Elements'],value) |
---|
3480 | Â Â Â Â Â Â data['Substances'][name]['Scatt density']Â =Â \ |
---|
3481 | Â Â Â Â Â Â Â Â G2mth.XScattDen(data['Substances'][name]['Elements'],data['Substances'][name]['Volume'])[0] |
---|
3482 | Â Â Â Â Â Â contrst,absorb =Â G2mth.XScattDen(data['Substances'][name]['Elements'],data['Substances'][name]['Volume'],wave)Â Â Â Â Â |
---|
3483 | Â Â Â Â Â Â data['Substances'][name]['XAnom density']Â =Â contrst |
---|
3484 | Â Â Â Â Â Â data['Substances'][name]['XAbsorption']Â =Â absorb |
---|
3485 | Â Â Â Â Â Â wx.CallAfter(UpdateSubstanceGrid,G2frame,data) |
---|
3486 | Â Â Â Â |
---|
3487 | Â Â Â Â Indx =Â {} |
---|
3488 | Â Â Â Â substSizer =Â wx.BoxSizer(wx.VERTICAL) |
---|
3489 | Â Â Â Â substSizer.Add(wx.StaticText(parent=G2frame.dataDisplay,label=' Substance list: wavelength: %.5fA'%(wave)), |
---|
3490 | Â Â Â Â Â Â 0,WACV) |
---|
3491 |     for name in data['Substances']: |
---|
3492 | Â Â Â Â Â Â G2G.HorizontalLine(substSizer,G2frame.dataDisplay)Â Â |
---|
3493 | Â Â Â Â Â Â substSizer.Add(wx.StaticText(parent=G2frame.dataDisplay,label=' Data for '+name+':'), |
---|
3494 | Â Â Â Â Â Â Â Â 0,WACV) |
---|
3495 |       if name == 'vacuum': |
---|
3496 | Â Â Â Â Â Â Â Â substSizer.Add(wx.StaticText(parent=G2frame.dataDisplay,label='Â Â Â Â Not applicable'), |
---|
3497 | Â Â Â Â Â Â Â Â Â Â 0,WACV) |
---|
3498 | Â Â Â Â Â Â else:Â Â |
---|
3499 | Â Â Â Â Â Â Â Â elSizer =Â wx.FlexGridSizer(0,6,5,5) |
---|
3500 | Â Â Â Â Â Â Â Â Substance =Â data['Substances'][name] |
---|
3501 | Â Â Â Â Â Â Â Â Elems =Â Substance['Elements'] |
---|
3502 |         for El in Elems:  #do elements as pull downs for isotopes for neutrons |
---|
3503 | Â Â Â Â Â Â Â Â Â Â elSizer.Add(wx.StaticText(parent=G2frame.dataDisplay,label=' '+El+': '), |
---|
3504 | Â Â Â Â Â Â Â Â Â Â Â Â 0,WACV) |
---|
3505 | Â Â Â Â Â Â Â Â Â Â num =Â wx.TextCtrl(G2frame.dataDisplay,value='%.2f'%(Elems[El]['Num']),style=wx.TE_PROCESS_ENTER) |
---|
3506 | Â Â Â Â Â Â Â Â Â Â Indx[num.GetId()]Â =Â [name,El,'Num'] |
---|
3507 | Â Â Â Â Â Â Â Â Â Â num.Bind(wx.EVT_TEXT_ENTER,OnValueChange)Â Â Â Â |
---|
3508 | Â Â Â Â Â Â Â Â Â Â num.Bind(wx.EVT_KILL_FOCUS,OnValueChange) |
---|
3509 | Â Â Â Â Â Â Â Â Â Â elSizer.Add(num,0,WACV) |
---|
3510 | Â Â Â Â Â Â Â Â substSizer.Add(elSizer,0) |
---|
3511 | Â Â Â Â Â Â Â Â vdsSizer =Â wx.FlexGridSizer(0,4,5,5) |
---|
3512 | Â Â Â Â Â Â Â Â vdsSizer.Add(wx.StaticText(parent=G2frame.dataDisplay,label=' Volume: '), |
---|
3513 | Â Â Â Â Â Â Â Â Â Â 0,WACV) |
---|
3514 | Â Â Â Â Â Â Â Â vol =Â wx.TextCtrl(G2frame.dataDisplay,value='%.3f'%(Substance['Volume']),style=wx.TE_PROCESS_ENTER) |
---|
3515 | Â Â Â Â Â Â Â Â Indx[vol.GetId()]Â =Â [name,'Volume'] |
---|
3516 | Â Â Â Â Â Â Â Â vol.Bind(wx.EVT_TEXT_ENTER,OnValueChange)Â Â Â Â |
---|
3517 | Â Â Â Â Â Â Â Â vol.Bind(wx.EVT_KILL_FOCUS,OnValueChange) |
---|
3518 | Â Â Â Â Â Â Â Â vdsSizer.Add(vol,0,WACV)Â Â Â Â Â Â Â Â |
---|
3519 | Â Â Â Â Â Â Â Â vdsSizer.Add(wx.StaticText(parent=G2frame.dataDisplay,label=' Density: '), |
---|
3520 | Â Â Â Â Â Â Â Â Â Â 0,WACV) |
---|
3521 | Â Â Â Â Â Â Â Â den =Â wx.TextCtrl(G2frame.dataDisplay,value='%.3f'%(Substance['Density']),style=wx.TE_PROCESS_ENTER) |
---|
3522 | Â Â Â Â Â Â Â Â Indx[den.GetId()]Â =Â [name,'Density'] |
---|
3523 | Â Â Â Â Â Â Â Â den.Bind(wx.EVT_TEXT_ENTER,OnValueChange)Â Â Â Â |
---|
3524 | Â Â Â Â Â Â Â Â den.Bind(wx.EVT_KILL_FOCUS,OnValueChange) |
---|
3525 | Â Â Â Â Â Â Â Â vdsSizer.Add(den,0,WACV) |
---|
3526 | Â Â Â Â Â Â Â Â substSizer.Add(vdsSizer,0) |
---|
3527 | Â Â Â Â Â Â Â Â substSizer.Add(wx.StaticText(G2frame.dataDisplay, |
---|
3528 |           label=' Scattering density : %.2f *10%scm%s'%(Substance['Scatt density'],Pwr10,Pwrm2)), |
---|
3529 | Â Â Â Â Â Â Â Â Â Â 0,WACV)Â Â Â Â Â Â Â Â |
---|
3530 |         substSizer.Add(wx.StaticText(G2frame.dataDisplay,    #allow neutrons here into NAnom density & NAbsorption |
---|
3531 |           label=' Anomalous density : %.2f *10%scm%s'%(Substance['XAnom density'],Pwr10,Pwrm2)), |
---|
3532 | Â Â Â Â Â Â Â Â Â Â 0,WACV)Â Â Â Â Â Â Â Â |
---|
3533 | Â Â Â Â Â Â Â Â substSizer.Add(wx.StaticText(G2frame.dataDisplay, |
---|
3534 |           label=' X-ray absorption  : %.2f cm%s'%(Substance['XAbsorption'],Pwrm1)), |
---|
3535 | Â Â Â Â Â Â Â Â Â Â 0,WACV)Â Â Â Â Â Â Â Â |
---|
3536 |     return substSizer |
---|
3537 | Â Â Â Â Â Â |
---|
3538 |   Inst = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId, 'Instrument Parameters'))[0] |
---|
3539 | Â Â wave =Â G2mth.getWave(Inst) |
---|
3540 |   if G2frame.dataDisplay: |
---|
3541 | Â Â Â Â G2frame.dataFrame.DestroyChildren()Â # is this a ScrolledWindow? If so, bad! |
---|
3542 | Â Â G2gd.SetDataMenuBar(G2frame,G2frame.dataFrame.SubstanceMenu) |
---|
3543 |   if not G2frame.dataFrame.GetStatusBar(): |
---|
3544 | Â Â Â Â Status =Â G2frame.dataFrame.CreateStatusBar() |
---|
3545 | Â Â G2frame.dataDisplay =Â wxscroll.ScrolledPanel(G2frame.dataFrame) |
---|
3546 | Â Â G2frame.dataFrame.SetLabel('Substances') |
---|
3547 |   G2frame.dataFrame.Bind(wx.EVT_MENU, OnLoadSubstance, id=G2gd.wxID_LOADSUBSTANCE)  |
---|
3548 |   G2frame.dataFrame.Bind(wx.EVT_MENU, OnAddSubstance, id=G2gd.wxID_ADDSUBSTANCE) |
---|
3549 |   G2frame.dataFrame.Bind(wx.EVT_MENU, OnCopySubstance, id=G2gd.wxID_COPYSUBSTANCE) |
---|
3550 |   G2frame.dataFrame.Bind(wx.EVT_MENU, OnDeleteSubstance, id=G2gd.wxID_DELETESUBSTANCE)  |
---|
3551 |   G2frame.dataFrame.Bind(wx.EVT_MENU, OnAddElement, id=G2gd.wxID_ELEMENTADD) |
---|
3552 |   G2frame.dataFrame.Bind(wx.EVT_MENU, OnDeleteElement, id=G2gd.wxID_ELEMENTDELETE) |
---|
3553 | Â Â mainSizer =Â wx.BoxSizer(wx.VERTICAL) |
---|
3554 | Â Â mainSizer.Add(SubstSizer(),0) |
---|
3555 | |
---|
3556 | Â Â mainSizer.Layout()Â Â |
---|
3557 | Â Â G2frame.dataDisplay.SetSizer(mainSizer) |
---|
3558 | Â Â G2frame.dataDisplay.SetAutoLayout(1) |
---|
3559 | Â Â G2frame.dataDisplay.SetupScrolling() |
---|
3560 | Â Â Size =Â mainSizer.Fit(G2frame.dataFrame) |
---|
3561 | Â Â Size[0]Â +=Â 25 |
---|
3562 | Â Â G2frame.dataDisplay.SetSize(Size) |
---|
3563 | Â Â G2frame.dataFrame.setSizePosLeft(Size)Â Â |
---|
3564 | Â Â Â Â |
---|
3565 | ################################################################################ |
---|
3566 | #####Â SASD Models |
---|
3567 | ################################################################################Â Â Â Â Â Â |
---|
3568 | Â Â Â Â |
---|
3569 | def UpdateModelsGrid(G2frame,data): |
---|
3570 | Â Â '''respond to selection of SASD Models data tree item. |
---|
3571 | Â Â ''' |
---|
3572 | Â Â #patches |
---|
3573 |   if 'Current' not in data: |
---|
3574 | Â Â Â Â data['Current']Â =Â 'Size dist.' |
---|
3575 |   if 'logBins' not in data['Size']: |
---|
3576 | Â Â Â Â data['Size']['logBins']Â =Â True |
---|
3577 |   if 'MinMaxDiam' in data['Size']: |
---|
3578 | Â Â Â Â data['Size']['MinDiam']Â =Â 50. |
---|
3579 | Â Â Â Â data['Size']['MaxDiam']Â =Â 10000. |
---|
3580 |     del data['Size']['MinMaxDiam'] |
---|
3581 |   if isinstance(data['Size']['MaxEnt']['Sky'],float): |
---|
3582 | Â Â Â Â data['Size']['MaxEnt']['Sky']Â =Â -3 |
---|
3583 |   if 'Power' not in data['Size']['IPG']: |
---|
3584 | Â Â Â Â data['Size']['IPG']['Power']Â =Â -1 |
---|
3585 |   if 'Matrix' not in data['Particle']: |
---|
3586 | Â Â Â Â data['Particle']['Matrix']Â =Â {'Name':'vacuum','VolFrac':[0.0,False]} |
---|
3587 |   if 'BackFile' not in data: |
---|
3588 | Â Â Â Â data['BackFile']Â =Â '' |
---|
3589 | Â Â #end patches |
---|
3590 | Â Â |
---|
3591 |   def RefreshPlots(newPlot=False): |
---|
3592 | Â Â Â Â PlotText =Â G2frame.G2plotNB.nb.GetPageText(G2frame.G2plotNB.nb.GetSelection()) |
---|
3593 |     if 'Powder' in PlotText: |
---|
3594 | Â Â Â Â Â Â G2plt.PlotPatterns(G2frame,plotType='SASD',newPlot=newPlot) |
---|
3595 |     elif 'Size' in PlotText: |
---|
3596 | Â Â Â Â Â Â G2plt.PlotSASDSizeDist(G2frame) |
---|
3597 | Â Â Â Â Â Â Â Â |
---|
3598 |   def OnAddModel(event): |
---|
3599 |     if data['Current'] == 'Particle fit': |
---|
3600 | Â Â Â Â Â Â material =Â 'vacuum' |
---|
3601 |       if len(data['Particle']['Levels']): |
---|
3602 | Â Â Â Â Â Â Â Â material =Â data['Particle']['Levels'][-1]['Controls']['Material'] |
---|
3603 | Â Â Â Â Â Â data['Particle']['Levels'].append({ |
---|
3604 | Â Â Â Â Â Â Â Â 'Controls':{'FormFact':'Sphere','DistType':'LogNormal','Material':material, |
---|
3605 | Â Â Â Â Â Â Â Â Â Â 'FFargs':{},'SFargs':{},'NumPoints':50,'Cutoff':0.01,'Contrast':0.0, |
---|
3606 |           'SlitSmear':[0.0,False],'StrFact':'Dilute'},  #last 2 not used - future? |
---|
3607 | Â Â Â Â Â Â Â Â 'LogNormal':{'Volume':[0.05,False],'Mean':[1000.,False],'StdDev':[0.5,False],'MinSize':[10.,False],}, |
---|
3608 | Â Â Â Â Â Â Â Â 'Gaussian':{'Volume':[0.05,False],'Mean':[1000.,False],'StdDev':[300.,False],}, |
---|
3609 | Â Â Â Â Â Â Â Â 'LSW':{'Volume':[0.05,False],'Mean':[1000.0,False],}, |
---|
3610 | Â Â Â Â Â Â Â Â 'Schulz-Zimm':{'Volume':[0.05,False],'Mean':[1000.,False],'StdDev':[300.,False],}, |
---|
3611 | Â Â Â Â Â Â Â Â 'Unified':{'G':[1.e3,False],'Rg':[100,False],'B':[1.e-5,False],'P':[4,False],'Cutoff':[1e-5,False],}, |
---|
3612 | Â Â Â Â Â Â Â Â 'Porod':{'B':[1.e-4,False],'P':[4,False],'Cutoff':[1e-5,False],}, |
---|
3613 |         'Monodisperse':{'Volume':[0.05,False],'Radius':[100,False],},  #OK for spheres |
---|
3614 | Â Â Â Â Â Â Â Â 'Bragg':{'PkInt':[100,False],'PkPos':[0.2,False], |
---|
3615 |           'PkSig':[10,False],'PkGam':[10,False],},    #reasonable 31A peak |
---|
3616 | Â Â Â Â Â Â Â Â }) |
---|
3617 | Â Â Â Â Â Â G2sasd.ModelFxn(Profile,ProfDict,Limits,Sample,data) |
---|
3618 | Â Â Â Â Â Â RefreshPlots(True) |
---|
3619 | Â Â Â Â Â Â Â Â Â Â |
---|
3620 | Â Â Â Â wx.CallAfter(UpdateModelsGrid,G2frame,data) |
---|
3621 | Â Â Â Â |
---|
3622 |   def OnCopyModel(event): |
---|
3623 | Â Â Â Â hst =Â G2frame.PatternTree.GetItemText(G2frame.PatternId) |
---|
3624 | Â Â Â Â histList =Â GetHistsLikeSelected(G2frame) |
---|
3625 |     if not histList: |
---|
3626 | Â Â Â Â Â Â G2frame.ErrorDialog('No match','No histograms match '+hst,G2frame.dataFrame) |
---|
3627 | Â Â Â Â Â Â return |
---|
3628 | Â Â Â Â copyList =Â [] |
---|
3629 | Â Â Â Â dlg =Â G2G.G2MultiChoiceDialog( |
---|
3630 |       G2frame.dataFrame, |
---|
3631 | Â Â Â Â Â Â 'Copy models from\n'+hst[5:]+' to...', |
---|
3632 |       'Copy models', histList) |
---|
3633 | Â Â Â Â try: |
---|
3634 |       if dlg.ShowModal() == wx.ID_OK: |
---|
3635 |         for i in dlg.GetSelections(): |
---|
3636 | Â Â Â Â Â Â Â Â Â Â copyList.append(histList[i]) |
---|
3637 | Â Â Â Â finally: |
---|
3638 | Â Â Â Â Â Â dlg.Destroy()Â Â Â Â |
---|
3639 |     for item in copyList: |
---|
3640 | Â Â Â Â Â Â Id =Â G2gd.GetPatternTreeItemId(G2frame,G2frame.root,item) |
---|
3641 | Â Â Â Â Â Â newdata =Â copy.deepcopy(data) |
---|
3642 | Â Â Â Â Â Â G2frame.PatternTree.SetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Id,'Models'),newdata) |
---|
3643 |       if newdata['BackFile']: |
---|
3644 | Â Â Â Â Â Â Â Â Profile =Â G2frame.PatternTree.GetItemPyData(Id)[1] |
---|
3645 | Â Â Â Â Â Â Â Â BackId =Â G2gd.GetPatternTreeItemId(G2frame,G2frame.root,newdata['BackFile']) |
---|
3646 |         BackSample = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,BackId, 'Sample Parameters')) |
---|
3647 | Â Â Â Â Â Â Â Â Profile[5]Â =Â BackSample['Scale'][0]*G2frame.PatternTree.GetItemPyData(BackId)[1][1] |
---|
3648 | Â Â Â Â RefreshPlots(True) |
---|
3649 | Â Â Â Â Â Â Â Â |
---|
3650 |   def OnCopyFlags(event): |
---|
3651 | Â Â Â Â thisModel =Â copy.deepcopy(data) |
---|
3652 | Â Â Â Â hst =Â G2frame.PatternTree.GetItemText(G2frame.PatternId) |
---|
3653 | Â Â Â Â histList =Â GetHistsLikeSelected(G2frame) |
---|
3654 |     if not histList: |
---|
3655 | Â Â Â Â Â Â G2frame.ErrorDialog('No match','No histograms match '+hst,G2frame.dataFrame) |
---|
3656 | Â Â Â Â Â Â return |
---|
3657 | Â Â Â Â dlg =Â G2G.G2MultiChoiceDialog( |
---|
3658 |       G2frame.dataFrame, |
---|
3659 | Â Â Â Â Â Â 'Copy sample ref. flags from\n'+str(hst[5:])+' to...', |
---|
3660 |       'Copy sample flags', histList) |
---|
3661 | Â Â Â Â distChoice =Â ['LogNormal','Gaussian','LSW','Schulz-Zimm','Bragg','Unified', |
---|
3662 | Â Â Â Â Â Â 'Porod','Monodisperse',] |
---|
3663 | Â Â Â Â parmOrder =Â ['Volume','Radius','Mean','StdDev','G','Rg','B','P', |
---|
3664 | Â Â Â Â Â Â 'Cutoff','PkInt','PkPos','PkSig','PkGam','VolFr','Dist',] |
---|
3665 | Â Â Â Â try: |
---|
3666 |       if dlg.ShowModal() == wx.ID_OK: |
---|
3667 | Â Â Â Â Â Â Â Â result =Â dlg.GetSelections() |
---|
3668 |         for i in result: |
---|
3669 | Â Â Â Â Â Â Â Â Â Â item =Â histList[i] |
---|
3670 | Â Â Â Â Â Â Â Â Â Â Id =Â G2gd.GetPatternTreeItemId(G2frame,G2frame.root,item) |
---|
3671 | Â Â Â Â Â Â Â Â Â Â newModel =Â G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Id,'Models')) |
---|
3672 | Â Â Â Â Â Â Â Â Â Â newModel['Back'][1]Â =Â copy.copy(thisModel['Back'][1]) |
---|
3673 |           for ilev,level in enumerate(newModel['Particle']['Levels']): |
---|
3674 |             for form in level: |
---|
3675 |               if form in distChoice: |
---|
3676 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â thisForm =Â thisModel['Particle']['Levels'][ilev][form]Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
---|
3677 |                 for item in parmOrder: |
---|
3678 |                   if item in thisForm: |
---|
3679 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â level[form][item][1]Â =Â copy.copy(thisForm[item][1]) |
---|
3680 |               elif form == 'Controls': |
---|
3681 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â thisForm =Â thisModel['Particle']['Levels'][ilev][form]['SFargs'] |
---|
3682 |                 for item in parmOrder: |
---|
3683 |                   if item in thisForm: |
---|
3684 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â level[form]['SFargs'][item][1]Â =Â copy.copy(thisForm[item][1]) |
---|
3685 | Â Â Â Â finally: |
---|
3686 | Â Â Â Â Â Â dlg.Destroy() |
---|
3687 | Â Â Â Â Â Â Â Â |
---|
3688 |   def OnFitModelAll(event): |
---|
3689 | Â Â Â Â choices =Â G2gd.GetPatternTreeDataNames(G2frame,['SASD',]) |
---|
3690 | Â Â Â Â sel =Â [] |
---|
3691 |     dlg = G2G.G2MultiChoiceDialog(G2frame.dataFrame, 'Sequential SASD refinement', |
---|
3692 | Â Â Â Â Â Â Â 'Select dataset to include',choices) |
---|
3693 | Â Â Â Â dlg.SetSelections(sel) |
---|
3694 | Â Â Â Â names =Â [] |
---|
3695 |     if dlg.ShowModal() == wx.ID_OK: |
---|
3696 |       for sel in dlg.GetSelections(): |
---|
3697 | Â Â Â Â Â Â Â Â names.append(choices[sel]) |
---|
3698 | Â Â Â Â dlg.Destroy() |
---|
3699 | Â Â Â Â SeqResult =Â {'histNames':names} |
---|
3700 | Â Â Â Â Reverse =Â False |
---|
3701 | Â Â Â Â CopyForward =Â False |
---|
3702 | Â Â Â Â choice =Â ['Reverse sequence','Copy from prev.'] |
---|
3703 | Â Â Â Â dlg =Â wx.MultiChoiceDialog(G2frame.dataFrame,'Sequential controls','Select controls',choice) |
---|
3704 |     if dlg.ShowModal() == wx.ID_OK: |
---|
3705 |       for sel in dlg.GetSelections(): |
---|
3706 |         if sel: |
---|
3707 | Â Â Â Â Â Â Â Â Â Â CopyForward =Â True |
---|
3708 | Â Â Â Â Â Â Â Â else: |
---|
3709 | Â Â Â Â Â Â Â Â Â Â Reverse =Â True |
---|
3710 | Â Â Â Â dlg.Destroy() |
---|
3711 |     dlg = wx.ProgressDialog('SASD Sequential fit','Data set name = '+names[0],len(names), |
---|
3712 | Â Â Â Â Â Â style =Â wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE|wx.PD_REMAINING_TIME|wx.PD_CAN_ABORT) |
---|
3713 | Â Â Â Â wx.BeginBusyCursor() |
---|
3714 |     if Reverse: |
---|
3715 | Â Â Â Â Â Â names.reverse() |
---|
3716 | Â Â Â Â try: |
---|
3717 |       for i,name in enumerate(names): |
---|
3718 |         print ' Sequential fit for ',name |
---|
3719 | Â Â Â Â Â Â Â Â GoOn =Â dlg.Update(i,newmsg='Data set name = '+name)[0] |
---|
3720 |         if not GoOn: |
---|
3721 | Â Â Â Â Â Â Â Â Â Â break |
---|
3722 | Â Â Â Â Â Â Â Â Id =Â G2gd.GetPatternTreeItemId(G2frame,G2frame.root,name) |
---|
3723 |         if i and CopyForward: |
---|
3724 |           G2frame.PatternTree.SetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Id, 'Models'),JModel) |
---|
3725 | Â Â Â Â Â Â Â Â IProfDict,IProfile =Â G2frame.PatternTree.GetItemPyData(Id)[:2] |
---|
3726 |         IModel = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Id, 'Models')) |
---|
3727 |         ISample = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Id, 'Sample Parameters')) |
---|
3728 |         ILimits = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Id, 'Limits')) |
---|
3729 | Â Â Â Â Â Â Â Â IfOK,result,varyList,sig,Rvals,covMatrix,parmDict,Msg =Â G2sasd.ModelFit(IProfile,IProfDict,ILimits,ISample,IModel) |
---|
3730 | Â Â Â Â Â Â Â Â JModel =Â copy.deepcopy(IModel) |
---|
3731 |         if not IfOK: |
---|
3732 | Â Â Â Â Â Â Â Â Â Â G2frame.ErrorDialog('Failed sequential refinement for data '+name, |
---|
3733 | Â Â Â Â Â Â Â Â Â Â Â Â ' Msg: '+Msg+'\nYou need to rethink your selection of parameters\n'+Â Â \ |
---|
3734 | Â Â Â Â Â Â Â Â Â Â Â Â ' Model restored to previous version for'+name) |
---|
3735 | Â Â Â Â Â Â Â Â Â Â SeqResult['histNames']Â =Â names[:i] |
---|
3736 | Â Â Â Â Â Â Â Â Â Â dlg.Destroy() |
---|
3737 | Â Â Â Â Â Â Â Â Â Â break |
---|
3738 | Â Â Â Â Â Â Â Â else: |
---|
3739 |           G2frame.PatternTree.SetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Id, 'Models'),copy.deepcopy(IModel)) |
---|
3740 | Â Â Â Â Â Â Â Â |
---|
3741 | Â Â Â Â Â Â Â Â G2sasd.ModelFxn(IProfile,IProfDict,ILimits,ISample,IModel) |
---|
3742 | Â Â Â Â Â Â Â Â SeqResult[name]Â =Â {'variables':result[0],'varyList':varyList,'sig':sig,'Rvals':Rvals, |
---|
3743 | Â Â Â Â Â Â Â Â Â Â 'covMatrix':covMatrix,'title':name,'parmDict':parmDict} |
---|
3744 | Â Â Â Â Â Â else: |
---|
3745 | Â Â Â Â Â Â Â Â dlg.Destroy() |
---|
3746 |         print ' ***** Small angle sequential refinement successful *****' |
---|
3747 | Â Â Â Â finally: |
---|
3748 | Â Â Â Â Â Â wx.EndBusyCursor()Â Â |
---|
3749 | Â Â Â Â Id =Â G2gd.GetPatternTreeItemId(G2frame,G2frame.root,'Sequential results') |
---|
3750 |     if Id: |
---|
3751 | Â Â Â Â Â Â G2frame.PatternTree.SetItemPyData(Id,SeqResult) |
---|
3752 | Â Â Â Â else: |
---|
3753 | Â Â Â Â Â Â Id =Â G2frame.PatternTree.AppendItem(parent=G2frame.root,text='Sequential results') |
---|
3754 | Â Â Â Â Â Â G2frame.PatternTree.SetItemPyData(Id,SeqResult) |
---|
3755 | Â Â Â Â G2frame.PatternTree.SelectItem(Id) |
---|
3756 | Â Â Â Â |
---|
3757 |   def OnFitModel(event): |
---|
3758 |     if data['Current'] == 'Size dist.': |
---|
3759 |       if not any(Sample['Contrast']): |
---|
3760 | Â Â Â Â Â Â Â Â G2frame.ErrorDialog('No contrast; your sample is a vacuum!', |
---|
3761 | Â Â Â Â Â Â Â Â Â Â 'You need to define a scattering substance!\n'+Â Â \ |
---|
3762 | Â Â Â Â Â Â Â Â Â Â ' Do Substances and then Sample parameters') |
---|
3763 | Â Â Â Â Â Â Â Â return |
---|
3764 | Â Â Â Â Â Â G2sasd.SizeDistribution(Profile,ProfDict,Limits,Sample,data) |
---|
3765 | Â Â Â Â Â Â G2plt.PlotSASDSizeDist(G2frame) |
---|
3766 | Â Â Â Â Â Â RefreshPlots(True) |
---|
3767 | Â Â Â Â Â Â |
---|
3768 |     elif data['Current'] == 'Particle fit': |
---|
3769 | Â Â Â Â Â Â SaveState() |
---|
3770 | Â Â Â Â Â Â Results =Â G2sasd.ModelFit(Profile,ProfDict,Limits,Sample,data) |
---|
3771 |       if not Results[0]: |
---|
3772 | Â Â Â Â Â Â Â Â Â Â G2frame.ErrorDialog('Failed refinement', |
---|
3773 | Â Â Â Â Â Â Â Â Â Â Â Â ' Msg: '+Results[-1]+'\nYou need to rethink your selection of parameters\n'+Â Â \ |
---|
3774 | Â Â Â Â Â Â Â Â Â Â Â Â ' Model restored to previous version') |
---|
3775 | Â Â Â Â Â Â G2sasd.ModelFxn(Profile,ProfDict,Limits,Sample,data) |
---|
3776 | Â Â Â Â Â Â RefreshPlots(True) |
---|
3777 | Â Â Â Â Â Â wx.CallAfter(UpdateModelsGrid,G2frame,data) |
---|
3778 | Â Â Â Â Â Â |
---|
3779 |   def OnUnDo(event): |
---|
3780 | Â Â Â Â DoUnDo() |
---|
3781 | Â Â Â Â data =Â G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame, |
---|
3782 | Â Â Â Â Â Â G2frame.PatternId,'Models')) |
---|
3783 | Â Â Â Â G2frame.dataFrame.SasdUndo.Enable(False) |
---|
3784 | Â Â Â Â UpdateModelsGrid(G2frame,data) |
---|
3785 | Â Â Â Â G2sasd.ModelFxn(Profile,ProfDict,Limits,Sample,data) |
---|
3786 | Â Â Â Â RefreshPlots(True) |
---|
3787 | |
---|
3788 |   def DoUnDo(): |
---|
3789 |     print 'Undo last refinement' |
---|
3790 | Â Â Â Â file =Â open(G2frame.undosasd,'rb') |
---|
3791 | Â Â Â Â PatternId =Â G2frame.PatternId |
---|
3792 |     G2frame.PatternTree.SetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Models'),cPickle.load(file)) |
---|
3793 |     print ' Models recovered' |
---|
3794 | Â Â Â Â file.close() |
---|
3795 | Â Â Â Â |
---|
3796 |   def SaveState(): |
---|
3797 | Â Â Â Â G2frame.undosasd =Â os.path.join(G2frame.dirname,'GSASIIsasd.save') |
---|
3798 | Â Â Â Â file =Â open(G2frame.undosasd,'wb') |
---|
3799 | Â Â Â Â PatternId =Â G2frame.PatternId |
---|
3800 |     for item in ['Models']: |
---|
3801 | Â Â Â Â Â Â cPickle.dump(G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId,item)),file,1) |
---|
3802 | Â Â Â Â file.close() |
---|
3803 | Â Â Â Â G2frame.dataFrame.SasdUndo.Enable(True) |
---|
3804 | Â Â Â Â |
---|
3805 |   def OnSelectFit(event): |
---|
3806 | Â Â Â Â data['Current']Â =Â fitSel.GetValue() |
---|
3807 | Â Â Â Â wx.CallAfter(UpdateModelsGrid,G2frame,data) |
---|
3808 | Â Â Â Â |
---|
3809 |   def OnCheckBox(event): |
---|
3810 | Â Â Â Â Obj =Â event.GetEventObject() |
---|
3811 | Â Â Â Â item,ind =Â Indx[Obj.GetId()] |
---|
3812 | Â Â Â Â item[ind]Â =Â Obj.GetValue() |
---|
3813 | Â Â Â Â |
---|
3814 |   def OnIntVal(event): |
---|
3815 | Â Â Â Â Obj =Â event.GetEventObject() |
---|
3816 | Â Â Â Â item,ind,minVal =Â Indx[Obj.GetId()] |
---|
3817 | Â Â Â Â try: |
---|
3818 | Â Â Â Â Â Â value =Â int(Obj.GetValue()) |
---|
3819 |       if value <= minVal: |
---|
3820 |         raise ValueError |
---|
3821 |     except ValueError: |
---|
3822 | Â Â Â Â Â Â value =Â item[ind] |
---|
3823 | Â Â Â Â Obj.SetValue(str(value)) |
---|
3824 | Â Â Â Â item[ind]Â =Â value |
---|
3825 | |
---|
3826 |   def SizeSizer(): |
---|
3827 | Â Â Â Â |
---|
3828 |     def OnShape(event): |
---|
3829 | Â Â Â Â Â Â data['Size']['Shape'][0]Â =Â partsh.GetValue() |
---|
3830 | Â Â Â Â Â Â wx.CallAfter(UpdateModelsGrid,G2frame,data) |
---|
3831 | Â Â Â Â Â Â |
---|
3832 |     def OnMethod(event): |
---|
3833 | Â Â Â Â Â Â data['Size']['Method']Â =Â method.GetValue() |
---|
3834 | Â Â Â Â Â Â wx.CallAfter(UpdateModelsGrid,G2frame,data) |
---|
3835 | Â Â Â Â Â Â |
---|
3836 |     def OnPartVal(event): |
---|
3837 | Â Â Â Â Â Â try: |
---|
3838 | Â Â Â Â Â Â Â Â val =Â max(0.0,float(partprm.GetValue())) |
---|
3839 |       except ValueError: |
---|
3840 | Â Â Â Â Â Â Â Â val =Â 1 |
---|
3841 | Â Â Â Â Â Â data['Size']['Shape'][1]Â =Â val |
---|
3842 | Â Â Â Â Â Â partprm.SetValue('%.3f'%(val)) |
---|
3843 | Â Â Â Â Â Â |
---|
3844 | Â Â Â Â sizeSizer =Â wx.BoxSizer(wx.VERTICAL) |
---|
3845 | Â Â Â Â sizeSizer.Add(wx.StaticText(G2frame.dataDisplay,label=' Size distribution parameters: '),0,WACV) |
---|
3846 | Â Â Â Â binSizer =Â wx.FlexGridSizer(0,7,5,5) |
---|
3847 | Â Â Â Â binSizer.Add(wx.StaticText(G2frame.dataDisplay,label=' No. size bins: '),0,WACV) |
---|
3848 | Â Â Â Â bins =Â ['50','100','150','200'] |
---|
3849 | Â Â Â Â nbins =Â wx.ComboBox(G2frame.dataDisplay,value=str(data['Size']['Nbins']),choices=bins, |
---|
3850 | Â Â Â Â Â Â style=wx.CB_READONLY|wx.CB_DROPDOWN) |
---|
3851 | Â Â Â Â Indx[nbins.GetId()]Â =Â [data['Size'],'Nbins',0] |
---|
3852 | Â Â Â Â nbins.Bind(wx.EVT_COMBOBOX,OnIntVal)Â Â Â Â |
---|
3853 | Â Â Â Â binSizer.Add(nbins,0,WACV) |
---|
3854 | Â Â Â Â binSizer.Add(wx.StaticText(G2frame.dataDisplay,label=' Min diam.: '),0,WACV) |
---|
3855 | Â Â Â Â minDias =Â ['10','25','50','100','150','200'] |
---|
3856 | Â Â Â Â mindiam =Â wx.ComboBox(G2frame.dataDisplay,value=str(data['Size']['MinDiam']),choices=minDias, |
---|
3857 | Â Â Â Â Â Â style=wx.CB_DROPDOWN) |
---|
3858 | Â Â Â Â mindiam.Bind(wx.EVT_LEAVE_WINDOW,OnIntVal) |
---|
3859 | Â Â Â Â mindiam.Bind(wx.EVT_TEXT_ENTER,OnIntVal)Â Â Â Â |
---|
3860 | Â Â Â Â mindiam.Bind(wx.EVT_KILL_FOCUS,OnIntVal) |
---|
3861 | Â Â Â Â Indx[mindiam.GetId()]Â =Â [data['Size'],'MinDiam',0] |
---|
3862 | Â Â Â Â binSizer.Add(mindiam,0,WACV) |
---|
3863 | Â Â Â Â binSizer.Add(wx.StaticText(G2frame.dataDisplay,label=' Max diam.: '),0,WACV) |
---|
3864 |     maxDias = [str(1000*(i+1)) for i in range(10)] |
---|
3865 | Â Â Â Â maxdiam =Â wx.ComboBox(G2frame.dataDisplay,value=str(data['Size']['MaxDiam']),choices=maxDias, |
---|
3866 | Â Â Â Â Â Â style=wx.CB_DROPDOWN) |
---|
3867 | Â Â Â Â maxdiam.Bind(wx.EVT_LEAVE_WINDOW,OnIntVal) |
---|
3868 | Â Â Â Â maxdiam.Bind(wx.EVT_TEXT_ENTER,OnIntVal)Â Â Â Â |
---|
3869 | Â Â Â Â maxdiam.Bind(wx.EVT_KILL_FOCUS,OnIntVal) |
---|
3870 | Â Â Â Â Indx[maxdiam.GetId()]Â =Â [data['Size'],'MaxDiam',0] |
---|
3871 | Â Â Â Â binSizer.Add(maxdiam,0,WACV) |
---|
3872 | Â Â Â Â logbins =Â wx.CheckBox(G2frame.dataDisplay,label='Log bins?') |
---|
3873 | Â Â Â Â Indx[logbins.GetId()]Â =Â [data['Size'],'logBins'] |
---|
3874 | Â Â Â Â logbins.SetValue(data['Size']['logBins']) |
---|
3875 |     logbins.Bind(wx.EVT_CHECKBOX, OnCheckBox) |
---|
3876 | Â Â Â Â binSizer.Add(logbins,0,WACV) |
---|
3877 | Â Â Â Â sizeSizer.Add(binSizer,0) |
---|
3878 | Â Â Â Â sizeSizer.Add((5,5),0) |
---|
3879 | Â Â Â Â partSizer =Â wx.BoxSizer(wx.HORIZONTAL) |
---|
3880 | Â Â Â Â partSizer.Add(wx.StaticText(G2frame.dataDisplay,label='Particle description: '),0,WACV) |
---|
3881 | Â Â Â Â shapes =Â {'Spheroid':' Aspect ratio: ','Cylinder':' Diameter ','Cylinder AR':' Aspect ratio: ', |
---|
3882 | Â Â Â Â Â Â 'Unified sphere':'','Unified rod':' Diameter: ','Unified rod AR':' Aspect ratio: ', |
---|
3883 | Â Â Â Â Â Â 'Unified disk':' Thickness: '} |
---|
3884 | Â Â Â Â partsh =Â wx.ComboBox(G2frame.dataDisplay,value=str(data['Size']['Shape'][0]),choices=shapes.keys(), |
---|
3885 | Â Â Â Â Â Â style=wx.CB_READONLY|wx.CB_DROPDOWN) |
---|
3886 | Â Â Â Â partsh.Bind(wx.EVT_COMBOBOX,OnShape)Â Â Â Â |
---|
3887 | Â Â Â Â partSizer.Add(partsh,0,WACV) |
---|
3888 |     if data['Size']['Shape'][0] not in ['Unified sphere',]: |
---|
3889 | Â Â Â Â Â Â partSizer.Add(wx.StaticText(G2frame.dataDisplay,label=shapes[data['Size']['Shape'][0]]),0,WACV) |
---|
3890 | Â Â Â Â Â Â partprm =Â wx.TextCtrl(G2frame.dataDisplay,value='%.3f'%(data['Size']['Shape'][1]), |
---|
3891 | Â Â Â Â Â Â Â Â style=wx.TE_PROCESS_ENTER) |
---|
3892 | Â Â Â Â Â Â partprm.Bind(wx.EVT_TEXT_ENTER,OnPartVal)Â Â Â Â |
---|
3893 | Â Â Â Â Â Â partprm.Bind(wx.EVT_KILL_FOCUS,OnPartVal) |
---|
3894 | Â Â Â Â Â Â partSizer.Add(partprm,0,WACV) |
---|
3895 | Â Â Â Â sizeSizer.Add(partSizer,0) |
---|
3896 | Â Â Â Â sizeSizer.Add((5,5),0) |
---|
3897 | Â Â Â Â fitSizer =Â wx.BoxSizer(wx.HORIZONTAL) |
---|
3898 | Â Â Â Â methods =Â ['MaxEnt','IPG',] |
---|
3899 | Â Â Â Â fitSizer.Add(wx.StaticText(G2frame.dataDisplay,label='Fitting method: '),0,WACV) |
---|
3900 | Â Â Â Â method =Â wx.ComboBox(G2frame.dataDisplay,value=data['Size']['Method'],choices=methods, |
---|
3901 | Â Â Â Â Â Â style=wx.CB_READONLY|wx.CB_DROPDOWN) |
---|
3902 | Â Â Â Â method.Bind(wx.EVT_COMBOBOX,OnMethod) |
---|
3903 | Â Â Â Â fitSizer.Add(method,0,WACV) |
---|
3904 | Â Â Â Â iters =Â ['10','25','50','100','150','200']Â Â Â Â |
---|
3905 | Â Â Â Â fitSizer.Add(wx.StaticText(G2frame.dataDisplay,label=' No. iterations: '),0,WACV) |
---|
3906 | Â Â Â Â Method =Â data['Size']['Method'] |
---|
3907 |     iter = wx.ComboBox(G2frame.dataDisplay,value=str(data['Size'][Method]['Niter']),choices=iters, |
---|
3908 | Â Â Â Â Â Â style=wx.CB_READONLY|wx.CB_DROPDOWN) |
---|
3909 | Â Â Â Â Indx[iter.GetId()]Â =Â [data['Size'][Method],'Niter',0] |
---|
3910 | Â Â Â Â iter.Bind(wx.EVT_COMBOBOX,OnIntVal) |
---|
3911 | Â Â Â Â fitSizer.Add(iter,0,WACV) |
---|
3912 |     if 'MaxEnt' in data['Size']['Method']: |
---|
3913 | Â Â Â Â Â Â fitSizer.Add(wx.StaticText(G2frame.dataDisplay,label=' Log floor factor: '),0,WACV) |
---|
3914 |       floors = [str(-i) for i in range(9)] |
---|
3915 | Â Â Â Â Â Â floor =Â wx.ComboBox(G2frame.dataDisplay,value=str(data['Size']['MaxEnt']['Sky']),choices=floors, |
---|
3916 | Â Â Â Â Â Â Â Â style=wx.CB_READONLY|wx.CB_DROPDOWN) |
---|
3917 | Â Â Â Â Â Â Indx[floor.GetId()]Â =Â [data['Size']['MaxEnt'],'Sky',-10] |
---|
3918 | Â Â Â Â Â Â floor.Bind(wx.EVT_COMBOBOX,OnIntVal) |
---|
3919 | Â Â Â Â Â Â fitSizer.Add(floor,0,WACV) |
---|
3920 |     elif 'IPG' in data['Size']['Method']: |
---|
3921 | Â Â Â Â Â Â fitSizer.Add(wx.StaticText(G2frame.dataDisplay,label=' Q power weight (-1 for sigma): '),0,WACV) |
---|
3922 | Â Â Â Â Â Â choices =Â ['-1','0','1','2','3','4'] |
---|
3923 | Â Â Â Â Â Â power =Â wx.ComboBox(G2frame.dataDisplay,value=str(data['Size']['IPG']['Power']),choices=choices, |
---|
3924 | Â Â Â Â Â Â Â Â style=wx.CB_READONLY|wx.CB_DROPDOWN) |
---|
3925 | Â Â Â Â Â Â Indx[power.GetId()]Â =Â [data['Size']['IPG'],'Power',-2] |
---|
3926 | Â Â Â Â Â Â power.Bind(wx.EVT_COMBOBOX,OnIntVal) |
---|
3927 | Â Â Â Â Â Â fitSizer.Add(power,0,WACV) |
---|
3928 | Â Â Â Â sizeSizer.Add(fitSizer,0) |
---|
3929 | |
---|
3930 |     return sizeSizer |
---|
3931 | Â Â Â Â |
---|
3932 |   def PartSizer(): |
---|
3933 | Â Â Â Â |
---|
3934 | Â Â Â Â FormFactors =Â {'Sphere':{},'Spheroid':{'Aspect ratio':[1.0,False]}, |
---|
3935 | Â Â Â Â Â Â 'Cylinder':{'Length':[100.,False]},'Cylinder diam':{'Diameter':[100.,False]}, |
---|
3936 | Â Â Â Â Â Â 'Cylinder AR':{'Aspect ratio':[1.0,False]},'Unified sphere':{}, |
---|
3937 | Â Â Â Â Â Â 'Unified rod':{'Length':[100.,False]},'Unified rod AR':{'Aspect ratio':[1.0,False]}, |
---|
3938 | Â Â Â Â Â Â 'Unified disk':{'Thickness':[100.,False]}, |
---|
3939 | Â Â Â Â Â Â 'Unified tube':{'Length':[100.,False],'Thickness':[10.,False]},} |
---|
3940 | Â Â Â Â Â Â Â Â |
---|
3941 | Â Â Â Â StructureFactors =Â {'Dilute':{},'Hard sphere':{'VolFr':[0.1,False],'Dist':[100.,False]}, |
---|
3942 | Â Â Â Â Â Â 'Sticky hard sphere':{'VolFr':[0.1,False],'Dist':[100.,False],'epis':[0.05,False],'Sticky':[0.2,False]}, |
---|
3943 | Â Â Â Â Â Â 'Square well':{'VolFr':[0.1,False],'Dist':[100.,False],'Depth':[0.1,False],'Width':[1.,False]}, |
---|
3944 | Â Â Â Â Â Â 'InterPrecipitate':{'VolFr':[0.1,False],'Dist':[100.,False]},} |
---|
3945 | Â Â Â Â Â Â Â Â |
---|
3946 | Â Â Â Â ffDistChoices =Â ['Sphere','Spheroid','Cylinder','Cylinder diam', |
---|
3947 | Â Â Â Â Â Â 'Cylinder AR','Unified sphere','Unified rod','Unified rod AR', |
---|
3948 | Â Â Â Â Â Â 'Unified disk','Unified tube',] |
---|
3949 | Â Â Â Â Â Â Â Â |
---|
3950 | Â Â Â Â ffMonoChoices =Â ['Sphere','Spheroid','Cylinder','Cylinder AR',] |
---|
3951 | Â Â Â Â |
---|
3952 | Â Â Â Â sfChoices =Â ['Dilute','Hard sphere','Sticky hard sphere','Square well','InterPrecipitate',] |
---|
3953 | Â Â Â Â Â Â |
---|
3954 | Â Â Â Â slMult =Â 1000. |
---|
3955 | Â Â Â Â Â Â Â Â Â |
---|
3956 |     def OnValue(event): |
---|
3957 | Â Â Â Â Â Â Obj =Â event.GetEventObject() |
---|
3958 | Â Â Â Â Â Â item,key,sldrObj =Â Indx[Obj.GetId()] |
---|
3959 | Â Â Â Â Â Â try: |
---|
3960 | Â Â Â Â Â Â Â Â value =Â float(Obj.GetValue()) |
---|
3961 |         if value <= 0.: |
---|
3962 |           raise ValueError |
---|
3963 |       except ValueError: |
---|
3964 | Â Â Â Â Â Â Â Â value =Â item[key][0] |
---|
3965 | Â Â Â Â Â Â item[key][0]Â =Â value |
---|
3966 | Â Â Â Â Â Â Obj.SetValue('%.3g'%(value)) |
---|
3967 |       if key in ['P','epis','Sticky','Depth','Width','VolFr','Dist']: |
---|
3968 | Â Â Â Â Â Â Â Â sldrObj.SetValue(slMult*value) |
---|
3969 | Â Â Â Â Â Â else: |
---|
3970 | Â Â Â Â Â Â Â Â logv =Â np.log10(value) |
---|
3971 | Â Â Â Â Â Â Â Â valMinMax =Â [logv-1,logv+1] |
---|
3972 | Â Â Â Â Â Â Â Â sldrObj.SetRange(slMult*valMinMax[0],slMult*valMinMax[1]) |
---|
3973 | Â Â Â Â Â Â Â Â sldrObj.SetValue(slMult*logv) |
---|
3974 | Â Â Â Â Â Â G2sasd.ModelFxn(Profile,ProfDict,Limits,Sample,data) |
---|
3975 | Â Â Â Â Â Â RefreshPlots() |
---|
3976 | Â Â Â Â Â Â |
---|
3977 |     def OnSelect(event): |
---|
3978 | Â Â Â Â Â Â Obj =Â event.GetEventObject() |
---|
3979 | Â Â Â Â Â Â item,key =Â Indx[Obj.GetId()] |
---|
3980 | Â Â Â Â Â Â item[key]Â =Â Obj.GetValue() |
---|
3981 |       if 'Refine' not in Obj.GetLabel(): |
---|
3982 |         if 'FormFact' in key : |
---|
3983 | Â Â Â Â Â Â Â Â Â Â item['FFargs']Â =Â FormFactors[Obj.GetValue()] |
---|
3984 |         elif 'StrFact' in key: |
---|
3985 | Â Â Â Â Â Â Â Â Â Â item['SFargs']Â =Â StructureFactors[Obj.GetValue()] |
---|
3986 | Â Â Â Â Â Â Â Â wx.CallAfter(UpdateModelsGrid,G2frame,data) |
---|
3987 | Â Â Â Â Â Â Â Â G2sasd.ModelFxn(Profile,ProfDict,Limits,Sample,data) |
---|
3988 | Â Â Â Â Â Â Â Â RefreshPlots() |
---|
3989 | Â Â Â Â Â Â Â Â |
---|
3990 |     def OnDelLevel(event): |
---|
3991 | Â Â Â Â Â Â Obj =Â event.GetEventObject() |
---|
3992 | Â Â Â Â Â Â item =Â Indx[Obj.GetId()] |
---|
3993 |       del data['Particle']['Levels'][item] |
---|
3994 | Â Â Â Â Â Â wx.CallAfter(UpdateModelsGrid,G2frame,data) |
---|
3995 | Â Â Â Â Â Â G2sasd.ModelFxn(Profile,ProfDict,Limits,Sample,data) |
---|
3996 | Â Â Â Â Â Â RefreshPlots() |
---|
3997 | Â Â Â Â Â Â |
---|
3998 |     def OnParmSlider(event): |
---|
3999 | Â Â Â Â Â Â Obj =Â event.GetEventObject() |
---|
4000 | Â Â Â Â Â Â item,key,pvObj =Â Indx[Obj.GetId()] |
---|
4001 | Â Â Â Â Â Â slide =Â Obj.GetValue() |
---|
4002 |       if key in ['P','epis','Sticky','Depth','Width','VolFr','Dist']: |
---|
4003 | Â Â Â Â Â Â Â Â value =Â float(slide/slMult) |
---|
4004 | Â Â Â Â Â Â else: |
---|
4005 | Â Â Â Â Â Â Â Â value =Â 10.**float(slide/slMult) |
---|
4006 | Â Â Â Â Â Â item[key][0]Â =Â value |
---|
4007 | Â Â Â Â Â Â pvObj.SetValue('%.3g'%(item[key][0])) |
---|
4008 | Â Â Â Â Â Â G2sasd.ModelFxn(Profile,ProfDict,Limits,Sample,data) |
---|
4009 | Â Â Â Â Â Â RefreshPlots() |
---|
4010 | Â Â Â Â Â Â |
---|
4011 |     def SizeSizer(): |
---|
4012 | Â Â Â Â Â Â sizeSizer =Â wx.FlexGridSizer(0,4,5,5) |
---|
4013 | Â Â Â Â Â Â sizeSizer.Add(wx.StaticText(G2frame.dataDisplay,label=' Distribution: '),0,WACV) |
---|
4014 | Â Â Â Â Â Â Distchoice =Â ['LogNormal','Gaussian','LSW','Schulz-Zimm','Bragg','Unified','Porod','Monodisperse',] |
---|
4015 | Â Â Â Â Â Â distChoice =Â wx.ComboBox(G2frame.dataDisplay,value=level['Controls']['DistType'],choices=Distchoice, |
---|
4016 | Â Â Â Â Â Â Â Â style=wx.CB_READONLY|wx.CB_DROPDOWN) |
---|
4017 | Â Â Â Â Â Â Indx[distChoice.GetId()]Â =Â [level['Controls'],'DistType'] |
---|
4018 | Â Â Â Â Â Â distChoice.Bind(wx.EVT_COMBOBOX,OnSelect) |
---|
4019 | Â Â Â Â Â Â sizeSizer.Add(distChoice,0,WACV)Â Â #put structure factor choices here |
---|
4020 |       if level['Controls']['DistType'] not in ['Bragg','Unified','Porod',]: |
---|
4021 | Â Â Â Â Â Â Â Â sizeSizer.Add(wx.StaticText(G2frame.dataDisplay,label=' Form Factor: '),0,WACV) |
---|
4022 |         if 'Mono' in level['Controls']['DistType']: |
---|
4023 | Â Â Â Â Â Â Â Â Â Â ffChoice =Â wx.ComboBox(G2frame.dataDisplay,value=level['Controls']['FormFact'],choices=ffMonoChoices, |
---|
4024 | Â Â Â Â Â Â Â Â Â Â Â Â style=wx.CB_READONLY|wx.CB_DROPDOWN) |
---|
4025 | Â Â Â Â Â Â Â Â else: |
---|
4026 | Â Â Â Â Â Â Â Â Â Â ffChoice =Â wx.ComboBox(G2frame.dataDisplay,value=level['Controls']['FormFact'],choices=ffDistChoices, |
---|
4027 | Â Â Â Â Â Â Â Â Â Â Â Â style=wx.CB_READONLY|wx.CB_DROPDOWN) |
---|
4028 | Â Â Â Â Â Â Â Â Indx[ffChoice.GetId()]Â =Â [level['Controls'],'FormFact'] |
---|
4029 | Â Â Â Â Â Â Â Â ffChoice.Bind(wx.EVT_COMBOBOX,OnSelect) |
---|
4030 | Â Â Â Â Â Â Â Â sizeSizer.Add(ffChoice,0,WACV) |
---|
4031 | Â Â Â Â Â Â Â Â |
---|
4032 | Â Â Â Â Â Â Â Â sizeSizer.Add(wx.StaticText(G2frame.dataDisplay,label=' Material: '),0,WACV) |
---|
4033 | Â Â Â Â Â Â Â Â matSel =Â wx.ComboBox(G2frame.dataDisplay,value=level['Controls']['Material'], |
---|
4034 | Â Â Â Â Â Â Â Â Â Â choices=Substances['Substances'].keys(),style=wx.CB_READONLY|wx.CB_DROPDOWN) |
---|
4035 | Â Â Â Â Â Â Â Â Indx[matSel.GetId()]Â =Â [level['Controls'],'Material'] |
---|
4036 | Â Â Â Â Â Â Â Â matSel.Bind(wx.EVT_COMBOBOX,OnSelect)Â Â Â Â |
---|
4037 | Â Â Â Â Â Â Â Â sizeSizer.Add(matSel,0,WACV)Â #do neutron test here? |
---|
4038 | Â Â Â Â Â Â Â Â rho =Â Substances['Substances'][level['Controls']['Material']].get('XAnom density',0.0) |
---|
4039 | Â Â Â Â Â Â Â Â level['Controls']['Contrast']Â =Â contrast =Â (rho-rhoMat)**2Â Â Â Â Â Â Â Â Â |
---|
4040 | Â Â Â Â Â Â Â Â sizeSizer.Add(wx.StaticText(G2frame.dataDisplay,label=' Resonant X-ray contrast: '),0,WACV) |
---|
4041 |         sizeSizer.Add(wx.StaticText(G2frame.dataDisplay,label=' %.2f 10%scm%s'%(contrast,Pwr20,Pwrm4)),0,WACV) |
---|
4042 |         if 'Mono' not in level['Controls']['DistType']: |
---|
4043 | Â Â Â Â Â Â Â Â Â Â sizeSizer.Add(wx.StaticText(G2frame.dataDisplay,label=' Num. radii: '),0,WACV) |
---|
4044 | Â Â Â Â Â Â Â Â Â Â radii =Â ['25','50','75','100','200'] |
---|
4045 | Â Â Â Â Â Â Â Â Â Â nRadii =Â wx.ComboBox(G2frame.dataDisplay,value=str(level['Controls']['NumPoints']),choices=radii, |
---|
4046 | Â Â Â Â Â Â Â Â Â Â Â Â style=wx.CB_READONLY|wx.CB_DROPDOWN) |
---|
4047 | Â Â Â Â Â Â Â Â Â Â Indx[nRadii.GetId()]Â =Â [level['Controls'],'NumPoints'] |
---|
4048 | Â Â Â Â Â Â Â Â Â Â nRadii.Bind(wx.EVT_COMBOBOX,OnSelect) |
---|
4049 | Â Â Â Â Â Â Â Â Â Â sizeSizer.Add(nRadii,0,WACV) |
---|
4050 | Â Â Â Â Â Â Â Â Â Â sizeSizer.Add(wx.StaticText(G2frame.dataDisplay,label=' R dist. cutoff: '),0,WACV) |
---|
4051 | Â Â Â Â Â Â Â Â Â Â rCutoff =Â G2G.ValidatedTxtCtrl(G2frame.dataDisplay,level['Controls'],'Cutoff', |
---|
4052 | Â Â Â Â Â Â Â Â Â Â Â Â min=0.001,max=0.1,typeHint=float) |
---|
4053 | Â Â Â Â Â Â Â Â Â Â sizeSizer.Add(rCutoff,0,WACV) |
---|
4054 |       elif level['Controls']['DistType'] in ['Unified',]: |
---|
4055 | Â Â Â Â Â Â Â Â Parms =Â level['Unified'] |
---|
4056 | Â Â Â Â Â Â Â Â Best =Â G2sasd.Bestimate(Parms['G'][0],Parms['Rg'][0],Parms['P'][0]) |
---|
4057 | Â Â Â Â Â Â Â Â sizeSizer.Add(wx.StaticText(G2frame.dataDisplay,label=' Estimated Dist B: %12.4g'%(Best)),0,WACV) |
---|
4058 |       return sizeSizer |
---|
4059 | Â Â Â Â Â Â |
---|
4060 |     def ParmSizer(): |
---|
4061 | Â Â Â Â Â Â parmSizer =Â wx.FlexGridSizer(0,3,5,5) |
---|
4062 | Â Â Â Â Â Â parmSizer.AddGrowableCol(2,1) |
---|
4063 | Â Â Â Â Â Â parmSizer.SetFlexibleDirection(wx.HORIZONTAL) |
---|
4064 | Â Â Â Â Â Â Parms =Â level[level['Controls']['DistType']] |
---|
4065 | Â Â Â Â Â Â FFargs =Â level['Controls']['FFargs'] |
---|
4066 | Â Â Â Â Â Â SFargs =Â level['Controls'].get('SFargs',{}) |
---|
4067 | Â Â Â Â Â Â parmOrder =Â ['Volume','Radius','Mean','StdDev','MinSize','G','Rg','B','P','Cutoff', |
---|
4068 | Â Â Â Â Â Â Â Â 'PkInt','PkPos','PkSig','PkGam',] |
---|
4069 |       for parm in parmOrder: |
---|
4070 |         if parm in Parms: |
---|
4071 |           if parm == 'MinSize': |
---|
4072 | Â Â Â Â Â Â Â Â Â Â Â Â parmSizer.Add(wx.StaticText(G2frame.dataDisplay,label=' Dist '+parm),0,wx.ALIGN_CENTER) |
---|
4073 | Â Â Â Â Â Â Â Â Â Â else: |
---|
4074 | Â Â Â Â Â Â Â Â Â Â Â Â parmVar =Â wx.CheckBox(G2frame.dataDisplay,label='Refine? Dist '+parm)Â |
---|
4075 | Â Â Â Â Â Â Â Â Â Â Â Â parmVar.SetValue(Parms[parm][1]) |
---|
4076 |             parmVar.Bind(wx.EVT_CHECKBOX, OnSelect) |
---|
4077 | Â Â Â Â Â Â Â Â Â Â Â Â parmSizer.Add(parmVar,0,WACV) |
---|
4078 | Â Â Â Â Â Â Â Â Â Â Â Â Indx[parmVar.GetId()]Â =Â [Parms[parm],1] |
---|
4079 | Â Â Â Â Â Â Â Â Â Â parmValue =Â wx.TextCtrl(G2frame.dataDisplay,value='%.3g'%(Parms[parm][0]), |
---|
4080 | Â Â Â Â Â Â Â Â Â Â Â Â style=wx.TE_PROCESS_ENTER) |
---|
4081 | Â Â Â Â Â Â Â Â Â Â parmValue.Bind(wx.EVT_TEXT_ENTER,OnValue)Â Â Â Â |
---|
4082 | Â Â Â Â Â Â Â Â Â Â parmValue.Bind(wx.EVT_KILL_FOCUS,OnValue) |
---|
4083 | Â Â Â Â Â Â Â Â Â Â parmSizer.Add(parmValue,0,WACV) |
---|
4084 |           if parm == 'P': |
---|
4085 | Â Â Â Â Â Â Â Â Â Â Â Â value =Â Parms[parm][0] |
---|
4086 | Â Â Â Â Â Â Â Â Â Â Â Â valMinMax =Â [0.1,4.2] |
---|
4087 | Â Â Â Â Â Â Â Â Â Â else: |
---|
4088 | Â Â Â Â Â Â Â Â Â Â Â Â value =Â np.log10(Parms[parm][0]) |
---|
4089 | Â Â Â Â Â Â Â Â Â Â Â Â valMinMax =Â [value-1,value+1] |
---|
4090 | Â Â Â Â Â Â Â Â Â Â parmSldr =Â wx.Slider(G2frame.dataDisplay,minValue=slMult*valMinMax[0], |
---|
4091 | Â Â Â Â Â Â Â Â Â Â Â Â maxValue=slMult*valMinMax[1],value=slMult*value) |
---|
4092 | Â Â Â Â Â Â Â Â Â Â Indx[parmValue.GetId()]Â =Â [Parms,parm,parmSldr] |
---|
4093 | Â Â Â Â Â Â Â Â Â Â Indx[parmSldr.GetId()]Â =Â [Parms,parm,parmValue] |
---|
4094 | Â Â Â Â Â Â Â Â Â Â parmSldr.Bind(wx.EVT_SLIDER,OnParmSlider) |
---|
4095 | Â Â Â Â Â Â Â Â Â Â parmSizer.Add(parmSldr,1,wx.EXPAND) |
---|
4096 |       if level['Controls']['DistType'] not in ['Bragg']: |
---|
4097 | Â Â Â Â Â Â Â Â parmOrder =Â ['Aspect ratio','Length','Diameter','Thickness','VolFr','Dist','epis','Sticky','Depth','Width'] |
---|
4098 | Â Â Â Â Â Â Â Â fTypes =Â ['FF ','SF '] |
---|
4099 |         for iarg,Args in enumerate([FFargs,SFargs]): |
---|
4100 |           for parm in parmOrder: |
---|
4101 |             if parm in Args: |
---|
4102 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â parmVar =Â wx.CheckBox(G2frame.dataDisplay,label='Refine? '+fTypes[iarg]+parm)Â |
---|
4103 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â parmVar.SetValue(Args[parm][1]) |
---|
4104 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Indx[parmVar.GetId()]Â =Â [Args[parm],1] |
---|
4105 |               parmVar.Bind(wx.EVT_CHECKBOX, OnSelect) |
---|
4106 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â parmSizer.Add(parmVar,0,WACV) |
---|
4107 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â parmValue =Â wx.TextCtrl(G2frame.dataDisplay,value='%.3g'%(Args[parm][0]), |
---|
4108 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â style=wx.TE_PROCESS_ENTER) |
---|
4109 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â parmValue.Bind(wx.EVT_TEXT_ENTER,OnValue)Â Â Â Â |
---|
4110 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â parmValue.Bind(wx.EVT_KILL_FOCUS,OnValue) |
---|
4111 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â parmSizer.Add(parmValue,0,WACV) |
---|
4112 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â value =Â Args[parm][0] |
---|
4113 |               if parm == 'epis': |
---|
4114 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â valMinMax =Â [0,.1] |
---|
4115 | Â Â |
---|