1 | # -*- coding: utf-8 -*- |
---|
2 | ''' |
---|
3 | *GSASIIplot: plotting routines* |
---|
4 | =============================== |
---|
5 | |
---|
6 | ''' |
---|
7 | ########### SVN repository information ################### |
---|
8 | # $Date: 2015-04-06 20:45:25 +0000 (Mon, 06 Apr 2015) $ |
---|
9 | # $Author: vondreele $ |
---|
10 | # $Revision: 1779 $ |
---|
11 | # $URL: trunk/GSASIIplot.py $ |
---|
12 | # $Id: GSASIIplot.py 1779 2015-04-06 20:45:25Z vondreele $ |
---|
13 | ########### SVN repository information ################### |
---|
14 | import math |
---|
15 | import time |
---|
16 | import copy |
---|
17 | import sys |
---|
18 | import os.path |
---|
19 | import numpy as np |
---|
20 | import numpy.ma as ma |
---|
21 | import numpy.linalg as nl |
---|
22 | import wx |
---|
23 | import wx.aui |
---|
24 | import wx.glcanvas |
---|
25 | import matplotlib as mpl |
---|
26 | import mpl_toolkits.mplot3d.axes3d as mp3d |
---|
27 | import GSASIIpath |
---|
28 | GSASIIpath.SetVersionNumber("$Revision: 1779 $") |
---|
29 | import GSASIIgrid as G2gd |
---|
30 | import GSASIIimage as G2img |
---|
31 | import GSASIIpwd as G2pwd |
---|
32 | import GSASIIIO as G2IO |
---|
33 | import GSASIIpwdGUI as G2pdG |
---|
34 | import GSASIIimgGUI as G2imG |
---|
35 | import GSASIIphsGUI as G2phG |
---|
36 | import GSASIIlattice as G2lat |
---|
37 | import GSASIIspc as G2spc |
---|
38 | import GSASIImath as G2mth |
---|
39 | import GSASIIctrls as G2G |
---|
40 | import pytexture as ptx |
---|
41 | from OpenGL.GL import * |
---|
42 | from OpenGL.GLU import * |
---|
43 | from OpenGL.GLE import * |
---|
44 | import gltext |
---|
45 | from matplotlib.backends.backend_wx import _load_bitmap |
---|
46 | from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as Canvas |
---|
47 | from matplotlib.backends.backend_wxagg import NavigationToolbar2Wx as Toolbar |
---|
48 | |
---|
49 | # useful degree trig functions |
---|
50 | sind = lambda x: math.sin(x*math.pi/180.) |
---|
51 | cosd = lambda x: math.cos(x*math.pi/180.) |
---|
52 | tand = lambda x: math.tan(x*math.pi/180.) |
---|
53 | asind = lambda x: 180.*math.asin(x)/math.pi |
---|
54 | acosd = lambda x: 180.*math.acos(x)/math.pi |
---|
55 | atan2d = lambda x,y: 180.*math.atan2(y,x)/math.pi |
---|
56 | atand = lambda x: 180.*math.atan(x)/math.pi |
---|
57 | # numpy versions |
---|
58 | npsind = lambda x: np.sin(x*np.pi/180.) |
---|
59 | npcosd = lambda x: np.cos(x*np.pi/180.) |
---|
60 | nptand = lambda x: np.tan(x*np.pi/180.) |
---|
61 | npacosd = lambda x: 180.*np.arccos(x)/np.pi |
---|
62 | npasind = lambda x: 180.*np.arcsin(x)/np.pi |
---|
63 | npatand = lambda x: 180.*np.arctan(x)/np.pi |
---|
64 | npatan2d = lambda x,y: 180.*np.arctan2(x,y)/np.pi |
---|
65 | GkDelta =Â unichr(0x0394) |
---|
66 | Â Â |
---|
67 | class G2PlotMpl(wx.Panel):  |
---|
68 | Â Â 'needs a doc string' |
---|
69 |   def __init__(self,parent,id=-1,dpi=None,**kwargs): |
---|
70 | Â Â Â Â wx.Panel.__init__(self,parent,id=id,**kwargs) |
---|
71 | Â Â Â Â mpl.rcParams['legend.fontsize']Â =Â 10 |
---|
72 | Â Â Â Â self.figure =Â mpl.figure.Figure(dpi=dpi,figsize=(5,6)) |
---|
73 | Â Â Â Â self.canvas =Â Canvas(self,-1,self.figure) |
---|
74 | Â Â Â Â self.toolbar =Â GSASIItoolbar(self.canvas) |
---|
75 | |
---|
76 | Â Â Â Â self.toolbar.Realize() |
---|
77 | Â Â Â Â |
---|
78 | Â Â Â Â sizer=wx.BoxSizer(wx.VERTICAL) |
---|
79 | Â Â Â Â sizer.Add(self.canvas,1,wx.EXPAND) |
---|
80 | Â Â Â Â sizer.Add(self.toolbar,0,wx.LEFT|wx.EXPAND) |
---|
81 | Â Â Â Â self.SetSizer(sizer) |
---|
82 | Â Â Â Â |
---|
83 | class G2PlotOgl(wx.Panel): |
---|
84 | Â Â 'needs a doc string' |
---|
85 |   def __init__(self,parent,id=-1,dpi=None,**kwargs): |
---|
86 | Â Â Â Â self.figure =Â wx.Panel.__init__(self,parent,id=id,**kwargs) |
---|
87 |     if 'win' in sys.platform:      #Windows (& Mac) already double buffered |
---|
88 | Â Â Â Â Â Â self.canvas =Â wx.glcanvas.GLCanvas(self,-1,**kwargs) |
---|
89 | Â Â Â Â else:Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #fix from Jim Hester for X systems |
---|
90 | Â Â Â Â Â Â attribs =Â (wx.glcanvas.WX_GL_DOUBLEBUFFER,)Â Â Â Â Â |
---|
91 | Â Â Â Â Â Â self.canvas =Â wx.glcanvas.GLCanvas(self,-1,attribList=attribs,**kwargs) |
---|
92 | Â Â Â Â # create GL context for wx > 2.8 |
---|
93 | Â Â Â Â i,j=Â wx.__version__.split('.')[0:2] |
---|
94 |     if int(i)+int(j)/10. > 2.8: |
---|
95 | Â Â Â Â Â Â self.context =Â wx.glcanvas.GLContext(self.canvas) |
---|
96 | Â Â Â Â Â Â self.canvas.SetCurrent(self.context) |
---|
97 | Â Â Â Â else: |
---|
98 | Â Â Â Â Â Â self.context =Â None |
---|
99 | Â Â Â Â self.camera =Â {} |
---|
100 | Â Â Â Â sizer=wx.BoxSizer(wx.VERTICAL) |
---|
101 | Â Â Â Â sizer.Add(self.canvas,1,wx.EXPAND) |
---|
102 | Â Â Â Â self.SetSizer(sizer) |
---|
103 | Â Â Â Â |
---|
104 | class G2Plot3D(wx.Panel): |
---|
105 | Â Â 'needs a doc string' |
---|
106 |   def __init__(self,parent,id=-1,dpi=None,**kwargs): |
---|
107 | Â Â Â Â wx.Panel.__init__(self,parent,id=id,**kwargs) |
---|
108 | Â Â Â Â self.figure =Â mpl.figure.Figure(dpi=dpi,figsize=(6,6)) |
---|
109 | Â Â Â Â self.canvas =Â Canvas(self,-1,self.figure) |
---|
110 | Â Â Â Â self.toolbar =Â GSASIItoolbar(self.canvas) |
---|
111 | |
---|
112 | Â Â Â Â self.toolbar.Realize() |
---|
113 | Â Â Â Â |
---|
114 | Â Â Â Â sizer=wx.BoxSizer(wx.VERTICAL) |
---|
115 | Â Â Â Â sizer.Add(self.canvas,1,wx.EXPAND) |
---|
116 | Â Â Â Â sizer.Add(self.toolbar,0,wx.LEFT|wx.EXPAND) |
---|
117 | Â Â Â Â self.SetSizer(sizer) |
---|
118 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
---|
119 | class G2PlotNoteBook(wx.Panel): |
---|
120 | Â Â 'create a tabbed window for plotting' |
---|
121 |   def __init__(self,parent,id=-1): |
---|
122 | Â Â Â Â wx.Panel.__init__(self,parent,id=id) |
---|
123 | Â Â Â Â #so one can't delete a plot page!! |
---|
124 |     self.nb = wx.aui.AuiNotebook(self, \ |
---|
125 | Â Â Â Â Â Â style=wx.aui.AUI_NB_DEFAULT_STYLE ^Â wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB) |
---|
126 | Â Â Â Â sizer =Â wx.BoxSizer() |
---|
127 | Â Â Â Â sizer.Add(self.nb,1,wx.EXPAND) |
---|
128 | Â Â Â Â self.SetSizer(sizer) |
---|
129 | Â Â Â Â self.status =Â parent.CreateStatusBar() |
---|
130 | Â Â Â Â self.status.SetFieldsCount(2) |
---|
131 | Â Â Â Â self.status.SetStatusWidths([150,-1]) |
---|
132 |     self.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGED, self.OnPageChanged) |
---|
133 | Â Â Â Â self.nb.Bind(wx.EVT_KEY_UP,self.OnNotebookKey) |
---|
134 | Â Â Â Â |
---|
135 | Â Â Â Â self.plotList =Â [] |
---|
136 | Â Â Â Â Â Â |
---|
137 |   def OnNotebookKey(self,event): |
---|
138 | Â Â Â Â '''Called when a keystroke event gets picked up by the notebook window |
---|
139 | Â Â Â Â rather the child. This is not expected, but somehow it does sometimes |
---|
140 | Â Â Â Â on the Mac and perhaps Linux. |
---|
141 | |
---|
142 | Â Â Â Â Assume that the page associated with the currently displayed tab |
---|
143 | Â Â Â Â has a child, .canvas; give that child the focus and pass it the event. |
---|
144 | Â Â Â Â ''' |
---|
145 | Â Â Â Â try: |
---|
146 | Â Â Â Â Â Â Page =Â self.nb.GetPage(self.nb.GetSelection()) |
---|
147 |     except ValueError: # occurs with no plot tabs |
---|
148 | Â Â Â Â Â Â return |
---|
149 | Â Â Â Â try: |
---|
150 | Â Â Â Â Â Â Page.canvas.SetFocus() |
---|
151 | Â Â Â Â Â Â wx.PostEvent(Page.canvas,event) |
---|
152 |     except AttributeError: |
---|
153 | Â Â Â Â Â Â pass |
---|
154 | |
---|
155 |   def addMpl(self,name=""): |
---|
156 | Â Â Â Â 'Add a tabbed page with a matplotlib plot' |
---|
157 | Â Â Â Â page =Â G2PlotMpl(self.nb) |
---|
158 | Â Â Â Â self.nb.AddPage(page,name) |
---|
159 | Â Â Â Â |
---|
160 | Â Â Â Â self.plotList.append(name) |
---|
161 | Â Â Â Â |
---|
162 |     return page.figure |
---|
163 | Â Â Â Â |
---|
164 |   def add3D(self,name=""): |
---|
165 | Â Â Â Â 'Add a tabbed page with a 3D plot' |
---|
166 | Â Â Â Â page =Â G2Plot3D(self.nb) |
---|
167 | Â Â Â Â self.nb.AddPage(page,name) |
---|
168 | Â Â Â Â |
---|
169 | Â Â Â Â self.plotList.append(name) |
---|
170 | Â Â Â Â |
---|
171 |     return page.figure |
---|
172 | Â Â Â Â |
---|
173 |   def addOgl(self,name=""): |
---|
174 | Â Â Â Â 'Add a tabbed page with an openGL plot' |
---|
175 | Â Â Â Â page =Â G2PlotOgl(self.nb) |
---|
176 | Â Â Â Â self.nb.AddPage(page,name) |
---|
177 | Â Â Â Â |
---|
178 | Â Â Â Â self.plotList.append(name) |
---|
179 | Â Â Â Â |
---|
180 |     return page.figure |
---|
181 | Â Â Â Â |
---|
182 |   def Delete(self,name): |
---|
183 | Â Â Â Â 'delete a tabbed page' |
---|
184 | Â Â Â Â try: |
---|
185 | Â Â Â Â Â Â item =Â self.plotList.index(name) |
---|
186 |       del self.plotList[item] |
---|
187 | Â Â Â Â Â Â self.nb.DeletePage(item) |
---|
188 |     except ValueError:     #no plot of this name - do nothing |
---|
189 |       return   |
---|
190 | Â Â Â Â Â Â Â Â |
---|
191 |   def clear(self): |
---|
192 | Â Â Â Â 'clear all pages from plot window' |
---|
193 |     while self.nb.GetPageCount(): |
---|
194 | Â Â Â Â Â Â self.nb.DeletePage(0) |
---|
195 | Â Â Â Â self.plotList =Â [] |
---|
196 | Â Â Â Â self.status.DestroyChildren() |
---|
197 | Â Â Â Â |
---|
198 |   def Rename(self,oldName,newName): |
---|
199 | Â Â Â Â 'rename a tab' |
---|
200 | Â Â Â Â try: |
---|
201 | Â Â Â Â Â Â item =Â self.plotList.index(oldName) |
---|
202 | Â Â Â Â Â Â self.plotList[item]Â =Â newName |
---|
203 | Â Â Â Â Â Â self.nb.SetPageText(item,newName) |
---|
204 |     except ValueError:     #no plot of this name - do nothing |
---|
205 |       return   |
---|
206 | Â Â Â Â |
---|
207 |   def OnPageChanged(self,event): |
---|
208 | Â Â Â Â 'respond to someone pressing a tab on the plot window' |
---|
209 |     if self.plotList: |
---|
210 | Â Â Â Â Â Â self.status.SetStatusText('Better to select this from GSAS-II data tree',1) |
---|
211 | Â Â Â Â self.status.DestroyChildren()Â Â Â Â Â Â Â Â Â Â Â Â Â Â #get rid of special stuff on status bar |
---|
212 | Â Â Â Â |
---|
213 | class GSASIItoolbar(Toolbar): |
---|
214 | Â Â 'Override the matplotlib toolbar so we can add more icons' |
---|
215 | Â Â ON_MPL_HELP =Â wx.NewId() |
---|
216 | Â Â ON_MPL_KEY =Â wx.NewId() |
---|
217 | Â Â arrows =Â {} |
---|
218 |   for direc in ('left','right','up','down','Expand X', |
---|
219 | Â Â Â Â Â Â Â Â Â 'Shrink X','Expand Y','Shrink Y'): |
---|
220 | Â Â Â Â arrows[direc]Â =Â wx.NewId() |
---|
221 |   def __init__(self,plotCanvas): |
---|
222 | Â Â Â Â '''Adds additional icons to toolbar''' |
---|
223 | Â Â Â Â Toolbar.__init__(self,plotCanvas) |
---|
224 | Â Â Â Â self.plotCanvas =Â plotCanvas |
---|
225 | Â Â Â Â POSITION_OF_CONFIGURE_SUBPLOTS_BTN =Â 6Â # remove one button, nos. start at 1! |
---|
226 | Â Â Â Â self.DeleteToolByPos(POSITION_OF_CONFIGURE_SUBPLOTS_BTN) |
---|
227 | Â Â Â Â self.parent =Â self.GetParent() |
---|
228 | Â Â Â Â key =Â os.path.join(os.path.split(__file__)[0],'key.ico') |
---|
229 | Â Â Â Â self.AddSimpleTool(self.ON_MPL_KEY,_load_bitmap(key),'Key press','Select key press') |
---|
230 | Â Â Â Â wx.EVT_TOOL(self,self.ON_MPL_KEY,self.OnKey) |
---|
231 | Â Â Â Â help =Â os.path.join(os.path.split(__file__)[0],'help.ico') |
---|
232 | Â Â Â Â self.AddSimpleTool(self.ON_MPL_HELP,_load_bitmap(help),'Help on','Show help on') |
---|
233 | Â Â Â Â wx.EVT_TOOL(self,self.ON_MPL_HELP,self.OnHelp) |
---|
234 | Â Â Â Â # add arrow keys to control zooming |
---|
235 |     for direc in ('left','right','up','down'): |
---|
236 | Â Â Â Â Â Â wx.EVT_TOOL(self,self.arrows[direc],self.OnArrow) |
---|
237 | Â Â Â Â Â Â icon =Â os.path.join(os.path.split(__file__)[0],direc[0]+'arrow.ico') |
---|
238 | Â Â Â Â Â Â self.AddSimpleTool(self.arrows[direc],_load_bitmap(icon), |
---|
239 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 'Shift '+direc,'Shift plot '+direc) |
---|
240 |     for direc in ('Expand X','Shrink X','Expand Y','Shrink Y'): |
---|
241 |       fil = ''.join([i[0].lower() for i in direc.split()]+['arrow.ico']) |
---|
242 | Â Â Â Â Â Â wx.EVT_TOOL(self,self.arrows[direc],self.OnArrow) |
---|
243 | Â Â Â Â Â Â icon =Â os.path.join(os.path.split(__file__)[0],fil) |
---|
244 | Â Â Â Â Â Â self.AddSimpleTool(self.arrows[direc],_load_bitmap(icon), |
---|
245 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â direc,'Zoom: '+direc) |
---|
246 |   def OnArrow(self,event): |
---|
247 | Â Â Â Â 'reposition limits to scan or zoom by button press' |
---|
248 | Â Â Â Â ax =Â self.plotCanvas.figure.get_axes()[0] |
---|
249 | Â Â Â Â xmin,xmax,ymin,ymax =Â ax.axis() |
---|
250 | Â Â Â Â #print xmin,xmax,ymin,ymax |
---|
251 |     if event.Id == self.arrows['right']: |
---|
252 | Â Â Â Â Â Â delta =Â (xmax-xmin)/10. |
---|
253 | Â Â Â Â Â Â xmin -=Â delta |
---|
254 | Â Â Â Â Â Â xmax -=Â delta |
---|
255 |     elif event.Id == self.arrows['left']: |
---|
256 | Â Â Â Â Â Â delta =Â (xmax-xmin)/10. |
---|
257 | Â Â Â Â Â Â xmin +=Â delta |
---|
258 | Â Â Â Â Â Â xmax +=Â delta |
---|
259 |     elif event.Id == self.arrows['up']: |
---|
260 | Â Â Â Â Â Â delta =Â (ymax-ymin)/10. |
---|
261 | Â Â Â Â Â Â ymin -=Â delta |
---|
262 | Â Â Â Â Â Â ymax -=Â delta |
---|
263 |     elif event.Id == self.arrows['down']: |
---|
264 | Â Â Â Â Â Â delta =Â (ymax-ymin)/10. |
---|
265 | Â Â Â Â Â Â ymin +=Â delta |
---|
266 | Â Â Â Â Â Â ymax +=Â delta |
---|
267 |     elif event.Id == self.arrows['Expand X']: |
---|
268 | Â Â Â Â Â Â delta =Â (xmax-xmin)/10. |
---|
269 | Â Â Â Â Â Â xmin +=Â delta |
---|
270 | Â Â Â Â Â Â xmax -=Â delta |
---|
271 |     elif event.Id == self.arrows['Expand Y']: |
---|
272 | Â Â Â Â Â Â delta =Â (ymax-ymin)/10. |
---|
273 | Â Â Â Â Â Â ymin +=Â delta |
---|
274 | Â Â Â Â Â Â ymax -=Â delta |
---|
275 |     elif event.Id == self.arrows['Shrink X']: |
---|
276 | Â Â Â Â Â Â delta =Â (xmax-xmin)/10. |
---|
277 | Â Â Â Â Â Â xmin -=Â delta |
---|
278 | Â Â Â Â Â Â xmax +=Â delta |
---|
279 |     elif event.Id == self.arrows['Shrink Y']: |
---|
280 | Â Â Â Â Â Â delta =Â (ymax-ymin)/10. |
---|
281 | Â Â Â Â Â Â ymin -=Â delta |
---|
282 | Â Â Â Â Â Â ymax +=Â delta |
---|
283 | Â Â Â Â else: |
---|
284 | Â Â Â Â Â Â # should not happen! |
---|
285 | Â Â Â Â Â Â GSASIIpath.IPyBreak() |
---|
286 | Â Â Â Â self.parent.toolbar.push_current() |
---|
287 | Â Â Â Â ax.axis((xmin,xmax,ymin,ymax)) |
---|
288 | Â Â Â Â #print xmin,xmax,ymin,ymax |
---|
289 | Â Â Â Â self.plotCanvas.figure.canvas.draw() |
---|
290 | Â Â Â Â self.parent.toolbar.draw() |
---|
291 | #Â Â Â Â self.parent.toolbar.push_current() |
---|
292 | Â Â Â Â |
---|
293 |   def OnHelp(self,event): |
---|
294 | Â Â Â Â 'Respond to press of help button on plot toolbar' |
---|
295 | Â Â Â Â Page =Â self.GetParent().GetParent() |
---|
296 | Â Â Â Â pageNo =Â Page.GetSelection() |
---|
297 | Â Â Â Â bookmark =Â Page.GetPageText(pageNo) |
---|
298 | Â Â Â Â bookmark =Â bookmark.strip(')').replace('(','_') |
---|
299 | Â Â Â Â G2G.ShowHelp(bookmark,self.TopLevelParent) |
---|
300 |   def OnKey(self,event): |
---|
301 | Â Â Â Â '''Provide user with list of keystrokes defined for plot as well as an |
---|
302 | Â Â Â Â alternate way to access the same functionality |
---|
303 | Â Â Â Â ''' |
---|
304 | Â Â Â Â parent =Â self.GetParent() |
---|
305 |     if parent.Choice: |
---|
306 | Â Â Â Â Â Â dlg =Â wx.SingleChoiceDialog(parent,'Select','Key press',list(parent.Choice)) |
---|
307 |       if dlg.ShowModal() == wx.ID_OK: |
---|
308 | Â Â Â Â Â Â Â Â sel =Â dlg.GetSelection() |
---|
309 | Â Â Â Â Â Â Â Â event.key =Â parent.Choice[sel][0] |
---|
310 | Â Â Â Â Â Â Â Â parent.keyPress(event) |
---|
311 | Â Â Â Â Â Â dlg.Destroy() |
---|
312 | Â Â Â Â Â Â |
---|
313 | ################################################################################ |
---|
314 | ##### PlotSngl |
---|
315 | ################################################################################ |
---|
316 | Â Â Â Â Â Â |
---|
317 | def PlotSngl(G2frame,newPlot=False,Data=None,hklRef=None,Title=''): |
---|
318 | Â Â '''Structure factor plotting package - displays zone of reflections as rings proportional |
---|
319 | Â Â Â Â to F, F**2, etc. as requested |
---|
320 | Â Â ''' |
---|
321 |   from matplotlib.patches import Circle,CirclePolygon |
---|
322 |   global HKL,HKLF |
---|
323 | Â Â |
---|
324 |   def OnSCKeyPress(event): |
---|
325 | Â Â Â Â i =Â zones.index(Data['Zone']) |
---|
326 | Â Â Â Â newPlot =Â False |
---|
327 | Â Â Â Â pwdrChoice =Â {'f':'Fo','s':'Fosq','u':'Unit Fc'} |
---|
328 | Â Â Â Â hklfChoice =Â {'1':'|DFsq|>sig','3':'|DFsq|>3sig','w':'|DFsq|/sig','f':'Fo','s':'Fosq','i':'Unit Fc'} |
---|
329 |     if event.key == 'h': |
---|
330 | Â Â Â Â Â Â Data['Zone']Â =Â '100' |
---|
331 | Â Â Â Â Â Â newPlot =Â True |
---|
332 |     elif event.key == 'k': |
---|
333 | Â Â Â Â Â Â Data['Zone']Â =Â '010' |
---|
334 | Â Â Â Â Â Â newPlot =Â True |
---|
335 |     elif event.key == 'l': |
---|
336 | Â Â Â Â Â Â Data['Zone']Â =Â '001' |
---|
337 | Â Â Â Â Â Â newPlot =Â True |
---|
338 |     elif event.key == 'i': |
---|
339 | Â Â Â Â Â Â Data['Scale']Â *=Â 1.1 |
---|
340 |     elif event.key == 'd': |
---|
341 | Â Â Â Â Â Â Data['Scale']Â /=Â 1.1 |
---|
342 |     elif event.key in ['+','=']: |
---|
343 | Â Â Â Â Â Â Data['Layer']Â =Â min(Data['Layer']+1,HKLmax[i]) |
---|
344 |     elif event.key == '-': |
---|
345 | Â Â Â Â Â Â Data['Layer']Â =Â max(Data['Layer']-1,HKLmin[i]) |
---|
346 |     elif event.key == '0': |
---|
347 | Â Â Â Â Â Â Data['Layer']Â =Â 0 |
---|
348 | Â Â Â Â Â Â Data['Scale']Â =Â 1.0 |
---|
349 |     elif event.key in hklfChoice and 'HKLF' in Name: |
---|
350 | Â Â Â Â Â Â Data['Type']Â =Â hklfChoice[event.key]Â Â Â Â Â Â |
---|
351 | Â Â Â Â Â Â newPlot =Â True |
---|
352 |     elif event.key in pwdrChoice and 'PWDR' in Name: |
---|
353 | Â Â Â Â Â Â Data['Type']Â =Â pwdrChoice[event.key]Â Â Â Â Â Â |
---|
354 |       newPlot = True    |
---|
355 | Â Â Â Â PlotSngl(G2frame,newPlot,Data,hklRef,Title) |
---|
356 | |
---|
357 |   def OnSCMotion(event): |
---|
358 | Â Â Â Â xpos =Â event.xdata |
---|
359 |     if xpos: |
---|
360 | Â Â Â Â Â Â xpos =Â round(xpos)Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #avoid out of frame mouse position |
---|
361 | Â Â Â Â Â Â ypos =Â round(event.ydata) |
---|
362 | Â Â Â Â Â Â zpos =Â Data['Layer'] |
---|
363 |       if '100' in Data['Zone']: |
---|
364 | Â Â Â Â Â Â Â Â HKLtxt =Â '(%3d,%3d,%3d)'%(zpos,xpos,ypos) |
---|
365 |       elif '010' in Data['Zone']: |
---|
366 | Â Â Â Â Â Â Â Â HKLtxt =Â '(%3d,%3d,%3d)'%(xpos,zpos,ypos) |
---|
367 |       elif '001' in Data['Zone']: |
---|
368 | Â Â Â Â Â Â Â Â HKLtxt =Â '(%3d,%3d,%3d)'%(xpos,ypos,zpos) |
---|
369 | Â Â Â Â Â Â Page.canvas.SetToolTipString(HKLtxt) |
---|
370 | Â Â Â Â Â Â G2frame.G2plotNB.status.SetStatusText('HKL = '+HKLtxt,0) |
---|
371 | Â Â Â Â Â Â G2frame.G2plotNB.status.SetStatusText('Use K-box to set plot controls',1) |
---|
372 | Â Â Â Â Â Â Â Â |
---|
373 |   def OnSCPress(event): |
---|
374 | Â Â Â Â zpos =Â Data['Layer'] |
---|
375 | Â Â Â Â xpos =Â event.xdata |
---|
376 |     if xpos: |
---|
377 | Â Â Â Â Â Â pos =Â int(round(event.xdata)),int(round(event.ydata)) |
---|
378 |       if '100' in Data['Zone']: |
---|
379 | Â Â Â Â Â Â Â Â Page.canvas.SetToolTipString('(picked:(%3d,%3d,%3d))'%(zpos,pos[0],pos[1])) |
---|
380 | Â Â Â Â Â Â Â Â hkl =Â np.array([zpos,pos[0],pos[1]]) |
---|
381 |       elif '010' in Data['Zone']: |
---|
382 | Â Â Â Â Â Â Â Â Page.canvas.SetToolTipString('(picked:(%3d,%3d,%3d))'%(pos[0],zpos,pos[1])) |
---|
383 | Â Â Â Â Â Â Â Â hkl =Â np.array([pos[0],zpos,pos[1]]) |
---|
384 |       elif '001' in Data['Zone']: |
---|
385 | Â Â Â Â Â Â Â Â Page.canvas.SetToolTipString('(picked:(%3d,%3d,%3d))'%(pos[0],pos[1],zpos)) |
---|
386 | Â Â Â Â Â Â Â Â hkl =Â np.array([pos[0],pos[1],zpos]) |
---|
387 | Â Â Â Â Â Â h,k,l =Â hkl |
---|
388 | Â Â Â Â Â Â hklf =Â HKLF[np.where(np.all(HKL-hkl ==Â [0,0,0],axis=1))] |
---|
389 |       if len(hklf): |
---|
390 | Â Â Â Â Â Â Â Â Fosq,sig,Fcsq =Â hklf[0] |
---|
391 |         HKLtxt = '( %.2f %.3f %.2f %.2f)'%(Fosq,sig,Fcsq,(Fosq-Fcsq)/(scale*sig)) |
---|
392 | Â Â Â Â Â Â Â Â G2frame.G2plotNB.status.SetStatusText('Fosq, sig, Fcsq, delFsq/sig = '+HKLtxt,1) |
---|
393 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
---|
394 | Â Â Name =Â G2frame.PatternTree.GetItemText(G2frame.PatternId) |
---|
395 |   if not Title: |
---|
396 | Â Â Â Â Title =Â Name |
---|
397 | Â Â try: |
---|
398 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index('Structure Factors') |
---|
399 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
400 |     if not newPlot: |
---|
401 | Â Â Â Â Â Â Plot =Â Page.figure.gca()Â Â Â Â Â #get previous powder plot & get limits |
---|
402 | Â Â Â Â Â Â xylim =Â Plot.get_xlim(),Plot.get_ylim() |
---|
403 | Â Â Â Â Page.figure.clf() |
---|
404 | Â Â Â Â Plot =Â Page.figure.gca()Â Â Â Â Â #get a fresh plot after clf() |
---|
405 |   except ValueError: |
---|
406 | Â Â Â Â Plot =Â G2frame.G2plotNB.addMpl('Structure Factors').gca() |
---|
407 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index('Structure Factors') |
---|
408 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
409 |     Page.canvas.mpl_connect('button_press_event', OnSCPress) |
---|
410 |     Page.canvas.mpl_connect('motion_notify_event', OnSCMotion) |
---|
411 |     Page.canvas.mpl_connect('key_press_event', OnSCKeyPress) |
---|
412 | Â Â Â Â Page.keyPress =Â OnSCKeyPress |
---|
413 | Â Â Â Â Page.Choice =Â (' key press','i: increase scale','d: decrease scale', |
---|
414 | Â Â Â Â Â Â 'h: select 100 zone','k: select 010 zone','l: select 001 zone', |
---|
415 | Â Â Â Â Â Â 'f: select Fo','s: select Fosq','u: select unit Fc', |
---|
416 | Â Â Â Â Â Â '+: increase index','-: decrease index','0: zero layer',) |
---|
417 |     if 'HKLF' in Name: |
---|
418 | Â Â Â Â Â Â Page.Choice +=Â ('w: select |DFsq|/sig','1: select |DFsq|>sig','3: select |DFsq|>3sig',) |
---|
419 | Â Â Page.SetFocus() |
---|
420 | Â Â |
---|
421 | Â Â G2frame.G2plotNB.status.SetStatusText('Use K-box to set plot controls',1) |
---|
422 | Â Â Plot.set_aspect(aspect='equal') |
---|
423 | Â Â |
---|
424 | Â Â Type =Â Data['Type']Â Â Â Â Â Â |
---|
425 | Â Â scale =Â Data['Scale'] |
---|
426 | Â Â HKLmax =Â Data['HKLmax'] |
---|
427 | Â Â HKLmin =Â Data['HKLmin'] |
---|
428 | Â Â FosqMax =Â Data['FoMax'] |
---|
429 | Â Â Super =Â Data['Super'] |
---|
430 | Â Â SuperVec =Â [] |
---|
431 |   if Super: |
---|
432 | Â Â Â Â SuperVec =Â np.array(Data['SuperVec'][0]) |
---|
433 | Â Â FoMax =Â math.sqrt(FosqMax) |
---|
434 | Â Â xlabel =Â ['k, h=','h, k=','h, l='] |
---|
435 | Â Â ylabel =Â ['l','l','k'] |
---|
436 | Â Â zones =Â ['100','010','001'] |
---|
437 | Â Â pzone =Â [[1,2],[0,2],[0,1]] |
---|
438 | Â Â izone =Â zones.index(Data['Zone']) |
---|
439 | Â Â Plot.set_title(Data['Type']+' for '+Title) |
---|
440 | Â Â HKL =Â [] |
---|
441 | Â Â HKLF =Â [] |
---|
442 | Â Â time0 =Â time.time() |
---|
443 |   for refl in hklRef: |
---|
444 | Â Â Â Â H =Â refl[:3] |
---|
445 |     if 'HKLF' in Name: |
---|
446 | Â Â Â Â Â Â Fosq,sig,Fcsq =Â refl[5+Super:8+Super] |
---|
447 | Â Â Â Â else: |
---|
448 | Â Â Â Â Â Â Fosq,sig,Fcsq =Â refl[8+Super],1.0,refl[9+Super] |
---|
449 |     if Super: |
---|
450 | Â Â Â Â Â Â HKL.append(H+SuperVec*refl[3]) |
---|
451 | Â Â Â Â else: |
---|
452 | Â Â Â Â Â Â HKL.append(H) |
---|
453 | Â Â Â Â HKLF.append([Fosq,sig,Fcsq]) |
---|
454 |     if H[izone] == Data['Layer']: |
---|
455 | Â Â Â Â Â Â A =Â 0 |
---|
456 | Â Â Â Â Â Â B =Â 0 |
---|
457 |       if Type == 'Fosq': |
---|
458 | Â Â Â Â Â Â Â Â A =Â scale*Fosq/FosqMax |
---|
459 | Â Â Â Â Â Â Â Â B =Â scale*Fcsq/FosqMax |
---|
460 | Â Â Â Â Â Â Â Â C =Â abs(A-B) |
---|
461 |       elif Type == 'Fo': |
---|
462 | Â Â Â Â Â Â Â Â A =Â scale*math.sqrt(max(0,Fosq))/FoMax |
---|
463 | Â Â Â Â Â Â Â Â B =Â scale*math.sqrt(max(0,Fcsq))/FoMax |
---|
464 | Â Â Â Â Â Â Â Â C =Â abs(A-B) |
---|
465 |       elif Type == 'Unit Fc': |
---|
466 | Â Â Â Â Â Â Â Â A =Â scale/2 |
---|
467 | Â Â Â Â Â Â Â Â B =Â scale/2 |
---|
468 | Â Â Â Â Â Â Â Â C =Â 0.0 |
---|
469 |         if Fcsq and Fosq > 0: |
---|
470 | Â Â Â Â Â Â Â Â Â Â A *=Â min(1.0,Fosq/Fcsq) |
---|
471 | Â Â Â Â Â Â Â Â Â Â C =Â abs(A-B) |
---|
472 |       elif Type == '|DFsq|/sig': |
---|
473 |         if sig > 0.: |
---|
474 | Â Â Â Â Â Â Â Â Â Â A =Â (Fosq-Fcsq)/(3*sig) |
---|
475 | Â Â Â Â Â Â Â Â B =Â 0 |
---|
476 |       elif Type == '|DFsq|>sig': |
---|
477 |         if sig > 0.: |
---|
478 | Â Â Â Â Â Â Â Â Â Â A =Â (Fosq-Fcsq)/(3*sig) |
---|
479 |         if abs(A) < 1.0: A = 0 |
---|
480 | Â Â Â Â Â Â Â Â B =Â 0Â Â Â Â Â Â Â Â Â Â |
---|
481 |       elif Type == '|DFsq|>3sig': |
---|
482 |         if sig > 0.: |
---|
483 | Â Â Â Â Â Â Â Â Â Â A =Â (Fosq-Fcsq)/(3*sig) |
---|
484 |         if abs(A) < 3.0: A = 0 |
---|
485 | Â Â Â Â Â Â Â Â B =Â 0 |
---|
486 |       if Super: |
---|
487 | Â Â Â Â Â Â Â Â h =Â H+SuperVec*refl[3]Â Â Â Â Â Â Â Â |
---|
488 | Â Â Â Â Â Â else: |
---|
489 | Â Â Â Â Â Â Â Â h =Â H |
---|
490 | Â Â Â Â Â Â xy =Â (h[pzone[izone][0]],h[pzone[izone][1]]) |
---|
491 |       if Type in ['|DFsq|/sig','|DFsq|>sig','|DFsq|>3sig']: |
---|
492 |         if A > 0.0: |
---|
493 | Â Â Â Â Â Â Â Â Â Â Plot.add_artist(Circle(xy,radius=A,ec='g',fc='w')) |
---|
494 | Â Â Â Â Â Â Â Â else: |
---|
495 | Â Â Â Â Â Â Â Â Â Â Plot.add_artist(Circle(xy,radius=-A,ec='r',fc='w')) |
---|
496 | Â Â Â Â Â Â else: |
---|
497 |         if A > 0.0 and A > B: |
---|
498 | Â Â Â Â Â Â Â Â Â Â Plot.add_artist(Circle(xy,radius=A,ec='g',fc='w')) |
---|
499 |         if B: |
---|
500 | Â Â Â Â Â Â Â Â Â Â Plot.add_artist(Circle(xy,radius=B,ec='b',fc='w')) |
---|
501 |           if A < B: |
---|
502 | Â Â Â Â Â Â Â Â Â Â Â Â Plot.add_artist(Circle(xy,radius=A,ec='g',fc='w')) |
---|
503 | Â Â Â Â Â Â Â Â Â Â radius =Â C |
---|
504 |           if radius > 0: |
---|
505 |             if A > B: |
---|
506 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Plot.add_artist(Circle(xy,radius=radius,ec='g',fc='g')) |
---|
507 | Â Â Â Â Â Â Â Â Â Â Â Â else:Â Â Â Â Â Â Â Â Â Â |
---|
508 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Plot.add_artist(Circle(xy,radius=radius,ec='r',fc='r')) |
---|
509 | #Â Â print 'plot time: %.3f'%(time.time()-time0) |
---|
510 | Â Â HKL =Â np.array(HKL) |
---|
511 | Â Â HKLF =Â np.array(HKLF) |
---|
512 | Â Â Plot.set_xlabel(xlabel[izone]+str(Data['Layer']),fontsize=12) |
---|
513 | Â Â Plot.set_ylabel(ylabel[izone],fontsize=12) |
---|
514 |   if not newPlot: |
---|
515 | Â Â Â Â Page.toolbar.push_current() |
---|
516 | Â Â Â Â Plot.set_xlim(xylim[0]) |
---|
517 | Â Â Â Â Plot.set_ylim(xylim[1]) |
---|
518 | #Â Â Â Â xylim = [] |
---|
519 | Â Â Â Â Page.toolbar.push_current() |
---|
520 | Â Â Â Â Page.toolbar.draw() |
---|
521 | Â Â else: |
---|
522 | Â Â Â Â Plot.set_xlim((HKLmin[pzone[izone][0]],HKLmax[pzone[izone][0]])) |
---|
523 | Â Â Â Â Plot.set_ylim((HKLmin[pzone[izone][1]],HKLmax[pzone[izone][1]])) |
---|
524 | Â Â Â Â Page.canvas.draw() |
---|
525 | Â Â Â Â |
---|
526 | ################################################################################ |
---|
527 | ##### Plot3DSngl |
---|
528 | ################################################################################ |
---|
529 | |
---|
530 | def Plot3DSngl(G2frame,newPlot=False,Data=None,hklRef=None,Title=False): |
---|
531 | Â Â '''3D Structure factor plotting package - displays reflections as rings proportional |
---|
532 | Â Â Â Â to F, F**2, etc. as requested as 3D array |
---|
533 | Â Â ''' |
---|
534 | |
---|
535 |   global ifBox |
---|
536 | Â Â ifBox =Â False |
---|
537 |   def OnKeyBox(event): |
---|
538 | Â Â Â Â mode =Â cb.GetValue() |
---|
539 |     if mode in ['jpeg','bmp','tiff',]: |
---|
540 | Â Â Â Â Â Â try: |
---|
541 |         import Image as Im |
---|
542 |       except ImportError: |
---|
543 | Â Â Â Â Â Â Â Â try: |
---|
544 |           from PIL import Image as Im |
---|
545 |         except ImportError: |
---|
546 |           print "PIL/pillow Image module not present. Cannot save images without this" |
---|
547 |           raise Exception("PIL/pillow Image module not found") |
---|
548 | Â Â Â Â Â Â try: |
---|
549 | Â Â Â Â Â Â Â Â Fname =Â os.path.join(Mydir,generalData['Name']+'.'+mode) |
---|
550 |       except NameError:  #for when generalData doesn't exist! |
---|
551 | Â Â Â Â Â Â Â Â Fname =Â os.path.join(Mydir,'unknown'+'.'+mode) |
---|
552 |       print Fname+' saved' |
---|
553 | Â Â Â Â Â Â size =Â Page.canvas.GetSize() |
---|
554 |       glPixelStorei(GL_UNPACK_ALIGNMENT, 1) |
---|
555 |       if mode in ['jpeg',]: |
---|
556 |         Pix = glReadPixels(0,0,size[0],size[1],GL_RGBA, GL_UNSIGNED_BYTE) |
---|
557 |         im = Im.new("RGBA", (size[0],size[1])) |
---|
558 | Â Â Â Â Â Â else: |
---|
559 |         Pix = glReadPixels(0,0,size[0],size[1],GL_RGB, GL_UNSIGNED_BYTE) |
---|
560 |         im = Im.new("RGB", (size[0],size[1])) |
---|
561 | Â Â Â Â Â Â im.fromstring(Pix) |
---|
562 | Â Â Â Â Â Â im.save(Fname,mode) |
---|
563 | Â Â Â Â Â Â cb.SetValue(' save as/key:') |
---|
564 | Â Â Â Â Â Â G2frame.G2plotNB.status.SetStatusText('Drawing saved to: '+Fname,1) |
---|
565 | Â Â Â Â else: |
---|
566 | Â Â Â Â Â Â event.key =Â cb.GetValue()[0] |
---|
567 | Â Â Â Â Â Â cb.SetValue(' save as/key:') |
---|
568 | Â Â Â Â Â Â wx.CallAfter(OnKey,event) |
---|
569 | Â Â Â Â Page.canvas.SetFocus()Â # redirect the Focus from the button back to the plot |
---|
570 | Â Â Â Â |
---|
571 |   def OnKey(event):      #on key UP!! |
---|
572 |     global ifBox |
---|
573 | Â Â Â Â Choice =Â {'F':'Fo','S':'Fosq','U':'Unit','D':'dFsq','W':'dFsq/sig'} |
---|
574 | Â Â Â Â try: |
---|
575 | Â Â Â Â Â Â keyCode =Â event.GetKeyCode() |
---|
576 |       if keyCode > 255: |
---|
577 | Â Â Â Â Â Â Â Â keyCode =Â 0 |
---|
578 | Â Â Â Â Â Â key =Â chr(keyCode) |
---|
579 |     except AttributeError:    #if from OnKeyBox above |
---|
580 | Â Â Â Â Â Â key =Â str(event.key).upper() |
---|
581 |     if key in ['C']: |
---|
582 | Â Â Â Â Â Â drawingData['viewPoint'][0]Â =Â drawingData['default'] |
---|
583 | Â Â Â Â Â Â drawingData['viewDir']Â =Â [0,0,1] |
---|
584 | Â Â Â Â Â Â drawingData['oldxy']Â =Â [] |
---|
585 | Â Â Â Â Â Â V0 =Â np.array([0,0,1]) |
---|
586 | Â Â Â Â Â Â V =Â np.inner(Amat,V0) |
---|
587 | Â Â Â Â Â Â V /=Â np.sqrt(np.sum(V**2)) |
---|
588 | Â Â Â Â Â Â A =Â np.arccos(np.sum(V*V0)) |
---|
589 | Â Â Â Â Â Â Q =Â G2mth.AV2Q(A,[0,1,0]) |
---|
590 | Â Â Â Â Â Â drawingData['Quaternion']Â =Â Q |
---|
591 | Â Â Â Â Â Â Q =Â drawingData['Quaternion'] |
---|
592 |     elif key in 'B': |
---|
593 |       ifBox = not ifBox |
---|
594 |     elif key in ['+','=']: |
---|
595 | Â Â Â Â Â Â Data['Scale']Â *=Â 1.25 |
---|
596 |     elif key == '-': |
---|
597 | Â Â Â Â Â Â Data['Scale']Â /=Â 1.25 |
---|
598 |     elif key == '0': |
---|
599 | Â Â Â Â Â Â drawingData['viewPoint'][0]Â =Â [0,0,0] |
---|
600 | Â Â Â Â Â Â Data['Scale']Â =Â 1.0 |
---|
601 |     elif key == 'I': |
---|
602 |       Data['Iscale'] = not Data['Iscale'] |
---|
603 |     elif key in Choice: |
---|
604 | Â Â Â Â Â Â Data['Type']Â =Â Choice[key] |
---|
605 | Â Â Â Â Draw('key') |
---|
606 | Â Â Â Â Â Â |
---|
607 | Â Â Name =Â G2frame.PatternTree.GetItemText(G2frame.PatternId) |
---|
608 |   if Title: #NB: save image as e.g. jpeg will fail if False; MyDir is unknown |
---|
609 | Â Â Â Â generalData =Â G2frame.GetPhaseData()[Title]['General'] |
---|
610 | Â Â Â Â cell =Â generalData['Cell'][1:7] |
---|
611 | Â Â Â Â Mydir =Â generalData['Mydir'] |
---|
612 | Â Â else: |
---|
613 | Â Â Â Â cell =Â [10,10,10,90,90,90] |
---|
614 | Â Â Â Â Mydir =Â G2frame.dirname |
---|
615 | Â Â drawingData =Â Data['Drawing'] |
---|
616 | Â Â Super =Â Data['Super'] |
---|
617 | Â Â SuperVec =Â [] |
---|
618 |   if Super: |
---|
619 | Â Â Â Â SuperVec =Â np.array(Data['SuperVec'][0]) |
---|
620 | Â Â defaultViewPt =Â copy.copy(drawingData['viewPoint']) |
---|
621 | Â Â Amat,Bmat =Â G2lat.cell2AB(cell)Â Â Â Â Â #Amat - crystal to cartesian, Bmat - inverse |
---|
622 | Â Â Gmat,gmat =Â G2lat.cell2Gmat(cell) |
---|
623 | Â Â invcell =Â G2lat.Gmat2cell(Gmat) |
---|
624 | Â Â A4mat =Â np.concatenate((np.concatenate((Amat,[[0],[0],[0]]),axis=1),[[0,0,0,1],]),axis=0) |
---|
625 | Â Â B4mat =Â np.concatenate((np.concatenate((Bmat,[[0],[0],[0]]),axis=1),[[0,0,0,1],]),axis=0) |
---|
626 | Â Â drawingData['Quaternion']Â =Â G2mth.AV2Q(2*np.pi,np.inner(Bmat,[0,0,1])) |
---|
627 | Â Â Wt =Â np.array([255,255,255]) |
---|
628 | Â Â Rd =Â np.array([255,0,0]) |
---|
629 | Â Â Gr =Â np.array([0,255,0]) |
---|
630 | Â Â wxGreen =Â wx.Colour(0,255,0) |
---|
631 | Â Â Bl =Â np.array([0,0,255]) |
---|
632 | Â Â Or =Â np.array([255,128,0]) |
---|
633 | Â Â wxOrange =Â wx.Colour(255,128,0) |
---|
634 | Â Â uBox =Â np.array([[0,0,0],[1,0,0],[1,1,0],[0,1,0],[0,0,1],[1,0,1],[1,1,1],[0,1,1]]) |
---|
635 | Â Â uEdges =Â np.array([ |
---|
636 |     [uBox[0],uBox[1]],[uBox[0],uBox[3]],[uBox[0],uBox[4]],[uBox[1],uBox[2]], |
---|
637 |     [uBox[2],uBox[3]],[uBox[1],uBox[5]],[uBox[2],uBox[6]],[uBox[3],uBox[7]], |
---|
638 | Â Â Â Â [uBox[4],uBox[5]],[uBox[5],uBox[6]],[uBox[6],uBox[7]],[uBox[7],uBox[4]]]) |
---|
639 |   uColors = [Rd,Gr,Bl, Wt,Wt,Wt, Wt,Wt,Wt, Wt,Wt,Wt] |
---|
640 |   def FillHKLRC(): |
---|
641 | Â Â Â Â R =Â np.zeros(len(hklRef)) |
---|
642 | Â Â Â Â C =Â [] |
---|
643 | Â Â Â Â HKL =Â [] |
---|
644 | Â Â Â Â RC =Â [] |
---|
645 |     for i,refl in enumerate(hklRef): |
---|
646 | Â Â Â Â Â Â H =Â refl[:3] |
---|
647 |       if 'HKLF' in Name: |
---|
648 | Â Â Â Â Â Â Â Â Fosq,sig,Fcsq =Â refl[5+Super:8+Super] |
---|
649 | Â Â Â Â Â Â else: |
---|
650 | Â Â Â Â Â Â Â Â Fosq,sig,Fcsq =Â refl[8+Super],1.0,refl[9+Super] |
---|
651 |       if Super: |
---|
652 | Â Â Â Â Â Â Â Â HKL.append(H+SuperVec*refl[3]) |
---|
653 | Â Â Â Â Â Â else: |
---|
654 | Â Â Â Â Â Â Â Â HKL.append(H) |
---|
655 |       if Data['Type'] == 'Unit': |
---|
656 | Â Â Â Â Â Â Â Â R[i]Â =Â 0.1 |
---|
657 | Â Â Â Â Â Â Â Â C.append(Gr) |
---|
658 |       elif Data['Type'] == 'Fosq': |
---|
659 |         if Fosq > 0: |
---|
660 | Â Â Â Â Â Â Â Â Â Â R[i]Â =Â Fosq |
---|
661 | Â Â Â Â Â Â Â Â Â Â C.append(Gr) |
---|
662 | Â Â Â Â Â Â Â Â else: |
---|
663 | Â Â Â Â Â Â Â Â Â Â R[i]Â =Â -Fosq |
---|
664 | Â Â Â Â Â Â Â Â Â Â C.append(Rd) |
---|
665 |       elif Data['Type'] == 'Fo': |
---|
666 |         if Fosq > 0: |
---|
667 | Â Â Â Â Â Â Â Â Â Â R[i]Â =Â np.sqrt(Fosq) |
---|
668 | Â Â Â Â Â Â Â Â Â Â C.append(Gr) |
---|
669 | Â Â Â Â Â Â Â Â else: |
---|
670 | Â Â Â Â Â Â Â Â Â Â R[i]Â =Â np.sqrt(-Fosq) |
---|
671 | Â Â Â Â Â Â Â Â Â Â C.append(Rd) |
---|
672 |       elif Data['Type'] == 'dFsq/sig': |
---|
673 | Â Â Â Â Â Â Â Â dFsig =Â (Fosq-Fcsq)/sig |
---|
674 |         if dFsig > 0: |
---|
675 | Â Â Â Â Â Â Â Â Â Â R[i]Â =Â dFsig |
---|
676 | Â Â Â Â Â Â Â Â Â Â C.append(Gr) |
---|
677 | Â Â Â Â Â Â Â Â else: |
---|
678 | Â Â Â Â Â Â Â Â Â Â R[i]Â =Â -dFsig |
---|
679 | Â Â Â Â Â Â Â Â Â Â C.append(Rd) |
---|
680 |       elif Data['Type'] == 'dFsq': |
---|
681 | Â Â Â Â Â Â Â Â dF =Â Fosq-Fcsq |
---|
682 |         if dF > 0: |
---|
683 | Â Â Â Â Â Â Â Â Â Â R[i]Â =Â dF |
---|
684 | Â Â Â Â Â Â Â Â Â Â C.append(Gr) |
---|
685 | Â Â Â Â Â Â Â Â else: |
---|
686 | Â Â Â Â Â Â Â Â Â Â R[i]Â =Â -dF |
---|
687 | Â Â Â Â Â Â Â Â Â Â C.append(Rd) |
---|
688 | Â Â Â Â R /=Â np.max(R) |
---|
689 | Â Â Â Â R *=Â Data['Scale'] |
---|
690 | Â Â Â Â R =Â np.where(R<1.e-5,1.e-5,R) |
---|
691 |     if Data['Iscale']: |
---|
692 | Â Â Â Â Â Â R =Â np.where(R<=1.,R,1.) |
---|
693 | Â Â Â Â Â Â C =Â np.array(C) |
---|
694 | Â Â Â Â Â Â C =Â (C.T*R).T |
---|
695 | Â Â Â Â Â Â R =Â np.ones_like(R)*0.05Â Â Â |
---|
696 |     return HKL,zip(list(R),C) |
---|
697 | |
---|
698 |   def SetTranslation(newxy): |
---|
699 | #first get translation vector in screen coords.    |
---|
700 | Â Â Â Â oldxy =Â drawingData['oldxy'] |
---|
701 |     if not len(oldxy): oldxy = list(newxy) |
---|
702 | Â Â Â Â dxy =Â newxy-oldxy |
---|
703 | Â Â Â Â drawingData['oldxy']Â =Â list(newxy) |
---|
704 | Â Â Â Â V =Â np.array([-dxy[0],dxy[1],0.]) |
---|
705 | #then transform to rotated crystal coordinates & apply to view point    |
---|
706 | Â Â Â Â Q =Â drawingData['Quaternion'] |
---|
707 | Â Â Â Â V =Â np.inner(Bmat,G2mth.prodQVQ(G2mth.invQ(Q),V)) |
---|
708 | Â Â Â Â Tx,Ty,Tz =Â drawingData['viewPoint'][0] |
---|
709 | Â Â Â Â Tx +=Â V[0]*0.1 |
---|
710 | Â Â Â Â Ty +=Â V[1]*0.1 |
---|
711 | Â Â Â Â Tz +=Â V[2]*0.1 |
---|
712 | Â Â Â Â drawingData['viewPoint'][0]Â =Â Tx,Ty,Tz |
---|
713 | Â Â Â Â |
---|
714 |   def SetRotation(newxy): |
---|
715 | Â Â Â Â 'Perform a rotation in x-y space due to a left-mouse drag' |
---|
716 |   #first get rotation vector in screen coords. & angle increment    |
---|
717 | Â Â Â Â oldxy =Â drawingData['oldxy'] |
---|
718 |     if not len(oldxy): oldxy = list(newxy) |
---|
719 | Â Â Â Â dxy =Â newxy-oldxy |
---|
720 | Â Â Â Â drawingData['oldxy']Â =Â list(newxy) |
---|
721 | Â Â Â Â V =Â np.array([dxy[1],dxy[0],0.]) |
---|
722 | Â Â Â Â A =Â 0.25*np.sqrt(dxy[0]**2+dxy[1]**2) |
---|
723 |     if not A: return # nothing changed, nothing to do |
---|
724 | Â Â # next transform vector back to xtal coordinates via inverse quaternion |
---|
725 | Â Â # & make new quaternion |
---|
726 | Â Â Â Â Q =Â drawingData['Quaternion'] |
---|
727 | Â Â Â Â V =Â G2mth.prodQVQ(G2mth.invQ(Q),np.inner(Bmat,V)) |
---|
728 | Â Â Â Â DQ =Â G2mth.AVdeg2Q(A,V) |
---|
729 | Â Â Â Â Q =Â G2mth.prodQQ(Q,DQ) |
---|
730 | Â Â Â Â drawingData['Quaternion']Â =Â Q |
---|
731 | Â Â # finally get new view vector - last row of rotation matrix |
---|
732 | Â Â Â Â VD =Â np.inner(Bmat,G2mth.Q2Mat(Q)[2]) |
---|
733 | Â Â Â Â VD /=Â np.sqrt(np.sum(VD**2)) |
---|
734 | Â Â Â Â drawingData['viewDir']Â =Â VD |
---|
735 | Â Â Â Â |
---|
736 |   def SetRotationZ(newxy):            |
---|
737 | #first get rotation vector (= view vector) in screen coords. & angle increment    |
---|
738 | Â Â Â Â View =Â glGetIntegerv(GL_VIEWPORT) |
---|
739 | Â Â Â Â cent =Â [View[2]/2,View[3]/2] |
---|
740 | Â Â Â Â oldxy =Â drawingData['oldxy'] |
---|
741 |     if not len(oldxy): oldxy = list(newxy) |
---|
742 | Â Â Â Â dxy =Â newxy-oldxy |
---|
743 | Â Â Â Â drawingData['oldxy']Â =Â list(newxy) |
---|
744 | Â Â Â Â V =Â drawingData['viewDir'] |
---|
745 | Â Â Â Â A =Â [0,0] |
---|
746 | Â Â Â Â A[0]Â =Â dxy[1]*.25 |
---|
747 | Â Â Â Â A[1]Â =Â dxy[0]*.25 |
---|
748 |     if newxy[0] > cent[0]: |
---|
749 | Â Â Â Â Â Â A[0]Â *=Â -1 |
---|
750 |     if newxy[1] < cent[1]: |
---|
751 | Â Â Â Â Â Â A[1]Â *=Â -1Â Â Â Â |
---|
752 | # next transform vector back to xtal coordinates & make new quaternion |
---|
753 | Â Â Â Â Q =Â drawingData['Quaternion'] |
---|
754 | Â Â Â Â V =Â np.inner(Amat,V) |
---|
755 | Â Â Â Â Qx =Â G2mth.AVdeg2Q(A[0],V) |
---|
756 | Â Â Â Â Qy =Â G2mth.AVdeg2Q(A[1],V) |
---|
757 | Â Â Â Â Q =Â G2mth.prodQQ(Q,Qx) |
---|
758 | Â Â Â Â Q =Â G2mth.prodQQ(Q,Qy) |
---|
759 | Â Â Â Â drawingData['Quaternion']Â =Â Q |
---|
760 | |
---|
761 |   def OnMouseDown(event): |
---|
762 | Â Â Â Â xy =Â event.GetPosition() |
---|
763 | Â Â Â Â drawingData['oldxy']Â =Â list(xy) |
---|
764 | Â Â Â Â |
---|
765 |   def OnMouseMove(event): |
---|
766 |     if event.ShiftDown():      #don't want any inadvertant moves when picking |
---|
767 | Â Â Â Â Â Â return |
---|
768 | Â Â Â Â newxy =Â event.GetPosition() |
---|
769 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
---|
770 |     if event.Dragging(): |
---|
771 |       if event.LeftIsDown(): |
---|
772 | Â Â Â Â Â Â Â Â SetRotation(newxy) |
---|
773 | Â Â Â Â Â Â Â Â Q =Â drawingData['Quaternion'] |
---|
774 |       elif event.RightIsDown(): |
---|
775 | Â Â Â Â Â Â Â Â SetTranslation(newxy) |
---|
776 | Â Â Â Â Â Â Â Â Tx,Ty,Tz =Â drawingData['viewPoint'][0] |
---|
777 |       elif event.MiddleIsDown(): |
---|
778 | Â Â Â Â Â Â Â Â SetRotationZ(newxy) |
---|
779 | Â Â Â Â Â Â Â Â Q =Â drawingData['Quaternion'] |
---|
780 | Â Â Â Â Â Â Draw('move') |
---|
781 | Â Â Â Â |
---|
782 |   def OnMouseWheel(event): |
---|
783 |     if event.ShiftDown(): |
---|
784 | Â Â Â Â Â Â return |
---|
785 | Â Â Â Â drawingData['cameraPos']Â +=Â event.GetWheelRotation()/120. |
---|
786 | Â Â Â Â drawingData['cameraPos']Â =Â max(0.1,min(20.00,drawingData['cameraPos'])) |
---|
787 | Â Â Â Â Draw('wheel') |
---|
788 | Â Â Â Â |
---|
789 |   def SetBackground(): |
---|
790 | Â Â Â Â R,G,B,A =Â Page.camera['backColor'] |
---|
791 | Â Â Â Â glClearColor(R,G,B,A) |
---|
792 | Â Â Â Â glClear(GL_COLOR_BUFFER_BIT |Â GL_DEPTH_BUFFER_BIT) |
---|
793 | Â Â Â Â |
---|
794 |   def SetLights(): |
---|
795 | Â Â Â Â glEnable(GL_DEPTH_TEST) |
---|
796 | Â Â Â Â glShadeModel(GL_SMOOTH) |
---|
797 | Â Â Â Â glEnable(GL_LIGHTING) |
---|
798 | Â Â Â Â glEnable(GL_LIGHT0) |
---|
799 | Â Â Â Â glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,0) |
---|
800 | Â Â Â Â glLightfv(GL_LIGHT0,GL_AMBIENT,[1,1,1,.8]) |
---|
801 | Â Â Â Â glLightfv(GL_LIGHT0,GL_DIFFUSE,[1,1,1,1]) |
---|
802 | Â Â Â Â |
---|
803 |   def RenderBox(x,y,z): |
---|
804 | Â Â Â Â xyz =Â np.array([x,y,z]) |
---|
805 | Â Â Â Â glEnable(GL_COLOR_MATERIAL) |
---|
806 | Â Â Â Â glLineWidth(1) |
---|
807 | Â Â Â Â glPushMatrix() |
---|
808 | Â Â Â Â glTranslate(x,y,z) |
---|
809 | Â Â Â Â glColor4ubv([0,0,0,0]) |
---|
810 | Â Â Â Â glBegin(GL_LINES) |
---|
811 |     for line,color in zip(uEdges,uColors): |
---|
812 | Â Â Â Â Â Â glColor3ubv(color) |
---|
813 | Â Â Â Â Â Â glVertex3fv(line[0]) |
---|
814 | Â Â Â Â Â Â glVertex3fv(line[1]) |
---|
815 | Â Â Â Â glEnd() |
---|
816 | Â Â Â Â glPopMatrix() |
---|
817 | Â Â Â Â glColor4ubv([0,0,0,0]) |
---|
818 | Â Â Â Â glDisable(GL_COLOR_MATERIAL) |
---|
819 | Â Â Â Â |
---|
820 |   def RenderUnitVectors(x,y,z): |
---|
821 | Â Â Â Â xyz =Â np.array([x,y,z]) |
---|
822 | Â Â Â Â glEnable(GL_COLOR_MATERIAL) |
---|
823 | Â Â Â Â glLineWidth(1) |
---|
824 | Â Â Â Â glPushMatrix() |
---|
825 | Â Â Â Â glTranslate(x,y,z) |
---|
826 | Â Â Â Â glBegin(GL_LINES) |
---|
827 |     for line,color in zip(uEdges,uColors)[:3]: |
---|
828 | Â Â Â Â Â Â glColor3ubv(color) |
---|
829 | Â Â Â Â Â Â glVertex3fv(-line[1]) |
---|
830 | Â Â Â Â Â Â glVertex3fv(line[1]) |
---|
831 | Â Â Â Â glEnd() |
---|
832 | Â Â Â Â glPopMatrix() |
---|
833 | Â Â Â Â glColor4ubv([0,0,0,0]) |
---|
834 | Â Â Â Â glDisable(GL_COLOR_MATERIAL) |
---|
835 | Â Â Â Â Â Â Â Â |
---|
836 |   def RenderDots(XYZ,RC): |
---|
837 | Â Â Â Â glEnable(GL_COLOR_MATERIAL) |
---|
838 | Â Â Â Â XYZ =Â np.array(XYZ) |
---|
839 | Â Â Â Â glPushMatrix() |
---|
840 |     for xyz,rc in zip(XYZ,RC): |
---|
841 | Â Â Â Â Â Â x,y,z =Â xyz |
---|
842 | Â Â Â Â Â Â r,c =Â rc |
---|
843 | Â Â Â Â Â Â glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,c) |
---|
844 | Â Â Â Â Â Â glPointSize(r*50) |
---|
845 | Â Â Â Â Â Â glBegin(GL_POINTS) |
---|
846 | Â Â Â Â Â Â glVertex3fv(xyz) |
---|
847 | Â Â Â Â Â Â glEnd() |
---|
848 | Â Â Â Â glPopMatrix() |
---|
849 | Â Â Â Â glColor4ubv([0,0,0,0]) |
---|
850 | Â Â Â Â glDisable(GL_COLOR_MATERIAL) |
---|
851 | Â Â Â Â |
---|
852 |   def Draw(caller=''): |
---|
853 | #useful debug?    |
---|
854 | #Â Â Â Â if caller: |
---|
855 | #Â Â Â Â Â Â print caller |
---|
856 | # end of useful debug |
---|
857 |     G2frame.G2plotNB.status.SetStatusText('Plot type = %s for %s'%(Data['Type'],Name),1) |
---|
858 | Â Â Â Â VS =Â np.array(Page.canvas.GetSize()) |
---|
859 | Â Â Â Â aspect =Â float(VS[0])/float(VS[1]) |
---|
860 | Â Â Â Â cPos =Â drawingData['cameraPos'] |
---|
861 | Â Â Â Â Zclip =Â drawingData['Zclip']*cPos/20. |
---|
862 | Â Â Â Â Q =Â drawingData['Quaternion'] |
---|
863 | Â Â Â Â Tx,Ty,Tz =Â drawingData['viewPoint'][0] |
---|
864 | Â Â Â Â G,g =Â G2lat.cell2Gmat(cell) |
---|
865 | Â Â Â Â GS =Â G |
---|
866 | Â Â Â Â GS[0][1]Â =Â GS[1][0]Â =Â math.sqrt(GS[0][0]*GS[1][1]) |
---|
867 | Â Â Â Â GS[0][2]Â =Â GS[2][0]Â =Â math.sqrt(GS[0][0]*GS[2][2]) |
---|
868 | Â Â Â Â GS[1][2]Â =Â GS[2][1]Â =Â math.sqrt(GS[1][1]*GS[2][2]) |
---|
869 | Â Â Â Â |
---|
870 | Â Â Â Â HKL,RC =Â FillHKLRC() |
---|
871 | Â Â Â Â |
---|
872 | Â Â Â Â SetBackground() |
---|
873 | Â Â Â Â glInitNames() |
---|
874 | Â Â Â Â glPushName(0) |
---|
875 | Â Â Â Â |
---|
876 | Â Â Â Â glMatrixMode(GL_PROJECTION) |
---|
877 | Â Â Â Â glLoadIdentity() |
---|
878 | Â Â Â Â glViewport(0,0,VS[0],VS[1]) |
---|
879 | Â Â Â Â gluPerspective(20.,aspect,cPos-Zclip,cPos+Zclip) |
---|
880 | Â Â Â Â gluLookAt(0,0,cPos,0,0,0,0,1,0) |
---|
881 | Â Â Â Â SetLights()Â Â Â Â Â Â |
---|
882 | Â Â Â Â Â Â |
---|
883 | Â Â Â Â glMatrixMode(GL_MODELVIEW) |
---|
884 | Â Â Â Â glLoadIdentity() |
---|
885 | Â Â Â Â matRot =Â G2mth.Q2Mat(Q) |
---|
886 | Â Â Â Â matRot =Â np.concatenate((np.concatenate((matRot,[[0],[0],[0]]),axis=1),[[0,0,0,1],]),axis=0) |
---|
887 | Â Â Â Â glMultMatrixf(matRot.T) |
---|
888 | Â Â Â Â glMultMatrixf(B4mat.T) |
---|
889 | Â Â Â Â glTranslate(-Tx,-Ty,-Tz) |
---|
890 | Â Â Â Â x,y,z =Â drawingData['viewPoint'][0] |
---|
891 |     if ifBox: |
---|
892 | Â Â Â Â Â Â RenderBox(x,y,z) |
---|
893 | Â Â Â Â else: |
---|
894 | Â Â Â Â Â Â RenderUnitVectors(x,y,z) |
---|
895 | Â Â Â Â RenderUnitVectors(0,0,0) |
---|
896 | Â Â Â Â RenderDots(HKL,RC) |
---|
897 | Â Â Â Â time0 =Â time.time() |
---|
898 |     if Page.context: Page.canvas.SetCurrent(Page.context)  # wx 2.9 fix |
---|
899 | Â Â Â Â Page.canvas.SwapBuffers() |
---|
900 | |
---|
901 | Â Â # PlotStructure execution starts here (N.B. initialization above) |
---|
902 | Â Â try: |
---|
903 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index('3D Structure Factors') |
---|
904 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum)Â Â Â Â |
---|
905 |   except ValueError: |
---|
906 | Â Â Â Â Plot =Â G2frame.G2plotNB.addOgl('3D Structure Factors') |
---|
907 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index('3D Structure Factors') |
---|
908 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
909 | Â Â Â Â Page.views =Â False |
---|
910 | Â Â Â Â view =Â False |
---|
911 | Â Â Â Â altDown =Â False |
---|
912 | Â Â Font =Â Page.GetFont() |
---|
913 | Â Â Page.SetFocus() |
---|
914 | Â Â Page.Choice =Â None |
---|
915 | Â Â choice =Â [' save as/key:','jpeg','tiff','bmp','c: recenter to default','b: toggle box ','+: increase scale', |
---|
916 | Â Â '-: decrease scale','f: Fobs','s: Fobs**2','u: unit','d: Fo-Fc','w: DF/sig','i: toggle intensity scaling'] |
---|
917 | Â Â cb =Â wx.ComboBox(G2frame.G2plotNB.status,style=wx.CB_DROPDOWN|wx.CB_READONLY,choices=choice) |
---|
918 |   cb.Bind(wx.EVT_COMBOBOX, OnKeyBox) |
---|
919 | Â Â cb.SetValue(' save as/key:') |
---|
920 |   Page.canvas.Bind(wx.EVT_MOUSEWHEEL, OnMouseWheel) |
---|
921 |   Page.canvas.Bind(wx.EVT_LEFT_DOWN, OnMouseDown) |
---|
922 |   Page.canvas.Bind(wx.EVT_RIGHT_DOWN, OnMouseDown) |
---|
923 |   Page.canvas.Bind(wx.EVT_MIDDLE_DOWN, OnMouseDown) |
---|
924 |   Page.canvas.Bind(wx.EVT_KEY_UP, OnKey) |
---|
925 |   Page.canvas.Bind(wx.EVT_MOTION, OnMouseMove) |
---|
926 | #Â Â Page.canvas.Bind(wx.EVT_SIZE, OnSize) |
---|
927 | Â Â Page.camera['position']Â =Â drawingData['cameraPos'] |
---|
928 | Â Â Page.camera['viewPoint']Â =Â np.inner(Amat,drawingData['viewPoint'][0]) |
---|
929 | Â Â Page.camera['backColor']Â =Â np.array(list(drawingData['backColor'])+[0,])/255. |
---|
930 | Â Â Page.controls =Â Data |
---|
931 | Â Â try: |
---|
932 | Â Â Â Â Page.canvas.SetCurrent() |
---|
933 | Â Â except: |
---|
934 | Â Â Â Â pass |
---|
935 | Â Â Draw('main') |
---|
936 | #Â Â if firstCall: Draw('main') # draw twice the first time that graphics are displayed |
---|
937 | |
---|
938 | Â Â Â Â |
---|
939 | ################################################################################ |
---|
940 | ##### PlotPatterns |
---|
941 | ################################################################################ |
---|
942 | Â Â Â Â Â Â |
---|
943 | def PlotPatterns(G2frame,newPlot=False,plotType='PWDR'): |
---|
944 | Â Â '''Powder pattern plotting package - displays single or multiple powder patterns as intensity vs |
---|
945 | Â Â 2-theta, q or TOF. Can display multiple patterns as "waterfall plots" or contour plots. Log I |
---|
946 | Â Â plotting available. |
---|
947 | Â Â ''' |
---|
948 |   global HKL |
---|
949 |   global exclLines |
---|
950 |   global DifLine |
---|
951 |   global Ymax |
---|
952 | Â Â plottype =Â plotType |
---|
953 | #patch |
---|
954 | Â Â data =Â G2frame.PatternTree.GetItemPyData(G2frame.PatternId) |
---|
955 |   if 'Offset' not in data[0] and plotType in ['PWDR','SASD']:   #plot offset data |
---|
956 | Â Â Â Â data[0].update({'Offset':[0.0,0.0],'delOffset':0.02,'refOffset':-1.0, |
---|
957 | Â Â Â Â Â Â 'refDelt':0.01,}) |
---|
958 | Â Â Â Â G2frame.PatternTree.SetItemPyData(G2frame.PickId,data) |
---|
959 | #end patch |
---|
960 |   def OnPlotKeyPress(event): |
---|
961 | Â Â Â Â try:Â Â Â Â #one way to check if key stroke will work on plot |
---|
962 |       Parms,Parms2 = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId, 'Instrument Parameters')) |
---|
963 |     except TypeError: |
---|
964 | Â Â Â Â Â Â G2frame.G2plotNB.status.SetStatusText('Select '+plottype+' pattern first',1) |
---|
965 | Â Â Â Â Â Â return |
---|
966 | Â Â Â Â newPlot =Â False |
---|
967 |     if event.key == 'w': |
---|
968 |       G2frame.Weight = not G2frame.Weight |
---|
969 |       if not G2frame.Weight and 'PWDR' in plottype: |
---|
970 | Â Â Â Â Â Â Â Â G2frame.SinglePlot =Â True |
---|
971 | Â Â Â Â Â Â newPlot =Â True |
---|
972 |     elif event.key == 'e' and 'SASD' in plottype: |
---|
973 |       G2frame.ErrorBars = not G2frame.ErrorBars |
---|
974 |     elif event.key == 'b': |
---|
975 |       G2frame.SubBack = not G2frame.SubBack |
---|
976 |       if not G2frame.SubBack: |
---|
977 |         G2frame.SinglePlot = True        |
---|
978 |     elif event.key == 'n': |
---|
979 |       if G2frame.Contour: |
---|
980 | Â Â Â Â Â Â Â Â pass |
---|
981 | Â Â Â Â Â Â else: |
---|
982 |         G2frame.logPlot = not G2frame.logPlot |
---|
983 |         if not G2frame.logPlot: |
---|
984 | Â Â Â Â Â Â Â Â Â Â Pattern[0]['Offset'][0]Â =Â 0 |
---|
985 | Â Â Â Â Â Â Â Â newPlot =Â True |
---|
986 |     elif event.key == 's' and 'PWDR' in plottype: |
---|
987 |       if G2frame.Contour: |
---|
988 |         choice = [m for m in mpl.cm.datad.keys() if not m.endswith("_r")] |
---|
989 | Â Â Â Â Â Â Â Â choice.sort() |
---|
990 | Â Â Â Â Â Â Â Â dlg =Â wx.SingleChoiceDialog(G2frame,'Select','Color scheme',choice) |
---|
991 |         if dlg.ShowModal() == wx.ID_OK: |
---|
992 | Â Â Â Â Â Â Â Â Â Â sel =Â dlg.GetSelection() |
---|
993 | Â Â Â Â Â Â Â Â Â Â G2frame.ContourColor =Â choice[sel] |
---|
994 | Â Â Â Â Â Â Â Â else: |
---|
995 | Â Â Â Â Â Â Â Â Â Â G2frame.ContourColor =Â 'Paired' |
---|
996 | Â Â Â Â Â Â Â Â dlg.Destroy() |
---|
997 |       elif G2frame.SinglePlot: |
---|
998 |         G2frame.plotStyle['sqrtPlot'] = not G2frame.plotStyle['sqrtPlot'] |
---|
999 |         if G2frame.plotStyle['sqrtPlot']: |
---|
1000 | Â Â Â Â Â Â Â Â Â Â Pattern[0]['delOffset']Â =Â .002 |
---|
1001 | Â Â Â Â Â Â Â Â Â Â Pattern[0]['refOffset']Â =Â -1.0 |
---|
1002 | Â Â Â Â Â Â Â Â Â Â Pattern[0]['refDelt']Â =Â .001 |
---|
1003 | Â Â Â Â Â Â Â Â else: |
---|
1004 | Â Â Â Â Â Â Â Â Â Â Pattern[0]['delOffset']Â =Â .02 |
---|
1005 | Â Â Â Â Â Â Â Â Â Â Pattern[0]['refOffset']Â =Â -1.0 |
---|
1006 | Â Â Â Â Â Â Â Â Â Â Pattern[0]['refDelt']Â =Â .01 |
---|
1007 | Â Â Â Â Â Â newPlot =Â True |
---|
1008 |     elif event.key == 'u' and (G2frame.Contour or not G2frame.SinglePlot): |
---|
1009 |       if G2frame.Contour: |
---|
1010 | Â Â Â Â Â Â Â Â G2frame.Cmax =Â min(1.0,G2frame.Cmax*1.2) |
---|
1011 |       elif Pattern[0]['Offset'][0] < 100.: |
---|
1012 | Â Â Â Â Â Â Â Â Pattern[0]['Offset'][0]Â +=Â 1. |
---|
1013 |     elif event.key == 'd' and (G2frame.Contour or not G2frame.SinglePlot): |
---|
1014 |       if G2frame.Contour: |
---|
1015 | Â Â Â Â Â Â Â Â G2frame.Cmax =Â max(0.0,G2frame.Cmax*0.8) |
---|
1016 |       elif Pattern[0]['Offset'][0] > 0.: |
---|
1017 | Â Â Â Â Â Â Â Â Pattern[0]['Offset'][0]Â -=Â 1. |
---|
1018 |     elif event.key == 'l' and not G2frame.SinglePlot: |
---|
1019 | Â Â Â Â Â Â Pattern[0]['Offset'][1]Â -=Â 1. |
---|
1020 |     elif event.key == 'r' and not G2frame.SinglePlot: |
---|
1021 | Â Â Â Â Â Â Pattern[0]['Offset'][1]Â +=Â 1. |
---|
1022 |     elif event.key == 'o' and not G2frame.SinglePlot: |
---|
1023 | Â Â Â Â Â Â G2frame.Cmax =Â 1.0 |
---|
1024 | Â Â Â Â Â Â Pattern[0]['Offset']Â =Â [0,0] |
---|
1025 |     elif event.key == 'c' and 'PWDR' in plottype: |
---|
1026 | Â Â Â Â Â Â newPlot =Â True |
---|
1027 |       if not G2frame.Contour: |
---|
1028 | Â Â Â Â Â Â Â Â G2frame.SinglePlot =Â False |
---|
1029 | Â Â Â Â Â Â Â Â Pattern[0]['Offset']Â =Â [0.,0.] |
---|
1030 | Â Â Â Â Â Â else: |
---|
1031 |         G2frame.SinglePlot = True        |
---|
1032 |       G2frame.Contour = not G2frame.Contour |
---|
1033 |     elif event.key == 'q': |
---|
1034 |       if 'PWDR' in plottype: |
---|
1035 | Â Â Â Â Â Â Â Â newPlot =Â True |
---|
1036 |         G2frame.plotStyle['qPlot'] = not G2frame.plotStyle['qPlot'] |
---|
1037 | Â Â Â Â Â Â Â Â G2frame.plotStyle['dPlot']Â =Â False |
---|
1038 |       elif 'SASD' in plottype: |
---|
1039 | Â Â Â Â Â Â Â Â newPlot =Â True |
---|
1040 |         G2frame.plotStyle['sqPlot'] = not G2frame.plotStyle['sqPlot'] |
---|
1041 |     elif event.key == 't' and 'PWDR' in plottype: |
---|
1042 |       G2frame.plotStyle['dPlot'] = not G2frame.plotStyle['dPlot'] |
---|
1043 | Â Â Â Â Â Â G2frame.plotStyle['qPlot']Â =Â False |
---|
1044 |       newPlot = True   |
---|
1045 |     elif event.key == 'm': |
---|
1046 | Â Â Â Â Â Â G2frame.plotStyle['sqrtPlot']Â =Â False |
---|
1047 |       G2frame.SinglePlot = not G2frame.SinglePlot        |
---|
1048 | Â Â Â Â Â Â newPlot =Â True |
---|
1049 |     elif event.key in ['+','=']: |
---|
1050 |       if G2frame.PickId: |
---|
1051 | Â Â Â Â Â Â Â Â G2frame.PickId =Â False |
---|
1052 |     elif event.key == 'i' and G2frame.Contour:         #for smoothing contour plot |
---|
1053 | Â Â Â Â Â Â choice =Â ['nearest','bilinear','bicubic','spline16','spline36','hanning', |
---|
1054 | Â Â Â Â Â Â Â Â 'hamming','hermite','kaiser','quadric','catrom','gaussian','bessel', |
---|
1055 | Â Â Â Â Â Â Â Â 'mitchell','sinc','lanczos'] |
---|
1056 | Â Â Â Â Â Â dlg =Â wx.SingleChoiceDialog(G2frame,'Select','Interpolation',choice) |
---|
1057 |       if dlg.ShowModal() == wx.ID_OK: |
---|
1058 | Â Â Â Â Â Â Â Â sel =Â dlg.GetSelection() |
---|
1059 | Â Â Â Â Â Â Â Â G2frame.Interpolate =Â choice[sel] |
---|
1060 | Â Â Â Â Â Â else: |
---|
1061 | Â Â Â Â Â Â Â Â G2frame.Interpolate =Â 'nearest' |
---|
1062 | Â Â Â Â Â Â dlg.Destroy() |
---|
1063 | Â Â Â Â else: |
---|
1064 | #Â Â Â Â Â Â print 'no binding for key',event.key |
---|
1065 | Â Â Â Â Â Â #GSASIIpath.IPyBreak() |
---|
1066 | Â Â Â Â Â Â return |
---|
1067 | Â Â Â Â wx.CallAfter(PlotPatterns,G2frame,newPlot=newPlot,plotType=plottype) |
---|
1068 | Â Â Â Â |
---|
1069 |   def OnMotion(event): |
---|
1070 | Â Â Â Â xpos =Â event.xdata |
---|
1071 |     if xpos:                    #avoid out of frame mouse position |
---|
1072 | Â Â Â Â Â Â ypos =Â event.ydata |
---|
1073 | Â Â Â Â Â Â Page.canvas.SetCursor(wx.CROSS_CURSOR) |
---|
1074 | Â Â Â Â Â Â try: |
---|
1075 |         Parms,Parms2 = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId, 'Instrument Parameters')) |
---|
1076 |         if G2frame.plotStyle['qPlot'] and 'PWDR' in plottype: |
---|
1077 | Â Â Â Â Â Â Â Â Â Â q =Â xpos |
---|
1078 | Â Â Â Â Â Â Â Â Â Â dsp =Â 2.*np.pi/q |
---|
1079 | Â Â Â Â Â Â Â Â Â Â try: |
---|
1080 | Â Â Â Â Â Â Â Â Â Â Â Â xpos =Â G2lat.Dsp2pos(Parms,2.0*np.pi/xpos) |
---|
1081 |           except ValueError:   #avoid bad value in asin beyond upper limit |
---|
1082 | Â Â Â Â Â Â Â Â Â Â Â Â pass |
---|
1083 |         elif 'SASD' in plottype: |
---|
1084 | Â Â Â Â Â Â Â Â Â Â q =Â xpos |
---|
1085 | Â Â Â Â Â Â Â Â Â Â dsp =Â 2.*np.pi/q |
---|
1086 |         elif G2frame.plotStyle['dPlot']: |
---|
1087 | Â Â Â Â Â Â Â Â Â Â dsp =Â xpos |
---|
1088 | Â Â Â Â Â Â Â Â Â Â q =Â 2.*np.pi/dsp |
---|
1089 | Â Â Â Â Â Â Â Â Â Â xpos =Â G2lat.Dsp2pos(Parms,xpos) |
---|
1090 |         elif G2frame.Contour and 'T' in Parms['Type'][0]: |
---|
1091 | Â Â Â Â Â Â Â Â Â Â xpos =Â X[xpos]Â Â Â Â Â Â Â Â Â Â |
---|
1092 | Â Â Â Â Â Â Â Â Â Â dsp =Â G2lat.Pos2dsp(Parms,xpos) |
---|
1093 | Â Â Â Â Â Â Â Â Â Â q =Â 2.*np.pi/dsp |
---|
1094 | Â Â Â Â Â Â Â Â else: |
---|
1095 | Â Â Â Â Â Â Â Â Â Â dsp =Â G2lat.Pos2dsp(Parms,xpos) |
---|
1096 | Â Â Â Â Â Â Â Â Â Â q =Â 2.*np.pi/dsp |
---|
1097 |         if G2frame.Contour: #PWDR only |
---|
1098 |           if 'C' in Parms['Type'][0]: |
---|
1099 |             G2frame.G2plotNB.status.SetStatusText('2-theta =%9.3f d =%9.5f q = %9.5f pattern ID =%5d'%(xpos,dsp,q,int(ypos)),1) |
---|
1100 | Â Â Â Â Â Â Â Â Â Â else: |
---|
1101 |             G2frame.G2plotNB.status.SetStatusText('TOF =%9.3f d =%9.5f q = %9.5f pattern ID =%5d'%(xpos,dsp,q,int(ypos)),1) |
---|
1102 | Â Â Â Â Â Â Â Â else: |
---|
1103 |           if 'C' in Parms['Type'][0]: |
---|
1104 |             if 'PWDR' in plottype: |
---|
1105 |               if G2frame.plotStyle['sqrtPlot']: |
---|
1106 |                 G2frame.G2plotNB.status.SetStatusText('2-theta =%9.3f d =%9.5f q = %9.5f sqrt(Intensity) =%9.2f'%(xpos,dsp,q,ypos),1) |
---|
1107 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â else: |
---|
1108 |                 G2frame.G2plotNB.status.SetStatusText('2-theta =%9.3f d =%9.5f q = %9.5f Intensity =%9.2f'%(xpos,dsp,q,ypos),1) |
---|
1109 |             elif 'SASD' in plottype: |
---|
1110 |               G2frame.G2plotNB.status.SetStatusText('q =%12.5g Intensity =%12.5g d =%9.1f'%(q,ypos,dsp),1) |
---|
1111 | Â Â Â Â Â Â Â Â Â Â else: |
---|
1112 |             if G2frame.plotStyle['sqrtPlot']: |
---|
1113 |               G2frame.G2plotNB.status.SetStatusText('TOF =%9.3f d =%9.5f q =%9.5f sqrt(Intensity) =%9.2f'%(xpos,dsp,q,ypos),1) |
---|
1114 | Â Â Â Â Â Â Â Â Â Â Â Â else: |
---|
1115 |               G2frame.G2plotNB.status.SetStatusText('TOF =%9.3f d =%9.5f q =%9.5f Intensity =%9.2f'%(xpos,dsp,q,ypos),1) |
---|
1116 |         if G2frame.itemPicked: |
---|
1117 | Â Â Â Â Â Â Â Â Â Â Page.canvas.SetToolTipString('%9.5f'%(xpos)) |
---|
1118 |         if G2frame.PickId: |
---|
1119 | Â Â Â Â Â Â Â Â Â Â found =Â [] |
---|
1120 | Â Â Â Â Â Â Â Â Â Â pickIdText =Â G2frame.PatternTree.GetItemText(G2frame.PickId) |
---|
1121 |           if pickIdText in ['Index Peak List','Unit Cells List','Reflection Lists'] or \ |
---|
1122 |             'PWDR' in pickIdText: |
---|
1123 | Â Â Â Â Â Â Â Â Â Â Â Â indx =Â -1 |
---|
1124 |             if pickIdText in ['Index Peak List','Unit Cells List',]: |
---|
1125 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â indx =Â -2 |
---|
1126 |             if len(HKL): |
---|
1127 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â view =Â Page.toolbar._views.forward()[0][:2] |
---|
1128 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â wid =Â view[1]-view[0] |
---|
1129 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â found =Â HKL[np.where(np.fabs(HKL.T[indx]-xpos)Â <Â 0.002*wid)] |
---|
1130 |             if len(found): |
---|
1131 |               if len(found[0]) > 6:  #SS reflections |
---|
1132 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â h,k,l,m =Â found[0][:4] |
---|
1133 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Page.canvas.SetToolTipString('%d,%d,%d,%d'%(int(h),int(k),int(l),int(m))) |
---|
1134 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â else: |
---|
1135 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â h,k,l =Â found[0][:3]Â |
---|
1136 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Page.canvas.SetToolTipString('%d,%d,%d'%(int(h),int(k),int(l))) |
---|
1137 | Â Â Â Â Â Â Â Â Â Â Â Â else: |
---|
1138 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Page.canvas.SetToolTipString('') |
---|
1139 | |
---|
1140 |       except TypeError: |
---|
1141 | Â Â Â Â Â Â Â Â G2frame.G2plotNB.status.SetStatusText('Select '+plottype+' pattern first',1) |
---|
1142 | Â Â Â Â Â Â Â Â |
---|
1143 |   def OnPress(event): #ugh - this removes a matplotlib error for mouse clicks in log plots         |
---|
1144 | Â Â Â Â olderr =Â np.seterr(invalid='ignore') |
---|
1145 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
---|
1146 |   def OnPick(event): |
---|
1147 |     if G2frame.itemPicked is not None: return |
---|
1148 | Â Â Â Â PatternId =Â G2frame.PatternId |
---|
1149 | Â Â Â Â try: |
---|
1150 |       Parms,Parms2 = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId, 'Instrument Parameters')) |
---|
1151 |     except TypeError: |
---|
1152 | Â Â Â Â Â Â return |
---|
1153 | Â Â Â Â PickId =Â G2frame.PickId |
---|
1154 | Â Â Â Â pick =Â event.artist |
---|
1155 | Â Â Â Â mouse =Â event.mouseevent |
---|
1156 | Â Â Â Â xpos =Â pick.get_xdata() |
---|
1157 | Â Â Â Â ypos =Â pick.get_ydata() |
---|
1158 | Â Â Â Â ind =Â event.ind |
---|
1159 | Â Â Â Â xy =Â list(zip(np.take(xpos,ind),np.take(ypos,ind))[0]) |
---|
1160 |     if G2frame.PatternTree.GetItemText(PickId) == 'Peak List': |
---|
1161 |       if ind.all() != [0] and ObsLine[0].get_label() in str(pick):                  #picked a data point |
---|
1162 | Â Â Â Â Â Â Â Â data =Â G2frame.PatternTree.GetItemPyData(G2frame.PickId) |
---|
1163 |         if G2frame.plotStyle['qPlot']:               #qplot - convert back to 2-theta |
---|
1164 | Â Â Â Â Â Â Â Â Â Â xy[0]Â =Â G2lat.Dsp2pos(Parms,2*np.pi/xy[0]) |
---|
1165 |         elif G2frame.plotStyle['dPlot']:              #dplot - convert back to 2-theta |
---|
1166 | Â Â Â Â Â Â Â Â Â Â xy[0]Â =Â G2lat.Dsp2pos(Parms,xy[0]) |
---|
1167 | Â Â Â Â Â Â Â Â XY =Â G2mth.setPeakparms(Parms,Parms2,xy[0],xy[1]) |
---|
1168 | Â Â Â Â Â Â Â Â data['peaks'].append(XY) |
---|
1169 | Â Â Â Â Â Â Â Â data['sigDict']Â =Â {}Â Â #now invalid |
---|
1170 | Â Â Â Â Â Â Â Â G2pdG.UpdatePeakGrid(G2frame,data) |
---|
1171 | Â Â Â Â Â Â Â Â PlotPatterns(G2frame,plotType=plottype) |
---|
1172 | Â Â Â Â Â Â else:Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #picked a peak list line |
---|
1173 | Â Â Â Â Â Â Â Â G2frame.itemPicked =Â pick |
---|
1174 |     elif G2frame.PatternTree.GetItemText(PickId) == 'Limits': |
---|
1175 |       if ind.all() != [0]:                  #picked a data point |
---|
1176 |         LimitId = G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Limits') |
---|
1177 | Â Â Â Â Â Â Â Â data =Â G2frame.PatternTree.GetItemPyData(LimitId) |
---|
1178 |         if G2frame.plotStyle['qPlot']:               #qplot - convert back to 2-theta |
---|
1179 | Â Â Â Â Â Â Â Â Â Â xy[0]Â =Â G2lat.Dsp2pos(Parms,2*np.pi/xy[0]) |
---|
1180 |         elif G2frame.plotStyle['dPlot']:              #dplot - convert back to 2-theta |
---|
1181 | Â Â Â Â Â Â Â Â Â Â xy[0]Â =Â G2lat.Dsp2pos(Parms,xy[0]) |
---|
1182 |         if G2frame.ifGetExclude: |
---|
1183 | Â Â Â Â Â Â Â Â Â Â excl =Â [0,0] |
---|
1184 | Â Â Â Â Â Â Â Â Â Â excl[0]Â =Â max(data[1][0],min(xy[0],data[1][1])) |
---|
1185 | Â Â Â Â Â Â Â Â Â Â excl[1]Â =Â excl[0]+0.1 |
---|
1186 | Â Â Â Â Â Â Â Â Â Â data.append(excl) |
---|
1187 | Â Â Â Â Â Â Â Â Â Â G2frame.ifGetExclude =Â False |
---|
1188 | Â Â Â Â Â Â Â Â else: |
---|
1189 |           if mouse.button==1: |
---|
1190 | Â Â Â Â Â Â Â Â Â Â Â Â data[1][0]Â =Â min(xy[0],data[1][1]) |
---|
1191 |           if mouse.button==3: |
---|
1192 | Â Â Â Â Â Â Â Â Â Â Â Â data[1][1]Â =Â max(xy[0],data[1][0]) |
---|
1193 | Â Â Â Â Â Â Â Â G2frame.PatternTree.SetItemPyData(LimitId,data) |
---|
1194 | Â Â Â Â Â Â Â Â G2pdG.UpdateLimitsGrid(G2frame,data,plottype) |
---|
1195 | Â Â Â Â Â Â Â Â wx.CallAfter(PlotPatterns,G2frame,plotType=plottype) |
---|
1196 | Â Â Â Â Â Â else:Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #picked a limit line |
---|
1197 | Â Â Â Â Â Â Â Â G2frame.itemPicked =Â pick |
---|
1198 |     elif G2frame.PatternTree.GetItemText(PickId) == 'Models': |
---|
1199 |       if ind.all() != [0]:                  #picked a data point |
---|
1200 |         LimitId = G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Limits') |
---|
1201 | Â Â Â Â Â Â Â Â data =Â G2frame.PatternTree.GetItemPyData(LimitId) |
---|
1202 |         if mouse.button==1: |
---|
1203 | Â Â Â Â Â Â Â Â Â Â data[1][0]Â =Â min(xy[0],data[1][1]) |
---|
1204 |         if mouse.button==3: |
---|
1205 | Â Â Â Â Â Â Â Â Â Â data[1][1]Â =Â max(xy[0],data[1][0]) |
---|
1206 | Â Â Â Â Â Â Â Â G2frame.PatternTree.SetItemPyData(LimitId,data) |
---|
1207 | Â Â Â Â Â Â Â Â wx.CallAfter(PlotPatterns,G2frame,plotType=plottype) |
---|
1208 | Â Â Â Â Â Â else:Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #picked a limit line |
---|
1209 | Â Â Â Â Â Â Â Â G2frame.itemPicked =Â pick |
---|
1210 |     elif G2frame.PatternTree.GetItemText(PickId) == 'Reflection Lists' or \ |
---|
1211 |       'PWDR' in G2frame.PatternTree.GetItemText(PickId): |
---|
1212 | Â Â Â Â Â Â G2frame.itemPicked =Â pick |
---|
1213 | Â Â Â Â Â Â pick =Â str(pick) |
---|
1214 | Â Â Â Â |
---|
1215 |   def OnRelease(event): |
---|
1216 |     if G2frame.itemPicked is None: return |
---|
1217 | Â Â Â Â PickId =Â G2frame.PickId |
---|
1218 |     if str(DifLine[0]) == str(G2frame.itemPicked): |
---|
1219 | Â Â Â Â Â Â data =Â G2frame.PatternTree.GetItemPyData(PickId) |
---|
1220 | Â Â Â Â Â Â ypos =Â event.ydata |
---|
1221 | Â Â Â Â Â Â data[0]['delOffset']Â =Â -ypos/Ymax |
---|
1222 | Â Â Â Â Â Â G2frame.itemPicked =Â None |
---|
1223 | Â Â Â Â Â Â G2frame.PatternTree.SetItemPyData(PickId,data) |
---|
1224 | Â Â Â Â Â Â PlotPatterns(G2frame,plotType=plottype) |
---|
1225 | Â Â Â Â Â Â return |
---|
1226 |     Parms,Parms2 = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId, 'Instrument Parameters')) |
---|
1227 | Â Â Â Â xpos =Â event.xdata |
---|
1228 |     if G2frame.PatternTree.GetItemText(PickId) in ['Peak List','Limits'] and xpos: |
---|
1229 | Â Â Â Â Â Â lines =Â [] |
---|
1230 |       for line in G2frame.Lines: |
---|
1231 | Â Â Â Â Â Â Â Â lines.append(line.get_xdata()[0]) |
---|
1232 | Â Â Â Â Â Â try: |
---|
1233 | Â Â Â Â Â Â Â Â lineNo =Â lines.index(G2frame.itemPicked.get_xdata()[0]) |
---|
1234 |       except ValueError: |
---|
1235 | Â Â Â Â Â Â Â Â lineNo =Â -1 |
---|
1236 |       if lineNo in [0,1] or lineNo in exclLines: |
---|
1237 |         LimitId = G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId, 'Limits') |
---|
1238 | Â Â Â Â Â Â Â Â limits =Â G2frame.PatternTree.GetItemPyData(LimitId) |
---|
1239 |         id = lineNo/2+1 |
---|
1240 | Â Â Â Â Â Â Â Â id2 =Â lineNo%2 |
---|
1241 |         if G2frame.plotStyle['qPlot'] and 'PWDR' in plottype: |
---|
1242 | Â Â Â Â Â Â Â Â Â Â limits[id][id2]Â =Â G2lat.Dsp2pos(Parms,2.*np.pi/xpos) |
---|
1243 |         elif G2frame.plotStyle['dPlot'] and 'PWDR' in plottype: |
---|
1244 | Â Â Â Â Â Â Â Â Â Â limits[id][id2]Â =Â G2lat.Dsp2pos(Parms,xpos) |
---|
1245 | Â Â Â Â Â Â Â Â else: |
---|
1246 | Â Â Â Â Â Â Â Â Â Â limits[id][id2]Â =Â xpos |
---|
1247 |         if id > 1 and limits[id][0] > limits[id][1]: |
---|
1248 | Â Â Â Â Â Â Â Â Â Â Â Â limits[id].reverse() |
---|
1249 | Â Â Â Â Â Â Â Â limits[1][0]Â =Â min(max(limits[0][0],limits[1][0]),limits[1][1]) |
---|
1250 | Â Â Â Â Â Â Â Â limits[1][1]Â =Â max(min(limits[0][1],limits[1][1]),limits[1][0]) |
---|
1251 | Â Â Â Â Â Â Â Â G2frame.PatternTree.SetItemPyData(LimitId,limits) |
---|
1252 |         if G2frame.PatternTree.GetItemText(G2frame.PickId) == 'Limits': |
---|
1253 | Â Â Â Â Â Â Â Â Â Â G2pdG.UpdateLimitsGrid(G2frame,limits,plottype) |
---|
1254 |       elif lineNo > 1: |
---|
1255 |         PeakId = G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId, 'Peak List') |
---|
1256 | Â Â Â Â Â Â Â Â peaks =Â G2frame.PatternTree.GetItemPyData(PeakId) |
---|
1257 |         if event.button == 3: |
---|
1258 |           del peaks['peaks'][lineNo-2] |
---|
1259 | Â Â Â Â Â Â Â Â else: |
---|
1260 |           if G2frame.plotStyle['qPlot']: |
---|
1261 | Â Â Â Â Â Â Â Â Â Â Â Â peaks['peaks'][lineNo-2][0]Â =Â G2lat.Dsp2pos(Parms,2.*np.pi/xpos) |
---|
1262 |           elif G2frame.plotStyle['dPlot']: |
---|
1263 | Â Â Â Â Â Â Â Â Â Â Â Â peaks['peaks'][lineNo-2][0]Â =Â G2lat.Dsp2pos(Parms,xpos) |
---|
1264 | Â Â Â Â Â Â Â Â Â Â else: |
---|
1265 | Â Â Â Â Â Â Â Â Â Â Â Â peaks['peaks'][lineNo-2][0]Â =Â xpos |
---|
1266 | Â Â Â Â Â Â Â Â Â Â peaks['sigDict']Â =Â {}Â Â Â Â #no longer valid |
---|
1267 | Â Â Â Â Â Â Â Â G2frame.PatternTree.SetItemPyData(PeakId,peaks) |
---|
1268 | Â Â Â Â Â Â Â Â G2pdG.UpdatePeakGrid(G2frame,peaks) |
---|
1269 |     elif G2frame.PatternTree.GetItemText(PickId) in ['Models',] and xpos: |
---|
1270 | Â Â Â Â Â Â lines =Â [] |
---|
1271 |       for line in G2frame.Lines: |
---|
1272 | Â Â Â Â Â Â Â Â lines.append(line.get_xdata()[0]) |
---|
1273 | Â Â Â Â Â Â try: |
---|
1274 | Â Â Â Â Â Â Â Â lineNo =Â lines.index(G2frame.itemPicked.get_xdata()[0]) |
---|
1275 |       except ValueError: |
---|
1276 | Â Â Â Â Â Â Â Â lineNo =Â -1 |
---|
1277 |       if lineNo in [0,1]: |
---|
1278 |         LimitId = G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId, 'Limits') |
---|
1279 | Â Â Â Â Â Â Â Â data =Â G2frame.PatternTree.GetItemPyData(LimitId) |
---|
1280 | Â Â Â Â Â Â Â Â data[1][lineNo]Â =Â xpos |
---|
1281 | Â Â Â Â Â Â Â Â data[1][0]Â =Â min(max(data[0][0],data[1][0]),data[1][1]) |
---|
1282 | Â Â Â Â Â Â Â Â data[1][1]Â =Â max(min(data[0][1],data[1][1]),data[1][0]) |
---|
1283 | Â Â Â Â Â Â Â Â G2frame.PatternTree.SetItemPyData(LimitId,data)Â Â Â Â |
---|
1284 |     elif (G2frame.PatternTree.GetItemText(PickId) == 'Reflection Lists' or \ |
---|
1285 |       'PWDR' in G2frame.PatternTree.GetItemText(PickId)) and xpos: |
---|
1286 | Â Â Â Â Â Â Phases =Â G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId,'Reflection Lists')) |
---|
1287 | Â Â Â Â Â Â pick =Â str(G2frame.itemPicked).split('(')[1].strip(')') |
---|
1288 |       if 'line' not in pick:    #avoid data points, etc. |
---|
1289 | Â Â Â Â Â Â Â Â data =Â G2frame.PatternTree.GetItemPyData(PickId) |
---|
1290 | Â Â Â Â Â Â Â Â num =Â Phases.keys().index(pick) |
---|
1291 |         if num: |
---|
1292 | Â Â Â Â Â Â Â Â Â Â data[0]['refDelt']Â =Â -(event.ydata-Pattern[0]['refOffset'])/(num*Ymax) |
---|
1293 | Â Â Â Â Â Â Â Â else:Â Â Â Â #1st row of refl ticks |
---|
1294 | Â Â Â Â Â Â Â Â Â Â data[0]['refOffset']Â =Â event.ydata |
---|
1295 | Â Â Â Â Â Â Â Â G2frame.PatternTree.SetItemPyData(PickId,data) |
---|
1296 | Â Â Â Â PlotPatterns(G2frame,plotType=plottype) |
---|
1297 |     G2frame.itemPicked = None  |
---|
1298 | |
---|
1299 | Â Â try: |
---|
1300 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index('Powder Patterns') |
---|
1301 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
1302 |     if not newPlot: |
---|
1303 | Â Â Â Â Â Â Plot =Â Page.figure.gca()Â Â Â Â Â #get previous powder plot & get limits |
---|
1304 | Â Â Â Â Â Â xylim =Â Plot.get_xlim(),Plot.get_ylim() |
---|
1305 | Â Â Â Â Page.figure.clf() |
---|
1306 | Â Â Â Â Plot =Â Page.figure.gca()Â Â Â Â Â #get a fresh plot after clf() |
---|
1307 |   except ValueError: |
---|
1308 |     if plottype == 'SASD': |
---|
1309 | Â Â Â Â Â Â G2frame.logPlot =Â True |
---|
1310 | Â Â Â Â Â Â G2frame.ErrorBars =Â True |
---|
1311 | Â Â Â Â newPlot =Â True |
---|
1312 | Â Â Â Â G2frame.Cmax =Â 1.0 |
---|
1313 | Â Â Â Â Plot =Â G2frame.G2plotNB.addMpl('Powder Patterns').gca() |
---|
1314 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index('Powder Patterns') |
---|
1315 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
1316 |     Page.canvas.mpl_connect('key_press_event', OnPlotKeyPress) |
---|
1317 |     Page.canvas.mpl_connect('motion_notify_event', OnMotion) |
---|
1318 |     Page.canvas.mpl_connect('pick_event', OnPick) |
---|
1319 |     Page.canvas.mpl_connect('button_release_event', OnRelease) |
---|
1320 | Â Â Â Â Page.canvas.mpl_connect('button_press_event',OnPress) |
---|
1321 |   if plottype == 'PWDR': # avoids a very nasty clash with KILL_FOCUS in SASD TextCtrl? |
---|
1322 | Â Â Â Â Page.SetFocus() |
---|
1323 | Â Â G2frame.G2plotNB.status.DestroyChildren() |
---|
1324 |   if G2frame.Contour: |
---|
1325 | Â Â Â Â Page.Choice =Â (' key press','d: lower contour max','u: raise contour max','o: reset contour max', |
---|
1326 | Â Â Â Â Â Â 'i: interpolation method','s: color scheme','c: contour off') |
---|
1327 | Â Â else: |
---|
1328 |     if G2frame.logPlot: |
---|
1329 |       if 'PWDR' in plottype: |
---|
1330 |         if G2frame.SinglePlot: |
---|
1331 | Â Â Â Â Â Â Â Â Â Â Page.Choice =Â (' key press','n: log(I) off', |
---|
1332 | Â Â Â Â Â Â Â Â Â Â Â Â 'c: contour on','q: toggle q plot','t: toggle d-spacing plot', |
---|
1333 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â 'm: toggle multidata plot','w: toggle divide by sig','+: no selection') |
---|
1334 | Â Â Â Â Â Â Â Â else: |
---|
1335 | Â Â Â Â Â Â Â Â Â Â Page.Choice =Â (' key press','n: log(I) off', |
---|
1336 | Â Â Â Â Â Â Â Â Â Â Â Â 'd: offset down','l: offset left','r: offset right','u: offset up','o: reset offset', |
---|
1337 | Â Â Â Â Â Â Â Â Â Â Â Â 'c: contour on','q: toggle q plot','t: toggle d-spacing plot', |
---|
1338 | Â Â Â Â Â Â Â Â Â Â Â Â 'm: toggle multidata plot','w: toggle divide by sig','+: no selection') |
---|
1339 |       elif 'SASD' in plottype: |
---|
1340 |         if G2frame.SinglePlot: |
---|
1341 | Â Â Â Â Â Â Â Â Â Â Page.Choice =Â (' key press','b: toggle subtract background file','n: semilog on', |
---|
1342 | Â Â Â Â Â Â Â Â Â Â Â Â 'q: toggle S(q) plot','m: toggle multidata plot','w: toggle (Io-Ic)/sig plot','+: no selection') |
---|
1343 | Â Â Â Â Â Â Â Â else: |
---|
1344 | Â Â Â Â Â Â Â Â Â Â Page.Choice =Â (' key press','b: toggle subtract background file','n: semilog on', |
---|
1345 | Â Â Â Â Â Â Â Â Â Â Â Â 'd: offset down','l: offset left','r: offset right','u: offset up','o: reset offset', |
---|
1346 | Â Â Â Â Â Â Â Â Â Â Â Â 'q: toggle S(q) plot','m: toggle multidata plot','w: toggle (Io-Ic)/sig plot','+: no selection') |
---|
1347 | Â Â Â Â else: |
---|
1348 |       if 'PWDR' in plottype: |
---|
1349 |         if G2frame.SinglePlot: |
---|
1350 | Â Â Â Â Â Â Â Â Â Â Page.Choice =Â (' key press', |
---|
1351 | Â Â Â Â Â Â Â Â Â Â Â Â 'b: toggle subtract background','n: log(I) on','s: toggle sqrt plot','c: contour on', |
---|
1352 | Â Â Â Â Â Â Â Â Â Â Â Â 'q: toggle q plot','t: toggle d-spacing plot','m: toggle multidata plot', |
---|
1353 | Â Â Â Â Â Â Â Â Â Â Â Â 'w: toggle divide by sig','+: no selection') |
---|
1354 | Â Â Â Â Â Â Â Â else: |
---|
1355 | Â Â Â Â Â Â Â Â Â Â Page.Choice =Â (' key press','l: offset left','r: offset right','d: offset down', |
---|
1356 | Â Â Â Â Â Â Â Â Â Â Â Â 'u: offset up','o: reset offset','b: toggle subtract background','n: log(I) on','c: contour on', |
---|
1357 | Â Â Â Â Â Â Â Â Â Â Â Â 'q: toggle q plot','t: toggle d-spacing plot','m: toggle multidata plot', |
---|
1358 | Â Â Â Â Â Â Â Â Â Â Â Â 'w: toggle divide by sig','+: no selection') |
---|
1359 |       elif 'SASD' in plottype: |
---|
1360 |         if G2frame.SinglePlot: |
---|
1361 | Â Â Â Â Â Â Â Â Â Â Page.Choice =Â (' key press','b: toggle subtract background file','n: loglog on','e: toggle error bars', |
---|
1362 | Â Â Â Â Â Â Â Â Â Â Â Â 'q: toggle S(q) plot','m: toggle multidata plot','w: toggle (Io-Ic)/sig plot','+: no selection') |
---|
1363 | Â Â Â Â Â Â Â Â else: |
---|
1364 | Â Â Â Â Â Â Â Â Â Â Page.Choice =Â (' key press','b: toggle subtract background file','n: loglog on','e: toggle error bars', |
---|
1365 | Â Â Â Â Â Â Â Â Â Â Â Â 'd: offset down','l: offset left','r: offset right','u: offset up','o: reset offset', |
---|
1366 | Â Â Â Â Â Â Â Â Â Â Â Â 'q: toggle S(q) plot','m: toggle multidata plot','w: toggle (Io-Ic)/sig plot','+: no selection') |
---|
1367 | |
---|
1368 |   Page.keyPress = OnPlotKeyPress  |
---|
1369 | Â Â PickId =Â G2frame.PickId |
---|
1370 | Â Â PatternId =Â G2frame.PatternId |
---|
1371 | Â Â colors=['b','g','r','c','m','k'] |
---|
1372 | Â Â Lines =Â [] |
---|
1373 | Â Â exclLines =Â [] |
---|
1374 |   if G2frame.SinglePlot and PatternId: |
---|
1375 | Â Â Â Â Pattern =Â G2frame.PatternTree.GetItemPyData(PatternId) |
---|
1376 | Â Â Â Â Pattern.append(G2frame.PatternTree.GetItemText(PatternId)) |
---|
1377 | Â Â Â Â PlotList =Â [Pattern,] |
---|
1378 | Â Â Â Â Parms,Parms2 =Â G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame, |
---|
1379 |       G2frame.PatternId, 'Instrument Parameters')) |
---|
1380 |     Sample = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId, 'Sample Parameters')) |
---|
1381 | Â Â Â Â ParmList =Â [Parms,] |
---|
1382 | Â Â Â Â SampleList =Â [Sample,] |
---|
1383 | Â Â Â Â Title =Â Pattern[-1] |
---|
1384 | Â Â else:Â Â Â Â |
---|
1385 | Â Â Â Â Title =Â os.path.split(G2frame.GSASprojectfile)[1] |
---|
1386 | Â Â Â Â PlotList =Â [] |
---|
1387 | Â Â Â Â ParmList =Â [] |
---|
1388 | Â Â Â Â SampleList =Â [] |
---|
1389 |     item, cookie = G2frame.PatternTree.GetFirstChild(G2frame.root) |
---|
1390 |     while item: |
---|
1391 |       if plottype in G2frame.PatternTree.GetItemText(item): |
---|
1392 | Â Â Â Â Â Â Â Â Pattern =Â G2frame.PatternTree.GetItemPyData(item) |
---|
1393 |         if len(Pattern) < 3:          # put name on end if needed |
---|
1394 | Â Â Â Â Â Â Â Â Â Â Pattern.append(G2frame.PatternTree.GetItemText(item)) |
---|
1395 |         if 'Offset' not in Pattern[0]:   #plot offset data |
---|
1396 | Â Â Â Â Â Â Â Â Â Â Pattern[0].update({'Offset':[0.0,0.0],'delOffset':0.02,'refOffset':-1.0,'refDelt':0.01,}) |
---|
1397 | Â Â Â Â Â Â Â Â PlotList.append(Pattern) |
---|
1398 | Â Â Â Â Â Â Â Â ParmList.append(G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame, |
---|
1399 | Â Â Â Â Â Â Â Â Â Â item,'Instrument Parameters'))[0]) |
---|
1400 | Â Â Â Â Â Â Â Â SampleList.append(G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame, |
---|
1401 |           item, 'Sample Parameters'))) |
---|
1402 |       item, cookie = G2frame.PatternTree.GetNextChild(G2frame.root, cookie)        |
---|
1403 | Â Â lenX =Â 0 |
---|
1404 |   if PickId: |
---|
1405 |     if G2frame.PatternTree.GetItemText(PickId) in ['Reflection Lists']: |
---|
1406 | Â Â Â Â Â Â Phases =Â G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId,'Reflection Lists')) |
---|
1407 | Â Â Â Â Â Â HKL =Â [] |
---|
1408 |       if Phases: |
---|
1409 | Â Â Â Â Â Â Â Â try: |
---|
1410 |           for peak in Phases[G2frame.RefList]['RefList']: |
---|
1411 |             if len(peak) > 15: |
---|
1412 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â HKL.append(peak[:7])Â Â #SS reflection list - need peak[:7] |
---|
1413 | Â Â Â Â Â Â Â Â Â Â Â Â else: |
---|
1414 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â HKL.append(peak[:6]) |
---|
1415 |         except TypeError:  #old style patch |
---|
1416 |           for peak in Phases[G2frame.RefList]: |
---|
1417 | Â Â Â Â Â Â Â Â Â Â Â Â HKL.append(peak[:6])Â Â Â Â Â Â Â Â Â Â |
---|
1418 | Â Â Â Â Â Â Â Â HKL =Â np.array(HKL) |
---|
1419 | Â Â Â Â else: |
---|
1420 | Â Â Â Â Â Â HKL =Â np.array(G2frame.HKL) |
---|
1421 | Â Â Ymax =Â None |
---|
1422 |   for Pattern in PlotList: |
---|
1423 | Â Â Â Â xye =Â Pattern[1] |
---|
1424 |     if xye[1] is None: continue |
---|
1425 |     if Ymax is None: Ymax = max(xye[1]) |
---|
1426 | Â Â Â Â Ymax =Â max(Ymax,max(xye[1])) |
---|
1427 |   if Ymax is None: return # nothing to plot |
---|
1428 | Â Â offsetX =Â Pattern[0]['Offset'][1] |
---|
1429 | Â Â offsetY =Â Pattern[0]['Offset'][0] |
---|
1430 |   if G2frame.logPlot: |
---|
1431 | Â Â Â Â Title =Â 'log('+Title+')' |
---|
1432 | Â Â Plot.set_title(Title) |
---|
1433 |   if G2frame.plotStyle['qPlot'] or 'SASD' in plottype and not G2frame.Contour: |
---|
1434 | Â Â Â Â Plot.set_xlabel(r'$Q, \AA^{-1}$',fontsize=16) |
---|
1435 |   elif G2frame.plotStyle['dPlot'] and 'PWDR' in plottype and not G2frame.Contour: |
---|
1436 | Â Â Â Â Plot.set_xlabel(r'$d, \AA$',fontsize=16) |
---|
1437 | Â Â else: |
---|
1438 |     if 'C' in ParmList[0]['Type'][0]:    |
---|
1439 | Â Â Â Â Â Â Plot.set_xlabel(r'$\mathsf{2\theta}$',fontsize=16) |
---|
1440 | Â Â Â Â else: |
---|
1441 |       if G2frame.Contour: |
---|
1442 | Â Â Â Â Â Â Â Â Plot.set_xlabel(r'Channel no.',fontsize=16)Â Â Â Â Â Â |
---|
1443 | Â Â Â Â Â Â else: |
---|
1444 | Â Â Â Â Â Â Â Â Plot.set_xlabel(r'$TOF, \mathsf{\mu}$s',fontsize=16)Â Â Â Â Â Â |
---|
1445 |   if G2frame.Weight: |
---|
1446 |     if 'PWDR' in plottype: |
---|
1447 | Â Â Â Â Â Â Plot.set_ylabel(r'$\mathsf{I/\sigma(I)}$',fontsize=16) |
---|
1448 |     elif 'SASD' in plottype: |
---|
1449 | Â Â Â Â Â Â Plot.set_ylabel(r'$\mathsf{\Delta(I)/\sigma(I)}$',fontsize=16) |
---|
1450 | Â Â else: |
---|
1451 |     if 'C' in ParmList[0]['Type'][0]: |
---|
1452 |       if 'PWDR' in plottype: |
---|
1453 |         if G2frame.plotStyle['sqrtPlot']: |
---|
1454 | Â Â Â Â Â Â Â Â Â Â Plot.set_ylabel(r'$\sqrt{Intensity}$',fontsize=16) |
---|
1455 | Â Â Â Â Â Â Â Â else: |
---|
1456 | Â Â Â Â Â Â Â Â Â Â Plot.set_ylabel(r'$Intensity$',fontsize=16) |
---|
1457 |       elif 'SASD' in plottype: |
---|
1458 |         if G2frame.sqPlot: |
---|
1459 | Â Â Â Â Â Â Â Â Â Â Plot.set_ylabel(r'$S(Q)=I*Q^{4}$',fontsize=16) |
---|
1460 | Â Â Â Â Â Â Â Â else: |
---|
1461 | Â Â Â Â Â Â Â Â Â Â Plot.set_ylabel(r'$Intensity, cm^{-1}$',fontsize=16) |
---|
1462 | Â Â Â Â else: |
---|
1463 |       if G2frame.plotStyle['sqrtPlot']: |
---|
1464 | Â Â Â Â Â Â Â Â Plot.set_ylabel(r'$\sqrt{Normalized\ intensity}$',fontsize=16) |
---|
1465 | Â Â Â Â Â Â else: |
---|
1466 | Â Â Â Â Â Â Â Â Plot.set_ylabel(r'$Normalized\ intensity$',fontsize=16) |
---|
1467 |   if G2frame.Contour: |
---|
1468 | Â Â Â Â ContourZ =Â [] |
---|
1469 | Â Â Â Â ContourY =Â [] |
---|
1470 | Â Â Â Â Nseq =Â 0 |
---|
1471 |   for N,Pattern in enumerate(PlotList): |
---|
1472 | Â Â Â Â Parms =Â ParmList[N] |
---|
1473 | Â Â Â Â Sample =Â SampleList[N] |
---|
1474 |     if 'C' in Parms['Type'][0]: |
---|
1475 | Â Â Â Â Â Â wave =Â G2mth.getWave(Parms) |
---|
1476 | Â Â Â Â else: |
---|
1477 | Â Â Â Â Â Â difC =Â Parms['difC'][1] |
---|
1478 | Â Â Â Â ifpicked =Â False |
---|
1479 | Â Â Â Â LimitId =Â 0 |
---|
1480 |     if Pattern[1] is None: continue # skip over uncomputed simulations |
---|
1481 | Â Â Â Â xye =Â ma.array(ma.getdata(Pattern[1])) |
---|
1482 | Â Â Â Â Zero =Â Parms.get('Zero',[0.,0.])[1] |
---|
1483 |     if PickId: |
---|
1484 | Â Â Â Â Â Â ifpicked =Â Pattern[2]Â ==Â G2frame.PatternTree.GetItemText(PatternId) |
---|
1485 | Â Â Â Â Â Â LimitId =Â G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId,'Limits') |
---|
1486 | Â Â Â Â Â Â limits =Â G2frame.PatternTree.GetItemPyData(LimitId) |
---|
1487 | Â Â Â Â Â Â excls =Â limits[2:] |
---|
1488 |       for excl in excls: |
---|
1489 | Â Â Â Â Â Â Â Â xye[0]Â =Â ma.masked_inside(xye[0],excl[0],excl[1]) |
---|
1490 |     if G2frame.plotStyle['qPlot'] and 'PWDR' in plottype: |
---|
1491 |       Id = G2gd.GetPatternTreeItemId(G2frame,G2frame.root, Pattern[2]) |
---|
1492 | Â Â Â Â Â Â X =Â 2.*np.pi/G2lat.Pos2dsp(Parms,xye[0]) |
---|
1493 |     elif G2frame.plotStyle['dPlot'] and 'PWDR' in plottype: |
---|
1494 |       Id = G2gd.GetPatternTreeItemId(G2frame,G2frame.root, Pattern[2]) |
---|
1495 | Â Â Â Â Â Â X =Â G2lat.Pos2dsp(Parms,xye[0]) |
---|
1496 | Â Â Â Â else: |
---|
1497 | Â Â Â Â Â Â X =Â xye[0] |
---|
1498 |     if not lenX: |
---|
1499 | Â Â Â Â Â Â lenX =Â len(X) |
---|
1500 |     if 'PWDR' in plottype: |
---|
1501 |       if G2frame.plotStyle['sqrtPlot']: |
---|
1502 | Â Â Â Â Â Â Â Â olderr =Â np.seterr(invalid='ignore')Â #get around sqrt(-ve) error |
---|
1503 | Â Â Â Â Â Â Â Â Y =Â np.where(xye[1]>=0.,np.sqrt(xye[1]),-np.sqrt(-xye[1])) |
---|
1504 | Â Â Â Â Â Â Â Â np.seterr(invalid=olderr['invalid']) |
---|
1505 | Â Â Â Â Â Â else: |
---|
1506 | Â Â Â Â Â Â Â Â Y =Â xye[1]+offsetY*N*Ymax/100.0 |
---|
1507 |     elif 'SASD' in plottype: |
---|
1508 | Â Â Â Â Â Â B =Â xye[5] |
---|
1509 |       if G2frame.sqPlot: |
---|
1510 | Â Â Â Â Â Â Â Â Y =Â xye[1]*Sample['Scale'][0]*(1.05)**(offsetY*N)*X**4 |
---|
1511 | Â Â Â Â Â Â else: |
---|
1512 | Â Â Â Â Â Â Â Â Y =Â xye[1]*Sample['Scale'][0]*(1.05)**(offsetY*N) |
---|
1513 |     if LimitId and ifpicked: |
---|
1514 | Â Â Â Â Â Â limits =Â np.array(G2frame.PatternTree.GetItemPyData(LimitId)) |
---|
1515 | Â Â Â Â Â Â lims =Â limits[1] |
---|
1516 |       if G2frame.plotStyle['qPlot'] and 'PWDR' in plottype: |
---|
1517 | Â Â Â Â Â Â Â Â lims =Â 2.*np.pi/G2lat.Pos2dsp(Parms,lims) |
---|
1518 |       elif G2frame.plotStyle['dPlot'] and 'PWDR' in plottype: |
---|
1519 | Â Â Â Â Â Â Â Â lims =Â G2lat.Pos2dsp(Parms,lims) |
---|
1520 | Â Â Â Â Â Â Lines.append(Plot.axvline(lims[0],color='g',dashes=(5,5),picker=3.))Â Â |
---|
1521 | Â Â Â Â Â Â Lines.append(Plot.axvline(lims[1],color='r',dashes=(5,5),picker=3.)) |
---|
1522 |       for i,item in enumerate(limits[2:]): |
---|
1523 | Â Â Â Â Â Â Â Â Lines.append(Plot.axvline(item[0],color='m',dashes=(5,5),picker=3.))Â Â |
---|
1524 | Â Â Â Â Â Â Â Â Lines.append(Plot.axvline(item[1],color='m',dashes=(5,5),picker=3.)) |
---|
1525 | Â Â Â Â Â Â Â Â exclLines +=Â [2*i+2,2*i+3] |
---|
1526 |     if G2frame.Contour:      |
---|
1527 |       if lenX == len(X): |
---|
1528 | Â Â Â Â Â Â Â Â ContourY.append(N) |
---|
1529 | Â Â Â Â Â Â Â Â ContourZ.append(Y) |
---|
1530 |         if 'C' in ParmList[0]['Type'][0]:    |
---|
1531 | Â Â Â Â Â Â Â Â Â Â ContourX =Â X |
---|
1532 | Â Â Â Â Â Â Â Â else:Â #'T'OF |
---|
1533 | Â Â Â Â Â Â Â Â Â Â ContourX =Â range(lenX) |
---|
1534 | Â Â Â Â Â Â Â Â Nseq +=Â 1 |
---|
1535 | Â Â Â Â Â Â Â Â Plot.set_ylabel('Data sequence',fontsize=12) |
---|
1536 | Â Â Â Â else: |
---|
1537 |       if 'SASD' in plottype and G2frame.logPlot: |
---|
1538 | Â Â Â Â Â Â Â Â X *=Â (1.01)**(offsetX*N) |
---|
1539 | Â Â Â Â Â Â else: |
---|
1540 | Â Â Â Â Â Â Â Â X +=Â offsetX*.005*N |
---|
1541 | Â Â Â Â Â Â Xum =Â ma.getdata(X) |
---|
1542 | Â Â Â Â Â Â DifLine =Â [''] |
---|
1543 |       if ifpicked: |
---|
1544 |         if G2frame.plotStyle['sqrtPlot']: |
---|
1545 | Â Â Â Â Â Â Â Â Â Â olderr =Â np.seterr(invalid='ignore')Â #get around sqrt(-ve) error |
---|
1546 | Â Â Â Â Â Â Â Â Â Â Z =Â np.where(xye[3]>=0.,np.sqrt(xye[3]),-np.sqrt(-xye[3])) |
---|
1547 | Â Â Â Â Â Â Â Â Â Â np.seterr(invalid=olderr['invalid']) |
---|
1548 | Â Â Â Â Â Â Â Â else: |
---|
1549 | Â Â Â Â Â Â Â Â Â Â Z =Â xye[3]+offsetY*N*Ymax/100.0 |
---|
1550 |         if 'PWDR' in plottype: |
---|
1551 |           if G2frame.plotStyle['sqrtPlot']: |
---|
1552 | Â Â Â Â Â Â Â Â Â Â Â Â olderr =Â np.seterr(invalid='ignore')Â #get around sqrt(-ve) error |
---|
1553 | Â Â Â Â Â Â Â Â Â Â Â Â W =Â np.where(xye[4]>=0.,np.sqrt(xye[4]),-np.sqrt(-xye[4])) |
---|
1554 | Â Â Â Â Â Â Â Â Â Â Â Â np.seterr(invalid=olderr['invalid']) |
---|
1555 | Â Â Â Â Â Â Â Â Â Â Â Â D =Â np.where(xye[5],(Y-Z),0.)-Ymax*Pattern[0]['delOffset'] |
---|
1556 | Â Â Â Â Â Â Â Â Â Â else: |
---|
1557 | Â Â Â Â Â Â Â Â Â Â Â Â W =Â xye[4]+offsetY*N*Ymax/100.0 |
---|
1558 | Â Â Â Â Â Â Â Â Â Â Â Â D =Â xye[5]-Ymax*Pattern[0]['delOffset']Â #powder background |
---|
1559 |         elif 'SASD' in plottype: |
---|
1560 |           if G2frame.sqPlot: |
---|
1561 | Â Â Â Â Â Â Â Â Â Â Â Â W =Â xye[4]*X**4 |
---|
1562 | Â Â Â Â Â Â Â Â Â Â Â Â Z =Â xye[3]*X**4 |
---|
1563 | Â Â Â Â Â Â Â Â Â Â Â Â B =Â B*X**4 |
---|
1564 | Â Â Â Â Â Â Â Â Â Â else: |
---|
1565 | Â Â Â Â Â Â Â Â Â Â Â Â W =Â xye[4] |
---|
1566 |           if G2frame.SubBack: |
---|
1567 | Â Â Â Â Â Â Â Â Â Â Â Â YB =Â Y-B |
---|
1568 | Â Â Â Â Â Â Â Â Â Â Â Â ZB =Â Z |
---|
1569 | Â Â Â Â Â Â Â Â Â Â else: |
---|
1570 | Â Â Â Â Â Â Â Â Â Â Â Â YB =Â Y |
---|
1571 | Â Â Â Â Â Â Â Â Â Â Â Â ZB =Â Z+B |
---|
1572 | Â Â Â Â Â Â Â Â Â Â Plot.set_yscale("log",nonposy='mask') |
---|
1573 |           if np.any(W>0.): |
---|
1574 | Â Â Â Â Â Â Â Â Â Â Â Â Plot.set_ylim(bottom=np.min(np.trim_zeros(W))/2.,top=np.max(Y)*2.) |
---|
1575 | Â Â Â Â Â Â Â Â Â Â else: |
---|
1576 | Â Â Â Â Â Â Â Â Â Â Â Â Plot.set_ylim(bottom=np.min(np.trim_zeros(YB))/2.,top=np.max(Y)*2.) |
---|
1577 |         if G2frame.logPlot: |
---|
1578 |           if 'PWDR' in plottype: |
---|
1579 | Â Â Â Â Â Â Â Â Â Â Â Â Plot.set_yscale("log",nonposy='mask') |
---|
1580 | Â Â Â Â Â Â Â Â Â Â Â Â Plot.plot(X,Y,colors[N%6]+'+',picker=3.,clip_on=False) |
---|
1581 | Â Â Â Â Â Â Â Â Â Â Â Â Plot.plot(X,Z,colors[(N+1)%6],picker=False) |
---|
1582 | Â Â Â Â Â Â Â Â Â Â Â Â Plot.plot(X,W,colors[(N+2)%6],picker=False)Â Â Â #background |
---|
1583 |           elif 'SASD' in plottype: |
---|
1584 | Â Â Â Â Â Â Â Â Â Â Â Â Plot.set_xscale("log",nonposx='mask') |
---|
1585 | Â Â Â Â Â Â Â Â Â Â Â Â Ibeg =Â np.searchsorted(X,limits[1][0]) |
---|
1586 | Â Â Â Â Â Â Â Â Â Â Â Â Ifin =Â np.searchsorted(X,limits[1][1]) |
---|
1587 |             if G2frame.Weight: |
---|
1588 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Plot.set_yscale("linear") |
---|
1589 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â DS =Â (YB-ZB)*np.sqrt(xye[2]) |
---|
1590 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Plot.plot(X[Ibeg:Ifin],DS[Ibeg:Ifin],colors[(N+3)%6],picker=False) |
---|
1591 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Plot.axhline(0.,color=wx.BLACK) |
---|
1592 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Plot.set_ylim(bottom=np.min(DS[Ibeg:Ifin])*1.2,top=np.max(DS[Ibeg:Ifin])*1.2)Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
---|
1593 | Â Â Â Â Â Â Â Â Â Â Â Â else: |
---|
1594 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Plot.set_yscale("log",nonposy='mask') |
---|
1595 |               if G2frame.ErrorBars: |
---|
1596 |                 if G2frame.sqPlot: |
---|
1597 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Plot.errorbar(X,YB,yerr=X**4*Sample['Scale'][0]*np.sqrt(1./(Pattern[0]['wtFactor']*xye[2])), |
---|
1598 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ecolor=colors[N%6],picker=3.,clip_on=False) |
---|
1599 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â else: |
---|
1600 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Plot.errorbar(X,YB,yerr=Sample['Scale'][0]*np.sqrt(1./(Pattern[0]['wtFactor']*xye[2])), |
---|
1601 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ecolor=colors[N%6],picker=3.,clip_on=False) |
---|
1602 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â else: |
---|
1603 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Plot.plot(X,YB,colors[N%6]+'+',picker=3.,clip_on=False) |
---|
1604 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Plot.plot(X,W,colors[(N+2)%6],picker=False)Â Â Â #const. background |
---|
1605 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Plot.plot(X,ZB,colors[(N+1)%6],picker=False) |
---|
1606 |         elif G2frame.Weight and 'PWDR' in plottype: |
---|
1607 | Â Â Â Â Â Â Â Â Â Â DY =Â xye[1]*np.sqrt(xye[2]) |
---|
1608 | Â Â Â Â Â Â Â Â Â Â Ymax =Â max(DY) |
---|
1609 | Â Â Â Â Â Â Â Â Â Â DZ =Â xye[3]*np.sqrt(xye[2]) |
---|
1610 | Â Â Â Â Â Â Â Â Â Â DS =Â xye[5]*np.sqrt(xye[2])-Ymax*Pattern[0]['delOffset'] |
---|
1611 | Â Â Â Â Â Â Â Â Â Â ObsLine =Â Plot.plot(X,DY,colors[N%6]+'+',picker=3.,clip_on=False)Â Â Â Â Â #Io/sig(Io) |
---|
1612 | Â Â Â Â Â Â Â Â Â Â Plot.plot(X,DZ,colors[(N+1)%6],picker=False)Â Â Â Â Â Â Â Â Â Â #Ic/sig(Io) |
---|
1613 | Â Â Â Â Â Â Â Â Â Â DifLine =Â Plot.plot(X,DS,colors[(N+3)%6],picker=1.)Â Â Â Â Â Â Â Â Â Â #(Io-Ic)/sig(Io) |
---|
1614 | Â Â Â Â Â Â Â Â Â Â Plot.axhline(0.,color=wx.BLACK) |
---|
1615 | Â Â Â Â Â Â Â Â else: |
---|
1616 |           if G2frame.SubBack: |
---|
1617 |             if 'PWDR' in plottype: |
---|
1618 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Plot.plot(Xum,Y-W,colors[N%6]+'+',picker=False,clip_on=False)Â #Io-Ib |
---|
1619 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Plot.plot(X,Z-W,colors[(N+1)%6],picker=False)Â Â Â Â Â Â Â Â #Ic-Ib |
---|
1620 | Â Â Â Â Â Â Â Â Â Â Â Â else: |
---|
1621 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Plot.plot(X,YB,colors[N%6]+'+',picker=3.,clip_on=False) |
---|
1622 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Plot.plot(X,ZB,colors[(N+1)%6],picker=False) |
---|
1623 | Â Â Â Â Â Â Â Â Â Â else: |
---|
1624 |             if 'PWDR' in plottype: |
---|
1625 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â ObsLine =Â Plot.plot(Xum,Y,colors[N%6]+'+',picker=3.,clip_on=False)Â Â #Io |
---|
1626 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Plot.plot(X,Z,colors[(N+1)%6],picker=False)Â Â Â Â Â Â Â Â Â #Ic |
---|
1627 | Â Â Â Â Â Â Â Â Â Â Â Â else: |
---|
1628 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Plot.plot(X,YB,colors[N%6]+'+',picker=3.,clip_on=False) |
---|
1629 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Plot.plot(X,ZB,colors[(N+1)%6],picker=False) |
---|
1630 |           if 'PWDR' in plottype: |
---|
1631 | Â Â Â Â Â Â Â Â Â Â Â Â Plot.plot(X,W,colors[(N+2)%6],picker=False)Â Â Â Â Â Â Â Â Â #Ib |
---|
1632 | Â Â Â Â Â Â Â Â Â Â Â Â DifLine =Â Plot.plot(X,D,colors[(N+3)%6],picker=1.)Â Â Â Â Â Â Â Â Â #Io-Ic |
---|
1633 | Â Â Â Â Â Â Â Â Â Â Plot.axhline(0.,color=wx.BLACK) |
---|
1634 | Â Â Â Â Â Â Â Â Page.canvas.SetToolTipString('') |
---|
1635 |         if PickId: |
---|
1636 |           if G2frame.PatternTree.GetItemText(PickId) == 'Peak List': |
---|
1637 | Â Â Â Â Â Â Â Â Â Â Â Â tip =Â 'On data point: Pick peak - L or R MB. On line: L-move, R-delete' |
---|
1638 | Â Â Â Â Â Â Â Â Â Â Â Â Page.canvas.SetToolTipString(tip) |
---|
1639 |             data = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Peak List')) |
---|
1640 |             for item in data['peaks']: |
---|
1641 |               if G2frame.plotStyle['qPlot']: |
---|
1642 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Lines.append(Plot.axvline(2.*np.pi/G2lat.Pos2dsp(Parms,item[0]),color=colors[N%6],picker=2.)) |
---|
1643 |               elif G2frame.plotStyle['dPlot']: |
---|
1644 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Lines.append(Plot.axvline(G2lat.Pos2dsp(Parms,item[0]),color=colors[N%6],picker=2.)) |
---|
1645 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â else: |
---|
1646 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Lines.append(Plot.axvline(item[0],color=colors[N%6],picker=2.)) |
---|
1647 |           if G2frame.PatternTree.GetItemText(PickId) == 'Limits': |
---|
1648 | Â Â Â Â Â Â Â Â Â Â Â Â tip =Â 'On data point: Lower limit - L MB; Upper limit - R MB. On limit: MB down to move' |
---|
1649 | Â Â Â Â Â Â Â Â Â Â Â Â Page.canvas.SetToolTipString(tip) |
---|
1650 | Â Â Â Â Â Â Â Â Â Â Â Â data =Â G2frame.LimitsTable.GetData() |
---|
1651 | Â Â Â Â Â Â Â Â Â Â Â Â |
---|
1652 | Â Â Â Â Â Â else:Â Â #not picked |
---|
1653 |         if G2frame.logPlot: |
---|
1654 |           if 'PWDR' in plottype: |
---|
1655 | Â Â Â Â Â Â Â Â Â Â Â Â Plot.semilogy(X,Y,colors[N%6],picker=False,nonposy='mask') |
---|
1656 |           elif 'SASD' in plottype: |
---|
1657 | Â Â Â Â Â Â Â Â Â Â Â Â Plot.semilogy(X,Y,colors[N%6],picker=False,nonposy='mask') |
---|
1658 | Â Â Â Â Â Â Â Â else: |
---|
1659 |           if 'PWDR' in plottype: |
---|
1660 | Â Â Â Â Â Â Â Â Â Â Â Â Plot.plot(X,Y,colors[N%6],picker=False) |
---|
1661 |           elif 'SASD' in plottype: |
---|
1662 | Â Â Â Â Â Â Â Â Â Â Â Â Plot.loglog(X,Y,colors[N%6],picker=False,nonposy='mask') |
---|
1663 | Â Â Â Â Â Â Â Â Â Â Â Â Plot.set_ylim(bottom=np.min(np.trim_zeros(Y))/2.,top=np.max(Y)*2.) |
---|
1664 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
---|
1665 |         if G2frame.logPlot and 'PWDR' in plottype: |
---|
1666 | Â Â Â Â Â Â Â Â Â Â Plot.set_ylim(bottom=np.min(np.trim_zeros(Y))/2.,top=np.max(Y)*2.) |
---|
1667 |   if PickId and not G2frame.Contour: |
---|
1668 |     Parms,Parms2 = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Instrument Parameters')) |
---|
1669 |     if G2frame.PatternTree.GetItemText(PickId) in ['Index Peak List','Unit Cells List']: |
---|
1670 |       peaks = np.array((G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Index Peak List')))) |
---|
1671 |       if not len(peaks): return # are there any peaks? |
---|
1672 |       for peak in peaks[0]: |
---|
1673 |         if peak[2]: |
---|
1674 |           if G2frame.plotStyle['qPlot']: |
---|
1675 | Â Â Â Â Â Â Â Â Â Â Â Â Plot.axvline(2.*np.pi/G2lat.Pos2dsp(Parms,peak[0]),color='b') |
---|
1676 |           if G2frame.plotStyle['dPlot']: |
---|
1677 | Â Â Â Â Â Â Â Â Â Â Â Â Plot.axvline(G2lat.Pos2dsp(Parms,peak[0]),color='b') |
---|
1678 | Â Â Â Â Â Â Â Â Â Â else: |
---|
1679 | Â Â Â Â Â Â Â Â Â Â Â Â Plot.axvline(peak[0],color='b') |
---|
1680 |       for hkl in G2frame.HKL: |
---|
1681 | Â Â Â Â Â Â Â Â clr =Â 'r' |
---|
1682 |         if len(hkl) > 6 and hkl[3]: |
---|
1683 | Â Â Â Â Â Â Â Â Â Â clr =Â 'g' |
---|
1684 |         if G2frame.plotStyle['qPlot']: |
---|
1685 | Â Â Â Â Â Â Â Â Â Â Plot.axvline(2.*np.pi/G2lat.Pos2dsp(Parms,hkl[-2]),color=clr,dashes=(5,5)) |
---|
1686 |         if G2frame.plotStyle['dPlot']: |
---|
1687 | Â Â Â Â Â Â Â Â Â Â Plot.axvline(G2lat.Pos2dsp(Parms,hkl[-2]),color=clr,dashes=(5,5)) |
---|
1688 | Â Â Â Â Â Â Â Â else: |
---|
1689 | Â Â Â Â Â Â Â Â Â Â Plot.axvline(hkl[-2],color=clr,dashes=(5,5)) |
---|
1690 |     elif G2frame.PatternTree.GetItemText(PickId) in ['Reflection Lists'] or \ |
---|
1691 |       'PWDR' in G2frame.PatternTree.GetItemText(PickId): |
---|
1692 | Â Â Â Â Â Â refColors=['b','r','c','g','m','k'] |
---|
1693 | Â Â Â Â Â Â Phases =Â G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId,'Reflection Lists')) |
---|
1694 |       for pId,phase in enumerate(Phases): |
---|
1695 | Â Â Â Â Â Â Â Â try:Â Â #patch for old style reflection lists |
---|
1696 | Â Â Â Â Â Â Â Â Â Â peaks =Â Phases[phase]['RefList'] |
---|
1697 |         except TypeError: |
---|
1698 | Â Â Â Â Â Â Â Â Â Â peaks =Â Phases[phase] |
---|
1699 |         if not len(peaks): |
---|
1700 | Â Â Â Â Â Â Â Â Â Â continue |
---|
1701 |         if Phases[phase].get('Super',False): |
---|
1702 |           peak = np.array([[peak[5],peak[6]] for peak in peaks]) |
---|
1703 | Â Â Â Â Â Â Â Â else: |
---|
1704 |           peak = np.array([[peak[4],peak[5]] for peak in peaks]) |
---|
1705 | Â Â Â Â Â Â Â Â pos =Â Pattern[0]['refOffset']-pId*Ymax*Pattern[0]['refDelt']*np.ones_like(peak) |
---|
1706 |         if G2frame.plotStyle['qPlot']: |
---|
1707 | Â Â Â Â Â Â Â Â Â Â Plot.plot(2*np.pi/peak.T[0],pos,refColors[pId%6]+'|',mew=1,ms=8,picker=3.,label=phase) |
---|
1708 |         elif G2frame.plotStyle['dPlot']: |
---|
1709 | Â Â Â Â Â Â Â Â Â Â Plot.plot(peak.T[0],pos,refColors[pId%6]+'|',mew=1,ms=8,picker=3.,label=phase) |
---|
1710 | Â Â Â Â Â Â Â Â else: |
---|
1711 | Â Â Â Â Â Â Â Â Â Â Plot.plot(peak.T[1],pos,refColors[pId%6]+'|',mew=1,ms=8,picker=3.,label=phase) |
---|
1712 |       if len(Phases): |
---|
1713 | Â Â Â Â Â Â Â Â handles,legends =Â Plot.get_legend_handles_labels()Â #got double entries in the legends for some reason |
---|
1714 |         if handles: |
---|
1715 | Â Â Â Â Â Â Â Â Â Â Plot.legend(handles[::2],legends[::2],title='Phases',loc='best')Â Â #skip every other one |
---|
1716 | Â Â Â Â Â Â |
---|
1717 |   if G2frame.Contour: |
---|
1718 | Â Â Â Â acolor =Â mpl.cm.get_cmap(G2frame.ContourColor) |
---|
1719 |     Img = Plot.imshow(ContourZ,cmap=acolor,vmin=0,vmax=Ymax*G2frame.Cmax,interpolation=G2frame.Interpolate, |
---|
1720 | Â Â Â Â Â Â extent=[ContourX[0],ContourX[-1],ContourY[0],ContourY[-1]],aspect='auto',origin='lower') |
---|
1721 | Â Â Â Â Page.figure.colorbar(Img) |
---|
1722 | Â Â else: |
---|
1723 | Â Â Â Â G2frame.Lines =Â Lines |
---|
1724 |   if not newPlot: |
---|
1725 | Â Â Â Â Page.toolbar.push_current() |
---|
1726 | Â Â Â Â Plot.set_xlim(xylim[0]) |
---|
1727 | Â Â Â Â Plot.set_ylim(xylim[1]) |
---|
1728 | #Â Â Â Â xylim = [] |
---|
1729 | Â Â Â Â Page.toolbar.push_current() |
---|
1730 | Â Â Â Â Page.toolbar.draw() |
---|
1731 | Â Â else: |
---|
1732 | Â Â Â Â Page.canvas.draw() |
---|
1733 | Â Â olderr =Â np.seterr(invalid='ignore')Â #ugh - this removes a matplotlib error for mouse clicks in log plots |
---|
1734 |   # and sqrt(-ve) in np.where usage        |
---|
1735 | #Â Â G2frame.Pwdr = True |
---|
1736 | Â Â |
---|
1737 | ################################################################################ |
---|
1738 | ##### PlotDeltSig |
---|
1739 | ################################################################################ |
---|
1740 | Â Â Â Â Â Â |
---|
1741 | def PlotDeltSig(G2frame,kind): |
---|
1742 | Â Â 'needs a doc string' |
---|
1743 | Â Â try: |
---|
1744 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index('Error analysis') |
---|
1745 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
1746 | Â Â Â Â Page.figure.clf() |
---|
1747 | Â Â Â Â Plot =Â Page.figure.gca()Â Â Â Â Â #get a fresh plot after clf() |
---|
1748 |   except ValueError: |
---|
1749 | Â Â Â Â newPlot =Â True |
---|
1750 | Â Â Â Â G2frame.Cmax =Â 1.0 |
---|
1751 | Â Â Â Â Plot =Â G2frame.G2plotNB.addMpl('Error analysis').gca() |
---|
1752 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index('Error analysis') |
---|
1753 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
1754 | Â Â Page.Choice =Â None |
---|
1755 | Â Â PatternId =Â G2frame.PatternId |
---|
1756 | Â Â Pattern =Â G2frame.PatternTree.GetItemPyData(PatternId) |
---|
1757 | Â Â Pattern.append(G2frame.PatternTree.GetItemText(PatternId)) |
---|
1758 | Â Â wtFactor =Â Pattern[0]['wtFactor'] |
---|
1759 |   if kind == 'PWDR': |
---|
1760 |     limits = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Limits'))[1] |
---|
1761 | Â Â Â Â xye =Â np.array(Pattern[1]) |
---|
1762 | Â Â Â Â xmin =Â np.searchsorted(xye[0],limits[0]) |
---|
1763 | Â Â Â Â xmax =Â np.searchsorted(xye[0],limits[1]) |
---|
1764 | Â Â Â Â DS =Â xye[5][xmin:xmax]*np.sqrt(wtFactor*xye[2][xmin:xmax]) |
---|
1765 |   elif kind == 'HKLF': |
---|
1766 | Â Â Â Â refl =Â Pattern[1] |
---|
1767 | Â Â Â Â DS =Â [] |
---|
1768 |     for ref in refl: |
---|
1769 |       if ref[6] > 0.: |
---|
1770 | Â Â Â Â Â Â Â Â DS.append((ref[5]-ref[7])/ref[6]) |
---|
1771 | Â Â Page.SetFocus() |
---|
1772 | Â Â G2frame.G2plotNB.status.DestroyChildren() |
---|
1773 | Â Â DS.sort() |
---|
1774 | Â Â EDS =Â np.zeros_like(DS) |
---|
1775 | Â Â DX =Â np.linspace(0.,1.,num=len(DS),endpoint=True) |
---|
1776 | Â Â oldErr =Â np.seterr(invalid='ignore')Â Â #avoid problem at DX==0 |
---|
1777 | Â Â T =Â np.sqrt(np.log(1.0/DX**2)) |
---|
1778 | Â Â top =Â 2.515517+0.802853*T+0.010328*T**2 |
---|
1779 | Â Â bot =Â 1.0+1.432788*T+0.189269*T**2+0.001308*T**3 |
---|
1780 | Â Â EDS =Â np.where(DX>0,-(T-top/bot),(T-top/bot)) |
---|
1781 | Â Â low1 =Â np.searchsorted(EDS,-1.) |
---|
1782 | Â Â hi1 =Â np.searchsorted(EDS,1.) |
---|
1783 | Â Â slp,intcp =Â np.polyfit(EDS[low1:hi1],DS[low1:hi1],deg=1) |
---|
1784 | Â Â frac =Â 100.*(hi1-low1)/len(DS) |
---|
1785 | Â Â G2frame.G2plotNB.status.SetStatusText(Â \ |
---|
1786 |     'Over range -1. to 1. :'+' slope = %.3f, intercept = %.3f for %.2f%% of the fitted data'%(slp,intcp,frac),1) |
---|
1787 | Â Â Plot.set_title('Normal probability for '+Pattern[-1]) |
---|
1788 | Â Â Plot.set_xlabel(r'expected $\mathsf{\Delta/\sigma}$',fontsize=14) |
---|
1789 | Â Â Plot.set_ylabel(r'observed $\mathsf{\Delta/\sigma}$',fontsize=14) |
---|
1790 | Â Â Plot.plot(EDS,DS,'r+',label='result') |
---|
1791 | Â Â Plot.plot([-2,2],[-2,2],'k',dashes=(5,5),label='ideal') |
---|
1792 | Â Â Plot.legend(loc='upper left') |
---|
1793 | Â Â np.seterr(invalid='warn') |
---|
1794 | Â Â Page.canvas.draw() |
---|
1795 | Â Â Â Â |
---|
1796 | ################################################################################ |
---|
1797 | ##### PlotISFG |
---|
1798 | ################################################################################ |
---|
1799 | Â Â Â Â Â Â |
---|
1800 | def PlotISFG(G2frame,newPlot=False,type=''): |
---|
1801 | Â Â ''' Plotting package for PDF analysis; displays I(q), S(q), F(q) and G(r) as single |
---|
1802 | Â Â or multiple plots with waterfall and contour plots as options |
---|
1803 | Â Â ''' |
---|
1804 |   if not type: |
---|
1805 |     type = G2frame.G2plotNB.plotList[G2frame.G2plotNB.nb.GetSelection()] |
---|
1806 |   if type not in ['I(Q)','S(Q)','F(Q)','G(R)']: |
---|
1807 | Â Â Â Â return |
---|
1808 | Â Â superMinusOne =Â unichr(0xaf)+unichr(0xb9) |
---|
1809 | Â Â |
---|
1810 |   def OnPlotKeyPress(event): |
---|
1811 | Â Â Â Â newPlot =Â False |
---|
1812 |     if event.key == 'u': |
---|
1813 |       if G2frame.Contour: |
---|
1814 | Â Â Â Â Â Â Â Â G2frame.Cmax =Â min(1.0,G2frame.Cmax*1.2) |
---|
1815 |       elif Pattern[0]['Offset'][0] < 100.: |
---|
1816 | Â Â Â Â Â Â Â Â Pattern[0]['Offset'][0]Â +=Â 1. |
---|
1817 |     elif event.key == 'd': |
---|
1818 |       if G2frame.Contour: |
---|
1819 | Â Â Â Â Â Â Â Â G2frame.Cmax =Â max(0.0,G2frame.Cmax*0.8) |
---|
1820 |       elif Pattern[0]['Offset'][0] > 0.: |
---|
1821 | Â Â Â Â Â Â Â Â Pattern[0]['Offset'][0]Â -=Â 1. |
---|
1822 |     elif event.key == 'l': |
---|
1823 | Â Â Â Â Â Â Pattern[0]['Offset'][1]Â -=Â 1. |
---|
1824 |     elif event.key == 'r': |
---|
1825 | Â Â Â Â Â Â Pattern[0]['Offset'][1]Â +=Â 1. |
---|
1826 |     elif event.key == 'o': |
---|
1827 | Â Â Â Â Â Â Pattern[0]['Offset']Â =Â [0,0] |
---|
1828 |     elif event.key == 'c': |
---|
1829 | Â Â Â Â Â Â newPlot =Â True |
---|
1830 |       G2frame.Contour = not G2frame.Contour |
---|
1831 |       if not G2frame.Contour: |
---|
1832 | Â Â Â Â Â Â Â Â G2frame.SinglePlot =Â False |
---|
1833 | Â Â Â Â Â Â Â Â Pattern[0]['Offset']Â =Â [0.,0.] |
---|
1834 |     elif event.key == 's': |
---|
1835 |       if G2frame.Contour: |
---|
1836 |         choice = [m for m in mpl.cm.datad.keys() if not m.endswith("_r")] |
---|
1837 | Â Â Â Â Â Â Â Â choice.sort() |
---|
1838 | Â Â Â Â Â Â Â Â dlg =Â wx.SingleChoiceDialog(G2frame,'Select','Color scheme',choice) |
---|
1839 |         if dlg.ShowModal() == wx.ID_OK: |
---|
1840 | Â Â Â Â Â Â Â Â Â Â sel =Â dlg.GetSelection() |
---|
1841 | Â Â Â Â Â Â Â Â Â Â G2frame.ContourColor =Â choice[sel] |
---|
1842 | Â Â Â Â Â Â Â Â else: |
---|
1843 | Â Â Â Â Â Â Â Â Â Â G2frame.ContourColor =Â 'Paired' |
---|
1844 | Â Â Â Â Â Â Â Â dlg.Destroy() |
---|
1845 | Â Â Â Â Â Â else: |
---|
1846 |         G2frame.SinglePlot = not G2frame.SinglePlot        |
---|
1847 |     elif event.key == 'i':         #for smoothing contour plot |
---|
1848 | Â Â Â Â Â Â choice =Â ['nearest','bilinear','bicubic','spline16','spline36','hanning', |
---|
1849 | Â Â Â Â Â Â Â Â 'hamming','hermite','kaiser','quadric','catrom','gaussian','bessel', |
---|
1850 | Â Â Â Â Â Â Â Â 'mitchell','sinc','lanczos'] |
---|
1851 | Â Â Â Â Â Â dlg =Â wx.SingleChoiceDialog(G2frame,'Select','Interpolation',choice) |
---|
1852 |       if dlg.ShowModal() == wx.ID_OK: |
---|
1853 | Â Â Â Â Â Â Â Â sel =Â dlg.GetSelection() |
---|
1854 | Â Â Â Â Â Â Â Â G2frame.Interpolate =Â choice[sel] |
---|
1855 | Â Â Â Â Â Â else: |
---|
1856 | Â Â Â Â Â Â Â Â G2frame.Interpolate =Â 'nearest' |
---|
1857 | Â Â Â Â Â Â dlg.Destroy() |
---|
1858 |     elif event.key == 't' and not G2frame.Contour: |
---|
1859 |       G2frame.Legend = not G2frame.Legend |
---|
1860 | Â Â Â Â PlotISFG(G2frame,newPlot=newPlot,type=type) |
---|
1861 | Â Â Â Â |
---|
1862 |   def OnKeyBox(event): |
---|
1863 |     if G2frame.G2plotNB.nb.GetSelection() == G2frame.G2plotNB.plotList.index(type): |
---|
1864 | Â Â Â Â Â Â event.key =Â cb.GetValue()[0] |
---|
1865 | Â Â Â Â Â Â cb.SetValue(' key press') |
---|
1866 | Â Â Â Â Â Â wx.CallAfter(OnPlotKeyPress,event) |
---|
1867 | Â Â Â Â Page.canvas.SetFocus()Â # redirect the Focus from the button back to the plot |
---|
1868 | Â Â Â Â Â Â Â Â Â Â Â Â |
---|
1869 |   def OnMotion(event): |
---|
1870 | Â Â Â Â xpos =Â event.xdata |
---|
1871 |     if xpos:                    #avoid out of frame mouse position |
---|
1872 | Â Â Â Â Â Â ypos =Â event.ydata |
---|
1873 | Â Â Â Â Â Â Page.canvas.SetCursor(wx.CROSS_CURSOR) |
---|
1874 | Â Â Â Â Â Â try: |
---|
1875 |         if G2frame.Contour: |
---|
1876 | Â Â Â Â Â Â Â Â Â Â G2frame.G2plotNB.status.SetStatusText('R =%.3fA pattern ID =%5d'%(xpos,int(ypos)),1) |
---|
1877 | Â Â Â Â Â Â Â Â else: |
---|
1878 |           G2frame.G2plotNB.status.SetStatusText('R =%.3fA %s =%.2f'%(xpos,type,ypos),1)          |
---|
1879 |       except TypeError: |
---|
1880 | Â Â Â Â Â Â Â Â G2frame.G2plotNB.status.SetStatusText('Select '+type+' pattern first',1) |
---|
1881 | Â Â |
---|
1882 | Â Â xylim =Â [] |
---|
1883 | Â Â try: |
---|
1884 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index(type) |
---|
1885 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
1886 |     if not newPlot: |
---|
1887 | Â Â Â Â Â Â Plot =Â Page.figure.gca()Â Â Â Â Â #get previous plot & get limits |
---|
1888 | Â Â Â Â Â Â xylim =Â Plot.get_xlim(),Plot.get_ylim() |
---|
1889 | Â Â Â Â Page.figure.clf() |
---|
1890 | Â Â Â Â Plot =Â Page.figure.gca() |
---|
1891 |   except ValueError: |
---|
1892 | Â Â Â Â newPlot =Â True |
---|
1893 | Â Â Â Â G2frame.Cmax =Â 1.0 |
---|
1894 | Â Â Â Â Plot =Â G2frame.G2plotNB.addMpl(type).gca() |
---|
1895 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index(type) |
---|
1896 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
1897 |     Page.canvas.mpl_connect('key_press_event', OnPlotKeyPress) |
---|
1898 |     Page.canvas.mpl_connect('motion_notify_event', OnMotion) |
---|
1899 | Â Â |
---|
1900 | Â Â Page.SetFocus() |
---|
1901 | Â Â G2frame.G2plotNB.status.DestroyChildren() |
---|
1902 |   if G2frame.Contour: |
---|
1903 | Â Â Â Â Page.Choice =Â (' key press','d: lower contour max','u: raise contour max', |
---|
1904 | Â Â Â Â Â Â 'i: interpolation method','s: color scheme','c: contour off') |
---|
1905 | Â Â else: |
---|
1906 | Â Â Â Â Page.Choice =Â (' key press','l: offset left','r: offset right','d: offset down','u: offset up', |
---|
1907 | Â Â Â Â Â Â 'o: reset offset','t: toggle legend','c: contour on','s: toggle single plot') |
---|
1908 | Â Â Page.keyPress =Â OnPlotKeyPress |
---|
1909 | Â Â PatternId =Â G2frame.PatternId |
---|
1910 | Â Â PickId =Â G2frame.PickId |
---|
1911 | Â Â Plot.set_title(type) |
---|
1912 |   if type == 'G(R)': |
---|
1913 | Â Â Â Â Plot.set_xlabel(r'$R,\AA$',fontsize=14) |
---|
1914 | Â Â else: |
---|
1915 | Â Â Â Â Plot.set_xlabel(r'$Q,\AA$'+superMinusOne,fontsize=14) |
---|
1916 | Â Â Plot.set_ylabel(r''+type,fontsize=14) |
---|
1917 | Â Â colors=['b','g','r','c','m','k'] |
---|
1918 | Â Â name =Â G2frame.PatternTree.GetItemText(PatternId)[4:] |
---|
1919 | Â Â Pattern =Â []Â Â |
---|
1920 |   if G2frame.SinglePlot: |
---|
1921 | Â Â Â Â name =Â G2frame.PatternTree.GetItemText(PatternId) |
---|
1922 | Â Â Â Â name =Â type+name[4:] |
---|
1923 | Â Â Â Â Id =Â G2gd.GetPatternTreeItemId(G2frame,PatternId,name) |
---|
1924 | Â Â Â Â Pattern =Â G2frame.PatternTree.GetItemPyData(Id) |
---|
1925 |     if Pattern: |
---|
1926 | Â Â Â Â Â Â Pattern.append(name) |
---|
1927 | Â Â Â Â PlotList =Â [Pattern,] |
---|
1928 | Â Â else: |
---|
1929 | Â Â Â Â PlotList =Â [] |
---|
1930 |     item, cookie = G2frame.PatternTree.GetFirstChild(G2frame.root) |
---|
1931 |     while item: |
---|
1932 |       if 'PDF' in G2frame.PatternTree.GetItemText(item): |
---|
1933 | Â Â Â Â Â Â Â Â name =Â type+G2frame.PatternTree.GetItemText(item)[4:] |
---|
1934 | Â Â Â Â Â Â Â Â Id =Â G2gd.GetPatternTreeItemId(G2frame,item,name) |
---|
1935 | Â Â Â Â Â Â Â Â Pattern =Â G2frame.PatternTree.GetItemPyData(Id) |
---|
1936 |         if Pattern: |
---|
1937 | Â Â Â Â Â Â Â Â Â Â Pattern.append(name) |
---|
1938 | Â Â Â Â Â Â Â Â Â Â PlotList.append(Pattern) |
---|
1939 |       item, cookie = G2frame.PatternTree.GetNextChild(G2frame.root, cookie) |
---|
1940 |   PDFdata = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'PDF Controls')) |
---|
1941 | Â Â numbDen =Â G2pwd.GetNumDensity(PDFdata['ElList'],PDFdata['Form Vol']) |
---|
1942 | Â Â Xb =Â [0.,10.] |
---|
1943 | Â Â Yb =Â [0.,-40.*np.pi*numbDen] |
---|
1944 | Â Â Ymax =Â 1.0 |
---|
1945 | Â Â lenX =Â 0 |
---|
1946 |   for Pattern in PlotList: |
---|
1947 | Â Â Â Â try: |
---|
1948 | Â Â Â Â Â Â xye =Â Pattern[1] |
---|
1949 |     except IndexError: |
---|
1950 | Â Â Â Â Â Â return |
---|
1951 | Â Â Â Â Ymax =Â max(Ymax,max(xye[1])) |
---|
1952 | Â Â offset =Â Pattern[0]['Offset'][0]*Ymax/100.0 |
---|
1953 |   if G2frame.Contour: |
---|
1954 | Â Â Â Â ContourZ =Â [] |
---|
1955 | Â Â Â Â ContourY =Â [] |
---|
1956 | Â Â Â Â Nseq =Â 0 |
---|
1957 |   for N,Pattern in enumerate(PlotList): |
---|
1958 | Â Â Â Â xye =Â Pattern[1] |
---|
1959 |     if PickId: |
---|
1960 | Â Â Â Â Â Â ifpicked =Â Pattern[2]Â ==Â G2frame.PatternTree.GetItemText(PatternId) |
---|
1961 | Â Â Â Â X =Â xye[0] |
---|
1962 |     if not lenX: |
---|
1963 | Â Â Â Â Â Â lenX =Â len(X)Â Â Â Â Â Â |
---|
1964 | Â Â Â Â Y =Â xye[1]+offset*N |
---|
1965 |     if G2frame.Contour: |
---|
1966 |       if lenX == len(X): |
---|
1967 | Â Â Â Â Â Â Â Â ContourY.append(N) |
---|
1968 | Â Â Â Â Â Â Â Â ContourZ.append(Y) |
---|
1969 | Â Â Â Â Â Â Â Â ContourX =Â X |
---|
1970 | Â Â Â Â Â Â Â Â Nseq +=Â 1 |
---|
1971 | Â Â Â Â Â Â Â Â Plot.set_ylabel('Data sequence',fontsize=12) |
---|
1972 | Â Â Â Â else: |
---|
1973 | Â Â Â Â Â Â X =Â xye[0]+Pattern[0]['Offset'][1]*.005*N |
---|
1974 |       if ifpicked: |
---|
1975 | Â Â Â Â Â Â Â Â Plot.plot(X,Y,colors[N%6]+'+',picker=3.,clip_on=False) |
---|
1976 | Â Â Â Â Â Â Â Â Page.canvas.SetToolTipString('') |
---|
1977 | Â Â Â Â Â Â else: |
---|
1978 |         if G2frame.Legend: |
---|
1979 | Â Â Â Â Â Â Â Â Â Â Plot.plot(X,Y,colors[N%6],picker=False,label='Azm:'+Pattern[2].split('=')[1]) |
---|
1980 | Â Â Â Â Â Â Â Â else: |
---|
1981 | Â Â Â Â Â Â Â Â Â Â Plot.plot(X,Y,colors[N%6],picker=False) |
---|
1982 |       if type == 'G(R)': |
---|
1983 | Â Â Â Â Â Â Â Â Plot.plot(Xb,Yb,color='k',dashes=(5,5)) |
---|
1984 |       elif type == 'F(Q)': |
---|
1985 | Â Â Â Â Â Â Â Â Plot.axhline(0.,color=wx.BLACK) |
---|
1986 |       elif type == 'S(Q)': |
---|
1987 | Â Â Â Â Â Â Â Â Plot.axhline(1.,color=wx.BLACK) |
---|
1988 |   if G2frame.Contour: |
---|
1989 | Â Â Â Â acolor =Â mpl.cm.get_cmap(G2frame.ContourColor) |
---|
1990 |     Img = Plot.imshow(ContourZ,cmap=acolor,vmin=0,vmax=Ymax*G2frame.Cmax,interpolation=G2frame.Interpolate, |
---|
1991 | Â Â Â Â Â Â extent=[ContourX[0],ContourX[-1],ContourY[0],ContourY[-1]],aspect='auto',origin='lower') |
---|
1992 | Â Â Â Â Page.figure.colorbar(Img) |
---|
1993 |   elif G2frame.Legend: |
---|
1994 | Â Â Â Â Plot.legend(loc='best') |
---|
1995 |   if not newPlot: |
---|
1996 | Â Â Â Â Page.toolbar.push_current() |
---|
1997 | Â Â Â Â Plot.set_xlim(xylim[0]) |
---|
1998 | Â Â Â Â Plot.set_ylim(xylim[1]) |
---|
1999 | Â Â Â Â xylim =Â [] |
---|
2000 | Â Â Â Â Page.toolbar.push_current() |
---|
2001 | Â Â Â Â Page.toolbar.draw() |
---|
2002 | Â Â else: |
---|
2003 | Â Â Â Â Page.canvas.draw() |
---|
2004 | Â Â Â Â |
---|
2005 | ################################################################################ |
---|
2006 | ##### PlotCalib |
---|
2007 | ################################################################################ |
---|
2008 | Â Â Â Â Â Â |
---|
2009 | def PlotCalib(G2frame,Inst,XY,Sigs,newPlot=False): |
---|
2010 | Â Â '''plot of CW or TOF peak calibration |
---|
2011 | Â Â ''' |
---|
2012 |   def OnMotion(event): |
---|
2013 | Â Â Â Â xpos =Â event.xdata |
---|
2014 |     if xpos:                    #avoid out of frame mouse position |
---|
2015 | Â Â Â Â Â Â ypos =Â event.ydata |
---|
2016 | Â Â Â Â Â Â Page.canvas.SetCursor(wx.CROSS_CURSOR) |
---|
2017 | Â Â Â Â Â Â try: |
---|
2018 |         G2frame.G2plotNB.status.SetStatusText('X =%9.3f %s =%9.3g'%(xpos,Title,ypos),1)          |
---|
2019 |       except TypeError: |
---|
2020 | Â Â Â Â Â Â Â Â G2frame.G2plotNB.status.SetStatusText('Select '+Title+' pattern first',1) |
---|
2021 | Â Â Â Â Â Â found =Â [] |
---|
2022 | Â Â Â Â Â Â wid =Â 1 |
---|
2023 | Â Â Â Â Â Â view =Â Page.toolbar._views.forward() |
---|
2024 |       if view: |
---|
2025 | Â Â Â Â Â Â Â Â view =Â view[0][:2] |
---|
2026 | Â Â Â Â Â Â Â Â wid =Â view[1]-view[0] |
---|
2027 | Â Â Â Â Â Â found =Â XY[np.where(np.fabs(XY.T[0]-xpos)Â <Â 0.005*wid)] |
---|
2028 |       if len(found): |
---|
2029 | Â Â Â Â Â Â Â Â pos =Â found[0][1] |
---|
2030 |         if 'C' in Inst['Type'][0]: |
---|
2031 | Â Â Â Â Â Â Â Â Â Â Page.canvas.SetToolTipString('position=%.4f'%(pos)) |
---|
2032 | Â Â Â Â Â Â Â Â else: |
---|
2033 | Â Â Â Â Â Â Â Â Â Â Page.canvas.SetToolTipString('position=%.2f'%(pos)) |
---|
2034 | Â Â Â Â Â Â else: |
---|
2035 | Â Â Â Â Â Â Â Â Page.canvas.SetToolTipString('') |
---|
2036 | |
---|
2037 | Â Â Title =Â 'Position calibration' |
---|
2038 | Â Â try: |
---|
2039 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index(Title) |
---|
2040 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
2041 |     if not newPlot: |
---|
2042 | Â Â Â Â Â Â Plot =Â Page.figure.gca() |
---|
2043 | Â Â Â Â Â Â xylim =Â Plot.get_xlim(),Plot.get_ylim() |
---|
2044 | Â Â Â Â Page.figure.clf() |
---|
2045 | Â Â Â Â Plot =Â Page.figure.gca() |
---|
2046 |   except ValueError: |
---|
2047 | Â Â Â Â newPlot =Â True |
---|
2048 | Â Â Â Â Plot =Â G2frame.G2plotNB.addMpl(Title).gca() |
---|
2049 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index(Title) |
---|
2050 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
2051 |     Page.canvas.mpl_connect('motion_notify_event', OnMotion) |
---|
2052 | Â Â |
---|
2053 | Â Â Page.Choice =Â None |
---|
2054 | Â Â Page.SetFocus() |
---|
2055 | Â Â G2frame.G2plotNB.status.DestroyChildren() |
---|
2056 | Â Â Plot.set_title(Title) |
---|
2057 | Â Â Plot.set_xlabel(r'd-spacing',fontsize=14) |
---|
2058 |   if 'C' in Inst['Type'][0]: |
---|
2059 | Â Â Â Â Plot.set_ylabel(r'$\mathsf{\Delta(2\theta)}$',fontsize=14) |
---|
2060 | Â Â else: |
---|
2061 | Â Â Â Â Plot.set_ylabel(r'$\mathsf{\Delta}T/T$',fontsize=14) |
---|
2062 |   for ixy,xyw in enumerate(XY): |
---|
2063 |     if len(xyw) > 2: |
---|
2064 | Â Â Â Â Â Â X,Y,W =Â xyw |
---|
2065 | Â Â Â Â else: |
---|
2066 | Â Â Â Â Â Â X,Y =Â xyw |
---|
2067 | Â Â Â Â Â Â W =Â 0. |
---|
2068 | Â Â Â Â Yc =Â G2lat.Dsp2pos(Inst,X) |
---|
2069 |     if 'C' in Inst['Type'][0]: |
---|
2070 | Â Â Â Â Â Â Y =Â Y-Yc |
---|
2071 | Â Â Â Â Â Â E =Â Sigs[ixy] |
---|
2072 |       bin = W/2. |
---|
2073 | Â Â Â Â else: |
---|
2074 | Â Â Â Â Â Â Y =Â (Y-Yc)/Yc |
---|
2075 | Â Â Â Â Â Â E =Â Sigs[ixy]/Yc |
---|
2076 |       bin = W/(2.*Yc) |
---|
2077 |     if E: |
---|
2078 | Â Â Â Â Â Â Plot.errorbar(X,Y,ecolor='k',yerr=E) |
---|
2079 |     if ixy: |
---|
2080 | Â Â Â Â Â Â Plot.plot(X,Y,'kx',picker=3) |
---|
2081 | Â Â Â Â else: |
---|
2082 | Â Â Â Â Â Â Plot.plot(X,Y,'kx',label='peak') |
---|
2083 |     if W: |
---|
2084 |       if ixy: |
---|
2085 | Â Â Â Â Â Â Â Â Plot.plot(X,bin,'b+') |
---|
2086 | Â Â Â Â Â Â else: |
---|
2087 | Â Â Â Â Â Â Â Â Plot.plot(X,bin,'b+',label='bin width') |
---|
2088 | Â Â Â Â Â Â Plot.plot(X,-bin,'b+') |
---|
2089 | Â Â Â Â Plot.axhline(0.,color='r',linestyle='--') |
---|
2090 | Â Â Plot.legend(loc='best') |
---|
2091 |   if not newPlot: |
---|
2092 | Â Â Â Â Page.toolbar.push_current() |
---|
2093 | Â Â Â Â Plot.set_xlim(xylim[0]) |
---|
2094 | Â Â Â Â Plot.set_ylim(xylim[1]) |
---|
2095 | #Â Â Â Â xylim = [] |
---|
2096 | Â Â Â Â Page.toolbar.push_current() |
---|
2097 | Â Â Â Â Page.toolbar.draw() |
---|
2098 | Â Â else: |
---|
2099 | Â Â Â Â Page.canvas.draw() |
---|
2100 | |
---|
2101 | ################################################################################ |
---|
2102 | ##### PlotXY |
---|
2103 | ################################################################################ |
---|
2104 | Â Â Â Â Â Â |
---|
2105 | def PlotXY(G2frame,XY,XY2=None,labelX=None,labelY=None,newPlot=False,Title=''): |
---|
2106 | Â Â '''simple plot of xy data, used for diagnostic purposes |
---|
2107 | Â Â ''' |
---|
2108 |   def OnMotion(event): |
---|
2109 | Â Â Â Â xpos =Â event.xdata |
---|
2110 |     if xpos:                    #avoid out of frame mouse position |
---|
2111 | Â Â Â Â Â Â ypos =Â event.ydata |
---|
2112 | Â Â Â Â Â Â Page.canvas.SetCursor(wx.CROSS_CURSOR) |
---|
2113 | Â Â Â Â Â Â try: |
---|
2114 |         G2frame.G2plotNB.status.SetStatusText('X =%9.3f %s =%9.3f'%(xpos,Title,ypos),1)          |
---|
2115 |       except TypeError: |
---|
2116 | Â Â Â Â Â Â Â Â G2frame.G2plotNB.status.SetStatusText('Select '+Title+' pattern first',1) |
---|
2117 | |
---|
2118 | Â Â try: |
---|
2119 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index(Title) |
---|
2120 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
2121 |     if not newPlot: |
---|
2122 | Â Â Â Â Â Â Plot =Â Page.figure.gca() |
---|
2123 | Â Â Â Â Â Â xylim =Â Plot.get_xlim(),Plot.get_ylim() |
---|
2124 | Â Â Â Â Page.figure.clf() |
---|
2125 | Â Â Â Â Plot =Â Page.figure.gca() |
---|
2126 |   except ValueError: |
---|
2127 | Â Â Â Â newPlot =Â True |
---|
2128 | Â Â Â Â Plot =Â G2frame.G2plotNB.addMpl(Title).gca() |
---|
2129 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index(Title) |
---|
2130 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
2131 |     Page.canvas.mpl_connect('motion_notify_event', OnMotion) |
---|
2132 | Â Â |
---|
2133 | Â Â Page.Choice =Â None |
---|
2134 | Â Â Page.SetFocus() |
---|
2135 | Â Â G2frame.G2plotNB.status.DestroyChildren() |
---|
2136 | Â Â Plot.set_title(Title) |
---|
2137 |   if labelX: |
---|
2138 | Â Â Â Â Plot.set_xlabel(r''+labelX,fontsize=14) |
---|
2139 | Â Â else: |
---|
2140 | Â Â Â Â Plot.set_xlabel(r'X',fontsize=14) |
---|
2141 |   if labelY: |
---|
2142 | Â Â Â Â Plot.set_ylabel(r''+labelY,fontsize=14) |
---|
2143 | Â Â else: |
---|
2144 | Â Â Â Â Plot.set_ylabel(r'Y',fontsize=14) |
---|
2145 | Â Â colors=['b','g','r','c','m','k'] |
---|
2146 |   for ixy,xy in enumerate(XY): |
---|
2147 | Â Â Â Â X,Y =Â xy |
---|
2148 | Â Â Â Â Plot.plot(X,Y,colors[ixy%6]+'+',picker=False) |
---|
2149 |   if len(XY2): |
---|
2150 |     for ixy,xy in enumerate(XY2): |
---|
2151 | Â Â Â Â Â Â X,Y =Â xy |
---|
2152 | Â Â Â Â Â Â Plot.plot(X,Y,colors[ixy%6],picker=False) |
---|
2153 |   if not newPlot: |
---|
2154 | Â Â Â Â Page.toolbar.push_current() |
---|
2155 | Â Â Â Â Plot.set_xlim(xylim[0]) |
---|
2156 | Â Â Â Â Plot.set_ylim(xylim[1]) |
---|
2157 | Â Â Â Â xylim =Â [] |
---|
2158 | Â Â Â Â Page.toolbar.push_current() |
---|
2159 | Â Â Â Â Page.toolbar.draw() |
---|
2160 | Â Â else: |
---|
2161 | Â Â Â Â Page.canvas.draw() |
---|
2162 | |
---|
2163 | ################################################################################ |
---|
2164 | ##### PlotStrain |
---|
2165 | ################################################################################ |
---|
2166 | Â Â Â Â Â Â |
---|
2167 | def PlotStrain(G2frame,data,newPlot=False): |
---|
2168 | Â Â '''plot of strain data, used for diagnostic purposes |
---|
2169 | Â Â ''' |
---|
2170 |   def OnMotion(event): |
---|
2171 | Â Â Â Â xpos =Â event.xdata |
---|
2172 |     if xpos:                    #avoid out of frame mouse position |
---|
2173 | Â Â Â Â Â Â ypos =Â event.ydata |
---|
2174 | Â Â Â Â Â Â Page.canvas.SetCursor(wx.CROSS_CURSOR) |
---|
2175 | Â Â Â Â Â Â try: |
---|
2176 |         G2frame.G2plotNB.status.SetStatusText('d-spacing =%9.5f Azimuth =%9.3f'%(ypos,xpos),1)          |
---|
2177 |       except TypeError: |
---|
2178 | Â Â Â Â Â Â Â Â G2frame.G2plotNB.status.SetStatusText('Select Strain pattern first',1) |
---|
2179 | |
---|
2180 | Â Â try: |
---|
2181 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index('Strain') |
---|
2182 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
2183 |     if not newPlot: |
---|
2184 | Â Â Â Â Â Â Plot =Â Page.figure.gca() |
---|
2185 | Â Â Â Â Â Â xylim =Â Plot.get_xlim(),Plot.get_ylim() |
---|
2186 | Â Â Â Â Page.figure.clf() |
---|
2187 | Â Â Â Â Plot =Â Page.figure.gca() |
---|
2188 |   except ValueError: |
---|
2189 | Â Â Â Â newPlot =Â True |
---|
2190 | Â Â Â Â Plot =Â G2frame.G2plotNB.addMpl('Strain').gca() |
---|
2191 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index('Strain') |
---|
2192 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
2193 |     Page.canvas.mpl_connect('motion_notify_event', OnMotion) |
---|
2194 | Â Â |
---|
2195 | Â Â Page.Choice =Â None |
---|
2196 | Â Â Page.SetFocus() |
---|
2197 | Â Â G2frame.G2plotNB.status.DestroyChildren() |
---|
2198 | Â Â Plot.set_title('Strain') |
---|
2199 | Â Â Plot.set_ylabel(r'd-spacing',fontsize=14) |
---|
2200 | Â Â Plot.set_xlabel(r'Azimuth',fontsize=14) |
---|
2201 | Â Â colors=['b','g','r','c','m','k'] |
---|
2202 |   for N,item in enumerate(data['d-zero']): |
---|
2203 | Â Â Â Â Y,X =Â np.array(item['ImtaObs'])Â Â Â Â Â #plot azimuth as X & d-spacing as Y |
---|
2204 | Â Â Â Â Plot.plot(X,Y,colors[N%6]+'+',picker=False) |
---|
2205 | Â Â Â Â Y,X =Â np.array(item['ImtaCalc']) |
---|
2206 | Â Â Â Â Plot.plot(X,Y,colors[N%6],picker=False) |
---|
2207 |   if not newPlot: |
---|
2208 | Â Â Â Â Page.toolbar.push_current() |
---|
2209 | Â Â Â Â Plot.set_xlim(xylim[0]) |
---|
2210 | Â Â Â Â Plot.set_ylim(xylim[1]) |
---|
2211 | Â Â Â Â xylim =Â [] |
---|
2212 | Â Â Â Â Page.toolbar.push_current() |
---|
2213 | Â Â Â Â Page.toolbar.draw() |
---|
2214 | Â Â else: |
---|
2215 | Â Â Â Â Page.canvas.draw() |
---|
2216 | Â Â Â Â |
---|
2217 | ################################################################################ |
---|
2218 | ##### PlotSASDSizeDist |
---|
2219 | ################################################################################ |
---|
2220 | Â Â Â Â Â Â |
---|
2221 | def PlotSASDSizeDist(G2frame): |
---|
2222 | Â Â |
---|
2223 |   def OnPageChanged(event): |
---|
2224 | Â Â Â Â PlotText =Â G2frame.G2plotNB.nb.GetPageText(G2frame.G2plotNB.nb.GetSelection()) |
---|
2225 |     if 'Powder' in PlotText: |
---|
2226 | Â Â Â Â Â Â PlotPatterns(G2frame,plotType='SASD',newPlot=True) |
---|
2227 |     elif 'Size' in PlotText: |
---|
2228 | Â Â Â Â Â Â PlotSASDSizeDist(G2frame) |
---|
2229 | Â Â |
---|
2230 |   def OnMotion(event): |
---|
2231 | Â Â Â Â xpos =Â event.xdata |
---|
2232 |     if xpos:                    #avoid out of frame mouse position |
---|
2233 | Â Â Â Â Â Â ypos =Â event.ydata |
---|
2234 | Â Â Â Â Â Â Page.canvas.SetCursor(wx.CROSS_CURSOR) |
---|
2235 | Â Â Â Â Â Â try: |
---|
2236 |         G2frame.G2plotNB.status.SetStatusText('diameter =%9.3f f(D) =%9.3g'%(xpos,ypos),1)          |
---|
2237 |       except TypeError: |
---|
2238 | Â Â Â Â Â Â Â Â G2frame.G2plotNB.status.SetStatusText('Select Strain pattern first',1) |
---|
2239 | |
---|
2240 | Â Â try: |
---|
2241 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index('Size Distribution') |
---|
2242 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
2243 | Â Â Â Â Page.figure.clf() |
---|
2244 | Â Â Â Â Plot =Â Page.figure.gca()Â Â Â Â Â #get a fresh plot after clf() |
---|
2245 |   except ValueError: |
---|
2246 | Â Â Â Â newPlot =Â True |
---|
2247 | Â Â Â Â Plot =Â G2frame.G2plotNB.addMpl('Size Distribution').gca() |
---|
2248 | Â Â Â Â G2frame.G2plotNB.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGED,OnPageChanged) |
---|
2249 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index('Size Distribution') |
---|
2250 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
2251 |     Page.canvas.mpl_connect('motion_notify_event', OnMotion) |
---|
2252 | Â Â Page.Choice =Â None |
---|
2253 | Â Â Page.SetFocus() |
---|
2254 | Â Â PatternId =Â G2frame.PatternId |
---|
2255 |   data = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Models')) |
---|
2256 | Â Â Bins,Dbins,BinMag =Â data['Size']['Distribution'] |
---|
2257 | Â Â Plot.set_title('Size Distribution') |
---|
2258 | Â Â Plot.set_xlabel(r'$D, \AA$',fontsize=14) |
---|
2259 | Â Â Plot.set_ylabel(r'$Volume distribution f(D)$',fontsize=14) |
---|
2260 |   if data['Size']['logBins']: |
---|
2261 | Â Â Â Â Plot.set_xscale("log",nonposy='mask') |
---|
2262 | Â Â Â Â Plot.set_xlim([np.min(2.*Bins)/2.,np.max(2.*Bins)*2.]) |
---|
2263 | Â Â Plot.bar(2.*Bins-Dbins,BinMag,2.*Dbins,facecolor='white')Â Â Â Â #plot diameters |
---|
2264 |   if 'Size Calc' in data: |
---|
2265 | Â Â Â Â Rbins,Dist =Â data['Size Calc'] |
---|
2266 |     for i in range(len(Rbins)): |
---|
2267 |       if len(Rbins[i]): |
---|
2268 | Â Â Â Â Â Â Â Â Plot.plot(2.*Rbins[i],Dist[i])Â Â Â Â #plot diameters |
---|
2269 | Â Â Page.canvas.draw() |
---|
2270 | |
---|
2271 | ################################################################################ |
---|
2272 | ##### PlotPowderLines |
---|
2273 | ################################################################################ |
---|
2274 | Â Â Â Â Â Â |
---|
2275 | def PlotPowderLines(G2frame): |
---|
2276 | Â Â ''' plotting of powder lines (i.e. no powder pattern) as sticks |
---|
2277 | Â Â ''' |
---|
2278 |   global HKL |
---|
2279 | |
---|
2280 |   def OnMotion(event): |
---|
2281 | Â Â Â Â xpos =Â event.xdata |
---|
2282 |     if xpos:                    #avoid out of frame mouse position |
---|
2283 | Â Â Â Â Â Â Page.canvas.SetCursor(wx.CROSS_CURSOR) |
---|
2284 |       G2frame.G2plotNB.status.SetFields(['','2-theta =%9.3f '%(xpos,)]) |
---|
2285 |       if G2frame.PickId and G2frame.PatternTree.GetItemText(G2frame.PickId) in ['Index Peak List','Unit Cells List']: |
---|
2286 | Â Â Â Â Â Â Â Â found =Â [] |
---|
2287 |         if len(HKL): |
---|
2288 | Â Â Â Â Â Â Â Â Â Â view =Â Page.toolbar._views.forward()[0][:2] |
---|
2289 | Â Â Â Â Â Â Â Â Â Â wid =Â view[1]-view[0] |
---|
2290 | Â Â Â Â Â Â Â Â Â Â found =Â HKL[np.where(np.fabs(HKL.T[-1]-xpos)Â <Â 0.002*wid)] |
---|
2291 |         if len(found): |
---|
2292 | Â Â Â Â Â Â Â Â Â Â h,k,l =Â found[0][:3]Â |
---|
2293 | Â Â Â Â Â Â Â Â Â Â Page.canvas.SetToolTipString('%d,%d,%d'%(int(h),int(k),int(l))) |
---|
2294 | Â Â Â Â Â Â Â Â else: |
---|
2295 | Â Â Â Â Â Â Â Â Â Â Page.canvas.SetToolTipString('') |
---|
2296 | |
---|
2297 | Â Â try: |
---|
2298 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index('Powder Lines') |
---|
2299 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
2300 | Â Â Â Â Page.figure.clf() |
---|
2301 | Â Â Â Â Plot =Â Page.figure.gca() |
---|
2302 |   except ValueError: |
---|
2303 | Â Â Â Â Plot =Â G2frame.G2plotNB.addMpl('Powder Lines').gca() |
---|
2304 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index('Powder Lines') |
---|
2305 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
2306 |     Page.canvas.mpl_connect('motion_notify_event', OnMotion) |
---|
2307 | Â Â Â Â |
---|
2308 | Â Â Page.Choice =Â None |
---|
2309 | Â Â Page.SetFocus() |
---|
2310 | Â Â Plot.set_title('Powder Pattern Lines') |
---|
2311 | Â Â Plot.set_xlabel(r'$\mathsf{2\theta}$',fontsize=14) |
---|
2312 | Â Â PickId =Â G2frame.PickId |
---|
2313 | Â Â PatternId =Â G2frame.PatternId |
---|
2314 |   peaks = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Index Peak List'))[0] |
---|
2315 |   for peak in peaks: |
---|
2316 | Â Â Â Â Plot.axvline(peak[0],color='b') |
---|
2317 | Â Â HKL =Â np.array(G2frame.HKL) |
---|
2318 |   for hkl in G2frame.HKL: |
---|
2319 | Â Â Â Â Plot.axvline(hkl[-1],color='r',dashes=(5,5)) |
---|
2320 | Â Â xmin =Â peaks[0][0] |
---|
2321 | Â Â xmax =Â peaks[-1][0] |
---|
2322 | Â Â delt =Â xmax-xmin |
---|
2323 | Â Â xlim =Â [max(0,xmin-delt/20.),min(180.,xmax+delt/20.)] |
---|
2324 | Â Â Plot.set_xlim(xlim) |
---|
2325 | Â Â Page.canvas.draw() |
---|
2326 | Â Â Page.toolbar.push_current() |
---|
2327 | |
---|
2328 | ################################################################################ |
---|
2329 | ##### PlotPeakWidths |
---|
2330 | ################################################################################ |
---|
2331 | Â Â Â Â Â Â |
---|
2332 | def PlotPeakWidths(G2frame): |
---|
2333 | Â Â ''' Plotting of instrument broadening terms as function of 2-theta |
---|
2334 | Â Â Seen when "Instrument Parameters" chosen from powder pattern data tree |
---|
2335 | Â Â ''' |
---|
2336 | #Â Â sig = lambda Th,U,V,W: 1.17741*math.sqrt(U*tand(Th)**2+V*tand(Th)+W)*math.pi/18000. |
---|
2337 | #Â Â gam = lambda Th,X,Y: (X/cosd(Th)+Y*tand(Th))*math.pi/18000. |
---|
2338 |   gamFW = lambda s,g: np.exp(np.log(s**5+2.69269*s**4*g+2.42843*s**3*g**2+4.47163*s**2*g**3+0.07842*s*g**4+g**5)/5.) |
---|
2339 | #  gamFW2 = lambda s,g: math.sqrt(s**2+(0.4654996*g)**2)+.5345004*g #Ubaldo Bafile - private communication |
---|
2340 | Â Â PatternId =Â G2frame.PatternId |
---|
2341 |   limitID = G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Limits') |
---|
2342 |   if limitID: |
---|
2343 | Â Â Â Â limits =Â G2frame.PatternTree.GetItemPyData(limitID)[:2] |
---|
2344 | Â Â else: |
---|
2345 | Â Â Â Â return |
---|
2346 | Â Â Parms,Parms2 =Â G2frame.PatternTree.GetItemPyData(Â \ |
---|
2347 |     G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Instrument Parameters')) |
---|
2348 |   if 'C' in Parms['Type'][0]: |
---|
2349 | Â Â Â Â lam =Â G2mth.getWave(Parms) |
---|
2350 | Â Â else: |
---|
2351 | Â Â Â Â difC =Â Parms['difC'][0] |
---|
2352 | Â Â try:Â # PATCH: deal with older peak lists, before changed to dict to implement TOF |
---|
2353 |     peaks = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Peak List'))['peaks'] |
---|
2354 |   except TypeError: |
---|
2355 |     print "Your peak list needs reformatting...", |
---|
2356 |     item = G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Peak List') |
---|
2357 | Â Â Â Â G2frame.PatternTree.SelectItem(item)Â |
---|
2358 |     item = G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Instrument Parameters') |
---|
2359 | Â Â Â Â G2frame.PatternTree.SelectItem(item) |
---|
2360 |     print "done" |
---|
2361 | Â Â Â Â return |
---|
2362 | Â Â try: |
---|
2363 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index('Peak Widths') |
---|
2364 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
2365 | Â Â Â Â Page.figure.clf() |
---|
2366 | Â Â Â Â Plot =Â Page.figure.gca() |
---|
2367 |   except ValueError: |
---|
2368 | Â Â Â Â Plot =Â G2frame.G2plotNB.addMpl('Peak Widths').gca() |
---|
2369 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index('Peak Widths') |
---|
2370 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
2371 | Â Â Page.Choice =Â None |
---|
2372 | Â Â Page.SetFocus() |
---|
2373 | Â Â |
---|
2374 | Â Â Page.canvas.SetToolTipString('') |
---|
2375 | Â Â colors=['b','g','r','c','m','k'] |
---|
2376 | Â Â X =Â [] |
---|
2377 | Â Â Y =Â [] |
---|
2378 | Â Â Z =Â [] |
---|
2379 | Â Â W =Â [] |
---|
2380 |   if 'C' in Parms['Type'][0]: |
---|
2381 | Â Â Â Â Plot.set_title('Instrument and sample peak widths') |
---|
2382 | Â Â Â Â Plot.set_xlabel(r'$Q, \AA^{-1}$',fontsize=14) |
---|
2383 | Â Â Â Â Plot.set_ylabel(r'$\Delta Q/Q, \Delta d/d$',fontsize=14) |
---|
2384 | Â Â Â Â try: |
---|
2385 | Â Â Â Â Â Â Xmin,Xmax =Â limits[1] |
---|
2386 | Â Â Â Â Â Â X =Â np.linspace(Xmin,Xmax,num=101,endpoint=True) |
---|
2387 | Â Â Â Â Â Â Q =Â 4.*np.pi*npsind(X/2.)/lam |
---|
2388 | Â Â Â Â Â Â Z =Â np.ones_like(X) |
---|
2389 | Â Â Â Â Â Â data =Â G2mth.setPeakparms(Parms,Parms2,X,Z) |
---|
2390 | Â Â Â Â Â Â s =Â 1.17741*np.sqrt(data[4])*np.pi/18000. |
---|
2391 | Â Â Â Â Â Â g =Â data[6]*np.pi/18000. |
---|
2392 | Â Â Â Â Â Â G =Â G2pwd.getgamFW(g,s) |
---|
2393 | Â Â Â Â Â Â Y =Â s/nptand(X/2.) |
---|
2394 | Â Â Â Â Â Â Z =Â g/nptand(X/2.) |
---|
2395 | Â Â Â Â Â Â W =Â G/nptand(X/2.) |
---|
2396 | Â Â Â Â Â Â Plot.plot(Q,Y,color='r',label='Gaussian') |
---|
2397 | Â Â Â Â Â Â Plot.plot(Q,Z,color='g',label='Lorentzian') |
---|
2398 | Â Â Â Â Â Â Plot.plot(Q,W,color='b',label='G+L') |
---|
2399 | Â Â Â Â Â Â |
---|
2400 | Â Â Â Â Â Â fit =Â G2mth.setPeakparms(Parms,Parms2,X,Z,useFit=True) |
---|
2401 | Â Â Â Â Â Â sf =Â 1.17741*np.sqrt(fit[4])*np.pi/18000. |
---|
2402 | Â Â Â Â Â Â gf =Â fit[6]*np.pi/18000. |
---|
2403 | Â Â Â Â Â Â Gf =Â G2pwd.getgamFW(gf,sf) |
---|
2404 | Â Â Â Â Â Â Yf =Â sf/nptand(X/2.) |
---|
2405 | Â Â Â Â Â Â Zf =Â gf/nptand(X/2.) |
---|
2406 | Â Â Â Â Â Â Wf =Â Gf/nptand(X/2.) |
---|
2407 | Â Â Â Â Â Â Plot.plot(Q,Yf,color='r',dashes=(5,5),label='Gaussian fit') |
---|
2408 | Â Â Â Â Â Â Plot.plot(Q,Zf,color='g',dashes=(5,5),label='Lorentzian fit') |
---|
2409 | Â Â Â Â Â Â Plot.plot(Q,Wf,color='b',dashes=(5,5),label='G+L fit') |
---|
2410 | Â Â Â Â Â Â |
---|
2411 | Â Â Â Â Â Â X =Â [] |
---|
2412 | Â Â Â Â Â Â Y =Â [] |
---|
2413 | Â Â Â Â Â Â Z =Â [] |
---|
2414 | Â Â Â Â Â Â W =Â [] |
---|
2415 | Â Â Â Â Â Â V =Â [] |
---|
2416 |       for peak in peaks: |
---|
2417 | Â Â Â Â Â Â Â Â X.append(4.0*math.pi*sind(peak[0]/2.0)/lam) |
---|
2418 | Â Â Â Â Â Â Â Â try: |
---|
2419 | Â Â Â Â Â Â Â Â Â Â s =Â 1.17741*math.sqrt(peak[4])*math.pi/18000. |
---|
2420 |         except ValueError: |
---|
2421 | Â Â Â Â Â Â Â Â Â Â s =Â 0.01 |
---|
2422 | Â Â Â Â Â Â Â Â g =Â peak[6]*math.pi/18000. |
---|
2423 | Â Â Â Â Â Â Â Â G =Â G2pwd.getgamFW(g,s) |
---|
2424 | Â Â Â Â Â Â Â Â Y.append(s/tand(peak[0]/2.)) |
---|
2425 | Â Â Â Â Â Â Â Â Z.append(g/tand(peak[0]/2.)) |
---|
2426 | Â Â Â Â Â Â Â Â W.append(G/tand(peak[0]/2.)) |
---|
2427 |       if len(peaks): |
---|
2428 | Â Â Â Â Â Â Â Â Plot.plot(X,Y,'+',color='r',label='G peak') |
---|
2429 | Â Â Â Â Â Â Â Â Plot.plot(X,Z,'+',color='g',label='L peak') |
---|
2430 | Â Â Â Â Â Â Â Â Plot.plot(X,W,'+',color='b',label='G+L peak') |
---|
2431 | Â Â Â Â Â Â Plot.legend(loc='best') |
---|
2432 | Â Â Â Â Â Â Page.canvas.draw() |
---|
2433 |     except ValueError: |
---|
2434 |       print '**** ERROR - default U,V,W profile coefficients yield sqrt of negative value at 2theta =', \ |
---|
2435 | Â Â Â Â Â Â Â Â '%.3f'%(2*theta) |
---|
2436 | Â Â Â Â Â Â G2frame.G2plotNB.Delete('Peak Widths') |
---|
2437 | Â Â else:Â Â #'T'OF |
---|
2438 | Â Â Â Â Plot.set_title('Instrument and sample peak coefficients') |
---|
2439 | Â Â Â Â Plot.set_xlabel(r'$Q, \AA^{-1}$',fontsize=14) |
---|
2440 | Â Â Â Â Plot.set_ylabel(r'$\alpha, \beta, \Delta Q/Q, \Delta d/d$',fontsize=14) |
---|
2441 | Â Â Â Â Xmin,Xmax =Â limits[1] |
---|
2442 | Â Â Â Â T =Â np.linspace(Xmin,Xmax,num=101,endpoint=True) |
---|
2443 | Â Â Â Â Z =Â np.ones_like(T) |
---|
2444 | Â Â Â Â data =Â G2mth.setPeakparms(Parms,Parms2,T,Z) |
---|
2445 | Â Â Â Â ds =Â T/difC |
---|
2446 | Â Â Â Â Q =Â 2.*np.pi/ds |
---|
2447 | Â Â Â Â A =Â data[4] |
---|
2448 | Â Â Â Â B =Â data[6] |
---|
2449 | Â Â Â Â S =Â 1.17741*np.sqrt(data[8])/T |
---|
2450 | Â Â Â Â G =Â data[10]/T |
---|
2451 | Â Â Â Â Plot.plot(Q,A,color='r',label='Alpha') |
---|
2452 | Â Â Â Â Plot.plot(Q,B,color='g',label='Beta') |
---|
2453 | Â Â Â Â Plot.plot(Q,S,color='b',label='Gaussian') |
---|
2454 | Â Â Â Â Plot.plot(Q,G,color='m',label='Lorentzian') |
---|
2455 | |
---|
2456 | Â Â Â Â fit =Â G2mth.setPeakparms(Parms,Parms2,T,Z) |
---|
2457 | Â Â Â Â ds =Â T/difC |
---|
2458 | Â Â Â Â Q =Â 2.*np.pi/ds |
---|
2459 | Â Â Â Â Af =Â fit[4] |
---|
2460 | Â Â Â Â Bf =Â fit[6] |
---|
2461 | Â Â Â Â Sf =Â 1.17741*np.sqrt(fit[8])/T |
---|
2462 | Â Â Â Â Gf =Â fit[10]/T |
---|
2463 | Â Â Â Â Plot.plot(Q,Af,color='r',dashes=(5,5),label='Alpha fit') |
---|
2464 | Â Â Â Â Plot.plot(Q,Bf,color='g',dashes=(5,5),label='Beta fit') |
---|
2465 | Â Â Â Â Plot.plot(Q,Sf,color='b',dashes=(5,5),label='Gaussian fit') |
---|
2466 | Â Â Â Â Plot.plot(Q,Gf,color='m',dashes=(5,5),label='Lorentzian fit') |
---|
2467 | Â Â Â Â |
---|
2468 | Â Â Â Â T =Â [] |
---|
2469 | Â Â Â Â A =Â [] |
---|
2470 | Â Â Â Â B =Â [] |
---|
2471 | Â Â Â Â S =Â [] |
---|
2472 | Â Â Â Â G =Â [] |
---|
2473 | Â Â Â Â W =Â [] |
---|
2474 | Â Â Â Â Q =Â [] |
---|
2475 | Â Â Â Â V =Â [] |
---|
2476 |     for peak in peaks: |
---|
2477 | Â Â Â Â Â Â T.append(peak[0]) |
---|
2478 | Â Â Â Â Â Â A.append(peak[4]) |
---|
2479 | Â Â Â Â Â Â B.append(peak[6]) |
---|
2480 | Â Â Â Â Â Â Q.append(2.*np.pi*difC/peak[0]) |
---|
2481 | Â Â Â Â Â Â S.append(1.17741*np.sqrt(peak[8])/peak[0]) |
---|
2482 | Â Â Â Â Â Â G.append(peak[10]/peak[0]) |
---|
2483 | Â Â Â Â Â Â |
---|
2484 | Â Â Â Â |
---|
2485 | Â Â Â Â Plot.plot(Q,A,'+',color='r',label='Alpha peak') |
---|
2486 | Â Â Â Â Plot.plot(Q,B,'+',color='g',label='Beta peak') |
---|
2487 | Â Â Â Â Plot.plot(Q,S,'+',color='b',label='Gaussian peak') |
---|
2488 | Â Â Â Â Plot.plot(Q,G,'+',color='m',label='Lorentzian peak') |
---|
2489 | Â Â Â Â Plot.legend(loc='best') |
---|
2490 | Â Â Â Â Page.canvas.draw() |
---|
2491 | |
---|
2492 | Â Â |
---|
2493 | ################################################################################ |
---|
2494 | ##### PlotSizeStrainPO |
---|
2495 | ################################################################################ |
---|
2496 | Â Â Â Â Â Â |
---|
2497 | def PlotSizeStrainPO(G2frame,data,hist='',Start=False): |
---|
2498 | Â Â '''Plot 3D mustrain/size/preferred orientation figure. In this instance data is for a phase |
---|
2499 | Â Â ''' |
---|
2500 | Â Â |
---|
2501 | Â Â PatternId =Â G2frame.PatternId |
---|
2502 | Â Â generalData =Â data['General'] |
---|
2503 | Â Â SGData =Â generalData['SGData'] |
---|
2504 | Â Â SGLaue =Â SGData['SGLaue'] |
---|
2505 |   if Start:          #initialize the spherical harmonics qlmn arrays |
---|
2506 | Â Â Â Â ptx.pyqlmninit() |
---|
2507 | Â Â Â Â Start =Â False |
---|
2508 | #Â Â MuStrKeys = G2spc.MustrainNames(SGData) |
---|
2509 | Â Â cell =Â generalData['Cell'][1:] |
---|
2510 | Â Â A,B =Â G2lat.cell2AB(cell[:6]) |
---|
2511 | Â Â Vol =Â cell[6] |
---|
2512 | Â Â useList =Â data['Histograms'] |
---|
2513 | Â Â phase =Â generalData['Name'] |
---|
2514 | Â Â plotType =Â generalData['Data plot type'] |
---|
2515 | Â Â plotDict =Â {'Mustrain':'Mustrain','Size':'Size','Preferred orientation':'Pref.Ori.'} |
---|
2516 |   for ptype in plotDict: |
---|
2517 | Â Â Â Â G2frame.G2plotNB.Delete(ptype) |
---|
2518 |   if plotType in ['None']: |
---|
2519 |     return    |
---|
2520 |   if hist == '': |
---|
2521 | Â Â Â Â hist =Â useList.keys()[0] |
---|
2522 | Â Â numPlots =Â len(useList) |
---|
2523 | |
---|
2524 |   if plotType in ['Mustrain','Size']: |
---|
2525 | Â Â Â Â Plot =Â mp3d.Axes3D(G2frame.G2plotNB.add3D(plotType)) |
---|
2526 | Â Â else: |
---|
2527 | Â Â Â Â Plot =Â G2frame.G2plotNB.addMpl(plotType).gca()Â Â Â Â |
---|
2528 | Â Â plotNum =Â G2frame.G2plotNB.plotList.index(plotType) |
---|
2529 | Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
2530 | Â Â Page.Choice =Â None |
---|
2531 | Â Â Page.SetFocus() |
---|
2532 | Â Â G2frame.G2plotNB.status.SetStatusText('',1) |
---|
2533 |   if not Page.IsShown(): |
---|
2534 | Â Â Â Â Page.Show() |
---|
2535 | Â Â |
---|
2536 | Â Â PHI =Â np.linspace(0.,360.,30,True) |
---|
2537 | Â Â PSI =Â np.linspace(0.,180.,30,True) |
---|
2538 | Â Â X =Â np.outer(npsind(PHI),npsind(PSI)) |
---|
2539 | Â Â Y =Â np.outer(npcosd(PHI),npsind(PSI)) |
---|
2540 | Â Â Z =Â np.outer(np.ones(np.size(PHI)),npcosd(PSI)) |
---|
2541 | Â Â try:Â Â Â Â #temp patch instead of 'mustrain' for old files with 'microstrain' |
---|
2542 | Â Â Â Â coeff =Â useList[hist][plotDict[plotType]] |
---|
2543 |   except KeyError: |
---|
2544 | Â Â Â Â return |
---|
2545 |   if plotType in ['Mustrain','Size']: |
---|
2546 |     if coeff[0] == 'isotropic': |
---|
2547 | Â Â Â Â Â Â X *=Â coeff[1][0] |
---|
2548 | Â Â Â Â Â Â Y *=Â coeff[1][0] |
---|
2549 | Â Â Â Â Â Â Z *=Â coeff[1][0]Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
---|
2550 |     elif coeff[0] == 'uniaxial': |
---|
2551 | Â Â Â Â Â Â |
---|
2552 |       def uniaxCalc(xyz,iso,aniso,axes): |
---|
2553 | Â Â Â Â Â Â Â Â Z =Â np.array(axes) |
---|
2554 | Â Â Â Â Â Â Â Â cp =Â abs(np.dot(xyz,Z)) |
---|
2555 | Â Â Â Â Â Â Â Â sp =Â np.sqrt(1.-cp**2) |
---|
2556 | Â Â Â Â Â Â Â Â R =Â iso*aniso/np.sqrt((iso*cp)**2+(aniso*sp)**2) |
---|
2557 |         return R*xyz |
---|
2558 | Â Â Â Â Â Â Â Â |
---|
2559 | Â Â Â Â Â Â iso,aniso =Â coeff[1][:2] |
---|
2560 | Â Â Â Â Â Â axes =Â np.inner(A,np.array(coeff[3])) |
---|
2561 | Â Â Â Â Â Â axes /=Â nl.norm(axes) |
---|
2562 | Â Â Â Â Â Â Shkl =Â np.array(coeff[1]) |
---|
2563 | Â Â Â Â Â Â XYZ =Â np.dstack((X,Y,Z)) |
---|
2564 | Â Â Â Â Â Â XYZ =Â np.nan_to_num(np.apply_along_axis(uniaxCalc,2,XYZ,iso,aniso,axes)) |
---|
2565 | Â Â Â Â Â Â X,Y,Z =Â np.dsplit(XYZ,3) |
---|
2566 | Â Â Â Â Â Â X =Â X[:,:,0] |
---|
2567 | Â Â Â Â Â Â Y =Â Y[:,:,0] |
---|
2568 | Â Â Â Â Â Â Z =Â Z[:,:,0] |
---|
2569 | Â Â Â Â |
---|
2570 |     elif coeff[0] == 'ellipsoidal': |
---|
2571 | Â Â Â Â Â Â |
---|
2572 |       def ellipseCalc(xyz,E,R): |
---|
2573 | Â Â Â Â Â Â Â Â XYZ =Â xyz*E.T |
---|
2574 |         return np.inner(XYZ.T,R) |
---|
2575 | Â Â Â Â Â Â Â Â |
---|
2576 | Â Â Â Â Â Â S6 =Â coeff[4] |
---|
2577 | Â Â Â Â Â Â Sij =Â G2lat.U6toUij(S6) |
---|
2578 | Â Â Â Â Â Â E,R =Â nl.eigh(Sij) |
---|
2579 | Â Â Â Â Â Â XYZ =Â np.dstack((X,Y,Z)) |
---|
2580 | Â Â Â Â Â Â XYZ =Â np.nan_to_num(np.apply_along_axis(ellipseCalc,2,XYZ,E,R)) |
---|
2581 | Â Â Â Â Â Â X,Y,Z =Â np.dsplit(XYZ,3) |
---|
2582 | Â Â Â Â Â Â X =Â X[:,:,0] |
---|
2583 | Â Â Â Â Â Â Y =Â Y[:,:,0] |
---|
2584 | Â Â Â Â Â Â Z =Â Z[:,:,0] |
---|
2585 | Â Â Â Â Â Â |
---|
2586 |     elif coeff[0] == 'generalized': |
---|
2587 | Â Â Â Â Â Â |
---|
2588 |       def genMustrain(xyz,SGData,A,Shkl): |
---|
2589 | Â Â Â Â Â Â Â Â uvw =Â np.inner(A.T,xyz) |
---|
2590 | Â Â Â Â Â Â Â Â Strm =Â np.array(G2spc.MustrainCoeff(uvw,SGData)) |
---|
2591 | Â Â Â Â Â Â Â Â Sum =Â np.sum(np.multiply(Shkl,Strm)) |
---|
2592 | Â Â Â Â Â Â Â Â Sum =Â np.where(Sum >Â 0.01,Sum,0.01) |
---|
2593 | Â Â Â Â Â Â Â Â Sum =Â np.sqrt(Sum) |
---|
2594 |         return Sum*xyz |
---|
2595 | Â Â Â Â Â Â Â Â |
---|
2596 | Â Â Â Â Â Â Shkl =Â np.array(coeff[4]) |
---|
2597 |       if np.any(Shkl): |
---|
2598 | Â Â Â Â Â Â Â Â XYZ =Â np.dstack((X,Y,Z)) |
---|
2599 | Â Â Â Â Â Â Â Â XYZ =Â np.nan_to_num(np.apply_along_axis(genMustrain,2,XYZ,SGData,A,Shkl)) |
---|
2600 | Â Â Â Â Â Â Â Â X,Y,Z =Â np.dsplit(XYZ,3) |
---|
2601 | Â Â Â Â Â Â Â Â X =Â X[:,:,0] |
---|
2602 | Â Â Â Â Â Â Â Â Y =Â Y[:,:,0] |
---|
2603 | Â Â Â Â Â Â Â Â Z =Â Z[:,:,0] |
---|
2604 | Â Â Â Â Â Â Â Â Â Â |
---|
2605 |     if np.any(X) and np.any(Y) and np.any(Z): |
---|
2606 | Â Â Â Â Â Â errFlags =Â np.seterr(all='ignore') |
---|
2607 | Â Â Â Â Â Â Plot.plot_surface(X,Y,Z,rstride=1,cstride=1,color='g',linewidth=1) |
---|
2608 | Â Â Â Â Â Â np.seterr(all='ignore') |
---|
2609 | Â Â Â Â Â Â xyzlim =Â np.array([Plot.get_xlim3d(),Plot.get_ylim3d(),Plot.get_zlim3d()]).T |
---|
2610 | Â Â Â Â Â Â XYZlim =Â [min(xyzlim[0]),max(xyzlim[1])] |
---|
2611 | Â Â Â Â Â Â Plot.set_xlim3d(XYZlim) |
---|
2612 | Â Â Â Â Â Â Plot.set_ylim3d(XYZlim) |
---|
2613 | Â Â Â Â Â Â Plot.set_zlim3d(XYZlim) |
---|
2614 | Â Â Â Â Â Â Plot.set_aspect('equal') |
---|
2615 |     if plotType == 'Size': |
---|
2616 | Â Â Â Â Â Â Plot.set_title('Crystallite size for '+phase+'\n'+coeff[0]+' model') |
---|
2617 | Â Â Â Â Â Â Plot.set_xlabel(r'X, $\mu$m') |
---|
2618 | Â Â Â Â Â Â Plot.set_ylabel(r'Y, $\mu$m') |
---|
2619 | Â Â Â Â Â Â Plot.set_zlabel(r'Z, $\mu$m') |
---|
2620 | Â Â Â Â else:Â Â |
---|
2621 | Â Â Â Â Â Â Plot.set_title(r'$\mu$strain for '+phase+'\n'+coeff[0]+' model') |
---|
2622 | Â Â Â Â Â Â Plot.set_xlabel(r'X, $\mu$strain') |
---|
2623 | Â Â Â Â Â Â Plot.set_ylabel(r'Y, $\mu$strain') |
---|
2624 | Â Â Â Â Â Â Plot.set_zlabel(r'Z, $\mu$strain') |
---|
2625 | Â Â else: |
---|
2626 | Â Â Â Â h,k,l =Â generalData['POhkl'] |
---|
2627 |     if coeff[0] == 'MD': |
---|
2628 |       print 'March-Dollase preferred orientation plot' |
---|
2629 | Â Â Â Â |
---|
2630 | Â Â Â Â else: |
---|
2631 | Â Â Â Â Â Â PH =Â np.array(generalData['POhkl']) |
---|
2632 | Â Â Â Â Â Â phi,beta =Â G2lat.CrsAng(PH,cell[:6],SGData) |
---|
2633 | Â Â Â Â Â Â SHCoef =Â {} |
---|
2634 |       for item in coeff[5]: |
---|
2635 | Â Â Â Â Â Â Â Â L,N =Â eval(item.strip('C')) |
---|
2636 | Â Â Â Â Â Â Â Â SHCoef['C%d,0,%d'%(L,N)]Â =Â coeff[5][item]Â Â Â Â Â Â Â Â Â Â Â Â |
---|
2637 | Â Â Â Â Â Â ODFln =Â G2lat.Flnh(Start,SHCoef,phi,beta,SGData) |
---|
2638 | Â Â Â Â Â Â X =Â np.linspace(0,90.0,26) |
---|
2639 | Â Â Â Â Â Â Y =Â G2lat.polfcal(ODFln,'0',X,0.0) |
---|
2640 | Â Â Â Â Â Â Plot.plot(X,Y,color='k',label=str(PH)) |
---|
2641 | Â Â Â Â Â Â Plot.legend(loc='best') |
---|
2642 | Â Â Â Â Â Â Plot.set_title('Axial distribution for HKL='+str(PH)+' in '+phase+'\n'+hist) |
---|
2643 | Â Â Â Â Â Â Plot.set_xlabel(r'$\psi$',fontsize=16) |
---|
2644 | Â Â Â Â Â Â Plot.set_ylabel('MRD',fontsize=14) |
---|
2645 | Â Â Page.canvas.draw() |
---|
2646 | Â Â |
---|
2647 | ################################################################################ |
---|
2648 | ##### PlotTexture |
---|
2649 | ################################################################################ |
---|
2650 | Â Â Â Â Â Â |
---|
2651 | def PlotTexture(G2frame,data,Start=False): |
---|
2652 | Â Â '''Pole figure, inverse pole figure, 3D pole distribution and 3D inverse pole distribution |
---|
2653 | Â Â plotting. |
---|
2654 | Â Â dict generalData contains all phase info needed which is in data |
---|
2655 | Â Â ''' |
---|
2656 | |
---|
2657 | Â Â shModels =Â ['cylindrical','none','shear - 2/m','rolling - mmm'] |
---|
2658 | Â Â SamSym =Â dict(zip(shModels,['0','-1','2/m','mmm'])) |
---|
2659 | Â Â PatternId =Â G2frame.PatternId |
---|
2660 | Â Â generalData =Â data['General'] |
---|
2661 | Â Â SGData =Â generalData['SGData'] |
---|
2662 | Â Â textureData =Â generalData['SH Texture'] |
---|
2663 | Â Â G2frame.G2plotNB.Delete('Texture') |
---|
2664 |   if not textureData['Order']: |
---|
2665 |     return         #no plot!! |
---|
2666 | Â Â SHData =Â generalData['SH Texture'] |
---|
2667 | Â Â SHCoef =Â SHData['SH Coeff'][1] |
---|
2668 | Â Â cell =Â generalData['Cell'][1:7] |
---|
2669 | Â Â Amat,Bmat =Â G2lat.cell2AB(cell) |
---|
2670 | Â Â sq2 =Â 1.0/math.sqrt(2.0) |
---|
2671 | Â Â |
---|
2672 |   def rp2xyz(r,p): |
---|
2673 | Â Â Â Â z =Â npcosd(r) |
---|
2674 | Â Â Â Â xy =Â np.sqrt(1.-z**2) |
---|
2675 |     return xy*npsind(p),xy*npcosd(p),z |
---|
2676 | Â Â Â Â Â Â |
---|
2677 |   def OnMotion(event): |
---|
2678 | Â Â Â Â SHData =Â data['General']['SH Texture'] |
---|
2679 |     if event.xdata and event.ydata:         #avoid out of frame errors |
---|
2680 | Â Â Â Â Â Â xpos =Â event.xdata |
---|
2681 | Â Â Â Â Â Â ypos =Â event.ydata |
---|
2682 |       if 'Inverse' in SHData['PlotType']: |
---|
2683 | Â Â Â Â Â Â Â Â r =Â xpos**2+ypos**2 |
---|
2684 |         if r <= 1.0: |
---|
2685 |           if 'equal' in G2frame.Projection: |
---|
2686 | Â Â Â Â Â Â Â Â Â Â Â Â r,p =Â 2.*npasind(np.sqrt(r)*sq2),npatan2d(ypos,xpos) |
---|
2687 | Â Â Â Â Â Â Â Â Â Â else: |
---|
2688 | Â Â Â Â Â Â Â Â Â Â Â Â r,p =Â 2.*npatand(np.sqrt(r)),npatan2d(ypos,xpos) |
---|
2689 | Â Â Â Â Â Â Â Â Â Â ipf =Â G2lat.invpolfcal(IODFln,SGData,np.array([r,]),np.array([p,])) |
---|
2690 | Â Â Â Â Â Â Â Â Â Â xyz =Â np.inner(Amat.T,np.array([rp2xyz(r,p)])) |
---|
2691 | Â Â Â Â Â Â Â Â Â Â y,x,z =Â list(xyz/np.max(np.abs(xyz))) |
---|
2692 | Â Â Â Â Â Â Â Â Â Â |
---|
2693 | Â Â Â Â Â Â Â Â Â Â G2frame.G2plotNB.status.SetFields(['', |
---|
2694 |             'psi =%9.3f, beta =%9.3f, MRD =%9.3f hkl=%5.2f,%5.2f,%5.2f'%(r,p,ipf,x,y,z)]) |
---|
2695 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
---|
2696 |       elif 'Axial' in SHData['PlotType']: |
---|
2697 | Â Â Â Â Â Â Â Â pass |
---|
2698 | Â Â Â Â Â Â Â Â |
---|
2699 | Â Â Â Â Â Â else:Â Â Â Â Â Â Â Â Â Â Â Â #ordinary pole figure |
---|
2700 | Â Â Â Â Â Â Â Â z =Â xpos**2+ypos**2 |
---|
2701 |         if z <= 1.0: |
---|
2702 | Â Â Â Â Â Â Â Â Â Â z =Â np.sqrt(z) |
---|
2703 |           if 'equal' in G2frame.Projection: |
---|
2704 | Â Â Â Â Â Â Â Â Â Â Â Â r,p =Â 2.*npasind(z*sq2),npatan2d(ypos,xpos) |
---|
2705 | Â Â Â Â Â Â Â Â Â Â else: |
---|
2706 | Â Â Â Â Â Â Â Â Â Â Â Â r,p =Â 2.*npatand(z),npatan2d(ypos,xpos) |
---|
2707 | Â Â Â Â Â Â Â Â Â Â pf =Â G2lat.polfcal(ODFln,SamSym[textureData['Model']],np.array([r,]),np.array([p,])) |
---|
2708 | Â Â Â Â Â Â Â Â Â Â G2frame.G2plotNB.status.SetFields(['','phi =%9.3f, gam =%9.3f, MRD =%9.3f'%(r,p,pf)]) |
---|
2709 | Â Â |
---|
2710 | Â Â try: |
---|
2711 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index('Texture') |
---|
2712 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
2713 | Â Â Â Â Page.figure.clf() |
---|
2714 | Â Â Â Â Plot =Â Page.figure.gca() |
---|
2715 |     if not Page.IsShown(): |
---|
2716 | Â Â Â Â Â Â Page.Show() |
---|
2717 |   except ValueError: |
---|
2718 | Â Â Â Â Plot =Â G2frame.G2plotNB.addMpl('Texture').gca() |
---|
2719 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index('Texture') |
---|
2720 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
2721 |     Page.canvas.mpl_connect('motion_notify_event', OnMotion) |
---|
2722 | |
---|
2723 | Â Â Page.Choice =Â None |
---|
2724 | Â Â Page.SetFocus() |
---|
2725 | Â Â G2frame.G2plotNB.status.SetFields(['',''])Â Â |
---|
2726 | Â Â PH =Â np.array(SHData['PFhkl']) |
---|
2727 | Â Â phi,beta =Â G2lat.CrsAng(PH,cell,SGData) |
---|
2728 | Â Â ODFln =Â G2lat.Flnh(Start,SHCoef,phi,beta,SGData) |
---|
2729 | Â Â PX =Â np.array(SHData['PFxyz']) |
---|
2730 | Â Â gam =Â atan2d(PX[0],PX[1]) |
---|
2731 | Â Â xy =Â math.sqrt(PX[0]**2+PX[1]**2) |
---|
2732 | Â Â xyz =Â math.sqrt(PX[0]**2+PX[1]**2+PX[2]**2) |
---|
2733 | Â Â psi =Â asind(xy/xyz) |
---|
2734 | Â Â IODFln =Â G2lat.Glnh(Start,SHCoef,psi,gam,SamSym[textureData['Model']]) |
---|
2735 |   if 'Axial' in SHData['PlotType']: |
---|
2736 | Â Â Â Â X =Â np.linspace(0,90.0,26) |
---|
2737 | Â Â Â Â Y =Â G2lat.polfcal(ODFln,SamSym[textureData['Model']],X,0.0) |
---|
2738 | Â Â Â Â Plot.plot(X,Y,color='k',label=str(SHData['PFhkl'])) |
---|
2739 | Â Â Â Â Plot.legend(loc='best') |
---|
2740 | Â Â Â Â Plot.set_title('Axial distribution for HKL='+str(SHData['PFhkl'])) |
---|
2741 | Â Â Â Â Plot.set_xlabel(r'$\psi$',fontsize=16) |
---|
2742 | Â Â Â Â Plot.set_ylabel('MRD',fontsize=14) |
---|
2743 | Â Â Â Â |
---|
2744 | Â Â else:Â Â Â Â |
---|
2745 | Â Â Â Â npts =Â 201 |
---|
2746 |     if 'Inverse' in SHData['PlotType']: |
---|
2747 | Â Â Â Â Â Â X,Y =Â np.meshgrid(np.linspace(1.,-1.,npts),np.linspace(-1.,1.,npts)) |
---|
2748 | Â Â Â Â Â Â R,P =Â np.sqrt(X**2+Y**2).flatten(),npatan2d(X,Y).flatten() |
---|
2749 |       if 'equal' in G2frame.Projection: |
---|
2750 | Â Â Â Â Â Â Â Â R =Â np.where(R <=Â 1.,2.*npasind(R*sq2),0.0) |
---|
2751 | Â Â Â Â Â Â else: |
---|
2752 | Â Â Â Â Â Â Â Â R =Â np.where(R <=Â 1.,2.*npatand(R),0.0) |
---|
2753 | Â Â Â Â Â Â Z =Â np.zeros_like(R) |
---|
2754 | Â Â Â Â Â Â Z =Â G2lat.invpolfcal(IODFln,SGData,R,P) |
---|
2755 | Â Â Â Â Â Â Z =Â np.reshape(Z,(npts,npts)) |
---|
2756 | Â Â Â Â Â Â CS =Â Plot.contour(Y,X,Z,aspect='equal') |
---|
2757 | Â Â Â Â Â Â Plot.clabel(CS,fontsize=9,inline=1) |
---|
2758 | Â Â Â Â Â Â try: |
---|
2759 | Â Â Â Â Â Â Â Â Img =Â Plot.imshow(Z.T,aspect='equal',cmap=G2frame.ContourColor,extent=[-1,1,-1,1]) |
---|
2760 |       except ValueError: |
---|
2761 | Â Â Â Â Â Â Â Â pass |
---|
2762 | Â Â Â Â Â Â Page.figure.colorbar(Img) |
---|
2763 | Â Â Â Â Â Â Plot.set_title('Inverse pole figure for XYZ='+str(SHData['PFxyz'])) |
---|
2764 | Â Â Â Â Â Â Plot.set_xlabel(G2frame.Projection.capitalize()+' projection') |
---|
2765 | Â Â Â Â Â Â Â Â Â Â Â Â |
---|
2766 | Â Â Â Â else: |
---|
2767 | Â Â Â Â Â Â X,Y =Â np.meshgrid(np.linspace(1.,-1.,npts),np.linspace(-1.,1.,npts)) |
---|
2768 | Â Â Â Â Â Â R,P =Â np.sqrt(X**2+Y**2).flatten(),npatan2d(X,Y).flatten() |
---|
2769 |       if 'equal' in G2frame.Projection: |
---|
2770 | Â Â Â Â Â Â Â Â R =Â np.where(R <=Â 1.,2.*npasind(R*sq2),0.0) |
---|
2771 | Â Â Â Â Â Â else: |
---|
2772 | Â Â Â Â Â Â Â Â R =Â np.where(R <=Â 1.,2.*npatand(R),0.0) |
---|
2773 | Â Â Â Â Â Â Z =Â np.zeros_like(R) |
---|
2774 | Â Â Â Â Â Â Z =Â G2lat.polfcal(ODFln,SamSym[textureData['Model']],R,P) |
---|
2775 | Â Â Â Â Â Â Z =Â np.reshape(Z,(npts,npts)) |
---|
2776 | Â Â Â Â Â Â try: |
---|
2777 | Â Â Â Â Â Â Â Â CS =Â Plot.contour(Y,X,Z,aspect='equal') |
---|
2778 | Â Â Â Â Â Â Â Â Plot.clabel(CS,fontsize=9,inline=1) |
---|
2779 |       except ValueError: |
---|
2780 | Â Â Â Â Â Â Â Â pass |
---|
2781 | Â Â Â Â Â Â Img =Â Plot.imshow(Z.T,aspect='equal',cmap=G2frame.ContourColor,extent=[-1,1,-1,1]) |
---|
2782 | Â Â Â Â Â Â Page.figure.colorbar(Img) |
---|
2783 | Â Â Â Â Â Â Plot.set_title('Pole figure for HKL='+str(SHData['PFhkl'])) |
---|
2784 | Â Â Â Â Â Â Plot.set_xlabel(G2frame.Projection.capitalize()+' projection') |
---|
2785 | Â Â Page.canvas.draw() |
---|
2786 | |
---|
2787 | ################################################################################ |
---|
2788 | ##### Plot Modulation |
---|
2789 | ################################################################################ |
---|
2790 | |
---|
2791 | def ModulationPlot(G2frame,data,atom,ax,off=0): |
---|
2792 |   global Off,Atom,Ax |
---|
2793 | Â Â Off =Â off |
---|
2794 | Â Â Atom =Â atom |
---|
2795 | Â Â Ax =Â ax |
---|
2796 |   def OnMotion(event): |
---|
2797 | Â Â Â Â xpos =Â event.xdata |
---|
2798 |     if xpos:                    #avoid out of frame mouse position |
---|
2799 | Â Â Â Â Â Â ypos =Â event.ydata |
---|
2800 | Â Â Â Â Â Â Page.canvas.SetCursor(wx.CROSS_CURSOR) |
---|
2801 | Â Â Â Â Â Â try: |
---|
2802 |         G2frame.G2plotNB.status.SetStatusText('t =%9.3f %s =%9.3f'%(xpos,GkDelta+Ax,ypos),1)          |
---|
2803 |       except TypeError: |
---|
2804 | Â Â Â Â Â Â Â Â G2frame.G2plotNB.status.SetStatusText('Select '+Title+' pattern first',1) |
---|
2805 | Â Â |
---|
2806 |   def OnPlotKeyPress(event): |
---|
2807 |     global Off,Atom,Ax |
---|
2808 | Â Â Â Â newPlot =Â False |
---|
2809 |     if event.key == '0': |
---|
2810 | Â Â Â Â Â Â Off =Â 0 |
---|
2811 |     elif event.key in ['+','=']: |
---|
2812 | Â Â Â Â Â Â Off +=Â 1 |
---|
2813 |     elif event.key == '-': |
---|
2814 | Â Â Â Â Â Â Off -=Â 1 |
---|
2815 |     elif event.key in ['l','r',] and mapData['Flip']: |
---|
2816 | Â Â Â Â Â Â roll =Â 1 |
---|
2817 |       if event.key == 'l': |
---|
2818 | Â Â Â Â Â Â Â Â roll =Â -1 |
---|
2819 | Â Â Â Â Â Â rho =Â Map['rho'] |
---|
2820 | Â Â Â Â Â Â Map['rho']Â =Â np.roll(rho,roll,axis=3) |
---|
2821 | Â Â Â Â wx.CallAfter(ModulationPlot,G2frame,data,Atom,Ax,Off) |
---|
2822 | |
---|
2823 | Â Â try: |
---|
2824 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index('Modulation') |
---|
2825 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
2826 | Â Â Â Â Page.figure.clf() |
---|
2827 | Â Â Â Â Plot =Â Page.figure.gca() |
---|
2828 |     if not Page.IsShown(): |
---|
2829 | Â Â Â Â Â Â Page.Show() |
---|
2830 |   except ValueError: |
---|
2831 | Â Â Â Â Plot =Â G2frame.G2plotNB.addMpl('Modulation').gca() |
---|
2832 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index('Modulation') |
---|
2833 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
2834 |     Page.canvas.mpl_connect('motion_notify_event', OnMotion) |
---|
2835 |     Page.canvas.mpl_connect('key_press_event', OnPlotKeyPress) |
---|
2836 | Â Â |
---|
2837 | Â Â Page.SetFocus() |
---|
2838 | Â Â General =Â data['General'] |
---|
2839 | Â Â cx,ct,cs,cia =Â General['AtomPtrs'] |
---|
2840 | Â Â mapData =Â General['Map'] |
---|
2841 |   if mapData['Flip']: |
---|
2842 | Â Â Â Â Page.Choice =Â ['+: shift up','-: shift down','0: reset shift','l: move left','r: move right'] |
---|
2843 | Â Â else: |
---|
2844 | Â Â Â Â Page.Choice =Â ['+: shift up','-: shift down','0: reset shift'] |
---|
2845 | Â Â Page.keyPress =Â OnPlotKeyPress |
---|
2846 | Â Â Map =Â General['4DmapData'] |
---|
2847 | Â Â MapType =Â Map['MapType'] |
---|
2848 | Â Â rhoSize =Â np.array(Map['rho'].shape) |
---|
2849 | Â Â atxyz =Â np.array(atom[cx:cx+3]) |
---|
2850 | Â Â waveType =Â atom[-1]['SS1']['waveType'] |
---|
2851 | Â Â Spos =Â atom[-1]['SS1']['Spos'] |
---|
2852 | Â Â tau =Â np.linspace(0.,2.,101) |
---|
2853 | Â Â wave =Â np.zeros((3,101)) |
---|
2854 |   if len(Spos): |
---|
2855 | Â Â Â Â scof =Â [] |
---|
2856 | Â Â Â Â ccof =Â [] |
---|
2857 |     for i,spos in enumerate(Spos): |
---|
2858 |       if waveType in ['Sawtooth','ZigZag'] and not i: |
---|
2859 | Â Â Â Â Â Â Â Â Toff =Â spos[0][0] |
---|
2860 | Â Â Â Â Â Â Â Â slopes =Â np.array(spos[0][1:]) |
---|
2861 |         if waveType == 'Sawtooth': |
---|
2862 | Â Â Â Â Â Â Â Â Â Â wave =Â G2mth.posSawtooth(tau,Toff,slopes) |
---|
2863 |         elif waveType == 'ZigZag': |
---|
2864 | Â Â Â Â Â Â Â Â Â Â wave =Â G2mth.posZigZag(tau,Toff,slopes) |
---|
2865 | Â Â Â Â Â Â else: |
---|
2866 | Â Â Â Â Â Â Â Â scof.append(spos[0][:3]) |
---|
2867 | Â Â Â Â Â Â Â Â ccof.append(spos[0][3:]) |
---|
2868 | Â Â Â Â wave +=Â G2mth.posFourier(tau,np.array(scof),np.array(ccof)) |
---|
2869 |   if mapData['Flip']: |
---|
2870 | Â Â Â Â Title =Â 'Charge flip' |
---|
2871 | Â Â else: |
---|
2872 | Â Â Â Â Title =Â MapType |
---|
2873 | Â Â Title +=Â ' map for atom '+atom[0]+Â Â \ |
---|
2874 |     ' at %.4f %.4f %.4f'%(atxyz[0],atxyz[1],atxyz[2]) |
---|
2875 | Â Â ix =Â -np.array(np.rint(rhoSize[:3]*atxyz),dtype='i') |
---|
2876 | Â Â ix +=Â (rhoSize[:3]/2) |
---|
2877 | Â Â ix =Â ix%rhoSize[:3] |
---|
2878 | Â Â rho =Â np.roll(np.roll(np.roll(Map['rho'],ix[0],axis=0),ix[1],axis=1),ix[2],axis=2) |
---|
2879 | Â Â ix =Â rhoSize[:3]/2 |
---|
2880 | Â Â ib =Â 4 |
---|
2881 |   if Ax == 'x': |
---|
2882 | Â Â Â Â slab =Â np.sum(np.sum(rho[:,ix[1]-ib:ix[1]+ib,ix[2]-ib:ix[2]+ib,:],axis=2),axis=1) |
---|
2883 | Â Â Â Â Plot.plot(tau,wave[0]) |
---|
2884 |   elif Ax == 'y': |
---|
2885 | Â Â Â Â slab =Â np.sum(np.sum(rho[ix[0]-ib:ix[0]+ib,:,ix[2]-ib:ix[2]+ib,:],axis=2),axis=0) |
---|
2886 | Â Â Â Â Plot.plot(tau,wave[1]) |
---|
2887 |   elif Ax == 'z': |
---|
2888 | Â Â Â Â slab =Â np.sum(np.sum(rho[ix[0]-ib:ix[0]+ib,ix[1]-ib:ix[1]+ib,:,:],axis=1),axis=0) |
---|
2889 | Â Â Â Â Plot.plot(tau,wave[2]) |
---|
2890 | Â Â Plot.set_title(Title) |
---|
2891 | Â Â Plot.set_xlabel('t') |
---|
2892 | Â Â Plot.set_ylabel(r'$\mathsf{\Delta}$%s'%(Ax)) |
---|
2893 | Â Â Slab =Â np.hstack((slab,slab,slab)) |
---|
2894 | Â Â Plot.contour(Slab[:,:21],20,extent=(0.,2.,-.5+Off*.005,.5+Off*.005)) |
---|
2895 | Â Â Page.canvas.draw() |
---|
2896 | Â Â |
---|
2897 | ################################################################################ |
---|
2898 | ##### PlotCovariance |
---|
2899 | ################################################################################ |
---|
2900 | Â Â Â Â Â Â |
---|
2901 | def PlotCovariance(G2frame,Data): |
---|
2902 | Â Â 'needs a doc string' |
---|
2903 |   if not Data: |
---|
2904 |     print 'No covariance matrix available' |
---|
2905 | Â Â Â Â return |
---|
2906 | Â Â varyList =Â Data['varyList'] |
---|
2907 | Â Â values =Â Data['variables'] |
---|
2908 | Â Â Xmax =Â len(varyList) |
---|
2909 | Â Â covMatrix =Â Data['covMatrix'] |
---|
2910 | Â Â sig =Â np.sqrt(np.diag(covMatrix)) |
---|
2911 | Â Â xvar =Â np.outer(sig,np.ones_like(sig)) |
---|
2912 | Â Â covArray =Â np.divide(np.divide(covMatrix,xvar),xvar.T) |
---|
2913 | Â Â title =Â ' for\n'+Data['title'] |
---|
2914 | Â Â newAtomDict =Â Data.get('newAtomDict',{}) |
---|
2915 | Â Â G2frame.G2plotNB.Delete('Covariance') |
---|
2916 | Â Â |
---|
2917 | |
---|
2918 |   def OnPlotKeyPress(event): |
---|
2919 | Â Â Â Â newPlot =Â False |
---|
2920 |     if event.key == 's': |
---|
2921 |       choice = [m for m in mpl.cm.datad.keys() if not m.endswith("_r")] |
---|
2922 | Â Â Â Â Â Â choice.sort() |
---|
2923 | Â Â Â Â Â Â dlg =Â wx.SingleChoiceDialog(G2frame,'Select','Color scheme',choice) |
---|
2924 |       if dlg.ShowModal() == wx.ID_OK: |
---|
2925 | Â Â Â Â Â Â Â Â sel =Â dlg.GetSelection() |
---|
2926 | Â Â Â Â Â Â Â Â G2frame.VcovColor =Â choice[sel] |
---|
2927 | Â Â Â Â Â Â else: |
---|
2928 | Â Â Â Â Â Â Â Â G2frame.VcovColor =Â 'RdYlGn' |
---|
2929 | Â Â Â Â Â Â dlg.Destroy() |
---|
2930 | Â Â Â Â PlotCovariance(G2frame,Data) |
---|
2931 | |
---|
2932 |   def OnMotion(event): |
---|
2933 |     if event.button: |
---|
2934 | Â Â Â Â Â Â ytics =Â imgAx.get_yticks() |
---|
2935 | Â Â Â Â Â Â ytics =Â np.where(ytics<len(varyList),ytics,-1) |
---|
2936 |       ylabs = [np.where(0<=i ,varyList[int(i)],' ') for i in ytics] |
---|
2937 | Â Â Â Â Â Â imgAx.set_yticklabels(ylabs)Â Â Â Â Â Â |
---|
2938 |     if event.xdata and event.ydata:         #avoid out of frame errors |
---|
2939 | Â Â Â Â Â Â xpos =Â int(event.xdata+.5) |
---|
2940 | Â Â Â Â Â Â ypos =Â int(event.ydata+.5) |
---|
2941 |       if -1 < xpos < len(varyList) and -1 < ypos < len(varyList): |
---|
2942 |         if xpos == ypos: |
---|
2943 | Â Â Â Â Â Â Â Â Â Â value =Â values[xpos] |
---|
2944 | Â Â Â Â Â Â Â Â Â Â name =Â varyList[xpos] |
---|
2945 |           if varyList[xpos] in newAtomDict: |
---|
2946 | Â Â Â Â Â Â Â Â Â Â Â Â name,value =Â newAtomDict[name]Â Â Â Â Â Â Â Â Â Â Â Â |
---|
2947 |           msg = '%s value = %.4g, esd = %.4g'%(name,value,sig[xpos]) |
---|
2948 | Â Â Â Â Â Â Â Â else: |
---|
2949 |           msg = '%s - %s: %5.3f'%(varyList[xpos],varyList[ypos],covArray[xpos][ypos]) |
---|
2950 | Â Â Â Â Â Â Â Â Page.canvas.SetToolTipString(msg) |
---|
2951 | Â Â Â Â Â Â Â Â G2frame.G2plotNB.status.SetFields(['',msg]) |
---|
2952 | Â Â Â Â Â Â Â Â |
---|
2953 | Â Â try: |
---|
2954 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index('Covariance') |
---|
2955 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
2956 | Â Â Â Â Page.figure.clf() |
---|
2957 | Â Â Â Â Plot =Â Page.figure.gca() |
---|
2958 |     if not Page.IsShown(): |
---|
2959 | Â Â Â Â Â Â Page.Show() |
---|
2960 |   except ValueError: |
---|
2961 | Â Â Â Â Plot =Â G2frame.G2plotNB.addMpl('Covariance').gca() |
---|
2962 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index('Covariance') |
---|
2963 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
2964 |     Page.canvas.mpl_connect('motion_notify_event', OnMotion) |
---|
2965 |     Page.canvas.mpl_connect('key_press_event', OnPlotKeyPress) |
---|
2966 | Â Â Page.Choice =Â ['s: to change colors'] |
---|
2967 | Â Â Page.keyPress =Â OnPlotKeyPress |
---|
2968 | Â Â Page.SetFocus() |
---|
2969 | Â Â G2frame.G2plotNB.status.SetFields(['',''])Â Â |
---|
2970 | Â Â acolor =Â mpl.cm.get_cmap(G2frame.VcovColor) |
---|
2971 | Â Â Img =Â Plot.imshow(covArray,aspect='equal',cmap=acolor,interpolation='nearest',origin='lower', |
---|
2972 | Â Â Â Â vmin=-1.,vmax=1.) |
---|
2973 | Â Â imgAx =Â Img.get_axes() |
---|
2974 | Â Â ytics =Â imgAx.get_yticks() |
---|
2975 |   ylabs = [varyList[int(i)] for i in ytics[:-1]] |
---|
2976 | Â Â imgAx.set_yticklabels(ylabs) |
---|
2977 | Â Â colorBar =Â Page.figure.colorbar(Img) |
---|
2978 | Â Â Plot.set_title('V-Cov matrix'+title) |
---|
2979 | Â Â Plot.set_xlabel('Variable number') |
---|
2980 | Â Â Plot.set_ylabel('Variable name') |
---|
2981 | Â Â Page.canvas.draw() |
---|
2982 | Â Â |
---|
2983 | ################################################################################ |
---|
2984 | ##### PlotTorsion |
---|
2985 | ################################################################################ |
---|
2986 | |
---|
2987 | def PlotTorsion(G2frame,phaseName,Torsion,TorName,Names=[],Angles=[],Coeff=[]): |
---|
2988 | Â Â 'needs a doc string' |
---|
2989 | Â Â |
---|
2990 |   global names |
---|
2991 | Â Â names =Â Names |
---|
2992 |   sum = np.sum(Torsion) |
---|
2993 | Â Â torsion =Â np.log(2*Torsion+1.)/sum |
---|
2994 | Â Â tMin =Â np.min(torsion) |
---|
2995 | Â Â tMax =Â np.max(torsion) |
---|
2996 | Â Â torsion =Â 3.*(torsion-tMin)/(tMax-tMin) |
---|
2997 | Â Â X =Â np.linspace(0.,360.,num=45) |
---|
2998 | Â Â |
---|
2999 |   def OnPick(event): |
---|
3000 | Â Â Â Â ind =Â event.ind[0] |
---|
3001 | Â Â Â Â msg =Â 'atoms:'+names[ind] |
---|
3002 | Â Â Â Â Page.canvas.SetToolTipString(msg) |
---|
3003 | Â Â Â Â try: |
---|
3004 | Â Â Â Â Â Â page =Â G2frame.dataDisplay.GetSelection() |
---|
3005 | Â Â Â Â except: |
---|
3006 | Â Â Â Â Â Â return |
---|
3007 |     if G2frame.dataDisplay.GetPageText(page) == 'Torsion restraints': |
---|
3008 | Â Â Â Â Â Â torGrid =Â G2frame.dataDisplay.GetPage(page).Torsions |
---|
3009 | Â Â Â Â Â Â torGrid.ClearSelection() |
---|
3010 |       for row in range(torGrid.GetNumberRows()): |
---|
3011 |         if names[ind] in torGrid.GetCellValue(row,0): |
---|
3012 | Â Â Â Â Â Â Â Â Â Â torGrid.SelectRow(row) |
---|
3013 | Â Â Â Â Â Â torGrid.ForceRefresh() |
---|
3014 | Â Â Â Â Â Â Â Â |
---|
3015 |   def OnMotion(event): |
---|
3016 |     if event.xdata and event.ydata:         #avoid out of frame errors |
---|
3017 | Â Â Â Â Â Â xpos =Â event.xdata |
---|
3018 | Â Â Â Â Â Â ypos =Â event.ydata |
---|
3019 |       msg = 'torsion,energy: %5.3f %5.3f'%(xpos,ypos) |
---|
3020 | Â Â Â Â Â Â Page.canvas.SetToolTipString(msg) |
---|
3021 | |
---|
3022 | Â Â try: |
---|
3023 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index('Torsion') |
---|
3024 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
3025 | Â Â Â Â Page.figure.clf() |
---|
3026 | Â Â Â Â Plot =Â Page.figure.gca() |
---|
3027 |     if not Page.IsShown(): |
---|
3028 | Â Â Â Â Â Â Page.Show() |
---|
3029 |   except ValueError: |
---|
3030 | Â Â Â Â Plot =Â G2frame.G2plotNB.addMpl('Torsion').gca() |
---|
3031 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index('Torsion') |
---|
3032 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
3033 |     Page.canvas.mpl_connect('pick_event', OnPick) |
---|
3034 |     Page.canvas.mpl_connect('motion_notify_event', OnMotion) |
---|
3035 | Â Â |
---|
3036 | Â Â Page.SetFocus() |
---|
3037 | Â Â G2frame.G2plotNB.status.SetFields(['','Use mouse LB to identify torsion atoms']) |
---|
3038 | Â Â Plot.plot(X,torsion,'b+') |
---|
3039 |   if len(Coeff): |
---|
3040 | Â Â Â Â X2 =Â np.linspace(0.,360.,45) |
---|
3041 |     Y2 = np.array([-G2mth.calcTorsionEnergy(x,Coeff)[1] for x in X2]) |
---|
3042 | Â Â Â Â Plot.plot(X2,Y2,'r') |
---|
3043 |   if len(Angles): |
---|
3044 |     Eval = np.array([-G2mth.calcTorsionEnergy(x,Coeff)[1] for x in Angles]) |
---|
3045 | Â Â Â Â Plot.plot(Angles,Eval,'ro',picker=5) |
---|
3046 | Â Â Plot.set_xlim((0.,360.)) |
---|
3047 | Â Â Plot.set_title('Torsion angles for '+TorName+' in '+phaseName) |
---|
3048 | Â Â Plot.set_xlabel('angle',fontsize=16) |
---|
3049 | Â Â Plot.set_ylabel('Energy',fontsize=16) |
---|
3050 | Â Â Page.canvas.draw() |
---|
3051 | Â Â |
---|
3052 | ################################################################################ |
---|
3053 | ##### PlotRama |
---|
3054 | ################################################################################ |
---|
3055 | |
---|
3056 | def PlotRama(G2frame,phaseName,Rama,RamaName,Names=[],PhiPsi=[],Coeff=[]): |
---|
3057 | Â Â 'needs a doc string' |
---|
3058 | |
---|
3059 |   global names |
---|
3060 | Â Â names =Â Names |
---|
3061 | Â Â rama =Â np.log(2*Rama+1.) |
---|
3062 | Â Â ramaMax =Â np.max(rama) |
---|
3063 | Â Â rama =Â np.reshape(rama,(45,45)) |
---|
3064 |   global Phi,Psi |
---|
3065 | Â Â Phi =Â [] |
---|
3066 | Â Â Psi =Â [] |
---|
3067 | |
---|
3068 |   def OnPlotKeyPress(event): |
---|
3069 | Â Â Â Â newPlot =Â False |
---|
3070 |     if event.key == 's': |
---|
3071 |       choice = [m for m in mpl.cm.datad.keys() if not m.endswith("_r")] |
---|
3072 | Â Â Â Â Â Â choice.sort() |
---|
3073 | Â Â Â Â Â Â dlg =Â wx.SingleChoiceDialog(G2frame,'Select','Color scheme',choice) |
---|
3074 |       if dlg.ShowModal() == wx.ID_OK: |
---|
3075 | Â Â Â Â Â Â Â Â sel =Â dlg.GetSelection() |
---|
3076 | Â Â Â Â Â Â Â Â G2frame.RamaColor =Â choice[sel] |
---|
3077 | Â Â Â Â Â Â else: |
---|
3078 | Â Â Â Â Â Â Â Â G2frame.RamaColor =Â 'RdYlGn' |
---|
3079 | Â Â Â Â Â Â dlg.Destroy() |
---|
3080 | Â Â Â Â PlotRama(G2frame,phaseName,Rama) |
---|
3081 | |
---|
3082 |   def OnPick(event): |
---|
3083 | Â Â Â Â ind =Â event.ind[0] |
---|
3084 | Â Â Â Â msg =Â 'atoms:'+names[ind] |
---|
3085 | Â Â Â Â Page.canvas.SetToolTipString(msg) |
---|
3086 | Â Â Â Â try: |
---|
3087 | Â Â Â Â Â Â page =Â G2frame.dataDisplay.GetSelection() |
---|
3088 | Â Â Â Â except: |
---|
3089 | Â Â Â Â Â Â return |
---|
3090 |     if G2frame.dataDisplay.GetPageText(page) == 'Ramachandran restraints': |
---|
3091 | Â Â Â Â Â Â ramaGrid =Â G2frame.dataDisplay.GetPage(page).Ramas |
---|
3092 | Â Â Â Â Â Â ramaGrid.ClearSelection() |
---|
3093 |       for row in range(ramaGrid.GetNumberRows()): |
---|
3094 |         if names[ind] in ramaGrid.GetCellValue(row,0): |
---|
3095 | Â Â Â Â Â Â Â Â Â Â ramaGrid.SelectRow(row) |
---|
3096 | Â Â Â Â Â Â ramaGrid.ForceRefresh() |
---|
3097 | |
---|
3098 |   def OnMotion(event): |
---|
3099 |     if event.xdata and event.ydata:         #avoid out of frame errors |
---|
3100 | Â Â Â Â Â Â xpos =Â event.xdata |
---|
3101 | Â Â Â Â Â Â ypos =Â event.ydata |
---|
3102 |       msg = 'phi/psi: %5.3f %5.3f'%(xpos,ypos) |
---|
3103 | Â Â Â Â Â Â Page.canvas.SetToolTipString(msg) |
---|
3104 | Â Â Â Â Â Â |
---|
3105 | Â Â try: |
---|
3106 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index('Ramachandran') |
---|
3107 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
3108 | Â Â Â Â Page.figure.clf() |
---|
3109 | Â Â Â Â Plot =Â Page.figure.gca() |
---|
3110 |     if not Page.IsShown(): |
---|
3111 | Â Â Â Â Â Â Page.Show() |
---|
3112 |   except ValueError: |
---|
3113 | Â Â Â Â Plot =Â G2frame.G2plotNB.addMpl('Ramachandran').gca() |
---|
3114 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index('Ramachandran') |
---|
3115 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
3116 |     Page.canvas.mpl_connect('pick_event', OnPick) |
---|
3117 |     Page.canvas.mpl_connect('motion_notify_event', OnMotion) |
---|
3118 |     Page.canvas.mpl_connect('key_press_event', OnPlotKeyPress) |
---|
3119 | |
---|
3120 | Â Â Page.Choice =Â ['s: to change colors'] |
---|
3121 | Â Â Page.keyPress =Â OnPlotKeyPress |
---|
3122 | Â Â Page.SetFocus() |
---|
3123 | Â Â G2frame.G2plotNB.status.SetFields(['','Use mouse LB to identify phi/psi atoms']) |
---|
3124 | Â Â acolor =Â mpl.cm.get_cmap(G2frame.RamaColor) |
---|
3125 |   if RamaName == 'All' or '-1' in RamaName: |
---|
3126 |     if len(Coeff): |
---|
3127 | Â Â Â Â Â Â X,Y =Â np.meshgrid(np.linspace(-180.,180.,45),np.linspace(-180.,180.,45)) |
---|
3128 |       Z = np.array([-G2mth.calcRamaEnergy(x,y,Coeff)[1] for x,y in zip(X.flatten(),Y.flatten())]) |
---|
3129 | Â Â Â Â Â Â Plot.contour(X,Y,np.reshape(Z,(45,45))) |
---|
3130 | Â Â Â Â Img =Â Plot.imshow(rama,aspect='equal',cmap=acolor,interpolation='nearest', |
---|
3131 | Â Â Â Â Â Â extent=[-180,180,-180,180],origin='lower') |
---|
3132 |     if len(PhiPsi): |
---|
3133 | Â Â Â Â Â Â Phi,Psi =Â PhiPsi.T |
---|
3134 | Â Â Â Â Â Â Phi =Â np.where(Phi>180.,Phi-360.,Phi) |
---|
3135 | Â Â Â Â Â Â Psi =Â np.where(Psi>180.,Psi-360.,Psi) |
---|
3136 | Â Â Â Â Â Â Plot.plot(Phi,Psi,'ro',picker=5) |
---|
3137 | Â Â Â Â Plot.set_xlim((-180.,180.)) |
---|
3138 | Â Â Â Â Plot.set_ylim((-180.,180.)) |
---|
3139 | Â Â else: |
---|
3140 |     if len(Coeff): |
---|
3141 | Â Â Â Â Â Â X,Y =Â np.meshgrid(np.linspace(0.,360.,45),np.linspace(0.,360.,45)) |
---|
3142 |       Z = np.array([-G2mth.calcRamaEnergy(x,y,Coeff)[1] for x,y in zip(X.flatten(),Y.flatten())]) |
---|
3143 | Â Â Â Â Â Â Plot.contour(X,Y,np.reshape(Z,(45,45))) |
---|
3144 | Â Â Â Â Img =Â Plot.imshow(rama,aspect='equal',cmap=acolor,interpolation='nearest', |
---|
3145 | Â Â Â Â Â Â extent=[0,360,0,360],origin='lower') |
---|
3146 |     if len(PhiPsi): |
---|
3147 | Â Â Â Â Â Â Phi,Psi =Â PhiPsi.T |
---|
3148 | Â Â Â Â Â Â Plot.plot(Phi,Psi,'ro',picker=5) |
---|
3149 | Â Â Â Â Plot.set_xlim((0.,360.)) |
---|
3150 | Â Â Â Â Plot.set_ylim((0.,360.)) |
---|
3151 | Â Â Plot.set_title('Ramachandran for '+RamaName+' in '+phaseName) |
---|
3152 | Â Â Plot.set_xlabel(r'$\phi$',fontsize=16) |
---|
3153 | Â Â Plot.set_ylabel(r'$\psi$',fontsize=16) |
---|
3154 | Â Â colorBar =Â Page.figure.colorbar(Img) |
---|
3155 | Â Â Page.canvas.draw() |
---|
3156 | |
---|
3157 | |
---|
3158 | ################################################################################ |
---|
3159 | ##### PlotSeq |
---|
3160 | ################################################################################ |
---|
3161 | def PlotSelectedSequence(G2frame,ColumnList,TableGet,SelectX,fitnum=None,fitvals=None): |
---|
3162 | Â Â '''Plot a result from a sequential refinement |
---|
3163 | |
---|
3164 | Â Â :param wx.Frame G2frame: The main GSAS-II tree "window" |
---|
3165 | Â Â :param list ColumnList: list of int values corresponding to columns |
---|
3166 | Â Â Â selected as y values |
---|
3167 | Â Â :param function TableGet: a function that takes a column number |
---|
3168 | Â Â Â as argument and returns the column label, the values and there ESDs (or None) |
---|
3169 | Â Â :param function SelectX: a function that returns a selected column |
---|
3170 | Â Â Â number (or None) as the X-axis selection |
---|
3171 | Â Â ''' |
---|
3172 |   global Title,xLabel,yLabel |
---|
3173 | Â Â xLabel =Â yLabel =Â Title =Â '' |
---|
3174 |   def OnMotion(event): |
---|
3175 |     if event.xdata and event.ydata:         #avoid out of frame errors |
---|
3176 | Â Â Â Â Â Â xpos =Â event.xdata |
---|
3177 | Â Â Â Â Â Â ypos =Â event.ydata |
---|
3178 |       msg = '%5.3f %.6g'%(xpos,ypos) |
---|
3179 | Â Â Â Â Â Â Page.canvas.SetToolTipString(msg) |
---|
3180 | |
---|
3181 |   def OnKeyPress(event): |
---|
3182 |     global Title,xLabel,yLabel |
---|
3183 |     if event.key == 's': |
---|
3184 | Â Â Â Â Â Â G2frame.seqXaxis =Â G2frame.seqXselect() |
---|
3185 | Â Â Â Â Â Â Draw() |
---|
3186 |     elif event.key == 't': |
---|
3187 | Â Â Â Â Â Â dlg =Â G2gd.MultiStringDialog(G2frame,'Set titles & labels',[' Title ',' x-Label ',' y-Label '], |
---|
3188 | Â Â Â Â Â Â Â Â [Title,xLabel,yLabel]) |
---|
3189 |       if dlg.Show(): |
---|
3190 | Â Â Â Â Â Â Â Â Title,xLabel,yLabel =Â dlg.GetValues() |
---|
3191 | Â Â Â Â Â Â dlg.Destroy() |
---|
3192 | Â Â Â Â Â Â Draw() |
---|
3193 | Â Â Â Â Â Â |
---|
3194 |   def Draw(): |
---|
3195 |     global Title,xLabel,yLabel |
---|
3196 | Â Â Â Â Page.SetFocus() |
---|
3197 | Â Â Â Â G2frame.G2plotNB.status.SetStatusText('press s to select X axis, t to change titles',1) |
---|
3198 | Â Â Â Â Plot.clear() |
---|
3199 |     if G2frame.seqXaxis is not None:  |
---|
3200 | Â Â Â Â Â Â xName,X,Xsig =Â Page.seqTableGet(G2frame.seqXaxis) |
---|
3201 | Â Â Â Â else: |
---|
3202 | Â Â Â Â Â Â X =Â np.arange(0,G2frame.SeqTable.GetNumberRows(),1) |
---|
3203 | Â Â Â Â Â Â xName =Â 'Data sequence number' |
---|
3204 |     for col in Page.seqYaxisList: |
---|
3205 | Â Â Â Â Â Â name,Y,sig =Â Page.seqTableGet(col) |
---|
3206 | Â Â Â Â Â Â # deal with missing (None) values |
---|
3207 | Â Â Â Â Â Â Xnew =Â [] |
---|
3208 | Â Â Â Â Â Â Ynew =Â [] |
---|
3209 | Â Â Â Â Â Â Ysnew =Â [] |
---|
3210 |       for i in range(len(X)): |
---|
3211 |         if X[i] is None or Y[i] is None: continue |
---|
3212 | Â Â Â Â Â Â Â Â Xnew.append(X[i]) |
---|
3213 | Â Â Â Â Â Â Â Â Ynew.append(Y[i]) |
---|
3214 |         if sig: Ysnew.append(sig[i]) |
---|
3215 |       if Ysnew: |
---|
3216 |         if G2frame.seqReverse and not G2frame.seqXaxis: |
---|
3217 | Â Â Â Â Â Â Â Â Â Â Ynew =Â Ynew[::-1] |
---|
3218 | Â Â Â Â Â Â Â Â Â Â Ysnew =Â Ysnew[::-1] |
---|
3219 | Â Â Â Â Â Â Â Â Plot.errorbar(Xnew,Ynew,yerr=Ysnew,label=name) |
---|
3220 | Â Â Â Â Â Â else: |
---|
3221 |         if G2frame.seqReverse and not G2frame.seqXaxis: |
---|
3222 | Â Â Â Â Â Â Â Â Â Â Ynew =Â Ynew[::-1] |
---|
3223 | Â Â Â Â Â Â Â Â Plot.plot(Xnew,Ynew) |
---|
3224 | Â Â Â Â Â Â Â Â Plot.plot(Xnew,Ynew,'o',label=name) |
---|
3225 |     if Page.fitvals: # TODO: deal with fitting of None values |
---|
3226 |       if G2frame.seqReverse and not G2frame.seqXaxis: |
---|
3227 | Â Â Â Â Â Â Â Â Page.fitvals =Â Page.fitvals[::-1] |
---|
3228 | Â Â Â Â Â Â Plot.plot(X,Page.fitvals,label='Fit') |
---|
3229 | Â Â Â Â Â Â |
---|
3230 | Â Â Â Â Plot.legend(loc='best') |
---|
3231 |     print Title,xLabel,yLabel |
---|
3232 |     if Title: |
---|
3233 | Â Â Â Â Â Â Plot.set_title(Title) |
---|
3234 | Â Â Â Â else: |
---|
3235 | Â Â Â Â Â Â Plot.set_title('') |
---|
3236 |     if xLabel: |
---|
3237 | Â Â Â Â Â Â Plot.set_xlabel(xLabel) |
---|
3238 | Â Â Â Â else: |
---|
3239 | Â Â Â Â Â Â Plot.set_xlabel(xName) |
---|
3240 |     if yLabel: |
---|
3241 | Â Â Â Â Â Â Plot.set_ylabel(yLabel) |
---|
3242 | Â Â Â Â else: |
---|
3243 | Â Â Â Â Â Â Plot.set_ylabel('Parameter values') |
---|
3244 | Â Â Â Â Page.canvas.draw()Â Â Â Â Â Â |
---|
3245 | Â Â Â Â Â Â |
---|
3246 | Â Â G2frame.seqXselect =Â SelectX |
---|
3247 | Â Â try: |
---|
3248 | Â Â Â Â G2frame.seqXaxis |
---|
3249 | Â Â except: |
---|
3250 | Â Â Â Â G2frame.seqXaxis =Â None |
---|
3251 | |
---|
3252 |   if fitnum is None: |
---|
3253 | Â Â Â Â label =Â 'Sequential refinement' |
---|
3254 | Â Â else: |
---|
3255 | Â Â Â Â label =Â 'Parametric fit #'+str(fitnum+1) |
---|
3256 | Â Â try: |
---|
3257 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index(label) |
---|
3258 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
3259 | Â Â Â Â Page.figure.clf() |
---|
3260 | Â Â Â Â Plot =Â Page.figure.gca() |
---|
3261 |     if not Page.IsShown(): |
---|
3262 | Â Â Â Â Â Â Page.Show() |
---|
3263 |   except ValueError: |
---|
3264 | Â Â Â Â Plot =Â G2frame.G2plotNB.addMpl(label).gca() |
---|
3265 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index(label) |
---|
3266 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
3267 |     Page.canvas.mpl_connect('key_press_event', OnKeyPress) |
---|
3268 |     Page.canvas.mpl_connect('motion_notify_event', OnMotion) |
---|
3269 | Â Â Page.Choice =Â ['s - select x-axis','t - change titles',] |
---|
3270 | Â Â Page.keyPress =Â OnKeyPress |
---|
3271 | Â Â Page.seqYaxisList =Â ColumnList |
---|
3272 | Â Â Page.seqTableGet =Â TableGet |
---|
3273 | Â Â Page.fitvals =Â fitvals |
---|
3274 | Â Â Â Â |
---|
3275 | Â Â Draw() |
---|
3276 | Â Â G2frame.G2plotNB.nb.SetSelection(plotNum)Â # raises plot tab |
---|
3277 | Â Â Â Â Â Â Â Â |
---|
3278 | ################################################################################ |
---|
3279 | ##### PlotExposedImage & PlotImage |
---|
3280 | ################################################################################ |
---|
3281 | Â Â Â Â Â Â |
---|
3282 | def PlotExposedImage(G2frame,newPlot=False,event=None): |
---|
3283 | Â Â '''General access module for 2D image plotting |
---|
3284 | Â Â ''' |
---|
3285 | Â Â plotNo =Â G2frame.G2plotNB.nb.GetSelection() |
---|
3286 |   if G2frame.G2plotNB.nb.GetPageText(plotNo) == '2D Powder Image': |
---|
3287 | Â Â Â Â PlotImage(G2frame,newPlot,event,newImage=True) |
---|
3288 |   elif G2frame.G2plotNB.nb.GetPageText(plotNo) == '2D Integration': |
---|
3289 | Â Â Â Â PlotIntegration(G2frame,newPlot,event) |
---|
3290 | |
---|
3291 | def OnStartMask(G2frame): |
---|
3292 | Â Â '''Initiate the start of a Frame or Polygon map |
---|
3293 | |
---|
3294 | Â Â :param wx.Frame G2frame: The main GSAS-II tree "window" |
---|
3295 | Â Â :param str eventkey: a single letter ('f' or 'p') that |
---|
3296 |    determines what type of mask is created.  |
---|
3297 | Â Â ''' |
---|
3298 | Â Â Masks =Â G2frame.PatternTree.GetItemPyData( |
---|
3299 |     G2gd.GetPatternTreeItemId(G2frame,G2frame.Image, 'Masks')) |
---|
3300 |   if G2frame.MaskKey == 'f': |
---|
3301 | Â Â Â Â Masks['Frames']Â =Â [] |
---|
3302 |   elif G2frame.MaskKey == 'p': |
---|
3303 | Â Â Â Â Masks['Polygons'].append([]) |
---|
3304 |   elif G2frame.MaskKey == 's': |
---|
3305 | Â Â Â Â Masks['Points'].append([]) |
---|
3306 |   elif G2frame.MaskKey == 'a': |
---|
3307 | Â Â Â Â Masks['Arcs'].append([]) |
---|
3308 |   elif G2frame.MaskKey == 'r': |
---|
3309 | Â Â Â Â Masks['Rings'].append([]) |
---|
3310 | Â Â G2imG.UpdateMasks(G2frame,Masks) |
---|
3311 | Â Â PlotImage(G2frame,newImage=True) |
---|
3312 | Â Â |
---|
3313 | def OnStartNewDzero(G2frame): |
---|
3314 | Â Â '''Initiate the start of adding a new d-zero to a strain data set |
---|
3315 | |
---|
3316 | Â Â :param wx.Frame G2frame: The main GSAS-II tree "window" |
---|
3317 | Â Â :param str eventkey: a single letter ('a') that |
---|
3318 |    triggers the addition of a d-zero.  |
---|
3319 | Â Â ''' |
---|
3320 | Â Â G2frame.dataFrame.GetStatusBar().SetStatusText('Add strain ring active - LB pick d-zero value',0) |
---|
3321 |   G2frame.PickId = G2gd.GetPatternTreeItemId(G2frame,G2frame.Image, 'Stress/Strain') |
---|
3322 | Â Â data =Â G2frame.PatternTree.GetItemPyData(G2frame.PickId) |
---|
3323 |   return data |
---|
3324 | |
---|
3325 | def PlotImage(G2frame,newPlot=False,event=None,newImage=True): |
---|
3326 | Â Â '''Plot of 2D detector images as contoured plot. Also plot calibration ellipses, |
---|
3327 | Â Â masks, etc. |
---|
3328 | Â Â ''' |
---|
3329 |   from matplotlib.patches import Ellipse,Arc,Circle,Polygon |
---|
3330 |   import numpy.ma as ma |
---|
3331 |   Dsp = lambda tth,wave: wave/(2.*npsind(tth/2.)) |
---|
3332 |   global Data,Masks,StrSta |
---|
3333 | Â Â colors=['b','g','r','c','m','k'] |
---|
3334 | Â Â Data =Â G2frame.PatternTree.GetItemPyData( |
---|
3335 |     G2gd.GetPatternTreeItemId(G2frame,G2frame.Image, 'Image Controls')) |
---|
3336 | # patch |
---|
3337 |   if 'invert_x' not in Data: |
---|
3338 | Â Â Â Â Data['invert_x']Â =Â False |
---|
3339 | Â Â Â Â Data['invert_y']Â =Â True |
---|
3340 | # end patch |
---|
3341 | Â Â Masks =Â G2frame.PatternTree.GetItemPyData( |
---|
3342 |     G2gd.GetPatternTreeItemId(G2frame,G2frame.Image, 'Masks')) |
---|
3343 | Â Â try:Â Â #may be absent |
---|
3344 | Â Â Â Â StrSta =Â G2frame.PatternTree.GetItemPyData( |
---|
3345 |       G2gd.GetPatternTreeItemId(G2frame,G2frame.Image, 'Stress/Strain')) |
---|
3346 |   except TypeError:  #is missing |
---|
3347 | Â Â Â Â StrSta =Â {} |
---|
3348 | |
---|
3349 |   def OnImMotion(event): |
---|
3350 | Â Â Â Â Page.canvas.SetToolTipString('') |
---|
3351 | Â Â Â Â sizexy =Â Data['size'] |
---|
3352 | Â Â Â Â FlatBkg =Â Data.get('Flat Bkg',0.) |
---|
3353 |     if event.xdata and event.ydata and len(G2frame.ImageZ):         #avoid out of frame errors |
---|
3354 |       Page.canvas.SetToolTipString('%8.2f %8.2fmm'%(event.xdata,event.ydata)) |
---|
3355 | Â Â Â Â Â Â Page.canvas.SetCursor(wx.CROSS_CURSOR) |
---|
3356 | Â Â Â Â Â Â item =Â G2frame.itemPicked |
---|
3357 | Â Â Â Â Â Â pixelSize =Â Data['pixelSize'] |
---|
3358 | Â Â Â Â Â Â scalex =Â 1000./pixelSize[0] |
---|
3359 | Â Â Â Â Â Â scaley =Â 1000./pixelSize[1] |
---|
3360 |       if item and G2frame.PatternTree.GetItemText(G2frame.PickId) == 'Image Controls': |
---|
3361 |         if 'Text' in str(item): |
---|
3362 |           Page.canvas.SetToolTipString('%8.3f %8.3fmm'%(event.xdata,event.ydata)) |
---|
3363 | Â Â Â Â Â Â Â Â else: |
---|
3364 | Â Â Â Â Â Â Â Â Â Â xcent,ycent =Â Data['center'] |
---|
3365 | Â Â Â Â Â Â Â Â Â Â xpos =Â event.xdata-xcent |
---|
3366 | Â Â Â Â Â Â Â Â Â Â ypos =Â event.ydata-ycent |
---|
3367 | Â Â Â Â Â Â Â Â Â Â tth,azm =Â G2img.GetTthAzm(event.xdata,event.ydata,Data) |
---|
3368 |           if 'line3' in str(item) or 'line4' in str(item) and not Data['fullIntegrate']: |
---|
3369 |             Page.canvas.SetToolTipString('%6d deg'%(azm)) |
---|
3370 |           elif 'line1' in str(item) or 'line2' in str(item): |
---|
3371 |             Page.canvas.SetToolTipString('%8.3f deg'%(tth))              |
---|
3372 | Â Â Â Â Â Â else: |
---|
3373 | Â Â Â Â Â Â Â Â xpos =Â event.xdata |
---|
3374 | Â Â Â Â Â Â Â Â ypos =Â event.ydata |
---|
3375 | Â Â Â Â Â Â Â Â xpix =Â xpos*scalex |
---|
3376 | Â Â Â Â Â Â Â Â ypix =Â ypos*scaley |
---|
3377 | Â Â Â Â Â Â Â Â Int =Â 0 |
---|
3378 |         if (0 <= xpix <= sizexy[0]) and (0 <= ypix <= sizexy[1]): |
---|
3379 | Â Â Â Â Â Â Â Â Â Â Int =Â G2frame.ImageZ[ypix][xpix]-int(FlatBkg) |
---|
3380 | Â Â Â Â Â Â Â Â tth,azm,D,dsp =Â G2img.GetTthAzmDsp(xpos,ypos,Data) |
---|
3381 | Â Â Â Â Â Â Â Â Q =Â 2.*math.pi/dsp |
---|
3382 | Â Â Â Â Â Â Â Â fields =Â ['','Detector 2-th =%9.3fdeg, dsp =%9.3fA, Q = %6.5fA-1, azm = %7.2fdeg, I = %6d'%(tth,dsp,Q,azm,Int)] |
---|
3383 |         if G2frame.MaskKey in ['p','f']: |
---|
3384 | Â Â Â Â Â Â Â Â Â Â fields[1]Â =Â 'Polygon/frame mask pick - LB next point, RB close polygon' |
---|
3385 |         elif G2frame.StrainKey: |
---|
3386 | Â Â Â Â Â Â Â Â Â Â fields[0]Â =Â 'd-zero pick active' |
---|
3387 | Â Â Â Â Â Â Â Â G2frame.G2plotNB.status.SetFields(fields) |
---|
3388 | |
---|
3389 |   def OnImPlotKeyPress(event): |
---|
3390 | Â Â Â Â try: |
---|
3391 | Â Â Â Â Â Â PickName =Â G2frame.PatternTree.GetItemText(G2frame.PickId) |
---|
3392 |     except TypeError: |
---|
3393 | Â Â Â Â Â Â return |
---|
3394 |     if PickName == 'Masks': |
---|
3395 |       if event.key in ['l','p','f','s','a','r']: |
---|
3396 | Â Â Â Â Â Â Â Â G2frame.MaskKey =Â event.key |
---|
3397 | Â Â Â Â Â Â Â Â OnStartMask(G2frame) |
---|
3398 | Â Â Â Â Â Â Â Â PlotImage(G2frame,newPlot=False) |
---|
3399 | Â Â Â Â Â Â Â Â |
---|
3400 |     elif PickName == 'Stress/Strain': |
---|
3401 |       if event.key in ['a',]: |
---|
3402 | Â Â Â Â Â Â Â Â G2frame.StrainKey =Â event.key |
---|
3403 | Â Â Â Â Â Â Â Â StrSta =Â OnStartNewDzero(G2frame) |
---|
3404 | Â Â Â Â Â Â Â Â PlotImage(G2frame,newPlot=False) |
---|
3405 | Â Â Â Â Â Â Â Â |
---|
3406 |     elif PickName == 'Image Controls': |
---|
3407 |       if event.key in ['c',]: |
---|
3408 | Â Â Â Â Â Â Â Â Xpos =Â event.xdata |
---|
3409 |         if not Xpos:      #got point out of frame |
---|
3410 | Â Â Â Â Â Â Â Â Â Â return |
---|
3411 | Â Â Â Â Â Â Â Â Ypos =Â event.ydata |
---|
3412 | Â Â Â Â Â Â Â Â dlg =Â wx.MessageDialog(G2frame,'Are you sure you want to change the center?', |
---|
3413 | Â Â Â Â Â Â Â Â Â Â 'Center change',style=wx.OK|wx.CANCEL) |
---|
3414 | Â Â Â Â Â Â Â Â try: |
---|
3415 |           if dlg.ShowModal() == wx.ID_OK: |
---|
3416 |             print 'move center to: ',Xpos,Ypos |
---|
3417 | Â Â Â Â Â Â Â Â Â Â Â Â Data['center']Â =Â [Xpos,Ypos] |
---|
3418 | Â Â Â Â Â Â Â Â Â Â Â Â G2imG.UpdateImageControls(G2frame,Data,Masks) |
---|
3419 | Â Â Â Â Â Â Â Â Â Â Â Â PlotImage(G2frame,newPlot=False) |
---|
3420 | Â Â Â Â Â Â Â Â finally: |
---|
3421 | Â Â Â Â Â Â Â Â Â Â dlg.Destroy() |
---|
3422 | Â Â Â Â Â Â Â Â return |
---|
3423 |       elif event.key == 'l': |
---|
3424 |         G2frame.logPlot = not G2frame.logPlot |
---|
3425 |       elif event.key in ['x',]: |
---|
3426 |         Data['invert_x'] = not Data['invert_x'] |
---|
3427 |       elif event.key in ['y',]: |
---|
3428 |         Data['invert_y'] = not Data['invert_y'] |
---|
3429 | Â Â Â Â Â Â PlotImage(G2frame,newPlot=True) |
---|
3430 | Â Â Â Â Â Â |
---|
3431 |   def OnKeyBox(event): |
---|
3432 |     if G2frame.G2plotNB.nb.GetSelection() == G2frame.G2plotNB.plotList.index('2D Powder Image'): |
---|
3433 | Â Â Â Â Â Â event.key =Â cb.GetValue()[0] |
---|
3434 | Â Â Â Â Â Â cb.SetValue(' key press') |
---|
3435 |       if event.key in ['l','s','a','r','p','x','y']: |
---|
3436 | Â Â Â Â Â Â Â Â wx.CallAfter(OnImPlotKeyPress,event) |
---|
3437 | Â Â Â Â Page.canvas.SetFocus()Â # redirect the Focus from the button back to the plot |
---|
3438 | Â Â Â Â Â Â Â Â Â Â Â Â |
---|
3439 |   def OnImPick(event): |
---|
3440 |     if G2frame.PatternTree.GetItemText(G2frame.PickId) not in ['Image Controls','Masks']: |
---|
3441 | Â Â Â Â Â Â return |
---|
3442 |     if G2frame.itemPicked is not None: return |
---|
3443 | Â Â Â Â G2frame.itemPicked =Â event.artist |
---|
3444 | Â Â Â Â G2frame.mousePicked =Â event.mouseevent |
---|
3445 | Â Â Â Â |
---|
3446 |   def OnImRelease(event): |
---|
3447 | Â Â Â Â try: |
---|
3448 | Â Â Â Â Â Â PickName =Â G2frame.PatternTree.GetItemText(G2frame.PickId) |
---|
3449 |     except TypeError: |
---|
3450 | Â Â Â Â Â Â return |
---|
3451 |     if PickName not in ['Image Controls','Masks','Stress/Strain']: |
---|
3452 | Â Â Â Â Â Â return |
---|
3453 | Â Â Â Â pixelSize =Â Data['pixelSize'] |
---|
3454 | Â Â Â Â FlatBkg =Â Data.get('Flat Bkg',0.) |
---|
3455 | Â Â Â Â scalex =Â 1000./pixelSize[0] |
---|
3456 | Â Â Â Â scaley =Â 1000./pixelSize[1] |
---|
3457 | #Â Â Â Â pixLimit = Data['pixLimit']Â Â #can be too tight |
---|
3458 | Â Â Â Â pixLimit =Â 20Â Â Â Â #this makes the search box 40x40 pixels |
---|
3459 |     if G2frame.itemPicked is None and PickName == 'Image Controls' and len(G2frame.ImageZ): |
---|
3460 | Â Â Â Â Â Â Xpos =Â event.xdata |
---|
3461 |       if not (Xpos and G2frame.ifGetRing):          #got point out of frame |
---|
3462 | Â Â Â Â Â Â Â Â return |
---|
3463 | Â Â Â Â Â Â Ypos =Â event.ydata |
---|
3464 |       if Ypos and not Page.toolbar._active:     #make sure zoom/pan not selected |
---|
3465 |         if event.button == 1: |
---|
3466 | Â Â Â Â Â Â Â Â Â Â Xpix =Â Xpos*scalex |
---|
3467 | Â Â Â Â Â Â Â Â Â Â Ypix =Â Ypos*scaley |
---|
3468 | Â Â Â Â Â Â Â Â Â Â xpos,ypos,I,J =Â G2img.ImageLocalMax(G2frame.ImageZ-FlatBkg,pixLimit,Xpix,Ypix) |
---|
3469 |           if I and J: |
---|
3470 | Â Â Â Â Â Â Â Â Â Â Â Â xpos +=Â .5Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #shift to pixel center |
---|
3471 | Â Â Â Â Â Â Â Â Â Â Â Â ypos +=Â .5 |
---|
3472 |             xpos /= scalex             #convert to mm |
---|
3473 | Â Â Â Â Â Â Â Â Â Â Â Â ypos /=Â scaley |
---|
3474 | Â Â Â Â Â Â Â Â Â Â Â Â Data['ring'].append([xpos,ypos]) |
---|
3475 |         elif event.button == 3: |
---|
3476 | Â Â Â Â Â Â Â Â Â Â G2frame.dataFrame.GetStatusBar().SetStatusText('Calibrating...',0) |
---|
3477 |           if G2img.ImageCalibrate(G2frame,Data): |
---|
3478 | Â Â Â Â Â Â Â Â Â Â Â Â G2frame.dataFrame.GetStatusBar().SetStatusText('Calibration successful - Show ring picks to check',0) |
---|
3479 |             print 'Calibration successful' |
---|
3480 | Â Â Â Â Â Â Â Â Â Â else: |
---|
3481 | Â Â Â Â Â Â Â Â Â Â Â Â G2frame.dataFrame.GetStatusBar().SetStatusText('Calibration failed - Show ring picks to diagnose',0) |
---|
3482 |             print 'Calibration failed' |
---|
3483 | Â Â Â Â Â Â Â Â Â Â G2frame.ifGetRing =Â False |
---|
3484 | Â Â Â Â Â Â Â Â Â Â G2imG.UpdateImageControls(G2frame,Data,Masks) |
---|
3485 | Â Â Â Â Â Â Â Â Â Â return |
---|
3486 | Â Â Â Â Â Â Â Â PlotImage(G2frame,newImage=False) |
---|
3487 | Â Â Â Â Â Â return |
---|
3488 |     elif G2frame.MaskKey and PickName == 'Masks': |
---|
3489 | Â Â Â Â Â Â Xpos,Ypos =Â [event.xdata,event.ydata] |
---|
3490 |       if not Xpos or not Ypos or Page.toolbar._active: #got point out of frame or zoom/pan selected |
---|
3491 | Â Â Â Â Â Â Â Â return |
---|
3492 |       if G2frame.MaskKey == 's' and event.button == 1: |
---|
3493 | Â Â Â Â Â Â Â Â Masks['Points'][-1]Â =Â [Xpos,Ypos,1.] |
---|
3494 | Â Â Â Â Â Â Â Â G2frame.MaskKey =Â ''Â Â Â Â Â Â Â Â |
---|
3495 |       elif G2frame.MaskKey == 'r' and event.button == 1: |
---|
3496 | Â Â Â Â Â Â Â Â tth =Â G2img.GetTth(Xpos,Ypos,Data) |
---|
3497 | Â Â Â Â Â Â Â Â Masks['Rings'][-1]Â =Â [tth,0.1] |
---|
3498 | Â Â Â Â Â Â Â Â G2frame.MaskKey =Â ''Â Â Â Â Â Â Â Â |
---|
3499 |       elif G2frame.MaskKey == 'a' and event.button == 1: |
---|
3500 | Â Â Â Â Â Â Â Â tth,azm =Â G2img.GetTthAzm(Xpos,Ypos,Data) |
---|
3501 | Â Â Â Â Â Â Â Â azm =Â int(azm)Â Â Â Â Â Â Â Â |
---|
3502 | Â Â Â Â Â Â Â Â Masks['Arcs'][-1]Â =Â [tth,[azm-5,azm+5],0.1] |
---|
3503 | Â Â Â Â Â Â Â Â G2frame.MaskKey =Â ''Â Â Â Â Â Â Â Â |
---|
3504 |       elif G2frame.MaskKey =='p': |
---|
3505 | Â Â Â Â Â Â Â Â polygon =Â Masks['Polygons'][-1] |
---|
3506 |         if len(polygon) > 2 and event.button == 3: |
---|
3507 | Â Â Â Â Â Â Â Â Â Â x0,y0 =Â polygon[0] |
---|
3508 | Â Â Â Â Â Â Â Â Â Â polygon.append([x0,y0]) |
---|
3509 | Â Â Â Â Â Â Â Â Â Â G2frame.MaskKey =Â '' |
---|
3510 | Â Â Â Â Â Â Â Â Â Â G2frame.G2plotNB.status.SetFields(['','Polygon closed']) |
---|
3511 | Â Â Â Â Â Â Â Â else: |
---|
3512 | Â Â Â Â Â Â Â Â Â Â G2frame.G2plotNB.status.SetFields(['','New polygon point: %.1f,%.1f'%(Xpos,Ypos)]) |
---|
3513 | Â Â Â Â Â Â Â Â Â Â polygon.append([Xpos,Ypos]) |
---|
3514 |       elif G2frame.MaskKey =='f': |
---|
3515 | Â Â Â Â Â Â Â Â frame =Â Masks['Frames'] |
---|
3516 |         if len(frame) > 2 and event.button == 3: |
---|
3517 | Â Â Â Â Â Â Â Â Â Â x0,y0 =Â frame[0] |
---|
3518 | Â Â Â Â Â Â Â Â Â Â frame.append([x0,y0]) |
---|
3519 | Â Â Â Â Â Â Â Â Â Â G2frame.MaskKey =Â '' |
---|
3520 | Â Â Â Â Â Â Â Â Â Â G2frame.G2plotNB.status.SetFields(['','Frame closed']) |
---|
3521 | Â Â Â Â Â Â Â Â else: |
---|
3522 | Â Â Â Â Â Â Â Â Â Â G2frame.G2plotNB.status.SetFields(['','New frame point: %.1f,%.1f'%(Xpos,Ypos)]) |
---|
3523 | Â Â Â Â Â Â Â Â Â Â frame.append([Xpos,Ypos]) |
---|
3524 | Â Â Â Â Â Â G2imG.UpdateMasks(G2frame,Masks) |
---|
3525 | Â Â Â Â Â Â PlotImage(G2frame,newImage=False) |
---|
3526 |     elif PickName == 'Stress/Strain' and G2frame.StrainKey: |
---|
3527 | Â Â Â Â Â Â Xpos,Ypos =Â [event.xdata,event.ydata] |
---|
3528 |       if not Xpos or not Ypos or Page.toolbar._active: #got point out of frame or zoom/pan selected |
---|
3529 | Â Â Â Â Â Â Â Â return |
---|
3530 | Â Â Â Â Â Â dsp =Â G2img.GetDsp(Xpos,Ypos,Data) |
---|
3531 | Â Â Â Â Â Â StrSta['d-zero'].append({'Dset':dsp,'Dcalc':0.0,'pixLimit':10,'cutoff':0.5, |
---|
3532 | Â Â Â Â Â Â Â Â 'ImxyObs':[[],[]],'ImtaObs':[[],[]],'ImtaCalc':[[],[]],'Emat':[1.0,1.0,1.0]}) |
---|
3533 | Â Â Â Â Â Â R,r =Â G2img.MakeStrStaRing(StrSta['d-zero'][-1],G2frame.ImageZ-FlatBkg,Data) |
---|
3534 |       if not len(R): |
---|
3535 |         del StrSta['d-zero'][-1] |
---|
3536 | Â Â Â Â Â Â Â Â G2frame.ErrorDialog('Strain peak selection','WARNING - No points found for this ring selection') |
---|
3537 | Â Â Â Â Â Â StrSta['d-zero']Â =Â G2mth.sortArray(StrSta['d-zero'],'Dset',reverse=True) |
---|
3538 | Â Â Â Â Â Â G2frame.StrainKey =Â '' |
---|
3539 | Â Â Â Â Â Â G2imG.UpdateStressStrain(G2frame,StrSta) |
---|
3540 | Â Â Â Â Â Â PlotStrain(G2frame,StrSta) |
---|
3541 | Â Â Â Â Â Â PlotImage(G2frame,newPlot=False)Â Â Â Â Â Â |
---|
3542 | Â Â Â Â else: |
---|
3543 | Â Â Â Â Â Â Xpos,Ypos =Â [event.xdata,event.ydata] |
---|
3544 |       if not Xpos or not Ypos or Page.toolbar._active: #got point out of frame or zoom/pan selected |
---|
3545 | Â Â Â Â Â Â Â Â return |
---|
3546 |       if G2frame.ifGetRing:             #delete a calibration ring pick |
---|
3547 | Â Â Â Â Â Â Â Â xypos =Â [Xpos,Ypos] |
---|
3548 | Â Â Â Â Â Â Â Â rings =Â Data['ring'] |
---|
3549 |         for ring in rings: |
---|
3550 |           if np.allclose(ring,xypos,.01,0): |
---|
3551 | Â Â Â Â Â Â Â Â Â Â Â Â rings.remove(ring) |
---|
3552 | Â Â Â Â Â Â else: |
---|
3553 | Â Â Â Â Â Â Â Â tth,azm,dsp =Â G2img.GetTthAzmDsp(Xpos,Ypos,Data)[:3] |
---|
3554 | Â Â Â Â Â Â Â Â itemPicked =Â str(G2frame.itemPicked) |
---|
3555 |         if 'Line2D' in itemPicked and PickName == 'Image Controls': |
---|
3556 |           if 'line1' in itemPicked: |
---|
3557 | Â Â Â Â Â Â Â Â Â Â Â Â Data['IOtth'][0]Â =Â max(tth,0.001) |
---|
3558 |           elif 'line2' in itemPicked: |
---|
3559 | Â Â Â Â Â Â Â Â Â Â Â Â Data['IOtth'][1]Â =Â tth |
---|
3560 |           elif 'line3' in itemPicked: |
---|
3561 | Â Â Â Â Â Â Â Â Â Â Â Â Data['LRazimuth'][0]Â =Â int(azm) |
---|
3562 |           elif 'line4' in itemPicked and not Data['fullIntegrate']: |
---|
3563 | Â Â Â Â Â Â Â Â Â Â Â Â Data['LRazimuth'][1]Â =Â int(azm) |
---|
3564 | Â Â Â Â Â Â Â Â Â Â |
---|
3565 | Â Â Â Â Â Â Â Â Â Â Data['LRazimuth'][0]Â %=Â 360 |
---|
3566 | Â Â Â Â Â Â Â Â Â Â Data['LRazimuth'][1]Â %=Â 360 |
---|
3567 |           if Data['LRazimuth'][0] > Data['LRazimuth'][1]: |
---|
3568 | Â Â Â Â Â Â Â Â Â Â Â Â Data['LRazimuth'][1]Â +=Â 360Â Â Â Â Â Â Â Â Â Â Â Â |
---|
3569 |           if Data['fullIntegrate']: |
---|
3570 | Â Â Â Â Â Â Â Â Â Â Â Â Data['LRazimuth'][1]Â =Â Data['LRazimuth'][0]+360 |
---|
3571 | Â Â Â Â Â Â Â Â Â Â Â Â |
---|
3572 |           if Data['IOtth'][0] > Data['IOtth'][1]: |
---|
3573 | Â Â Â Â Â Â Â Â Â Â Â Â Data['IOtth'][0],Data['IOtth'][1]Â =Â Data['IOtth'][1],Data['IOtth'][0] |
---|
3574 | Â Â Â Â Â Â Â Â Â Â Â Â |
---|
3575 | Â Â Â Â Â Â Â Â Â Â G2frame.InnerTth.SetValue("%8.2f"Â %Â (Data['IOtth'][0])) |
---|
3576 | Â Â Â Â Â Â Â Â Â Â G2frame.OuterTth.SetValue("%8.2f"Â %Â (Data['IOtth'][1])) |
---|
3577 | Â Â Â Â Â Â Â Â Â Â G2frame.Lazim.SetValue("%6d"Â %Â (Data['LRazimuth'][0])) |
---|
3578 | Â Â Â Â Â Â Â Â Â Â G2frame.Razim.SetValue("%6d"Â %Â (Data['LRazimuth'][1])) |
---|
3579 |         elif 'Circle' in itemPicked and PickName == 'Masks': |
---|
3580 | Â Â Â Â Â Â Â Â Â Â spots =Â Masks['Points'] |
---|
3581 | Â Â Â Â Â Â Â Â Â Â newPos =Â itemPicked.split(')')[0].split('(')[2].split(',') |
---|
3582 | Â Â Â Â Â Â Â Â Â Â newPos =Â np.array([float(newPos[0]),float(newPos[1])]) |
---|
3583 |           for spot in spots: |
---|
3584 |             if spot and np.allclose(np.array([spot[:2]]),newPos): |
---|
3585 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â spot[:2]Â =Â Xpos,Ypos |
---|
3586 | Â Â Â Â Â Â Â Â Â Â G2imG.UpdateMasks(G2frame,Masks) |
---|
3587 |         elif 'Line2D' in itemPicked and PickName == 'Masks': |
---|
3588 | Â Â Â Â Â Â Â Â Â Â Obj =Â G2frame.itemPicked.findobj() |
---|
3589 | Â Â Â Â Â Â Â Â Â Â rings =Â Masks['Rings'] |
---|
3590 | Â Â Â Â Â Â Â Â Â Â arcs =Â Masks['Arcs'] |
---|
3591 | Â Â Â Â Â Â Â Â Â Â polygons =Â Masks['Polygons'] |
---|
3592 | Â Â Â Â Â Â Â Â Â Â frame =Â Masks['Frames'] |
---|
3593 |           for ring in G2frame.ringList: |
---|
3594 |             if Obj == ring[0]: |
---|
3595 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â rN =Â ring[1] |
---|
3596 |               if ring[2] == 'o': |
---|
3597 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â rings[rN][0]Â =Â G2img.GetTth(Xpos,Ypos,Data)-rings[rN][1]/2. |
---|
3598 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â else: |
---|
3599 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â rings[rN][0]Â =Â G2img.GetTth(Xpos,Ypos,Data)+rings[rN][1]/2. |
---|
3600 |           for arc in G2frame.arcList: |
---|
3601 |             if Obj == arc[0]: |
---|
3602 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â aN =Â arc[1] |
---|
3603 |               if arc[2] == 'o': |
---|
3604 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â arcs[aN][0]Â =Â G2img.GetTth(Xpos,Ypos,Data)-arcs[aN][2]/2 |
---|
3605 |               elif arc[2] == 'i': |
---|
3606 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â arcs[aN][0]Â =Â G2img.GetTth(Xpos,Ypos,Data)+arcs[aN][2]/2 |
---|
3607 |               elif arc[2] == 'l': |
---|
3608 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â arcs[aN][1][0]Â =Â int(G2img.GetAzm(Xpos,Ypos,Data)) |
---|
3609 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â else: |
---|
3610 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â arcs[aN][1][1]Â =Â int(G2img.GetAzm(Xpos,Ypos,Data)) |
---|
3611 |           for poly in G2frame.polyList:  #merging points problem here? |
---|
3612 |             if Obj == poly[0]: |
---|
3613 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â ind =Â G2frame.itemPicked.contains(G2frame.mousePicked)[1]['ind'][0] |
---|
3614 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â oldPos =Â np.array([G2frame.mousePicked.xdata,G2frame.mousePicked.ydata]) |
---|
3615 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â pN =Â poly[1] |
---|
3616 |               for i,xy in enumerate(polygons[pN]): |
---|
3617 |                 if np.allclose(np.array([xy]),oldPos,atol=1.0): |
---|
3618 |                   if event.button == 1: |
---|
3619 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â polygons[pN][i]Â =Â Xpos,Ypos |
---|
3620 |                   elif event.button == 3: |
---|
3621 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â polygons[pN].insert(i,[Xpos,Ypos]) |
---|
3622 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â break |
---|
3623 |           if frame: |
---|
3624 | Â Â Â Â Â Â Â Â Â Â Â Â oldPos =Â np.array([G2frame.mousePicked.xdata,G2frame.mousePicked.ydata]) |
---|
3625 |             for i,xy in enumerate(frame): |
---|
3626 |               if np.allclose(np.array([xy]),oldPos,atol=1.0): |
---|
3627 |                 if event.button == 1: |
---|
3628 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â frame[i]Â =Â Xpos,Ypos |
---|
3629 |                 elif event.button == 3: |
---|
3630 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â frame.insert(i,[Xpos,Ypos]) |
---|
3631 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â break |
---|
3632 | Â Â Â Â Â Â Â Â Â Â G2imG.UpdateMasks(G2frame,Masks) |
---|
3633 | #Â Â Â Â Â Â Â Â else:Â Â Â Â Â Â Â Â Â #keep for future debugging |
---|
3634 | #Â Â Â Â Â Â Â Â Â Â print str(G2frame.itemPicked),event.xdata,event.ydata,event.button |
---|
3635 | Â Â Â Â Â Â PlotImage(G2frame,newImage=True) |
---|
3636 | Â Â Â Â Â Â G2frame.itemPicked =Â None |
---|
3637 | Â Â Â Â Â Â |
---|
3638 | Â Â try: |
---|
3639 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index('2D Powder Image') |
---|
3640 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
3641 |     if not newPlot: |
---|
3642 | Â Â Â Â Â Â Plot =Â Page.figure.gca()Â Â Â Â Â #get previous powder plot & get limits |
---|
3643 | Â Â Â Â Â Â xylim =Â Plot.get_xlim(),Plot.get_ylim() |
---|
3644 |     if newImage: |
---|
3645 | Â Â Â Â Â Â Page.figure.clf() |
---|
3646 | Â Â Â Â Â Â Plot =Â Page.figure.gca()Â Â Â Â Â #get a fresh plot after clf() |
---|
3647 |   except ValueError: |
---|
3648 | Â Â Â Â Plot =Â G2frame.G2plotNB.addMpl('2D Powder Image').gca() |
---|
3649 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index('2D Powder Image') |
---|
3650 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
3651 |     Page.canvas.mpl_connect('key_press_event', OnImPlotKeyPress) |
---|
3652 |     Page.canvas.mpl_connect('motion_notify_event', OnImMotion) |
---|
3653 |     Page.canvas.mpl_connect('pick_event', OnImPick) |
---|
3654 |     Page.canvas.mpl_connect('button_release_event', OnImRelease) |
---|
3655 | Â Â Â Â xylim =Â [] |
---|
3656 | Â Â Page.Choice =Â None |
---|
3657 |   if not event:            #event from GUI TextCtrl - don't want focus to change to plot!!! |
---|
3658 | Â Â Â Â Page.SetFocus() |
---|
3659 | Â Â Title =Â G2frame.PatternTree.GetItemText(G2frame.Image)[4:] |
---|
3660 | Â Â G2frame.G2plotNB.status.DestroyChildren() |
---|
3661 |   if G2frame.logPlot: |
---|
3662 | Â Â Â Â Title =Â 'log('+Title+')' |
---|
3663 | Â Â Plot.set_title(Title) |
---|
3664 | Â Â try: |
---|
3665 |     if G2frame.PatternTree.GetItemText(G2frame.PickId) in ['Image Controls',]: |
---|
3666 | Â Â Â Â Â Â Page.Choice =Â (' key press','l: log(I) on','x: flip x','y: flip y',) |
---|
3667 |       if G2frame.logPlot: |
---|
3668 | Â Â Â Â Â Â Â Â Page.Choice[1]Â =Â 'l: log(I) off' |
---|
3669 | Â Â Â Â Â Â Page.keyPress =Â OnImPlotKeyPress |
---|
3670 |     elif G2frame.PatternTree.GetItemText(G2frame.PickId) in ['Masks',]: |
---|
3671 | Â Â Â Â Â Â Page.Choice =Â (' key press','l: log(I) on','s: spot mask','a: arc mask','r: ring mask', |
---|
3672 | Â Â Â Â Â Â Â Â 'p: polygon mask','f: frame mask',) |
---|
3673 |       if G2frame.logPlot: |
---|
3674 | Â Â Â Â Â Â Â Â Page.Choice[1]Â =Â 'l: log(I) off' |
---|
3675 | Â Â Â Â Â Â Page.keyPress =Â OnImPlotKeyPress |
---|
3676 |     elif G2frame.PatternTree.GetItemText(G2frame.PickId) in ['Stress/Strain',]: |
---|
3677 | Â Â Â Â Â Â Page.Choice =Â (' key press','a: add new ring',) |
---|
3678 | Â Â Â Â Â Â Page.keyPress =Â OnImPlotKeyPress |
---|
3679 |   except TypeError: |
---|
3680 | Â Â Â Â pass |
---|
3681 | Â Â size,imagefile =Â G2frame.PatternTree.GetItemPyData(G2frame.Image) |
---|
3682 | Â Â dark =Â Data.get('dark image',[0,'']) |
---|
3683 |   if dark[0]: |
---|
3684 |     darkfile = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame, |
---|
3685 | Â Â Â Â Â Â G2frame.root,dark[0]))[1] |
---|
3686 |   if imagefile != G2frame.oldImagefile: |
---|
3687 | Â Â Â Â imagefile =Â G2IO.CheckImageFile(G2frame,imagefile) |
---|
3688 |     if not imagefile: |
---|
3689 | Â Â Â Â Â Â G2frame.G2plotNB.Delete('2D Powder Image') |
---|
3690 | Â Â Â Â Â Â return |
---|
3691 | Â Â Â Â G2frame.PatternTree.SetItemPyData(G2frame.Image,[size,imagefile]) |
---|
3692 | Â Â Â Â G2frame.ImageZ =Â G2IO.GetImageData(G2frame,imagefile,imageOnly=True) |
---|
3693 |     if dark[0]: |
---|
3694 | Â Â Â Â Â Â darkImg =Â G2IO.GetImageData(G2frame,darkfile,imageOnly=True) |
---|
3695 | Â Â Â Â Â Â G2frame.ImageZ +=Â dark[1]*darkImg |
---|
3696 | Â Â Â Â G2frame.oldImagefile =Â imagefile |
---|
3697 | |
---|
3698 | Â Â imScale =Â 1 |
---|
3699 |   if len(G2frame.ImageZ) > 1024: |
---|
3700 | Â Â Â Â imScale =Â len(G2frame.ImageZ)/1024 |
---|
3701 | Â Â sizexy =Â Data['size'] |
---|
3702 | Â Â pixelSize =Â Data['pixelSize'] |
---|
3703 | Â Â scalex =Â 1000./pixelSize[0] |
---|
3704 | Â Â scaley =Â 1000./pixelSize[1] |
---|
3705 | Â Â Xmax =Â sizexy[0]*pixelSize[0]/1000. |
---|
3706 | Â Â Ymax =Â sizexy[1]*pixelSize[1]/1000. |
---|
3707 | Â Â xlim =Â (0,Xmax) |
---|
3708 | Â Â ylim =Â (Ymax,0) |
---|
3709 | Â Â Imin,Imax =Â Data['range'][1] |
---|
3710 | Â Â acolor =Â mpl.cm.get_cmap(Data['color']) |
---|
3711 | Â Â xcent,ycent =Â Data['center'] |
---|
3712 | Â Â Plot.set_xlabel('Image x-axis, mm',fontsize=12) |
---|
3713 | Â Â Plot.set_ylabel('Image y-axis, mm',fontsize=12) |
---|
3714 | Â Â #do threshold mask - "real" mask - others are just bondaries |
---|
3715 | Â Â Zlim =Â Masks['Thresholds'][1] |
---|
3716 | Â Â FlatBkg =Â Data.get('Flat Bkg',0.0) |
---|
3717 | Â Â wx.BeginBusyCursor() |
---|
3718 | Â Â try: |
---|
3719 | Â Â Â Â Â Â |
---|
3720 |     if newImage:          |
---|
3721 | Â Â Â Â Â Â Imin,Imax =Â Data['range'][1] |
---|
3722 | Â Â Â Â Â Â MA =Â ma.masked_greater(ma.masked_less(G2frame.ImageZ,Zlim[0]+FlatBkg),Zlim[1]+FlatBkg) |
---|
3723 | Â Â Â Â Â Â MaskA =Â ma.getmaskarray(MA) |
---|
3724 | Â Â Â Â Â Â A =Â G2img.ImageCompress(MA,imScale)-FlatBkg |
---|
3725 | Â Â Â Â Â Â AM =Â G2img.ImageCompress(MaskA,imScale) |
---|
3726 |       if G2frame.logPlot: |
---|
3727 | Â Â Â Â Â Â Â Â A =Â np.where(A>Imin,np.where(A<Imax,A,0),0) |
---|
3728 | Â Â Â Â Â Â Â Â A =Â np.where(A>0,np.log(A),0) |
---|
3729 | Â Â Â Â Â Â Â Â AM =Â np.where(AM>0,np.log(AM),0) |
---|
3730 | Â Â Â Â Â Â Â Â Imin,Imax =Â [np.amin(A),np.amax(A)] |
---|
3731 | Â Â Â Â Â Â ImgM =Â Plot.imshow(AM,aspect='equal',cmap='Reds', |
---|
3732 | Â Â Â Â Â Â Â Â interpolation='nearest',vmin=0,vmax=2,extent=[0,Xmax,Ymax,0]) |
---|
3733 | Â Â Â Â Â Â Img =Â Plot.imshow(A,aspect='equal',cmap=acolor, |
---|
3734 | Â Â Â Â Â Â Â Â interpolation='nearest',vmin=Imin,vmax=Imax,extent=[0,Xmax,Ymax,0]) |
---|
3735 | Â Â |
---|
3736 | Â Â Â Â Plot.plot(xcent,ycent,'x') |
---|
3737 | Â Â Â Â #G2frame.PatternTree.GetItemText(item) |
---|
3738 |     if Data['showLines']: |
---|
3739 | Â Â Â Â Â Â LRAzim =Â Data['LRazimuth']Â Â Â Â Â Â Â Â Â #NB: integers |
---|
3740 | Â Â Â Â Â Â Nazm =Â Data['outAzimuths'] |
---|
3741 | Â Â Â Â Â Â delAzm =Â float(LRAzim[1]-LRAzim[0])/Nazm |
---|
3742 | Â Â Â Â Â Â AzmthOff =Â Data['azmthOff'] |
---|
3743 | Â Â Â Â Â Â IOtth =Â Data['IOtth'] |
---|
3744 | Â Â Â Â Â Â wave =Â Data['wavelength'] |
---|
3745 | Â Â Â Â Â Â dspI =Â wave/(2.0*sind(IOtth[0]/2.0)) |
---|
3746 | Â Â Â Â Â Â ellI =Â G2img.GetEllipse(dspI,Data)Â Â Â Â Â Â #=False if dsp didn't yield an ellipse (ugh! a parabola or a hyperbola) |
---|
3747 | Â Â Â Â Â Â dspO =Â wave/(2.0*sind(IOtth[1]/2.0)) |
---|
3748 | Â Â Â Â Â Â ellO =Â G2img.GetEllipse(dspO,Data)Â Â Â Â Â Â #Ditto & more likely for outer ellipse |
---|
3749 | Â Â Â Â Â Â Azm =Â np.array(range(LRAzim[0],LRAzim[1]+1))-AzmthOff |
---|
3750 |       if ellI: |
---|
3751 | Â Â Â Â Â Â Â Â xyI =Â [] |
---|
3752 |         for azm in Azm: |
---|
3753 | Â Â Â Â Â Â Â Â Â Â xy =Â G2img.GetDetectorXY(dspI,azm,Data) |
---|
3754 |           if np.any(xy): |
---|
3755 | Â Â Â Â Â Â Â Â Â Â Â Â xyI.append(xy) |
---|
3756 |         if len(xyI): |
---|
3757 | Â Â Â Â Â Â Â Â Â Â xyI =Â np.array(xyI) |
---|
3758 | Â Â Â Â Â Â Â Â Â Â arcxI,arcyI =Â xyI.T |
---|
3759 | Â Â Â Â Â Â Â Â Â Â Plot.plot(arcxI,arcyI,picker=3) |
---|
3760 |       if ellO: |
---|
3761 | Â Â Â Â Â Â Â Â xyO =Â [] |
---|
3762 |         for azm in Azm: |
---|
3763 | Â Â Â Â Â Â Â Â Â Â xy =Â G2img.GetDetectorXY(dspO,azm,Data) |
---|
3764 |           if np.any(xy): |
---|
3765 | Â Â Â Â Â Â Â Â Â Â Â Â xyO.append(xy) |
---|
3766 |         if len(xyO): |
---|
3767 | Â Â Â Â Â Â Â Â Â Â xyO =Â np.array(xyO) |
---|
3768 | Â Â Â Â Â Â Â Â Â Â arcxO,arcyO =Â xyO.TÂ Â Â Â Â Â Â Â |
---|
3769 | Â Â Â Â Â Â Â Â Â Â Plot.plot(arcxO,arcyO,picker=3) |
---|
3770 |       if ellO and ellI: |
---|
3771 | Â Â Â Â Â Â Â Â Plot.plot([arcxI[0],arcxO[0]],[arcyI[0],arcyO[0]],picker=3) |
---|
3772 | Â Â Â Â Â Â Â Â Plot.plot([arcxI[-1],arcxO[-1]],[arcyI[-1],arcyO[-1]],picker=3) |
---|
3773 |       for i in range(Nazm): |
---|
3774 | Â Â Â Â Â Â Â Â cake =Â LRAzim[0]+i*delAzm-AzmthOff |
---|
3775 |         if Data['centerAzm']: |
---|
3776 | Â Â Â Â Â Â Â Â Â Â cake +=Â delAzm/2. |
---|
3777 | Â Â Â Â Â Â Â Â ind =Â np.searchsorted(Azm,cake) |
---|
3778 | Â Â Â Â Â Â Â Â Plot.plot([arcxI[ind],arcxO[ind]],[arcyI[ind],arcyO[ind]],color='k',dashes=(5,5)) |
---|
3779 | Â Â Â Â Â Â Â Â Â Â |
---|
3780 |     if G2frame.PatternTree.GetItemText(G2frame.PickId) in 'Image Controls': |
---|
3781 |       for xring,yring in Data['ring']: |
---|
3782 | Â Â Â Â Â Â Â Â Plot.plot(xring,yring,'r+',picker=3) |
---|
3783 |       if Data['setRings']: |
---|
3784 | Â Â Â Â Â Â Â Â N =Â 0 |
---|
3785 |         for ring in Data['rings']: |
---|
3786 | Â Â Â Â Â Â Â Â Â Â xring,yring =Â np.array(ring).T[:2] |
---|
3787 | Â Â Â Â Â Â Â Â Â Â Plot.plot(xring,yring,'.',color=colors[N%6]) |
---|
3788 | Â Â Â Â Â Â Â Â Â Â N +=Â 1Â Â Â Â Â Â |
---|
3789 |       for ellipse in Data['ellipses']:   #what about hyperbola? |
---|
3790 | Â Â Â Â Â Â Â Â cent,phi,[width,height],col =Â ellipse |
---|
3791 |         if width > 0:    #ellipses |
---|
3792 | Â Â Â Â Â Â Â Â Â Â Plot.add_artist(Ellipse([cent[0],cent[1]],2*width,2*height,phi,ec=col,fc='none')) |
---|
3793 | Â Â Â Â Â Â Â Â Â Â Plot.text(cent[0],cent[1],'+',color=col,ha='center',va='center') |
---|
3794 |     if G2frame.PatternTree.GetItemText(G2frame.PickId) in 'Stress/Strain': |
---|
3795 |       for N,ring in enumerate(StrSta['d-zero']): |
---|
3796 | Â Â Â Â Â Â Â Â xring,yring =Â ring['ImxyObs'] |
---|
3797 | Â Â Â Â Â Â Â Â Plot.plot(xring,yring,colors[N%6]+'.') |
---|
3798 | Â Â Â Â #masks - mask lines numbered after integration limit lines |
---|
3799 | Â Â Â Â spots =Â Masks['Points'] |
---|
3800 | Â Â Â Â rings =Â Masks['Rings'] |
---|
3801 | Â Â Â Â arcs =Â Masks['Arcs'] |
---|
3802 | Â Â Â Â polygons =Â Masks['Polygons'] |
---|
3803 |     if 'Frames' not in Masks: |
---|
3804 | Â Â Â Â Â Â Masks['Frames']Â =Â [] |
---|
3805 | Â Â Â Â frame =Â Masks['Frames'] |
---|
3806 |     for spot in spots: |
---|
3807 |       if spot: |
---|
3808 | Â Â Â Â Â Â Â Â x,y,d =Â spot |
---|
3809 | Â Â Â Â Â Â Â Â Plot.add_artist(Circle((x,y),radius=d/2,fc='none',ec='r',picker=3)) |
---|
3810 | Â Â Â Â G2frame.ringList =Â [] |
---|
3811 |     for iring,ring in enumerate(rings): |
---|
3812 |       if ring: |
---|
3813 | Â Â Â Â Â Â Â Â tth,thick =Â ring |
---|
3814 | Â Â Â Â Â Â Â Â wave =Â Data['wavelength'] |
---|
3815 | Â Â Â Â Â Â Â Â xy1 =Â [] |
---|
3816 | Â Â Â Â Â Â Â Â xy2 =Â [] |
---|
3817 | Â Â Â Â Â Â Â Â Azm =Â np.linspace(0,362,181) |
---|
3818 |         for azm in Azm: |
---|
3819 | Â Â Â Â Â Â Â Â Â Â xy1.append(G2img.GetDetectorXY(Dsp(tth+thick/2.,wave),azm,Data))Â Â Â #what about hyperbola |
---|
3820 | Â Â Â Â Â Â Â Â Â Â xy2.append(G2img.GetDetectorXY(Dsp(tth-thick/2.,wave),azm,Data))Â Â Â #what about hyperbola |
---|
3821 | Â Â Â Â Â Â Â Â x1,y1 =Â np.array(xy1).T |
---|
3822 | Â Â Â Â Â Â Â Â x2,y2 =Â np.array(xy2).T |
---|
3823 | Â Â Â Â Â Â Â Â G2frame.ringList.append([Plot.plot(x1,y1,'r',picker=3),iring,'o'])Â Â Â Â Â Â |
---|
3824 | Â Â Â Â Â Â Â Â G2frame.ringList.append([Plot.plot(x2,y2,'r',picker=3),iring,'i']) |
---|
3825 | Â Â Â Â G2frame.arcList =Â [] |
---|
3826 |     for iarc,arc in enumerate(arcs): |
---|
3827 |       if arc: |
---|
3828 |         tth,azm,thick = arc      |
---|
3829 | Â Â Â Â Â Â Â Â wave =Â Data['wavelength'] |
---|
3830 | Â Â Â Â Â Â Â Â xy1 =Â [] |
---|
3831 | Â Â Â Â Â Â Â Â xy2 =Â [] |
---|
3832 | Â Â Â Â Â Â Â Â aR =Â azm[0],azm[1],azm[1]-azm[0] |
---|
3833 |         if azm[1]-azm[0] > 180: |
---|
3834 | Â Â Â Â Â Â Â Â Â Â aR[2]Â /=Â 2 |
---|
3835 | Â Â Â Â Â Â Â Â Azm =Â np.linspace(aR[0],aR[1],aR[2]) |
---|
3836 |         for azm in Azm: |
---|
3837 | Â Â Â Â Â Â Â Â Â Â xy1.append(G2img.GetDetectorXY(Dsp(tth+thick/2.,wave),azm,Data))Â Â Â #what about hyperbola |
---|
3838 | Â Â Â Â Â Â Â Â Â Â xy2.append(G2img.GetDetectorXY(Dsp(tth-thick/2.,wave),azm,Data))Â Â Â #what about hyperbola |
---|
3839 | Â Â Â Â Â Â Â Â x1,y1 =Â np.array(xy1).T |
---|
3840 | Â Â Â Â Â Â Â Â x2,y2 =Â np.array(xy2).T |
---|
3841 | Â Â Â Â Â Â Â Â G2frame.arcList.append([Plot.plot(x1,y1,'r',picker=3),iarc,'o'])Â Â Â Â Â Â |
---|
3842 | Â Â Â Â Â Â Â Â G2frame.arcList.append([Plot.plot(x2,y2,'r',picker=3),iarc,'i']) |
---|
3843 | Â Â Â Â Â Â Â Â G2frame.arcList.append([Plot.plot([x1[0],x2[0]],[y1[0],y2[0]],'r',picker=3),iarc,'l']) |
---|
3844 | Â Â Â Â Â Â Â Â G2frame.arcList.append([Plot.plot([x1[-1],x2[-1]],[y1[-1],y2[-1]],'r',picker=3),iarc,'u']) |
---|
3845 | Â Â Â Â G2frame.polyList =Â [] |
---|
3846 |     for ipoly,polygon in enumerate(polygons): |
---|
3847 |       if polygon: |
---|
3848 | Â Â Â Â Â Â Â Â x,y =Â np.hsplit(np.array(polygon),2) |
---|
3849 | Â Â Â Â Â Â Â Â G2frame.polyList.append([Plot.plot(x,y,'r+',picker=10),ipoly]) |
---|
3850 | Â Â Â Â Â Â Â Â Plot.plot(x,y,'r')Â Â Â Â Â Â |
---|
3851 | Â Â Â Â G2frame.frameList =Â [] |
---|
3852 |     if frame: |
---|
3853 | Â Â Â Â Â Â x,y =Â np.hsplit(np.array(frame),2) |
---|
3854 | Â Â Â Â Â Â G2frame.frameList.append([Plot.plot(x,y,'g+',picker=10),0]) |
---|
3855 | Â Â Â Â Â Â Plot.plot(x,y,'g')Â Â Â Â Â Â |
---|
3856 |     if newImage: |
---|
3857 | Â Â Â Â Â Â colorBar =Â Page.figure.colorbar(Img) |
---|
3858 | Â Â Â Â Plot.set_xlim(xlim) |
---|
3859 | Â Â Â Â Plot.set_ylim(ylim) |
---|
3860 |     if Data['invert_x']: |
---|
3861 | Â Â Â Â Â Â Plot.invert_xaxis() |
---|
3862 |     if Data['invert_y']: |
---|
3863 | Â Â Â Â Â Â Plot.invert_yaxis() |
---|
3864 |     if not newPlot and xylim: |
---|
3865 | Â Â Â Â Â Â Page.toolbar.push_current() |
---|
3866 | Â Â Â Â Â Â Plot.set_xlim(xylim[0]) |
---|
3867 | Â Â Â Â Â Â Plot.set_ylim(xylim[1]) |
---|
3868 | Â Â Â Â Â Â xylim =Â [] |
---|
3869 | Â Â Â Â Â Â Page.toolbar.push_current() |
---|
3870 | Â Â Â Â Â Â Page.toolbar.draw() |
---|
3871 | Â Â Â Â Â Â # patch for wx 2.9 on Mac, to force a redraw |
---|
3872 | Â Â Â Â Â Â i,j=Â wx.__version__.split('.')[0:2] |
---|
3873 |       if int(i)+int(j)/10. > 2.8 and 'wxOSX' in wx.PlatformInfo: |
---|
3874 | Â Â Â Â Â Â Â Â Page.canvas.draw() |
---|
3875 | Â Â Â Â else: |
---|
3876 | Â Â Â Â Â Â Page.canvas.draw() |
---|
3877 | Â Â finally: |
---|
3878 | Â Â Â Â wx.EndBusyCursor() |
---|
3879 | Â Â Â Â |
---|
3880 | ################################################################################ |
---|
3881 | ##### PlotIntegration |
---|
3882 | ################################################################################ |
---|
3883 | Â Â Â Â Â Â |
---|
3884 | def PlotIntegration(G2frame,newPlot=False,event=None): |
---|
3885 | Â Â '''Plot of 2D image after image integration with 2-theta and azimuth as coordinates |
---|
3886 | Â Â ''' |
---|
3887 | Â Â Â Â Â Â |
---|
3888 |   def OnMotion(event): |
---|
3889 | Â Â Â Â Page.canvas.SetToolTipString('') |
---|
3890 | Â Â Â Â Page.canvas.SetCursor(wx.CROSS_CURSOR) |
---|
3891 | Â Â Â Â azm =Â event.ydata |
---|
3892 | Â Â Â Â tth =Â event.xdata |
---|
3893 |     if azm and tth: |
---|
3894 | Â Â Â Â Â Â G2frame.G2plotNB.status.SetFields(\ |
---|
3895 | Â Â Â Â Â Â Â Â ['','Detector 2-th =%9.3fdeg, azm = %7.2fdeg'%(tth,azm)]) |
---|
3896 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
---|
3897 | Â Â try: |
---|
3898 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index('2D Integration') |
---|
3899 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
3900 |     if not newPlot: |
---|
3901 | Â Â Â Â Â Â Plot =Â Page.figure.gca()Â Â Â Â Â #get previous plot & get limits |
---|
3902 | Â Â Â Â Â Â xylim =Â Plot.get_xlim(),Plot.get_ylim() |
---|
3903 | Â Â Â Â Page.figure.clf() |
---|
3904 | Â Â Â Â Plot =Â Page.figure.gca()Â Â Â Â Â #get a fresh plot after clf() |
---|
3905 | Â Â Â Â |
---|
3906 |   except ValueError: |
---|
3907 | Â Â Â Â Plot =Â G2frame.G2plotNB.addMpl('2D Integration').gca() |
---|
3908 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index('2D Integration') |
---|
3909 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
3910 |     Page.canvas.mpl_connect('motion_notify_event', OnMotion) |
---|
3911 | Â Â Â Â Page.views =Â False |
---|
3912 | Â Â Â Â view =Â False |
---|
3913 | Â Â Page.Choice =Â None |
---|
3914 |   if not event: |
---|
3915 | Â Â Â Â Page.SetFocus() |
---|
3916 | Â Â Â Â |
---|
3917 | Â Â Data =Â G2frame.PatternTree.GetItemPyData( |
---|
3918 |     G2gd.GetPatternTreeItemId(G2frame,G2frame.Image, 'Image Controls')) |
---|
3919 | Â Â image =Â G2frame.Integrate[0] |
---|
3920 | Â Â xsc =Â G2frame.Integrate[1] |
---|
3921 | Â Â ysc =Â G2frame.Integrate[2] |
---|
3922 | Â Â Imin,Imax =Â Data['range'][1] |
---|
3923 | Â Â acolor =Â mpl.cm.get_cmap(Data['color']) |
---|
3924 | Â Â Plot.set_title(G2frame.PatternTree.GetItemText(G2frame.Image)[4:]) |
---|
3925 | Â Â Plot.set_ylabel('azimuth',fontsize=12) |
---|
3926 | Â Â Plot.set_xlabel('2-theta',fontsize=12) |
---|
3927 |   Img = Plot.imshow(image,cmap=acolor,vmin=Imin,vmax=Imax,interpolation='nearest', \ |
---|
3928 | Â Â Â Â extent=[ysc[0],ysc[-1],xsc[-1],xsc[0]],aspect='auto') |
---|
3929 | Â Â colorBar =Â Page.figure.colorbar(Img) |
---|
3930 | #Â Â if Data['ellipses']:Â Â Â Â Â Â |
---|
3931 | #Â Â Â Â for ellipse in Data['ellipses']: |
---|
3932 | #Â Â Â Â Â Â x,y = np.array(G2img.makeIdealRing(ellipse[:3])) #skip color |
---|
3933 | #Â Â Â Â Â Â tth,azm = G2img.GetTthAzm(x,y,Data) |
---|
3934 | ##Â Â Â Â Â Â azm = np.where(azm < 0.,azm+360,azm) |
---|
3935 | #Â Â Â Â Â Â Plot.plot(tth,azm,'b,') |
---|
3936 |   if not newPlot: |
---|
3937 | Â Â Â Â Page.toolbar.push_current() |
---|
3938 | Â Â Â Â Plot.set_xlim(xylim[0]) |
---|
3939 | Â Â Â Â Plot.set_ylim(xylim[1]) |
---|
3940 | Â Â Â Â xylim =Â [] |
---|
3941 | Â Â Â Â Page.toolbar.push_current() |
---|
3942 | Â Â Â Â Page.toolbar.draw() |
---|
3943 | Â Â else: |
---|
3944 | Â Â Â Â Page.canvas.draw() |
---|
3945 | Â Â Â Â Â Â Â Â |
---|
3946 | ################################################################################ |
---|
3947 | ##### PlotTRImage |
---|
3948 | ################################################################################ |
---|
3949 | Â Â Â Â Â Â |
---|
3950 | def PlotTRImage(G2frame,tax,tay,taz,newPlot=False): |
---|
3951 | Â Â '''a test plot routine - not normally used |
---|
3952 | Â Â '''Â |
---|
3953 | Â Â Â Â Â Â |
---|
3954 |   def OnMotion(event): |
---|
3955 | Â Â Â Â Page.canvas.SetToolTipString('') |
---|
3956 | Â Â Â Â Page.canvas.SetCursor(wx.CROSS_CURSOR) |
---|
3957 | Â Â Â Â azm =Â event.xdata |
---|
3958 | Â Â Â Â tth =Â event.ydata |
---|
3959 |     if azm and tth: |
---|
3960 | Â Â Â Â Â Â G2frame.G2plotNB.status.SetFields(\ |
---|
3961 | Â Â Â Â Â Â Â Â ['','Detector 2-th =%9.3fdeg, azm = %7.2fdeg'%(tth,azm)]) |
---|
3962 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
---|
3963 | Â Â try: |
---|
3964 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index('2D Transformed Powder Image') |
---|
3965 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
3966 |     if not newPlot: |
---|
3967 | Â Â Â Â Â Â Plot =Â Page.figure.gca()Â Â Â Â Â #get previous plot & get limits |
---|
3968 | Â Â Â Â Â Â xylim =Â Plot.get_xlim(),Plot.get_ylim() |
---|
3969 | Â Â Â Â Page.figure.clf() |
---|
3970 | Â Â Â Â Plot =Â Page.figure.gca()Â Â Â Â Â #get a fresh plot after clf() |
---|
3971 | Â Â Â Â |
---|
3972 |   except ValueError: |
---|
3973 | Â Â Â Â Plot =Â G2frame.G2plotNB.addMpl('2D Transformed Powder Image').gca() |
---|
3974 | Â Â Â Â plotNum =Â G2frame.G2plotNB.plotList.index('2D Transformed Powder Image') |
---|
3975 | Â Â Â Â Page =Â G2frame.G2plotNB.nb.GetPage(plotNum) |
---|
3976 |     Page.canvas.mpl_connect('motion_notify_event', OnMotion) |
---|
3977 | Â Â Â Â Page.views =Â False |
---|
3978 | Â Â Â Â view =Â False |
---|
3979 | Â Â Page.Choice =Â None |
---|
3980 | Â Â Page.SetFocus() |
---|
3981 | Â Â Â Â |
---|
3982 | Â Â Data =Â G2frame.PatternTree.GetItemPyData( |
---|
3983 |     G2gd.GetPatternTreeItemId(G2frame,G2frame.Image, 'Image Controls')) |
---|
3984 | Â Â Imin,Imax =Â Data['range'][1] |
---|
3985 | Â Â step =Â (Imax-Imin)/5. |
---|
3986 | Â Â V =Â np.arange(Imin,Imax,step) |
---|
3987 | Â Â acolor =Â mpl.cm.get_cmap(Data['color']) |
---|
3988 | Â Â Plot.set_title(G2frame.PatternTree.GetItemText(G2frame.Image)[4:]) |
---|
3989 | Â Â Plot.set_xlabel('azimuth',fontsize=12) |
---|
3990 | Â Â Plot.set_ylabel('2-theta',fontsize=12) |
---|
3991 | Â Â Plot.contour(tax,tay,taz,V,cmap=acolor) |
---|
3992 |   if Data['showLines']: |
---|
3993 | Â Â Â Â IOtth =Â Data['IOtth'] |
---|
3994 |     if Data['fullIntegrate']: |
---|
3995 | Â Â Â Â Â Â LRAzim =Â [-180,180] |
---|
3996 | Â Â Â Â else: |
---|
3997 | Â Â Â Â Â Â LRAzim =Â Data['LRazimuth']Â Â Â Â Â Â Â Â Â #NB: integers |
---|
3998 | Â Â Â Â Plot.plot([LRAzim[0],LRAzim[1]],[IOtth[0],IOtth[0]],picker=True) |
---|
3999 | Â Â Â Â Plot.plot([LRAzim[0],LRAzim[1]],[IOtth[1],IOtth[1]],picker=True) |
---|
4000 |     if not Data['fullIntegrate']: |
---|
4001 | Â Â Â Â Â Â Plot.plot([LRAzim[0],LRAzim[0]],[IOtth[0],IOtth[1]],picker=True) |
---|
4002 | Â Â Â Â Â Â Plot.plot([LRAzim[1],LRAzim[1]],[IOtth[0],IOtth[1]],picker=True) |
---|
4003 |   if Data['setRings']: |
---|
4004 | Â Â Â Â rings =Â np.concatenate((Data['rings']),axis=0) |
---|
4005 |     for xring,yring,dsp in rings: |
---|
4006 | Â Â Â Â Â Â x,y =Â G2img.GetTthAzm(xring,yring,Data) |
---|
4007 | Â Â Â Â Â Â Plot.plot(y,x,'r+')Â Â Â Â Â Â |
---|
4008 |   if Data['ellipses']:      |
---|
4009 |     for ellipse in Data['ellipses']: |
---|
4010 | Â Â Â Â Â Â ring =Â np.array(G2img.makeIdealRing(ellipse[:3]))Â #skip color |
---|
4011 | Â Â Â Â Â Â x,y =Â np.hsplit(ring,2) |
---|
4012 | Â Â Â Â Â Â tth,azm =Â G2img.GetTthAzm(x,y,Data) |
---|
4013 | Â Â Â Â Â Â Plot.plot(azm,tth,'b,') |
---|
4014 |   if not newPlot: |
---|
4015 | Â Â Â Â Page.toolbar.push_current() |
---|
4016 | Â Â Â Â Plot.set_xlim(xylim[0]) |
---|
4017 | Â Â Â Â Plot.set_ylim(xylim[1]) |
---|
4018 | Â Â Â Â xylim =Â [] |
---|
4019 | Â Â Â Â Page.toolbar.push_current() |
---|
4020 | Â Â Â Â Page.toolbar.draw() |
---|
4021 | Â Â else: |
---|
4022 | Â Â Â Â Page.canvas.draw() |
---|
4023 | Â Â Â Â |
---|
4024 | ################################################################################ |
---|
4025 | ##### PlotStructure |
---|
4026 | ################################################################################ |
---|
4027 | Â Â Â Â Â Â |
---|
4028 | def PlotStructure(G2frame,data,firstCall=False): |
---|
4029 | Â Â '''Crystal structure plotting package. Can show structures as balls, sticks, lines, |
---|
4030 | Â Â thermal motion ellipsoids and polyhedra |
---|
4031 | Â Â ''' |
---|
4032 | |
---|
4033 |   def FindPeaksBonds(XYZ): |
---|
4034 | Â Â Â Â rFact =Â data['Drawing'].get('radiusFactor',0.85)Â Â #data['Drawing'] could be empty! |
---|
4035 |     Bonds = [[] for x in XYZ] |
---|
4036 |     for i,xyz in enumerate(XYZ): |
---|
4037 | Â Â Â Â Â Â Dx =Â XYZ-xyz |
---|
4038 | Â Â Â Â Â Â dist =Â np.sqrt(np.sum(np.inner(Dx,Amat)**2,axis=1)) |
---|
4039 | Â Â Â Â Â Â IndB =Â ma.nonzero(ma.masked_greater(dist,rFact*2.2)) |
---|
4040 |       for j in IndB[0]: |
---|
4041 | Â Â Â Â Â Â Â Â Bonds[i].append(Dx[j]/2.) |
---|
4042 | Â Â Â Â Â Â Â Â Bonds[j].append(-Dx[j]/2.) |
---|
4043 |     return Bonds |
---|
4044 | |
---|
4045 | Â Â # PlotStructure initialization here |
---|
4046 | Â Â ForthirdPI =Â 4.0*math.pi/3.0 |
---|
4047 | Â Â generalData =Â data['General'] |
---|
4048 | Â Â cell =Â generalData['Cell'][1:7] |
---|
4049 | Â Â Vol =Â generalData['Cell'][7:8][0] |
---|
4050 | Â Â Amat,Bmat =Â G2lat.cell2AB(cell)Â Â Â Â Â #Amat - crystal to cartesian, Bmat - inverse |
---|
4051 | Â Â Gmat,gmat =Â G2lat.cell2Gmat(cell) |
---|
4052 | Â Â A4mat =Â np.concatenate((np.concatenate((Amat,[[0],[0],[0]]),axis=1),[[0,0,0,1],]),axis=0) |
---|
4053 | Â Â B4mat =Â np.concatenate((np.concatenate((Bmat,[[0],[0],[0]]),axis=1),[[0,0,0,1],]),axis=0) |
---|
4054 | Â Â SGData =Â generalData['SGData'] |
---|
4055 |   if generalData['Type'] in ['modulated','magnetic']: |
---|
4056 | Â Â Â Â SSGData =Â generalData['SSGData'] |
---|
4057 | Â Â Mydir =Â generalData['Mydir'] |
---|
4058 | Â Â atomData =Â data['Atoms'] |
---|
4059 | Â Â mapPeaks =Â [] |
---|
4060 | Â Â drawingData =Â data['Drawing'] |
---|
4061 |   if not drawingData: |
---|
4062 |     return     #nothing setup, nothing to draw  |
---|
4063 |   if 'Map Peaks' in data: |
---|
4064 | Â Â Â Â mapPeaks =Â np.array(data['Map Peaks']) |
---|
4065 | Â Â Â Â peakMax =Â 100. |
---|
4066 |     if len(mapPeaks): |
---|
4067 | Â Â Â Â Â Â peakMax =Â np.max(mapPeaks.T[0]) |
---|
4068 | Â Â resRBData =Â data['RBModels'].get('Residue',[]) |
---|
4069 | Â Â vecRBData =Â data['RBModels'].get('Vector',[]) |
---|
4070 | Â Â rbAtmDict =Â {} |
---|
4071 |   for rbObj in resRBData+vecRBData: |
---|
4072 |     exclList = ['X' for i in range(len(rbObj['Ids']))] |
---|
4073 | Â Â Â Â rbAtmDict.update(dict(zip(rbObj['Ids'],exclList))) |
---|
4074 | Â Â testRBObj =Â data.get('testRBObj',{}) |
---|
4075 | Â Â rbObj =Â testRBObj.get('rbObj',{}) |
---|
4076 | Â Â MCSA =Â data.get('MCSA',{}) |
---|
4077 | Â Â mcsaModels =Â MCSA.get('Models',[]) |
---|
4078 |   if len(mcsaModels) > 1: |
---|
4079 | Â Â Â Â XYZs,Types =Â G2mth.UpdateMCSAxyz(Bmat,MCSA) |
---|
4080 | Â Â Â Â mcsaXYZ =Â [] |
---|
4081 | Â Â Â Â mcsaTypes =Â [] |
---|
4082 | Â Â Â Â neqv =Â 0 |
---|
4083 |     for xyz,atyp in zip(XYZs,Types): |
---|
4084 | Â Â Â Â Â Â equiv =Â G2spc.GenAtom(xyz,SGData,All=True,Move=False) |
---|
4085 | Â Â Â Â Â Â neqv =Â max(neqv,len(equiv)) |
---|
4086 |       for item in equiv: |
---|
4087 | Â Â Â Â Â Â Â Â mcsaXYZ.append(item[0])Â |
---|
4088 | Â Â Â Â Â Â Â Â mcsaTypes.append(atyp) |
---|
4089 | Â Â Â Â mcsaXYZ =Â np.array(mcsaXYZ) |
---|
4090 | Â Â Â Â mcsaTypes =Â np.array(mcsaTypes) |
---|
4091 | Â Â Â Â nuniq =Â mcsaXYZ.shape[0]/neqv |
---|
4092 | Â Â Â Â mcsaXYZ =Â np.reshape(mcsaXYZ,(nuniq,neqv,3)) |
---|
4093 | Â Â Â Â mcsaTypes =Â np.reshape(mcsaTypes,(nuniq,neqv)) |
---|
4094 | Â Â Â Â cent =Â np.fix(np.sum(mcsaXYZ+2.,axis=0)/nuniq)-2 |
---|
4095 | Â Â Â Â cent[0]Â =Â [0,0,0]Â Â #make sure 1st one isn't moved |
---|
4096 | Â Â Â Â mcsaXYZ =Â np.swapaxes(mcsaXYZ,0,1)-cent[:,np.newaxis,:] |
---|
4097 | Â Â Â Â mcsaTypes =Â np.swapaxes(mcsaTypes,0,1) |
---|
4098 | Â Â Â Â mcsaXYZ =Â np.reshape(mcsaXYZ,(nuniq*neqv,3)) |
---|
4099 | Â Â Â Â mcsaTypes =Â np.reshape(mcsaTypes,(nuniq*neqv))Â Â Â Â Â Â Â Â Â Â Â Â |
---|
4100 | Â Â Â Â mcsaBonds =Â FindPeaksBonds(mcsaXYZ)Â Â Â Â |
---|
4101 | Â Â drawAtoms =Â drawingData.get('Atoms',[]) |
---|
4102 | Â Â mapData =Â {} |
---|
4103 | Â Â flipData =Â {} |
---|
4104 | Â Â rhoXYZ =Â [] |
---|
4105 | Â Â showBonds =Â False |
---|
4106 |   if 'Map' in generalData: |
---|
4107 | Â Â Â Â mapData =Â generalData['Map'] |
---|
4108 | Â Â Â Â showBonds =Â mapData.get('Show bonds',False) |
---|
4109 |   if 'Flip' in generalData: |
---|
4110 | Â Â Â Â flipData =Â generalData['Flip']Â Â Â Â Â Â Â Â Â Â Â Â |
---|
4111 | Â Â Wt =Â np.array([255,255,255]) |
---|
4112 | Â Â Rd =Â np.array([255,0,0]) |
---|
4113 | Â Â Gr =Â np.array([0,255,0]) |
---|
4114 | Â Â wxGreen =Â wx.Colour(0,255,0) |
---|
4115 | Â Â Bl =Â np.array([0,0,255]) |
---|
4116 | Â Â Or =Â np.array([255,128,0]) |
---|
4117 | Â Â wxOrange =Â wx.Colour(255,128,0) |
---|
4118 | Â Â uBox =Â np.array([[0,0,0],[1,0,0],[1,1,0],[0,1,0],[0,0,1],[1,0,1],[1,1,1],[0,1,1]]) |
---|
4119 | Â Â uEdges =Â np.array([ |
---|
4120 |     [uBox[0],uBox[1]],[uBox[0],uBox[3]],[uBox[0],uBox[4]],[uBox[1],uBox[2]], |
---|
4121 |     [uBox[2],uBox[3]],[uBox[1],uBox[5]],[uBox[2],uBox[6]],[uBox[3],uBox[7]], |
---|
4122 | Â Â Â Â [uBox[4],uBox[5]],[uBox[5],uBox[6]],[uBox[6],uBox[7]],[uBox[7],uBox[4]]]) |
---|
4123 | Â Â mD =Â 0.1 |
---|
4124 | Â Â mV =Â np.array([[[-mD,0,0],[mD,0,0]],[[0,-mD,0],[0,mD,0]],[[0,0,-mD],[0,0,mD]]]) |
---|
4125 | Â Â mapPeakVecs =Â np.inner(mV,Bmat) |
---|
4126 | |
---|
4127 | Â Â backColor =Â np.array(list(drawingData['backColor'])+[0,]) |
---|
4128 | Â Â Bc =Â np.array(list(drawingData['backColor'])) |
---|
4129 |   uColors = [Rd,Gr,Bl,Wt-Bc, Wt-Bc,Wt-Bc,Wt-Bc,Wt-Bc, Wt-Bc,Wt-Bc,Wt-Bc,Wt-Bc] |
---|
4130 | Â Â altDown =Â False |
---|
4131 | Â Â shiftDown =Â False |
---|
4132 | Â Â ctrlDown =Â False |
---|
4133 | Â Â G2frame.tau =Â 0. |
---|
4134 | Â Â |
---|
4135 |   def OnKeyBox(event): |
---|
4136 | Â Â Â Â mode =Â cb.GetValue() |
---|
4137 |     if mode in ['jpeg','bmp','tiff',]: |
---|
4138 | Â Â Â Â Â Â try: |
---|
4139 |         import Image as Im |
---|
4140 |       except ImportError: |
---|
4141 | Â Â Â Â Â Â Â Â try: |
---|
4142 |           from PIL import Image as Im |
---|
4143 |         except ImportError: |
---|
4144 |           print "PIL/pillow Image module not present. Cannot save images without this" |
---|
4145 |           raise Exception("PIL/pillow Image module not found") |
---|
4146 | Â Â Â Â Â Â Fname =Â os.path.join(Mydir,generalData['Name']+'.'+mode) |
---|
4147 | Â Â Â Â Â Â size =Â Page.canvas.GetSize() |
---|
4148 |       glPixelStorei(GL_UNPACK_ALIGNMENT, 1) |
---|
4149 |       if mode in ['jpeg',]: |
---|
4150 |         Pix = glReadPixels(0,0,size[0],size[1],GL_RGBA, GL_UNSIGNED_BYTE) |
---|
4151 |         im = Im.new("RGBA", (size[0],size[1])) |
---|
4152 | Â Â Â Â Â Â else: |
---|
4153 |         Pix = glReadPixels(0,0,size[0],size[1],GL_RGB, GL_UNSIGNED_BYTE) |
---|
4154 |         im = Im.new("RGB", (size[0],size[1])) |
---|
4155 | Â Â Â Â Â Â im.fromstring(Pix) |
---|
4156 | Â Â Â Â Â Â im.save(Fname,mode) |
---|
4157 | Â Â Â Â Â Â cb.SetValue(' save as/key:') |
---|
4158 | Â Â Â Â Â Â G2frame.G2plotNB.status.SetStatusText('Drawing saved to: '+Fname,1) |
---|
4159 | Â Â Â Â else: |
---|
4160 | Â Â Â Â Â Â event.key =Â cb.GetValue()[0] |
---|
4161 | Â Â Â Â Â Â cb.SetValue(' save as/key:') |
---|
4162 | Â Â Â Â Â Â wx.CallAfter(OnKey,event) |
---|
4163 | Â Â Â Â Page.canvas.SetFocus()Â # redirect the Focus from the button back to the plot |
---|
4164 | |
---|
4165 |   def OnKey(event):      #on key UP!! |
---|
4166 | Â Â Â Â try: |
---|
4167 | Â Â Â Â Â Â keyCode =Â event.GetKeyCode() |
---|
4168 |       if keyCode > 255: |
---|
4169 | Â Â Â Â Â Â Â Â keyCode =Â 0 |
---|
4170 | Â Â Â Â Â Â key =Â chr(keyCode) |
---|
4171 |     except AttributeError:    #if from OnKeyBox above |
---|
4172 | Â Â Â Â Â Â key =Â str(event.key).upper() |
---|
4173 | Â Â Â Â indx =Â drawingData['selectedAtoms'] |
---|
4174 | Â Â Â Â cx,ct =Â drawingData['atomPtrs'][:2] |
---|
4175 |     if key in ['C']: |
---|
4176 | Â Â Â Â Â Â drawingData['viewPoint']Â =Â [[.5,.5,.5],[0,0]] |
---|
4177 | Â Â Â Â Â Â drawingData['viewDir']Â =Â [0,0,1] |
---|
4178 | Â Â Â Â Â Â drawingData['oldxy']Â =Â [] |
---|
4179 | Â Â Â Â Â Â V0 =Â np.array([0,0,1]) |
---|
4180 | Â Â Â Â Â Â V =Â np.inner(Amat,V0) |
---|
4181 | Â Â Â Â Â Â V /=Â np.sqrt(np.sum(V**2)) |
---|
4182 | Â Â Â Â Â Â A =Â np.arccos(np.sum(V*V0)) |
---|
4183 | Â Â Â Â Â Â Q =Â G2mth.AV2Q(A,[0,1,0]) |
---|
4184 | Â Â Â Â Â Â drawingData['Quaternion']Â =Â Q |
---|
4185 | Â Â Â Â Â Â SetViewPointText(drawingData['viewPoint'][0]) |
---|
4186 | Â Â Â Â Â Â SetViewDirText(drawingData['viewDir']) |
---|
4187 | Â Â Â Â Â Â Q =Â drawingData['Quaternion'] |
---|
4188 | Â Â Â Â Â Â G2frame.G2plotNB.status.SetStatusText('New quaternion: %.2f+, %.2fi+ ,%.2fj+, %.2fk'%(Q[0],Q[1],Q[2],Q[3]),1) |
---|
4189 |     elif key in ['N']: |
---|
4190 | Â Â Â Â Â Â drawAtoms =Â drawingData['Atoms'] |
---|
4191 |       if not len(drawAtoms):   #no atoms |
---|
4192 | Â Â Â Â Â Â Â Â return |
---|
4193 | Â Â Â Â Â Â pI =Â drawingData['viewPoint'][1] |
---|
4194 |       if not len(pI): |
---|
4195 | Â Â Â Â Â Â Â Â pI =Â [0,0] |
---|
4196 |       if indx: |
---|
4197 | Â Â Â Â Â Â Â Â pI[0]Â =Â indx[pI[1]] |
---|
4198 | Â Â Â Â Â Â Â Â Tx,Ty,Tz =Â drawAtoms[pI[0]][cx:cx+3] |
---|
4199 | Â Â Â Â Â Â Â Â pI[1]Â +=Â 1 |
---|
4200 |         if pI[1] >= len(indx): |
---|
4201 | Â Â Â Â Â Â Â Â Â Â pI[1]Â =Â 0 |
---|
4202 | Â Â Â Â Â Â else: |
---|
4203 | Â Â Â Â Â Â Â Â Tx,Ty,Tz =Â drawAtoms[pI[0]][cx:cx+3]Â Â Â Â Â Â Â Â |
---|
4204 | Â Â Â Â Â Â Â Â pI[0]Â +=Â 1 |
---|
4205 |         if pI[0] >= len(drawAtoms): |
---|
4206 | Â Â Â Â Â Â Â Â Â Â pI[0]Â =Â 0 |
---|
4207 | Â Â Â Â Â Â drawingData['viewPoint']Â =Â [[Tx,Ty,Tz],pI] |
---|
4208 | Â Â Â Â Â Â SetViewPointText(drawingData['viewPoint'][0]) |
---|
4209 | Â Â Â Â Â Â G2frame.G2plotNB.status.SetStatusText('View point at atom '+drawAtoms[pI[0]][ct-1]+str(pI),1) |
---|
4210 | Â Â Â Â Â Â Â Â |
---|
4211 |     elif key in ['P']: |
---|
4212 | Â Â Â Â Â Â drawAtoms =Â drawingData['Atoms'] |
---|
4213 |       if not len(drawAtoms):   #no atoms |
---|
4214 | Â Â Â Â Â Â Â Â return |
---|
4215 | Â Â Â Â Â Â pI =Â drawingData['viewPoint'][1] |
---|
4216 |       if not len(pI): |
---|
4217 | Â Â Â Â Â Â Â Â pI =Â [0,0] |
---|
4218 |       if indx: |
---|
4219 | Â Â Â Â Â Â Â Â pI[0]Â =Â indx[pI[1]] |
---|
4220 | Â Â Â Â Â Â Â Â Tx,Ty,Tz =Â drawAtoms[pI[0]][cx:cx+3] |
---|
4221 | Â Â Â Â Â Â Â Â pI[1]Â -=Â 1 |
---|
4222 |         if pI[1] < 0: |
---|
4223 | Â Â Â Â Â Â Â Â Â Â pI[1]Â =Â len(indx)-1 |
---|
4224 | Â Â Â Â Â Â else: |
---|
4225 | Â Â Â Â Â Â Â Â Tx,Ty,Tz =Â drawAtoms[pI[0]][cx:cx+3]Â Â Â Â Â Â Â Â |
---|
4226 | Â Â Â Â Â Â Â Â pI[0]Â -=Â 1 |
---|
4227 |         if pI[0] < 0: |
---|
4228 | Â Â Â Â Â Â Â Â Â Â pI[0]Â =Â len(drawAtoms)-1 |
---|
4229 | Â Â Â Â Â Â drawingData['viewPoint']Â =Â [[Tx,Ty,Tz],pI] |
---|
4230 | Â Â Â Â Â Â SetViewPointText(drawingData['viewPoint'][0])Â Â Â Â Â Â |
---|
4231 | Â Â Â Â Â Â G2frame.G2plotNB.status.SetStatusText('View point at atom '+drawAtoms[pI[0]][ct-1]+str(pI),1) |
---|
4232 |     elif key in ['U','D','L','R'] and mapData['Flip'] == True: |
---|
4233 | Â Â Â Â Â Â dirDict =Â {'U':[0,1],'D':[0,-1],'L':[-1,0],'R':[1,0]} |
---|
4234 | Â Â Â Â Â Â SetMapRoll(dirDict[key]) |
---|
4235 |       if 'rho' in generalData.get('4DmapData',{}): |
---|
4236 | Â Â Â Â Â Â Â Â Set4DMapRoll(dirDict[key]) |
---|
4237 | Â Â Â Â Â Â SetPeakRoll(dirDict[key]) |
---|
4238 | Â Â Â Â Â Â SetMapPeaksText(mapPeaks) |
---|
4239 |     elif key in ['+','-','=','0'] and generalData['Type'] in ['modulated','magnetic']: |
---|
4240 |       if key == '0': |
---|
4241 | Â Â Â Â Â Â Â Â G2frame.tau =Â 0. |
---|
4242 |       elif key in ['+','=']: |
---|
4243 | Â Â Â Â Â Â Â Â G2frame.tau +=Â 0.05 |
---|
4244 |       elif key == '-': |
---|
4245 | Â Â Â Â Â Â Â Â G2frame.tau -=Â 0.05 |
---|
4246 |       G2frame.tau %= 1.  #force 0-1 range |
---|
4247 | Â Â Â Â Draw('key') |
---|
4248 | Â Â Â Â Â Â |
---|
4249 |   def GetTruePosition(xy,Add=False): |
---|
4250 | Â Â Â Â View =Â glGetIntegerv(GL_VIEWPORT) |
---|
4251 | Â Â Â Â Proj =Â glGetDoublev(GL_PROJECTION_MATRIX) |
---|
4252 | Â Â Â Â Model =Â glGetDoublev(GL_MODELVIEW_MATRIX) |
---|
4253 | Â Â Â Â Zmax =Â 1. |
---|
4254 |     if Add: |
---|
4255 | Â Â Â Â Â Â Indx =Â GetSelectedAtoms() |
---|
4256 |     if G2frame.dataDisplay.GetPageText(getSelection()) == 'Map peaks': |
---|
4257 |       for i,peak in enumerate(mapPeaks): |
---|
4258 | Â Â Â Â Â Â Â Â x,y,z =Â peak[1:4] |
---|
4259 | Â Â Â Â Â Â Â Â X,Y,Z =Â gluProject(x,y,z,Model,Proj,View) |
---|
4260 | Â Â Â Â Â Â Â Â XY =Â [int(X),int(View[3]-Y)] |
---|
4261 |         if np.allclose(xy,XY,atol=10) and Z < Zmax: |
---|
4262 | Â Â Â Â Â Â Â Â Â Â Zmax =Â Z |
---|
4263 | Â Â Â Â Â Â Â Â Â Â try: |
---|
4264 | Â Â Â Â Â Â Â Â Â Â Â Â Indx.remove(i) |
---|
4265 | Â Â Â Â Â Â Â Â Â Â Â Â ClearSelectedAtoms() |
---|
4266 |             for id in Indx: |
---|
4267 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â SetSelectedAtoms(id,Add) |
---|
4268 | Â Â Â Â Â Â Â Â Â Â except: |
---|
4269 | Â Â Â Â Â Â Â Â Â Â Â Â SetSelectedAtoms(i,Add) |
---|
4270 | Â Â Â Â else: |
---|
4271 | Â Â Â Â Â Â cx =Â drawingData['atomPtrs'][0] |
---|
4272 |       for i,atom in enumerate(drawAtoms): |
---|
4273 | Â Â Â Â Â Â Â Â x,y,z =Â atom[cx:cx+3] |
---|
4274 | Â Â Â Â Â Â Â Â X,Y,Z =Â gluProject(x,y,z,Model,Proj,View) |
---|
4275 | Â Â Â Â Â Â Â Â XY =Â [int(X),int(View[3]-Y)] |
---|
4276 |         if np.allclose(xy,XY,atol=10) and Z < Zmax: |
---|
4277 | Â Â Â Â Â Â Â Â Â Â Zmax =Â Z |
---|
4278 | Â Â Â Â Â Â Â Â Â Â try: |
---|
4279 | Â Â Â Â Â Â Â Â Â Â Â Â Indx.remove(i) |
---|
4280 | Â Â Â Â Â Â Â Â Â Â Â Â ClearSelectedAtoms() |
---|
4281 |             for id in Indx: |
---|
4282 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â SetSelectedAtoms(id,Add) |
---|
4283 | Â Â Â Â Â Â Â Â Â Â except: |
---|
4284 | Â Â Â Â Â Â Â Â Â Â Â Â SetSelectedAtoms(i,Add) |
---|
4285 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
---|
4286 |   def OnMouseDown(event): |
---|
4287 | Â Â Â Â xy =Â event.GetPosition() |
---|
4288 |     if event.ShiftDown(): |
---|
4289 |       if event.LeftIsDown(): |
---|
4290 | Â Â Â Â Â Â Â Â GetTruePosition(xy) |
---|
4291 |       elif event.RightIsDown(): |
---|
4292 | Â Â Â Â Â Â Â Â GetTruePosition(xy,True) |
---|
4293 | Â Â Â Â else: |
---|
4294 | Â Â Â Â Â Â drawingData['oldxy']Â =Â list(xy) |
---|
4295 | Â Â Â Â |
---|
4296 |   def OnMouseMove(event): |
---|
4297 |     if event.ShiftDown():      #don't want any inadvertant moves when picking |
---|
4298 | Â Â Â Â Â Â return |
---|
4299 | Â Â Â Â newxy =Â event.GetPosition() |
---|
4300 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
---|
4301 |     if event.Dragging(): |
---|
4302 |       if event.AltDown() and rbObj: |
---|
4303 |         if event.LeftIsDown(): |
---|
4304 | Â Â Â Â Â Â Â Â Â Â SetRBRotation(newxy) |
---|
4305 | Â Â Â Â Â Â Â Â Â Â Q =Â rbObj['Orient'][0] |
---|
4306 | Â Â Â Â Â Â Â |
---|