Changeset 1237
- Timestamp:
- Mar 5, 2014 2:14:48 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIplot.py
r1232 r1237 522 522 G2frame.G2plotNB.status.SetStatusText('TOF =%9.3f d =%9.5f q = %9.5f Intensity =%9.2f'%(xpos,dsp,q,ypos),1) 523 523 if G2frame.itemPicked: 524 Page.canvas.SetToolTipString('%9. 3f'%(xpos))524 Page.canvas.SetToolTipString('%9.5f'%(xpos)) 525 525 if G2frame.PickId: 526 526 found = [] … … 539 539 except TypeError: 540 540 G2frame.G2plotNB.status.SetStatusText('Select '+plottype+' powder pattern first',1) 541 542 def OnPress(event): #ugh - this removes a matplotlib error for mouse clicks in log plots 543 olderr = np.seterr(invalid='ignore') 541 544 542 545 def OnPick(event): … … 553 556 PickId = G2frame.PickId 554 557 pick = event.artist 555 mouse = event.mouseevent 558 mouse = event.mouseevent 556 559 xpos = pick.get_xdata() 557 560 ypos = pick.get_ydata() … … 593 596 else: #picked a limit line 594 597 G2frame.itemPicked = pick 598 elif G2frame.PatternTree.GetItemText(PickId) == 'Models': 599 if ind.all() != [0]: #picked a data point 600 LimitId = G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Limits') 601 data = G2frame.PatternTree.GetItemPyData(LimitId) 602 if mouse.button==1: 603 data[1][0] = min(xy[0],data[1][1]) 604 if mouse.button==3: 605 data[1][1] = max(xy[0],data[1][0]) 606 G2frame.PatternTree.SetItemPyData(LimitId,data) 607 wx.CallAfter(PlotPatterns,G2frame,plotType=plottype) 608 else: #picked a limit line 609 G2frame.itemPicked = pick 595 610 elif G2frame.PatternTree.GetItemText(PickId) == 'Reflection Lists' or \ 596 611 'PWDR' in G2frame.PatternTree.GetItemText(PickId): … … 629 644 if id > 1 and data[id][0] > data[id][1]: 630 645 data[id].reverse() 631 data[1][0] = m ax(data[0][0],data[1][0])632 data[1][1] = m in(data[0][1],data[1][1])646 data[1][0] = min(max(data[0][0],data[1][0]),data[1][1]) 647 data[1][1] = max(min(data[0][1],data[1][1]),data[1][0]) 633 648 G2frame.PatternTree.SetItemPyData(LimitId,data) 634 649 if G2frame.PatternTree.GetItemText(G2frame.PickId) == 'Limits': … … 646 661 G2frame.PatternTree.SetItemPyData(PeakId,data) 647 662 G2pdG.UpdatePeakGrid(G2frame,data) 663 elif G2frame.PatternTree.GetItemText(PickId) in ['Models',] and xpos: 664 lines = [] 665 for line in G2frame.Lines: 666 lines.append(line.get_xdata()[0]) 667 try: 668 lineNo = lines.index(G2frame.itemPicked.get_xdata()[0]) 669 except ValueError: 670 lineNo = -1 671 if lineNo in [0,1]: 672 LimitId = G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId, 'Limits') 673 data = G2frame.PatternTree.GetItemPyData(LimitId) 674 data[1][lineNo] = xpos 675 data[1][0] = min(max(data[0][0],data[1][0]),data[1][1]) 676 data[1][1] = max(min(data[0][1],data[1][1]),data[1][0]) 677 G2frame.PatternTree.SetItemPyData(LimitId,data) 648 678 elif (G2frame.PatternTree.GetItemText(PickId) == 'Reflection Lists' or \ 649 679 'PWDR' in G2frame.PatternTree.GetItemText(PickId)) and xpos: … … 678 708 Page.canvas.mpl_connect('pick_event', OnPick) 679 709 Page.canvas.mpl_connect('button_release_event', OnRelease) 710 Page.canvas.mpl_connect('button_press_event',OnPress) 680 711 Page.SetFocus() 681 712 G2frame.G2plotNB.status.DestroyChildren() … … 701 732 'd: offset down','l: offset left','r: offset right','u: offset up','o: reset offset', 702 733 'q: toggle S(q) plot','s: toggle single plot','+: no selection') 703 Page.keyPress = OnPlotKeyPress 704 734 735 Page.keyPress = OnPlotKeyPress 705 736 PickId = G2frame.PickId 706 737 PatternId = G2frame.PatternId … … 869 900 Plot.set_yscale("log",nonposy='mask') 870 901 if G2frame.ErrorBars: 871 Plot.errorbar(X,Y,yerr=np.sqrt(1./xye[2]),ecolor=colors[N%6],picker=3.,clip_on=False) 902 Plot.errorbar(X,Y,yerr=np.sqrt(1./(Pattern[0]['wtFactor']*xye[2])), 903 ecolor=colors[N%6],picker=3.,clip_on=False) 872 904 else: 873 905 Plot.plot(X,Y,colors[N%6]+'+',picker=3.,clip_on=False) … … 983 1015 else: 984 1016 Page.canvas.draw() 1017 olderr = np.seterr(invalid='warn') #ugh - this removes a matplotlib error for mouse clicks in log plots 985 1018 # G2frame.Pwdr = True 986 1019 -
trunk/GSASIIpwdGUI.py
r1233 r1237 695 695 for i in range(len(data)-2): 696 696 rowLabels.append('exclude') 697 Types = 2*[wg.GRID_VALUE_FLOAT+':1 0,3',]697 Types = 2*[wg.GRID_VALUE_FLOAT+':12,5',] 698 698 G2frame.LimitsTable = G2gd.Table(data,rowLabels=rowLabels,colLabels=colLabels,types=Types) 699 699 G2frame.dataFrame.SetLabel('Limits') … … 2436 2436 data['Size']['logBins'] = True 2437 2437 if 'MinMaxDiam' in data['Size']: 2438 data['Size']['MinDiam'] = 50 2439 data['Size']['MaxDiam'] = 10000 2438 data['Size']['MinDiam'] = 50. 2439 data['Size']['MaxDiam'] = 10000. 2440 2440 del data['Size']['MinMaxDiam'] 2441 2441 #end patches … … 2448 2448 print 'fit model for '+data['Current'] 2449 2449 if data['Current'] == 'Size dist.': 2450 G2sasd.SizeDistribution(Profile, Limits,Substances,Sample,data)2450 G2sasd.SizeDistribution(Profile,ProfDict,Limits,Substances,Sample,data) 2451 2451 2452 2452 def OnSelectFit(event): … … 2466 2466 def OnCheckBox(event): 2467 2467 Obj = event.GetEventObject() 2468 item Key,ind = Indx[Obj.GetId()]2469 data[itemKey][ind] = Obj.GetValue()2468 item,ind = Indx[Obj.GetId()] 2469 item[ind] = Obj.GetValue() 2470 2470 2471 2471 def OnIntVal(event): … … 2518 2518 binSizer.Add(maxdiam,0,WACV) 2519 2519 logbins = wx.CheckBox(G2frame.dataDisplay,label='Log bins?') 2520 Indx[logbins.GetId()] = [ 'Size','logBins']2520 Indx[logbins.GetId()] = [data['Size'],'logBins'] 2521 2521 logbins.SetValue(data['Size']['logBins']) 2522 2522 logbins.Bind(wx.EVT_CHECKBOX, OnCheckBox) … … 2526 2526 partSizer = wx.BoxSizer(wx.HORIZONTAL) 2527 2527 partSizer.Add(wx.StaticText(G2frame.dataDisplay,label='Particle description: '),0,WACV) 2528 shapes = {'Spheroid':' Aspect ratio: ','Cylinder Diam.':' Diameter ','Cylinder AR':' Aspect ratio: ',2528 shapes = {'Spheroid':' Aspect ratio: ','Cylinder':' Diameter ','Cylinder AR':' Aspect ratio: ', 2529 2529 'Unified sphere':'','Unified rod':' Diameter: ','Unified rod AR':' Aspect ratio: ', 2530 2530 'Unified disk':' Thickness: '} … … 2574 2574 return unifSizer 2575 2575 2576 def OnEsdScale(event): 2577 try: 2578 value = float(esdScale.GetValue()) 2579 if value <= 0.: 2580 raise ValueError 2581 except ValueError: 2582 value = 1./np.sqrt(ProfDict['wtFactor']) 2583 ProfDict['wtFactor'] = 1./value**2 2584 esdScale.SetValue('%.3f'%(value)) 2585 G2plt.PlotPatterns(G2frame,plotType='SASD',newPlot=True) 2586 2576 2587 Sample = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId, 'Sample Parameters')) 2577 2588 Limits = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId, 'Limits')) 2578 2589 Inst = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId, 'Instrument Parameters')) 2579 2590 Substances = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId, 'Substances')) 2580 Prof ile = G2frame.PatternTree.GetItemPyData(G2frame.PatternId)[1]2591 ProfDict,Profile = G2frame.PatternTree.GetItemPyData(G2frame.PatternId)[:2] 2581 2592 2582 2593 if G2frame.dataDisplay: … … 2598 2609 fitSel.Bind(wx.EVT_COMBOBOX,OnSelectFit) 2599 2610 topSizer.Add(fitSel,0,WACV) 2611 topSizer.Add(wx.StaticText(G2frame.dataDisplay,label=' Error multiplier: '),0,WACV) 2612 esdScale = wx.TextCtrl(G2frame.dataDisplay,value='%.3f'%(1./np.sqrt(ProfDict['wtFactor'])),style=wx.TE_PROCESS_ENTER) 2613 esdScale.Bind(wx.EVT_TEXT_ENTER,OnEsdScale) 2614 esdScale.Bind(wx.EVT_KILL_FOCUS,OnEsdScale) 2615 topSizer.Add(esdScale,0,WACV) 2600 2616 mainSizer.Add(topSizer) 2601 2617 G2gd.HorizontalLine(mainSizer,G2frame.dataDisplay) -
trunk/GSASIIsasd.py
r1234 r1237 57 57 58 58 ############################################################################### 59 #### Particle form factors 59 #### Particle form factors & volumes as class definitions 60 60 ############################################################################### 61 61 62 62 class SASDParticles(object): 63 def __init__(self,Q,name=None,parms=None,parNames=None): 64 self.Q = Q 63 def __init__(self,name=None,parNames=None): 65 64 self.name = name 66 self.Parms = parms67 65 self.ParmNames = parmNames 68 66 … … 76 74 77 75 class Sphere(SASDParticles): 78 def __init__(self,Q,name=None,parms=None,parmNames=None): 79 self.Q = Q 76 def __init__(self,name=None,parmNames=None): 80 77 self.Name = name 81 78 if self.Name == None: 82 79 self.Name = 'Sphere' 83 self.Parms = parms84 if self.Parms == None:85 self.Parms = [50.0,]86 80 self.ParmNames = parmNames 87 81 if self.ParmNames == None: 88 82 self.ParmNames = ['Radius',] 89 83 90 def FormFactor(self ):84 def FormFactor(self,Q,Parms): 91 85 ''' Compute hard sphere form factor - can use numpy arrays 92 86 param float:Q Q value array (usually in A-1) … … 94 88 returns float: form factors as array as needed 95 89 ''' 96 QR = self.Q*self.Parms[0]90 QR = Q*Parms[0] 97 91 return (3./(QR**3))*(np.sin(QR)-(QR*np.cos(QR))) 98 92 99 def Volume(self ):93 def Volume(self,Parms): 100 94 ''' Compute volume of sphere 101 95 - numpy array friendly … … 103 97 returns float: volume 104 98 ''' 105 return (4./3.)*np.pi*self.Parms[0]**3 106 107 108 99 return (4./3.)*np.pi*Parms[0]**3 100 101 class Spheroid(SASDParticles): 102 def __init__(self,name=None,parmNames=None): 103 self.Name = name 104 if self.Name == None: 105 self.Name = 'Spheroid' 106 self.ParmNames = parmNames 107 if self.ParmNames == None: 108 self.ParmNames = ['Radius','Aspect ratio'] 109 110 def FormFactor(self,Q,Parms): 111 ''' Compute form factor of cylindrically symmetric ellipsoid (spheroid) 112 - can use numpy arrays for R & AR; will return corresponding numpy array 113 param float:Q Q value array (usually in A-1) 114 param float R: radius along 2 axes of spheroid 115 param float AR: aspect ratio so 3rd axis = R*AR 116 returns float: form factors as array as needed 117 ''' 118 R,AR = Parms 119 NP = 50 120 if 0.99 < AR < 1.01: 121 return SphereFF(Q,R,0) 122 else: 123 cth = np.linspace(0,1.,NP) 124 Rct = R*np.sqrt(1.+(AR**2-1.)*cth**2) 125 return np.sqrt(np.sum(SphereFF(Q[:,np.newaxis],Rct,0)**2,axis=1)/NP) 126 127 def Volume(self,Parms): 128 ''' Compute volume of cylindrically symmetric ellipsoid (spheroid) 129 - numpy array friendly 130 param float R: radius along 2 axes of spheroid 131 param float AR: aspect ratio so radius of 3rd axis = R*AR 132 returns float: volume 133 ''' 134 R,AR = Parms 135 return AR*(4./3.)*np.pi*R**3 136 137 ############################################################################### 138 #### Particle form factors 139 ############################################################################### 109 140 110 141 def SphereFF(Q,R,dummy=0): … … 274 305 ############################################################################### 275 306 276 def SizeDistribution(Profile,Limits,Substances,Sample,data): 307 def SizeDistribution(Profile,ProfDict,Limits,Substances,Sample,data): 308 if data['Size']['logBins']: 309 Bins = np.logspace(np.log10(data['Size']['MinDiam']),np.log10(data['Size']['MaxDiam']), 310 data['Size']['Nbins']+1,True) 311 else: 312 Bins = np.linspace(data['Size']['MinDiam'],data['Size']['MaxDiam'], 313 data['Size']['Nbins']+1,True) 314 Dbins = np.diff(Bins) 315 BinMag = Dbins*np.ones_like(Dbins) 316 print np.sum(BinMag) 317 277 318 print data['Size'] 278 319 # print Limits
Note: See TracChangeset
for help on using the changeset viewer.