Changeset 2660
- Timestamp:
- Jan 25, 2017 4:06:39 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASII.py
r2659 r2660 3600 3600 Id = self.PatternTree.AppendItem(parent=self.root,text='PDF '+PWDRname) 3601 3601 Data = { 3602 'Sample':{'Name':item,'Mult':1.0 ,'Add':0.0},3603 'Sample Bkg.':{'Name':'','Mult':-1.0 ,'Add':0.0},3604 'Container':{'Name':'','Mult':-1.0 ,'Add':0.0},3602 'Sample':{'Name':item,'Mult':1.0}, 3603 'Sample Bkg.':{'Name':'','Mult':-1.0}, 3604 'Container':{'Name':'','Mult':-1.0}, 3605 3605 'Container Bkg.':{'Name':'','Mult':-1.0,'Add':0.0},'ElList':ElList, 3606 3606 'Geometry':'Cylinder','Diam':1.0,'Pack':0.50,'Form Vol':10.0, -
trunk/GSASIIgrid.py
r2659 r2660 4582 4582 data = G2frame.PatternTree.GetItemPyData(GetPatternTreeItemId(G2frame,item,'PDF Controls')) 4583 4583 G2pdG.UpdatePDFGrid(G2frame,data) 4584 G2plt.PlotISFG(G2frame,data,plotType='G(R)') 4584 if len(data['G(R)']): 4585 G2plt.PlotISFG(G2frame,data,plotType='G(R)') 4585 4586 elif G2frame.PatternTree.GetItemText(item) == 'Phases': 4586 4587 G2frame.dataFrame.setSizePosLeft(defWid) … … 4592 4593 data = G2frame.PatternTree.GetItemPyData(GetPatternTreeItemId(G2frame,G2frame.PatternId,'PDF Controls')) 4593 4594 G2pdG.UpdatePDFPeaks(G2frame,peaks,data) 4594 G2plt.PlotISFG(G2frame,data,plotType='G(R)',newPlot=True,peaks=peaks) 4595 if len(data['G(R)']): 4596 G2plt.PlotISFG(G2frame,data,plotType='G(R)',newPlot=True,peaks=peaks) 4595 4597 elif G2frame.PatternTree.GetItemText(item) == 'PDF Controls': 4596 4598 for i in G2frame.ExportPDF: i.Enable(True) # this should be done on .gpx load; is done on OnMakePDFs (GSASII.py) … … 4599 4601 data = G2frame.PatternTree.GetItemPyData(item) 4600 4602 G2pdG.UpdatePDFGrid(G2frame,data) 4601 G2plt.PlotISFG(G2frame,data,plotType='I(Q)') 4602 G2plt.PlotISFG(G2frame,data,plotType='S(Q)') 4603 G2plt.PlotISFG(G2frame,data,plotType='F(Q)') 4604 G2plt.PlotISFG(G2frame,data,plotType='G(R)') 4603 if len(data['G(R)']): 4604 G2plt.PlotISFG(G2frame,data,plotType='I(Q)') 4605 G2plt.PlotISFG(G2frame,data,plotType='S(Q)') 4606 G2plt.PlotISFG(G2frame,data,plotType='F(Q)') 4607 G2plt.PlotISFG(G2frame,data,plotType='G(R)') 4605 4608 elif G2frame.PatternTree.GetItemText(parentID) == 'Phases': 4606 4609 data = G2frame.PatternTree.GetItemPyData(item) -
trunk/GSASIIplot.py
r2659 r2660 2353 2353 or multiple plots with waterfall and contour plots as options 2354 2354 ''' 2355 global Peaks 2356 Peaks = peaks 2355 2357 G2frame.ShiftDown = False 2356 2358 if not plotType: … … 2457 2459 except TypeError: 2458 2460 G2frame.G2plotNB.status.SetStatusText('Select '+plotType+' pattern first',1) 2461 2462 def OnPick(event): 2463 2464 def OnDragLine(event): 2465 '''Respond to dragging of a plot line 2466 ''' 2467 if event.xdata is None: return # ignore if cursor out of window 2468 Page.canvas.restore_region(savedplot) 2469 coords = G2frame.itemPicked.get_data() 2470 coords[0][0] = coords[0][1] = event.xdata 2471 coords = G2frame.itemPicked.set_data(coords) 2472 Page.figure.gca().draw_artist(G2frame.itemPicked) 2473 Page.canvas.blit(Page.figure.gca().bbox) 2474 2475 if Peaks == None: return 2476 if G2frame.itemPicked is not None: return 2477 pick = event.artist 2478 mouse = event.mouseevent 2479 xpos = pick.get_xdata() 2480 ypos = pick.get_ydata() 2481 ind = event.ind 2482 xy = list(zip(np.take(xpos,ind),np.take(ypos,ind))[0]) 2483 if not ind[0]: # a limit line - allow it to drag 2484 # prepare to animate move of line 2485 G2frame.itemPicked = pick 2486 pick.set_linestyle(':') # set line as dotted 2487 Page = G2frame.G2plotNB.nb.GetPage(plotNum) 2488 Page.figure.gca() 2489 Page.canvas.draw() # refresh without dotted line & save bitmap 2490 savedplot = Page.canvas.copy_from_bbox(Page.figure.gca().bbox) 2491 G2frame.cid = Page.canvas.mpl_connect('motion_notify_event', OnDragLine) 2492 pick.set_linestyle('--') # back to dashed 2493 else: # a profile point, e.g. a peak 2494 if mouse.button == 1: 2495 Peaks['Peaks'].append([xy[0],xy[1]*.5,.5,'','','',0.]) 2496 Peaks['Peaks'] = G2mth.sortArray(Peaks['Peaks'],0,reverse=False) 2497 PlotISFG(G2frame,data,peaks=Peaks,newPlot=False) 2498 G2pdG.UpdatePDFPeaks(G2frame,Peaks,data) 2499 2500 def OnRelease(event): 2501 if Peaks == None: return 2502 if G2frame.itemPicked == None: return 2503 if G2frame.cid is not None: # if there is a drag connection, delete it 2504 Page.canvas.mpl_disconnect(G2frame.cid) 2505 G2frame.cid = None 2506 if event.xdata is None or event.ydata is None: # ignore drag if cursor is outside of plot 2507 Page.canvas.mpl_disconnect(G2frame.cid) 2508 G2frame.cid = None 2509 PlotISFG(G2frame,data,peaks=Peaks,newPlot=False) 2510 return 2511 lines = [] 2512 for line in G2frame.Lines: 2513 lines.append(line.get_xdata()[0]) 2514 try: 2515 lineNo = lines.index(G2frame.itemPicked.get_xdata()[0]) 2516 except ValueError: 2517 lineNo = -1 2518 if lineNo in [0,1]: 2519 Peaks['Limits'][lineNo] = event.xdata 2520 if event.button == 3: 2521 del Peaks['Peaks'][lineNo-2] 2522 G2frame.itemPicked = None 2523 G2pdG.UpdatePDFPeaks(G2frame,Peaks,data) 2524 PlotISFG(G2frame,data,peaks=Peaks,newPlot=False) 2459 2525 2460 2526 xylim = [] … … 2470 2536 Page.canvas.mpl_connect('key_release_event', OnPlotKeyUp) 2471 2537 Page.canvas.mpl_connect('motion_notify_event', OnMotion) 2538 Page.canvas.mpl_connect('pick_event', OnPick) 2539 Page.canvas.mpl_connect('button_release_event', OnRelease) 2472 2540 Page.Offset = [0,0] 2473 2541 2474 2542 G2frame.G2plotNB.status.DestroyChildren() 2475 if peaks == None:2543 if Peaks == None: 2476 2544 if G2frame.Contour: 2477 2545 Page.Choice = (' key press','d: lower contour max','u: raise contour max', … … 2485 2553 Page.keyPress = OnPlotKeyPress 2486 2554 else: 2555 G2frame.cid = None 2487 2556 Page.Choice = () 2488 newPlot = True2489 2557 PatternId = G2frame.PatternId 2490 2558 name = G2frame.PatternTree.GetItemText(PatternId)[4:] … … 2519 2587 lenX = 0 2520 2588 for Pattern in PlotList: 2589 if not len(Pattern): return #no PDF's yet 2521 2590 xye = Pattern[1] 2522 2591 Ymax = max(Ymax,max(xye[1])) … … 2559 2628 Ymin = np.amin(XYlist.T[1]) 2560 2629 Ymax = np.amax(XYlist.T[1]) 2561 normcl = mpcls.Normalize(Ymin,Ymax)2562 2630 dy = 0.02*(Ymax-Ymin) 2563 2631 Plot.set_xlim(Xmin-dx,Xmax+dx) 2564 2632 Plot.set_ylim(Ymin-dy,Ymax+dy) 2565 acolor = mpl.cm.get_cmap(G2frame.ContourColor) 2566 wx.BeginBusyCursor() 2567 if XYlist.shape[0]>1: 2568 if G2frame.Waterfall: 2569 for xylist in XYlist: 2570 ymin = np.amin(xylist.T[1]) 2571 ymax = np.amax(xylist.T[1]) 2572 normcl = mpcls.Normalize(ymin,ymax) 2573 colorRange = xylist.T[1] 2574 segs = np.reshape(np.hstack((xylist[:-1],xylist[1:])),(-1,2,2)) 2633 if Peaks == None: 2634 normcl = mpcls.Normalize(Ymin,Ymax) 2635 acolor = mpl.cm.get_cmap(G2frame.ContourColor) 2636 wx.BeginBusyCursor() 2637 if XYlist.shape[0]>1: 2638 if G2frame.Waterfall: 2639 for xylist in XYlist: 2640 ymin = np.amin(xylist.T[1]) 2641 ymax = np.amax(xylist.T[1]) 2642 normcl = mpcls.Normalize(ymin,ymax) 2643 colorRange = xylist.T[1] 2644 segs = np.reshape(np.hstack((xylist[:-1],xylist[1:])),(-1,2,2)) 2645 line = mplC.LineCollection(segs,cmap=acolor,norm=normcl) 2646 line.set_array(colorRange) 2647 Plot.add_collection(line) 2648 axcb = Page.figure.colorbar(line) 2649 axcb.set_label(plotType) 2650 else: #ok 2651 lines = mplC.LineCollection(XYlist,cmap=acolor) 2652 lines.set_array(np.arange(XYlist.shape[0])) 2653 Plot.add_collection(lines) 2654 axcb = Page.figure.colorbar(lines) 2655 axcb.set_label('PDF number') 2656 else: 2657 if G2frame.Waterfall: 2658 colorRange = XYlist[0].T[1] 2659 segs = np.reshape(np.hstack((XYlist[0][:-1],XYlist[0][1:])),(-1,2,2)) 2575 2660 line = mplC.LineCollection(segs,cmap=acolor,norm=normcl) 2576 2661 line.set_array(colorRange) 2577 2662 Plot.add_collection(line) 2578 axcb = Page.figure.colorbar(line) 2579 axcb.set_label(plotType) 2580 else: #ok 2581 lines = mplC.LineCollection(XYlist,cmap=acolor) 2582 lines.set_array(np.arange(XYlist.shape[0])) 2583 Plot.add_collection(lines) 2584 axcb = Page.figure.colorbar(lines) 2585 axcb.set_label('PDF number') 2663 axcb = Page.figure.colorbar(line) 2664 axcb.set_label('Intensity') 2665 else: #ok 2666 line = mplC.LineCollection(XYlist,color=colors[0]) 2667 Plot.add_collection(line) 2668 wx.EndBusyCursor() 2669 if plotType == 'G(R)': 2670 Xb = [0.,2.5] 2671 Yb = [0.,-10.*np.pi*numbDen] 2672 Plot.plot(Xb,Yb,color='k',dashes=(5,5)) 2673 elif plotType == 'F(Q)': 2674 Plot.axhline(0.,color=wx.BLACK) 2675 elif plotType == 'S(Q)': 2676 Plot.axhline(1.,color=wx.BLACK) 2586 2677 else: 2587 if G2frame.Waterfall: 2588 colorRange = XYlist[0].T[1] 2589 segs = np.reshape(np.hstack((XYlist[0][:-1],XYlist[0][1:])),(-1,2,2)) 2590 line = mplC.LineCollection(segs,cmap=acolor,norm=normcl) 2591 line.set_array(colorRange) 2592 Plot.add_collection(line) 2593 axcb = Page.figure.colorbar(line) 2594 axcb.set_label('Intensity') 2595 else: #ok 2596 line = mplC.LineCollection(XYlist,color=colors[0]) 2597 Plot.add_collection(line) 2598 if peaks != None: 2599 Plot.axvline(peaks['Limits'][0],color='g',dashes=(5,5),picker=2.) 2600 Plot.axvline(peaks['Limits'][1],color='r',dashes=(5,5),picker=2.) 2601 wx.EndBusyCursor() 2602 if plotType == 'G(R)': 2603 Xb = [0.,2.5] 2604 Yb = [0.,-10.*np.pi*numbDen] 2678 G2frame.Lines = [] 2679 X = XYlist[0].T[0] 2680 Y = XYlist[0].T[1] 2681 Plot.plot(X,Y,color='b',picker=3) 2682 G2frame.Lines.append(Plot.axvline(peaks['Limits'][0],color='g',dashes=(5,5),picker=2.)) 2683 G2frame.Lines.append(Plot.axvline(peaks['Limits'][1],color='r',dashes=(5,5),picker=2.)) 2684 for peak in Peaks['Peaks']: 2685 G2frame.Lines.append(Plot.axvline(peak[0],color='r',picker=2.)) 2686 Xb = [0.,peaks['Limits'][1]] 2687 Yb = [0.,Xb[1]*peaks['Background'][1][1]] 2605 2688 Plot.plot(Xb,Yb,color='k',dashes=(5,5)) 2606 elif plotType == 'F(Q)':2607 Plot.axhline(0.,color=wx.BLACK)2608 elif plotType == 'S(Q)':2609 Plot.axhline(1.,color=wx.BLACK)2610 2611 2689 # elif G2frame.Legend: 2612 2690 # Plot.legend(loc='best') -
trunk/GSASIIpwd.py
r2659 r2660 295 295 IofQ[1] = np.array(IofQ[1])[:,Ibeg:Ifin] 296 296 if data['Sample Bkg.']['Name']: 297 IofQ[1][1] += (xydata['Sample Bkg.'][1][1][Ibeg:Ifin]+ 298 data['Sample Bkg.']['Add'])*data['Sample Bkg.']['Mult'] 297 IofQ[1][1] += xydata['Sample Bkg.'][1][1][Ibeg:Ifin]*data['Sample Bkg.']['Mult'] 299 298 if data['Container']['Name']: 300 xycontainer = (xydata['Container'][1][1]+data['Container']['Add'])*data['Container']['Mult']299 xycontainer = xydata['Container'][1][1]*data['Container']['Mult'] 301 300 if data['Container Bkg.']['Name']: 302 xycontainer += (xydata['Container Bkg.'][1][1][Ibeg:Ifin]+ 303 data['Container Bkg.']['Add'])*data['Container Bkg.']['Mult'] 301 xycontainer += xydata['Container Bkg.'][1][1][Ibeg:Ifin]*data['Container Bkg.']['Mult'] 304 302 IofQ[1][1] += xycontainer[Ibeg:Ifin] 305 data['IofQmin'] = IofQ[1][1][ Ifin-1]303 data['IofQmin'] = IofQ[1][1][-1] 306 304 IofQ[1][1] -= data.get('Flat Bkg',0.) 307 305 #get element data & absorption coeff. -
trunk/GSASIIpwdGUI.py
r2659 r2660 4625 4625 ''' 4626 4626 def FillFileSizer(fileSizer,key): 4627 #fileSizer is a FlexGridSizer(3, 6)4627 #fileSizer is a FlexGridSizer(3,4) 4628 4628 4629 4629 def OnSelectFile(event): … … 4666 4666 mulBox.Add(multSpin,0,WACV) 4667 4667 fileSizer.Add(mulBox,0,WACV) 4668 fileSizer.Add(wx.StaticText(parent=G2frame.dataDisplay,label='Add:'),0,WACV)4669 fileSizer.Add(G2G.ValidatedTxtCtrl(G2frame.dataDisplay,item,'Add',nDig=(10,0),4670 typeHint=float,OnLeave=AfterChange),0,)4671 4668 4672 4669 def SumElementVolumes(): … … 4800 4797 File.write("#GSAS-II PDF controls file; do not add/delete items!\n") 4801 4798 for item in data: 4802 File.write(item+':'+unicode(data[item])+'\n') 4799 if item[:] not in ['I(Q)','S(Q)','F(Q)','G(R)']: 4800 File.write(item+':'+unicode(data[item])+'\n') 4803 4801 File.close() 4804 4802 print 'PDF controls saved to: '+filename … … 4861 4859 Invoked by Optimize PDF button and from menu command. 4862 4860 ''' 4861 if not data['ElList']: 4862 G2frame.ErrorDialog('PDF error','Chemical formula not defined') 4863 return 4863 4864 wx.BeginBusyCursor() 4864 4865 try: … … 4871 4872 def OptimizePDF(data,showFit=True,maxCycles=5): 4872 4873 import scipy.optimize as opt 4873 Min,Init,Done = SetupPDFEval(data) 4874 SetUp = SetupPDFEval(data) 4875 Min,Init,Done = SetUp 4874 4876 xstart = Init() 4875 4877 if showFit: … … 4897 4899 '''Create functions needed to optimize the PDF at low r 4898 4900 ''' 4899 if not data['ElList']:4900 return None4901 4901 Data = copy.deepcopy(data) 4902 4902 xydata = {} … … 4986 4986 G2plt.PlotISFG(G2frame,data,newPlot=True,plotType='S(Q)') 4987 4987 G2plt.PlotISFG(G2frame,data,newPlot=True,plotType='F(Q)') 4988 G2plt.PlotISFG(G2frame,data,newPlot= False,plotType='G(R)')4988 G2plt.PlotISFG(G2frame,data,newPlot=True,plotType='G(R)') 4989 4989 else: 4990 4990 G2plt.PlotISFG(G2frame,data,newPlot=False) … … 5112 5112 mainSizer.Add(wx.StaticText(parent=G2frame.dataDisplay,label=str),0,WACV) 5113 5113 mainSizer.Add((5,5),0) 5114 fileSizer = wx.FlexGridSizer(0, 6,5,1)5114 fileSizer = wx.FlexGridSizer(0,4,5,1) 5115 5115 select = ['Sample Bkg.','Container'] 5116 5116 if data['Container']['Name']: … … 5259 5259 ############################################################################################################### 5260 5260 def UpdatePDFPeaks(G2frame,peaks,data): 5261 5261 5262 def limitSizer(): 5263 5264 def NewLim(invalid,value,tc): 5265 if invalid: 5266 return 5267 G2plt.PlotISFG(G2frame,data,newPlot=False,plotType='G(R)',peaks=peaks) 5268 5269 limitBox = wx.BoxSizer(wx.HORIZONTAL) 5270 limitBox.Add(wx.StaticText(G2frame.dataDisplay,label=' PDF Limits: '),0,WACV) 5271 lowLim = G2G.ValidatedTxtCtrl(G2frame.dataDisplay,peaks['Limits'],0,nDig=(10,3), 5272 min=0.,max=10.,typeHint=float,OnLeave=NewLim) 5273 limitBox.Add(lowLim,0,WACV) 5274 highLim = G2G.ValidatedTxtCtrl(G2frame.dataDisplay,peaks['Limits'],1,nDig=(10,3), 5275 min=peaks['Limits'][0],max=10.,typeHint=float,OnLeave=NewLim) 5276 limitBox.Add(highLim,0,WACV) 5277 return limitBox 5278 5279 def backSizer(): 5280 5281 def NewBack(invalid,value,tc): 5282 if invalid: 5283 return 5284 G2plt.PlotISFG(G2frame,data,newPlot=False,plotType='G(R)',peaks=peaks) 5285 5286 def OnRefBack(event): 5287 peaks['Background'][2] = refbk.GetValue() 5288 5289 backBox = wx.wx.BoxSizer(wx.HORIZONTAL) 5290 backBox.Add(wx.StaticText(G2frame.dataDisplay,label=' Background slope: '),0,WACV) 5291 slope = G2G.ValidatedTxtCtrl(G2frame.dataDisplay,peaks['Background'][1],1,nDig=(10,3), 5292 min=-4.*np.pi,max=0.,typeHint=float,OnLeave=NewBack) 5293 backBox.Add(slope,0,WACV) 5294 refbk = wx.CheckBox(parent=G2frame.dataDisplay,label=' Refine?') 5295 refbk.SetValue(peaks['Background'][2]) 5296 refbk.Bind(wx.EVT_CHECKBOX, OnRefBack) 5297 backBox.Add(refbk,0,WACV) 5298 return backBox 5299 5300 def peakSizer(): 5301 5302 for item in peaks['Peaks']: print item 5303 peakBox = wx.BoxSizer(wx.VERTICAL) 5304 5305 5306 return peakBox 5307 5262 5308 5263 5309 if G2frame.dataDisplay: … … 5270 5316 # G2frame.dataFrame.Bind(wx.EVT_MENU, OnSavePDFControls, id=G2gd.wxID_PDFSAVECONTROLS) 5271 5317 mainSizer = wx.BoxSizer(wx.VERTICAL) 5272 mainSizer.Add(wx.StaticText(parent=G2frame.dataDisplay,label=' PDF peaks: '),0,WACV) 5273 mainSizer.Add((5,5),0) 5274 5275 5318 mainSizer.Add((5,5),0) 5319 mainSizer.Add(wx.StaticText(G2frame.dataDisplay,label=' PDF peak fit controls:'),0,WACV) 5320 mainSizer.Add((5,5),0) 5321 mainSizer.Add(limitSizer(),0,WACV) 5322 mainSizer.Add((5,5),0) 5323 mainSizer.Add(backSizer()) 5324 mainSizer.Add((5,5),0) 5325 mainSizer.Add(peakSizer()) 5276 5326 5277 5327 mainSizer.Layout()
Note: See TracChangeset
for help on using the changeset viewer.