# Changeset 939 for trunk/GSASIIpwd.py

Ignore:
Timestamp:
Jun 2, 2013 11:07:35 PM (9 years ago)
Message:

fix & cleanup unit tests; add/change doc strings for sphinx; add all G2 py files to sphinx

File:
1 edited

Unmodified
Added
Removed
• ## trunk/GSASIIpwd.py

 r808 #/usr/bin/env python # -*- coding: utf-8 -*- #GSASII powder calculation module ''' *GSASII powder calculation module* ================================== ''' ########### SVN repository information ################### # \$Date\$ def Transmission(Geometry,Abs,Diam): #Calculate sample transmission #   Geometry: one of 'Cylinder','Bragg-Brentano','Tilting flat plate in transmission','Fixed flat plate' #   Abs: absorption coeff in cm-1 #   Diam: sample thickness/diameter in mm ''' Calculate sample transmission :param str Geometry: one of 'Cylinder','Bragg-Brentano','Tilting flat plate in transmission','Fixed flat plate' :param float Abs: absorption coeff in cm-1 :param float Diam: sample thickness/diameter in mm ''' if 'Cylinder' in Geometry:      #Lobanov & Alte da Veiga for 2-theta = 0; beam fully illuminates sample MuR = Abs*Diam/20.0 def Absorb(Geometry,MuR,Tth,Phi=0,Psi=0): #Calculate sample absorption #   Geometry: one of 'Cylinder','Bragg-Brentano','Tilting Flat Plate in transmission','Fixed flat plate' #   MuR: absorption coeff * sample thickness/2 or radius #   Tth: 2-theta scattering angle - can be numpy array #   Phi: flat plate tilt angle - future #   Psi: flat plate tilt axis - future '''Calculate sample absorption :param str Geometry: one of 'Cylinder','Bragg-Brentano','Tilting Flat Plate in transmission','Fixed flat plate' :param float MuR: absorption coeff * sample thickness/2 or radius :param Tth: 2-theta scattering angle - can be numpy array :param float Phi: flat plate tilt angle - future :param float Psi: flat plate tilt axis - future ''' Sth2 = npsind(Tth/2.0)**2 Cth2 = 1.-Sth2 def AbsorbDerv(Geometry,MuR,Tth,Phi=0,Psi=0): 'needs a doc string' dA = 0.001 AbsP = Absorb(Geometry,MuR+dA,Tth,Phi,Psi) def Polarization(Pola,Tth,Azm=0.0): """   Calculate angle dependent x-ray polarization correction (not scaled correctly!) input: Pola: polarization coefficient e.g 1.0 fully polarized, 0.5 unpolarized Azm: azimuthal angle e.g. 0.0 in plane of polarization Tth: 2-theta scattering angle - can be numpy array which (if either) of these is "right"? return: pola = ((1-Pola)*npcosd(Azm)**2+Pola*npsind(Azm)**2)*npcosd(Tth)**2+ \ (1-Pola)*npsind(Azm)**2+Pola*npcosd(Azm)**2 dpdPola: derivative needed for least squares :param Pola: polarization coefficient e.g 1.0 fully polarized, 0.5 unpolarized :param Azm: azimuthal angle e.g. 0.0 in plane of polarization :param Tth: 2-theta scattering angle - can be numpy array which (if either) of these is "right"? :return: (pola, dpdPola) * pola = ((1-Pola)*npcosd(Azm)**2+Pola*npsind(Azm)**2)*npcosd(Tth)**2+ \ (1-Pola)*npsind(Azm)**2+Pola*npcosd(Azm)**2 * dpdPola: derivative needed for least squares """ pola = ((1.0-Pola)*npcosd(Azm)**2+Pola*npsind(Azm)**2)*npcosd(Tth)**2+   \ def Oblique(ObCoeff,Tth): 'needs a doc string' if ObCoeff: return (1.-ObCoeff)/(1.0-np.exp(np.log(ObCoeff)/npcosd(Tth))) def Ruland(RulCoff,wave,Q,Compton): 'needs a doc string' C = 2.9978e8 D = 1.5e-3 def LorchWeight(Q): 'needs a doc string' return np.sin(np.pi*(Q[-1]-Q)/(2.0*Q[-1])) def GetAsfMean(ElList,Sthl2): #   Calculate various scattering factor terms for PDF calcs #   ElList: element dictionary contains scattering factor coefficients, etc. #   Sthl2: numpy array of sin theta/lambda squared values #   returns: mean(f^2), mean(f)^2, mean(compton) '''Calculate various scattering factor terms for PDF calcs :param dict ElList: element dictionary contains scattering factor coefficients, etc. :param np.array Sthl2: numpy array of sin theta/lambda squared values :returns: mean(f^2), mean(f)^2, mean(compton) ''' sumNoAtoms = 0.0 FF = np.zeros_like(Sthl2) def GetNumDensity(ElList,Vol): 'needs a doc string' sumNoAtoms = 0.0 for El in ElList: def CalcPDF(data,inst,xydata): 'needs a doc string' auxPlot = [] import copy def makeFFTsizeList(nmin=1,nmax=1023,thresh=15): ''' Provide list of optimal data sizes for FFT calculations Input: nmin: minimum data size >= 1 nmax: maximum data size > nmin thresh: maximum prime factor allowed Returns: list of data sizes where the maximum prime factor is < thresh :param int nmin: minimum data size >= 1 :param int nmax: maximum data size > nmin :param int thresh: maximum prime factor allowed :Returns: list of data sizes where the maximum prime factor is < thresh ''' plist = [] _norm_pdf_C = 1./math.sqrt(2*math.pi) class norm_gen(st.rv_continuous): 'needs a doc string' def pdf(self,x,*args,**kwds): loc,scale=kwds['loc'],kwds['scale'] class cauchy_gen(st.rv_continuous): 'needs a doc string' def pdf(self,x,*args,**kwds): Finger-Cox-Jephcoat D(2phi,2th) function for S/L = H/L Ref: J. Appl. Cryst. (1994) 27, 892-900. Parameters ----------------------------------------- x: array -1 to 1 t: 2-theta position of peak s: sum(S/L,H/L); S: sample height, H: detector opening, L: sample to detector opening distance dx: 2-theta step size in deg Result for fcj.pdf ----------------------------------------- T = x*dx+t s = S/L+H/L if x < 0: fcj.pdf = [1/sqrt({cos(T)**2/cos(t)**2}-1) - 1/s]/|cos(T)| if x >= 0: fcj.pdf = 0 :param x: array -1 to 1 :param t: 2-theta position of peak :param s: sum(S/L,H/L); S: sample height, H: detector opening, L: sample to detector opening distance :param dx: 2-theta step size in deg :returns: for fcj.pdf * T = x*dx+t * s = S/L+H/L * if x < 0:: fcj.pdf = [1/sqrt({cos(T)**2/cos(t)**2}-1) - 1/s]/|cos(T)| * if x >= 0: fcj.pdf = 0 """ def _pdf(self,x,t,s,dx): def getWidthsCW(pos,sig,gam,shl): 'needs a doc string' widths = [np.sqrt(sig)/100.,gam/200.] fwhm = 2.355*widths[0]+2.*widths[1] def getWidthsTOF(pos,alp,bet,sig,gam): 'needs a doc string' lnf = 3.3      # =log(0.001/2) widths = [np.sqrt(sig),gam] def getFWHM(TTh,Inst): 'needs a doc string' sig = lambda Th,U,V,W: 1.17741*math.sqrt(max(0.001,U*tand(Th)**2+V*tand(Th)+W))*math.pi/180. gam = lambda Th,X,Y: (X/cosd(Th)+Y*tand(Th))*math.pi/180. def getFCJVoigt(pos,intens,sig,gam,shl,xdata): 'needs a doc string' DX = xdata[1]-xdata[0] widths,fmin,fmax = getWidthsCW(pos,sig,gam,shl) def getBackground(pfx,parmDict,bakType,xdata): 'needs a doc string' yb = np.zeros_like(xdata) nBak = 0 def getBackgroundDerv(pfx,parmDict,bakType,xdata): 'needs a doc string' nBak = 0 while True: #use old fortran routine def getFCJVoigt3(pos,sig,gam,shl,xdata): 'needs a doc string' Df = pyd.pypsvfcj(len(xdata),xdata-pos,pos,sig,gam,shl) def getdFCJVoigt3(pos,sig,gam,shl,xdata): 'needs a doc string' Df,dFdp,dFds,dFdg,dFdsh = pyd.pydpsvfcj(len(xdata),xdata-pos,pos,sig,gam,shl) def getEpsVoigt(pos,alp,bet,sig,gam,xdata): 'needs a doc string' Df = pyd.pyepsvoigt(len(xdata),xdata-pos,alp,bet,sig,gam) Df /= np.sum(Df) def getdEpsVoigt(pos,alp,bet,sig,gam,xdata): 'needs a doc string' Df,dFdp,dFda,dFdb,dFds,dFdg = pyd.pydepsvoigt(len(xdata),xdata-pos,alp,bet,sig,gam) sumDf = np.sum(Df) def ellipseSize(H,Sij,GB): 'needs a doc string' HX = np.inner(H.T,GB) lenHX = np.sqrt(np.sum(HX**2)) def ellipseSizeDerv(H,Sij,GB): 'needs a doc string' lenR = ellipseSize(H,Sij,GB) delt = 0.001 def getHKLpeak(dmin,SGData,A): 'needs a doc string' HKL = G2lat.GenHLaue(dmin,SGData,A) HKLs = [] def getPeakProfile(dataType,parmDict,xdata,varyList,bakType): 'needs a doc string' yb = getBackground('',parmDict,bakType,xdata) def getPeakProfileDerv(dataType,parmDict,xdata,varyList,bakType): 'needs a doc string' # needs to return np.array([dMdx1,dMdx2,...]) in same order as varylist = backVary,insVary,peakVary order dMdv = np.zeros(shape=(len(varyList),len(xdata))) def SetBackgroundParms(Background): 'needs a doc string' if len(Background) == 1:            # fix up old backgrounds BackGround.append({'nDebye':0,'debyeTerms':[]}) def DoPeakFit(FitPgm,Peaks,Background,Limits,Inst,Inst2,data,oneCycle=False,controls=None,dlg=None): 'needs a doc string' def calcIncident(Iparm,xdata): 'needs a doc string' def IfunAdv(Iparm,xdata): NeedTestData = True def TestData(): 'needs a doc string' #    global NeedTestData NeedTestData = False
Note: See TracChangeset for help on using the changeset viewer.