Changeset 1731 for trunk/GSASIIplot.py
 Timestamp:
 Mar 17, 2015 3:32:23 PM (7 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/GSASIIplot.py
r1715 r1731 2492 2492 ################################################################################ 2493 2493 2494 def PlotSizeStrainPO(G2frame,data, Start=False):2494 def PlotSizeStrainPO(G2frame,data,hist='',Start=False): 2495 2495 '''Plot 3D mustrain/size/preferred orientation figure. In this instance data is for a phase 2496 2496 ''' … … 2515 2515 if plotType in ['None']: 2516 2516 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] 2524 2519 numPlots = len(useList) 2525 2520 … … 2536 2531 Page.Show() 2537 2532 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] 2555 2601 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 'MarchDollase 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 'MarchDollase 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) 2649 2642 Page.canvas.draw() 2650 2643
Note: See TracChangeset
for help on using the changeset viewer.