Changeset 1731


Ignore:
Timestamp:
Mar 17, 2015 3:32:23 PM (9 years ago)
Author:
vondreele
Message:

fixes to DData plotting for mustrain/size

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIddataGUI.py

    r1727 r1731  
    8080            Obj = event.GetEventObject()
    8181            generalData['Data plot type'] = Obj.GetStringSelection()
     82            G2plt.PlotSizeStrainPO(G2frame,data,hist)
    8283            wx.CallLater(100,UpdateDData,G2frame,DData,data)
    83             G2plt.PlotSizeStrainPO(G2frame,data)
    8484           
    8585        def OnPOhkl(event):
     
    9595            h,k,l = hkl
    9696            Obj.SetValue('%3d %3d %3d'%(h,k,l))
    97             G2plt.PlotSizeStrainPO(G2frame,data)
     97            G2plt.PlotSizeStrainPO(G2frame,data,hist)
    9898       
    9999        plotSizer = wx.BoxSizer(wx.VERTICAL)
     
    268268        hist = Indx[Obj.GetId()]
    269269        UseList[hist]['Size'][0] = Obj.GetValue()
    270         G2plt.PlotSizeStrainPO(G2frame,data)
     270        G2plt.PlotSizeStrainPO(G2frame,data,hist)
    271271        wx.CallLater(100,UpdateDData,G2frame,DData,data)
    272272       
     
    300300                pass
    301301            Obj.SetValue("%.5f"%(UseList[hist]['Size'][1][pid]))          #reset in case of error
    302         G2plt.PlotSizeStrainPO(G2frame,data)
     302        G2plt.PlotSizeStrainPO(G2frame,data,hist)
    303303       
    304304    def OnSizeAxis(event):           
     
    329329                UseList[item]['Size'][4][i] = 1.0
    330330                UseList[item]['Size'][4][i+3] = 0.0
    331         G2plt.PlotSizeStrainPO(G2frame,data)
     331        G2plt.PlotSizeStrainPO(G2frame,data,item)
    332332        wx.CallLater(100,UpdateDData,G2frame,DData,data)
    333333           
     
    337337        UseList[hist]['Mustrain'][0] = Obj.GetValue()
    338338        wx.CallLater(100,UpdateDData,G2frame,DData,data)
    339         G2plt.PlotSizeStrainPO(G2frame,data)
     339        G2plt.PlotSizeStrainPO(G2frame,data,hist)
    340340       
    341341    def OnStrainRef(event):
     
    367367        else:
    368368            Obj.SetValue("%.1f"%(UseList[hist]['Mustrain'][1][pid]))          #reset in case of error
    369         G2plt.PlotSizeStrainPO(G2frame,data)
     369        G2plt.PlotSizeStrainPO(G2frame,data,hist)
    370370       
    371371    def OnStrainAxis(event):
     
    382382        h,k,l = hkl
    383383        Obj.SetValue('%3d %3d %3d'%(h,k,l))
    384         G2plt.PlotSizeStrainPO(G2frame,data)
     384        G2plt.PlotSizeStrainPO(G2frame,data,hist)
    385385       
    386386    def OnResetStrain(event):
     
    400400            for i in range(nTerm):
    401401                UseList[item]['Mustrain'][4][i] = vals[i]
    402         G2plt.PlotSizeStrainPO(G2frame,data)
     402        G2plt.PlotSizeStrainPO(G2frame,data,item)
    403403        wx.CallLater(100,UpdateDData,G2frame,DData,data)
    404404           
     
    853853    def OnSelect(event):
    854854        hist = keyList[select.GetSelection()]
    855         G2plt.PlotSizeStrainPO(G2frame,data)
     855        G2plt.PlotSizeStrainPO(G2frame,data,hist)
    856856        wx.CallLater(100,UpdateDData,G2frame,DData,data,hist)
    857857       
     
    859859        hist = keyList[selSpin.GetValue()]
    860860        selSpin.Destroy() # remove button to discourage pressing too fast
    861         G2plt.PlotSizeStrainPO(G2frame,data)
     861        G2plt.PlotSizeStrainPO(G2frame,data,hist)
    862862        wx.CallLater(100,UpdateDData,G2frame,DData,data,hist)
    863863       
  • trunk/GSASIIphsGUI.py

    r1699 r1731  
    58245824            G2gd.SetDataMenuBar(G2frame,G2frame.dataFrame.DataMenu)
    58255825            G2ddG.UpdateDData(G2frame,DData,data)
    5826             G2plt.PlotSizeStrainPO(G2frame,data,Start=True)           
     5826            G2plt.PlotSizeStrainPO(G2frame,data,hist='',Start=True)           
    58275827        elif text == 'Atoms':
    58285828            G2gd.SetDataMenuBar(G2frame,G2frame.dataFrame.AtomsMenu)
  • trunk/GSASIIplot.py

    r1715 r1731  
    24922492################################################################################
    24932493           
    2494 def PlotSizeStrainPO(G2frame,data,Start=False):
     2494def PlotSizeStrainPO(G2frame,data,hist='',Start=False):
    24952495    '''Plot 3D mustrain/size/preferred orientation figure. In this instance data is for a phase
    24962496    '''
     
    25152515    if plotType in ['None']:
    25162516        return       
    2517 
    2518     for item in useList:
    2519         if useList[item]['Show']:
    2520             break
    2521     else:
    2522         return            #nothing to show!!
    2523    
     2517    if hist == '':
     2518        hist = useList.keys()[0]
    25242519    numPlots = len(useList)
    25252520
     
    25362531        Page.Show()
    25372532   
    2538     for item in useList:
    2539         if useList[item]['Show']:
    2540             PHI = np.linspace(0.,360.,30,True)
    2541             PSI = np.linspace(0.,180.,30,True)
    2542             X = np.outer(npsind(PHI),npsind(PSI))
    2543             Y = np.outer(npcosd(PHI),npsind(PSI))
    2544             Z = np.outer(np.ones(np.size(PHI)),npcosd(PSI))
    2545             try:        #temp patch instead of 'mustrain' for old files with 'microstrain'
    2546                 coeff = useList[item][plotDict[plotType]]
    2547             except KeyError:
    2548                 break
    2549             if plotType in ['Mustrain','Size']:
    2550                 if coeff[0] == 'isotropic':
    2551                     X *= coeff[1][0]
    2552                     Y *= coeff[1][0]
    2553                     Z *= coeff[1][0]                               
    2554                 elif coeff[0] == 'uniaxial':
     2533    PHI = np.linspace(0.,360.,30,True)
     2534    PSI = np.linspace(0.,180.,30,True)
     2535    X = np.outer(npsind(PHI),npsind(PSI))
     2536    Y = np.outer(npcosd(PHI),npsind(PSI))
     2537    Z = np.outer(np.ones(np.size(PHI)),npcosd(PSI))
     2538    try:        #temp patch instead of 'mustrain' for old files with 'microstrain'
     2539        coeff = useList[hist][plotDict[plotType]]
     2540    except KeyError:
     2541        return
     2542    if plotType in ['Mustrain','Size']:
     2543        if coeff[0] == 'isotropic':
     2544            X *= coeff[1][0]
     2545            Y *= coeff[1][0]
     2546            Z *= coeff[1][0]                               
     2547        elif coeff[0] == 'uniaxial':
     2548           
     2549            def uniaxCalc(xyz,iso,aniso,axes):
     2550                Z = np.array(axes)
     2551                cp = abs(np.dot(xyz,Z))
     2552                sp = np.sqrt(1.-cp**2)
     2553                R = iso*aniso/np.sqrt((iso*cp)**2+(aniso*sp)**2)
     2554                return R*xyz
     2555               
     2556            iso,aniso = coeff[1][:2]
     2557            axes = np.inner(A,np.array(coeff[3]))
     2558            axes /= nl.norm(axes)
     2559            Shkl = np.array(coeff[1])
     2560            XYZ = np.dstack((X,Y,Z))
     2561            XYZ = np.nan_to_num(np.apply_along_axis(uniaxCalc,2,XYZ,iso,aniso,axes))
     2562            X,Y,Z = np.dsplit(XYZ,3)
     2563            X = X[:,:,0]
     2564            Y = Y[:,:,0]
     2565            Z = Z[:,:,0]
     2566       
     2567        elif coeff[0] == 'ellipsoidal':
     2568           
     2569            def ellipseCalc(xyz,E,R):
     2570                XYZ = xyz*E.T
     2571                return np.inner(XYZ.T,R)
     2572               
     2573            S6 = coeff[4]
     2574            Sij = G2lat.U6toUij(S6)
     2575            E,R = nl.eigh(Sij)
     2576            XYZ = np.dstack((X,Y,Z))
     2577            XYZ = np.nan_to_num(np.apply_along_axis(ellipseCalc,2,XYZ,E,R))
     2578            X,Y,Z = np.dsplit(XYZ,3)
     2579            X = X[:,:,0]
     2580            Y = Y[:,:,0]
     2581            Z = Z[:,:,0]
     2582           
     2583        elif coeff[0] == 'generalized':
     2584           
     2585            def genMustrain(xyz,SGData,A,Shkl):
     2586                uvw = np.inner(A.T,xyz)
     2587                Strm = np.array(G2spc.MustrainCoeff(uvw,SGData))
     2588                Sum = np.sum(np.multiply(Shkl,Strm))
     2589                Sum = np.where(Sum > 0.01,Sum,0.01)
     2590                Sum = np.sqrt(Sum)
     2591                return Sum*xyz
     2592               
     2593            Shkl = np.array(coeff[4])
     2594            if np.any(Shkl):
     2595                XYZ = np.dstack((X,Y,Z))
     2596                XYZ = np.nan_to_num(np.apply_along_axis(genMustrain,2,XYZ,SGData,A,Shkl))
     2597                X,Y,Z = np.dsplit(XYZ,3)
     2598                X = X[:,:,0]
     2599                Y = Y[:,:,0]
     2600                Z = Z[:,:,0]
    25552601                   
    2556                     def uniaxCalc(xyz,iso,aniso,axes):
    2557                         Z = np.array(axes)
    2558                         cp = abs(np.dot(xyz,Z))
    2559                         sp = np.sqrt(1.-cp**2)
    2560                         R = iso*aniso/np.sqrt((iso*cp)**2+(aniso*sp)**2)
    2561                         return R*xyz
    2562                        
    2563                     iso,aniso = coeff[1][:2]
    2564                     axes = np.inner(A,np.array(coeff[3]))
    2565                     axes /= nl.norm(axes)
    2566                     Shkl = np.array(coeff[1])
    2567                     XYZ = np.dstack((X,Y,Z))
    2568                     XYZ = np.nan_to_num(np.apply_along_axis(uniaxCalc,2,XYZ,iso,aniso,axes))
    2569                     X,Y,Z = np.dsplit(XYZ,3)
    2570                     X = X[:,:,0]
    2571                     Y = Y[:,:,0]
    2572                     Z = Z[:,:,0]
    2573                
    2574                 elif coeff[0] == 'ellipsoidal':
    2575                    
    2576                     def ellipseCalc(xyz,E,R):
    2577                         XYZ = xyz*E.T
    2578                         return np.inner(XYZ.T,R)
    2579                        
    2580                     S6 = coeff[4]
    2581                     Sij = G2lat.U6toUij(S6)
    2582                     E,R = nl.eigh(Sij)
    2583                     XYZ = np.dstack((X,Y,Z))
    2584                     XYZ = np.nan_to_num(np.apply_along_axis(ellipseCalc,2,XYZ,E,R))
    2585                     X,Y,Z = np.dsplit(XYZ,3)
    2586                     X = X[:,:,0]
    2587                     Y = Y[:,:,0]
    2588                     Z = Z[:,:,0]
    2589                    
    2590                 elif coeff[0] == 'generalized':
    2591                    
    2592                     def genMustrain(xyz,SGData,A,Shkl):
    2593                         uvw = np.inner(A.T,xyz)
    2594                         Strm = np.array(G2spc.MustrainCoeff(uvw,SGData))
    2595                         Sum = np.sum(np.multiply(Shkl,Strm))
    2596                         Sum = np.where(Sum > 0.01,Sum,0.01)
    2597                         Sum = np.sqrt(Sum)
    2598                         return Sum*xyz
    2599                        
    2600                     Shkl = np.array(coeff[4])
    2601                     if np.any(Shkl):
    2602                         XYZ = np.dstack((X,Y,Z))
    2603                         XYZ = np.nan_to_num(np.apply_along_axis(genMustrain,2,XYZ,SGData,A,Shkl))
    2604                         X,Y,Z = np.dsplit(XYZ,3)
    2605                         X = X[:,:,0]
    2606                         Y = Y[:,:,0]
    2607                         Z = Z[:,:,0]
    2608                            
    2609                 if np.any(X) and np.any(Y) and np.any(Z):
    2610                     errFlags = np.seterr(all='ignore')
    2611                     Plot.plot_surface(X,Y,Z,rstride=1,cstride=1,color='g',linewidth=1)
    2612                     np.seterr(all='ignore')
    2613                     xyzlim = np.array([Plot.get_xlim3d(),Plot.get_ylim3d(),Plot.get_zlim3d()]).T
    2614                     XYZlim = [min(xyzlim[0]),max(xyzlim[1])]
    2615                     Plot.set_xlim3d(XYZlim)
    2616                     Plot.set_ylim3d(XYZlim)
    2617                     Plot.set_zlim3d(XYZlim)
    2618                     Plot.set_aspect('equal')
    2619                 if plotType == 'Size':
    2620                     Plot.set_title('Crystallite size for '+phase+'\n'+coeff[0]+' model')
    2621                     Plot.set_xlabel(r'X, $\mu$m')
    2622                     Plot.set_ylabel(r'Y, $\mu$m')
    2623                     Plot.set_zlabel(r'Z, $\mu$m')
    2624                 else:   
    2625                     Plot.set_title(r'$\mu$strain for '+phase+'\n'+coeff[0]+' model')
    2626                     Plot.set_xlabel(r'X, $\mu$strain')
    2627                     Plot.set_ylabel(r'Y, $\mu$strain')
    2628                     Plot.set_zlabel(r'Z, $\mu$strain')
    2629             else:
    2630                 h,k,l = generalData['POhkl']
    2631                 if coeff[0] == 'MD':
    2632                     print 'March-Dollase preferred orientation plot'
    2633                
    2634                 else:
    2635                     PH = np.array(generalData['POhkl'])
    2636                     phi,beta = G2lat.CrsAng(PH,cell[:6],SGData)
    2637                     SHCoef = {}
    2638                     for item in coeff[5]:
    2639                         L,N = eval(item.strip('C'))
    2640                         SHCoef['C%d,0,%d'%(L,N)] = coeff[5][item]                       
    2641                     ODFln = G2lat.Flnh(Start,SHCoef,phi,beta,SGData)
    2642                     X = np.linspace(0,90.0,26)
    2643                     Y = G2lat.polfcal(ODFln,'0',X,0.0)
    2644                     Plot.plot(X,Y,color='k',label=str(PH))
    2645                     Plot.legend(loc='best')
    2646                     Plot.set_title('Axial distribution for HKL='+str(PH)+' in '+phase)
    2647                     Plot.set_xlabel(r'$\psi$',fontsize=16)
    2648                     Plot.set_ylabel('MRD',fontsize=14)
     2602        if np.any(X) and np.any(Y) and np.any(Z):
     2603            errFlags = np.seterr(all='ignore')
     2604            Plot.plot_surface(X,Y,Z,rstride=1,cstride=1,color='g',linewidth=1)
     2605            np.seterr(all='ignore')
     2606            xyzlim = np.array([Plot.get_xlim3d(),Plot.get_ylim3d(),Plot.get_zlim3d()]).T
     2607            XYZlim = [min(xyzlim[0]),max(xyzlim[1])]
     2608            Plot.set_xlim3d(XYZlim)
     2609            Plot.set_ylim3d(XYZlim)
     2610            Plot.set_zlim3d(XYZlim)
     2611            Plot.set_aspect('equal')
     2612        if plotType == 'Size':
     2613            Plot.set_title('Crystallite size for '+phase+'\n'+coeff[0]+' model')
     2614            Plot.set_xlabel(r'X, $\mu$m')
     2615            Plot.set_ylabel(r'Y, $\mu$m')
     2616            Plot.set_zlabel(r'Z, $\mu$m')
     2617        else:   
     2618            Plot.set_title(r'$\mu$strain for '+phase+'\n'+coeff[0]+' model')
     2619            Plot.set_xlabel(r'X, $\mu$strain')
     2620            Plot.set_ylabel(r'Y, $\mu$strain')
     2621            Plot.set_zlabel(r'Z, $\mu$strain')
     2622    else:
     2623        h,k,l = generalData['POhkl']
     2624        if coeff[0] == 'MD':
     2625            print 'March-Dollase preferred orientation plot'
     2626       
     2627        else:
     2628            PH = np.array(generalData['POhkl'])
     2629            phi,beta = G2lat.CrsAng(PH,cell[:6],SGData)
     2630            SHCoef = {}
     2631            for item in coeff[5]:
     2632                L,N = eval(item.strip('C'))
     2633                SHCoef['C%d,0,%d'%(L,N)] = coeff[5][item]                       
     2634            ODFln = G2lat.Flnh(Start,SHCoef,phi,beta,SGData)
     2635            X = np.linspace(0,90.0,26)
     2636            Y = G2lat.polfcal(ODFln,'0',X,0.0)
     2637            Plot.plot(X,Y,color='k',label=str(PH))
     2638            Plot.legend(loc='best')
     2639            Plot.set_title('Axial distribution for HKL='+str(PH)+' in '+phase)
     2640            Plot.set_xlabel(r'$\psi$',fontsize=16)
     2641            Plot.set_ylabel('MRD',fontsize=14)
    26492642    Page.canvas.draw()
    26502643   
Note: See TracChangeset for help on using the changeset viewer.