Changeset 939 for trunk/GSASIIpwd.py


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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIpwd.py

    r808 r939  
    11#/usr/bin/env python
    22# -*- coding: utf-8 -*-
    3 #GSASII powder calculation module
     3'''
     4*GSASII powder calculation module*
     5==================================
     6
     7'''
    48########### SVN repository information ###################
    59# $Date$
     
    5458       
    5559def Transmission(Geometry,Abs,Diam):
    56 #Calculate sample transmission
    57 #   Geometry: one of 'Cylinder','Bragg-Brentano','Tilting flat plate in transmission','Fixed flat plate'
    58 #   Abs: absorption coeff in cm-1
    59 #   Diam: sample thickness/diameter in mm
     60    '''
     61    Calculate sample transmission
     62
     63    :param str Geometry: one of 'Cylinder','Bragg-Brentano','Tilting flat plate in transmission','Fixed flat plate'
     64    :param float Abs: absorption coeff in cm-1
     65    :param float Diam: sample thickness/diameter in mm
     66    '''
    6067    if 'Cylinder' in Geometry:      #Lobanov & Alte da Veiga for 2-theta = 0; beam fully illuminates sample
    6168        MuR = Abs*Diam/20.0
     
    8491
    8592def Absorb(Geometry,MuR,Tth,Phi=0,Psi=0):
    86 #Calculate sample absorption
    87 #   Geometry: one of 'Cylinder','Bragg-Brentano','Tilting Flat Plate in transmission','Fixed flat plate'
    88 #   MuR: absorption coeff * sample thickness/2 or radius
    89 #   Tth: 2-theta scattering angle - can be numpy array
    90 #   Phi: flat plate tilt angle - future
    91 #   Psi: flat plate tilt axis - future
     93    '''Calculate sample absorption
     94    :param str Geometry: one of 'Cylinder','Bragg-Brentano','Tilting Flat Plate in transmission','Fixed flat plate'
     95    :param float MuR: absorption coeff * sample thickness/2 or radius
     96    :param Tth: 2-theta scattering angle - can be numpy array
     97    :param float Phi: flat plate tilt angle - future
     98    :param float Psi: flat plate tilt axis - future
     99    '''
    92100    Sth2 = npsind(Tth/2.0)**2
    93101    Cth2 = 1.-Sth2
     
    127135       
    128136def AbsorbDerv(Geometry,MuR,Tth,Phi=0,Psi=0):
     137    'needs a doc string'
    129138    dA = 0.001
    130139    AbsP = Absorb(Geometry,MuR+dA,Tth,Phi,Psi)
     
    137146def Polarization(Pola,Tth,Azm=0.0):
    138147    """   Calculate angle dependent x-ray polarization correction (not scaled correctly!)
    139     input:
    140         Pola: polarization coefficient e.g 1.0 fully polarized, 0.5 unpolarized
    141         Azm: azimuthal angle e.g. 0.0 in plane of polarization
    142         Tth: 2-theta scattering angle - can be numpy array
    143             which (if either) of these is "right"?
    144     return:
    145         pola = ((1-Pola)*npcosd(Azm)**2+Pola*npsind(Azm)**2)*npcosd(Tth)**2+ \
    146             (1-Pola)*npsind(Azm)**2+Pola*npcosd(Azm)**2
    147         dpdPola: derivative needed for least squares
     148
     149    :param Pola: polarization coefficient e.g 1.0 fully polarized, 0.5 unpolarized
     150    :param Azm: azimuthal angle e.g. 0.0 in plane of polarization
     151    :param Tth: 2-theta scattering angle - can be numpy array
     152      which (if either) of these is "right"?
     153    :return: (pola, dpdPola)
     154      * pola = ((1-Pola)*npcosd(Azm)**2+Pola*npsind(Azm)**2)*npcosd(Tth)**2+ \
     155        (1-Pola)*npsind(Azm)**2+Pola*npcosd(Azm)**2
     156      * dpdPola: derivative needed for least squares
     157
    148158    """
    149159    pola = ((1.0-Pola)*npcosd(Azm)**2+Pola*npsind(Azm)**2)*npcosd(Tth)**2+   \
     
    153163   
    154164def Oblique(ObCoeff,Tth):
     165    'needs a doc string'
    155166    if ObCoeff:
    156167        return (1.-ObCoeff)/(1.0-np.exp(np.log(ObCoeff)/npcosd(Tth)))
     
    159170               
    160171def Ruland(RulCoff,wave,Q,Compton):
     172    'needs a doc string'
    161173    C = 2.9978e8
    162174    D = 1.5e-3
     
    168180   
    169181def LorchWeight(Q):
     182    'needs a doc string'
    170183    return np.sin(np.pi*(Q[-1]-Q)/(2.0*Q[-1]))
    171184           
    172185def GetAsfMean(ElList,Sthl2):
    173 #   Calculate various scattering factor terms for PDF calcs
    174 #   ElList: element dictionary contains scattering factor coefficients, etc.
    175 #   Sthl2: numpy array of sin theta/lambda squared values
    176 #   returns: mean(f^2), mean(f)^2, mean(compton)
     186    '''Calculate various scattering factor terms for PDF calcs
     187
     188    :param dict ElList: element dictionary contains scattering factor coefficients, etc.
     189    :param np.array Sthl2: numpy array of sin theta/lambda squared values
     190    :returns: mean(f^2), mean(f)^2, mean(compton)
     191    '''
    177192    sumNoAtoms = 0.0
    178193    FF = np.zeros_like(Sthl2)
     
    191206   
    192207def GetNumDensity(ElList,Vol):
     208    'needs a doc string'
    193209    sumNoAtoms = 0.0
    194210    for El in ElList:
     
    197213           
    198214def CalcPDF(data,inst,xydata):
     215    'needs a doc string'
    199216    auxPlot = []
    200217    import copy
     
    303320def makeFFTsizeList(nmin=1,nmax=1023,thresh=15):
    304321    ''' Provide list of optimal data sizes for FFT calculations
    305     Input:
    306         nmin: minimum data size >= 1
    307         nmax: maximum data size > nmin
    308         thresh: maximum prime factor allowed
    309     Returns:
    310         list of data sizes where the maximum prime factor is < thresh
     322
     323    :param int nmin: minimum data size >= 1
     324    :param int nmax: maximum data size > nmin
     325    :param int thresh: maximum prime factor allowed
     326    :Returns: list of data sizes where the maximum prime factor is < thresh
    311327    '''
    312328    plist = []
     
    325341_norm_pdf_C = 1./math.sqrt(2*math.pi)
    326342class norm_gen(st.rv_continuous):
    327        
     343    'needs a doc string'
     344     
    328345    def pdf(self,x,*args,**kwds):
    329346        loc,scale=kwds['loc'],kwds['scale']
     
    346363
    347364class cauchy_gen(st.rv_continuous):
     365    'needs a doc string'
    348366
    349367    def pdf(self,x,*args,**kwds):
     
    369387    Finger-Cox-Jephcoat D(2phi,2th) function for S/L = H/L
    370388    Ref: J. Appl. Cryst. (1994) 27, 892-900.
    371     Parameters
    372     -----------------------------------------
    373     x: array -1 to 1
    374     t: 2-theta position of peak
    375     s: sum(S/L,H/L); S: sample height, H: detector opening,
    376         L: sample to detector opening distance
    377     dx: 2-theta step size in deg
    378     Result for fcj.pdf
    379     -----------------------------------------
    380     T = x*dx+t
    381     s = S/L+H/L
    382     if x < 0:
    383         fcj.pdf = [1/sqrt({cos(T)**2/cos(t)**2}-1) - 1/s]/|cos(T)|   
    384     if x >= 0:
    385         fcj.pdf = 0   
     389
     390    :param x: array -1 to 1
     391    :param t: 2-theta position of peak
     392    :param s: sum(S/L,H/L); S: sample height, H: detector opening,
     393      L: sample to detector opening distance
     394    :param dx: 2-theta step size in deg
     395
     396    :returns: for fcj.pdf
     397
     398     * T = x*dx+t
     399     * s = S/L+H/L
     400     * if x < 0::
     401
     402        fcj.pdf = [1/sqrt({cos(T)**2/cos(t)**2}-1) - 1/s]/|cos(T)|
     403
     404     * if x >= 0: fcj.pdf = 0   
    386405    """
    387406    def _pdf(self,x,t,s,dx):
     
    402421               
    403422def getWidthsCW(pos,sig,gam,shl):
     423    'needs a doc string'
    404424    widths = [np.sqrt(sig)/100.,gam/200.]
    405425    fwhm = 2.355*widths[0]+2.*widths[1]
     
    411431   
    412432def getWidthsTOF(pos,alp,bet,sig,gam):
     433    'needs a doc string'
    413434    lnf = 3.3      # =log(0.001/2)
    414435    widths = [np.sqrt(sig),gam]
     
    419440   
    420441def getFWHM(TTh,Inst):
     442    'needs a doc string'
    421443    sig = lambda Th,U,V,W: 1.17741*math.sqrt(max(0.001,U*tand(Th)**2+V*tand(Th)+W))*math.pi/180.
    422444    gam = lambda Th,X,Y: (X/cosd(Th)+Y*tand(Th))*math.pi/180.
     
    427449               
    428450def getFCJVoigt(pos,intens,sig,gam,shl,xdata):   
     451    'needs a doc string'
    429452    DX = xdata[1]-xdata[0]
    430453    widths,fmin,fmax = getWidthsCW(pos,sig,gam,shl)
     
    448471
    449472def getBackground(pfx,parmDict,bakType,xdata):
     473    'needs a doc string'
    450474    yb = np.zeros_like(xdata)
    451475    nBak = 0
     
    529553   
    530554def getBackgroundDerv(pfx,parmDict,bakType,xdata):
     555    'needs a doc string'
    531556    nBak = 0
    532557    while True:
     
    626651#use old fortran routine
    627652def getFCJVoigt3(pos,sig,gam,shl,xdata):
     653    'needs a doc string'
    628654   
    629655    Df = pyd.pypsvfcj(len(xdata),xdata-pos,pos,sig,gam,shl)
     
    633659
    634660def getdFCJVoigt3(pos,sig,gam,shl,xdata):
     661    'needs a doc string'
    635662   
    636663    Df,dFdp,dFds,dFdg,dFdsh = pyd.pydpsvfcj(len(xdata),xdata-pos,pos,sig,gam,shl)
     
    640667
    641668def getEpsVoigt(pos,alp,bet,sig,gam,xdata):
     669    'needs a doc string'
    642670    Df = pyd.pyepsvoigt(len(xdata),xdata-pos,alp,bet,sig,gam)
    643671    Df /= np.sum(Df)
     
    645673   
    646674def getdEpsVoigt(pos,alp,bet,sig,gam,xdata):
     675    'needs a doc string'
    647676    Df,dFdp,dFda,dFdb,dFds,dFdg = pyd.pydepsvoigt(len(xdata),xdata-pos,alp,bet,sig,gam)
    648677    sumDf = np.sum(Df)
     
    650679
    651680def ellipseSize(H,Sij,GB):
     681    'needs a doc string'
    652682    HX = np.inner(H.T,GB)
    653683    lenHX = np.sqrt(np.sum(HX**2))
     
    658688
    659689def ellipseSizeDerv(H,Sij,GB):
     690    'needs a doc string'
    660691    lenR = ellipseSize(H,Sij,GB)
    661692    delt = 0.001
     
    668699
    669700def getHKLpeak(dmin,SGData,A):
     701    'needs a doc string'
    670702    HKL = G2lat.GenHLaue(dmin,SGData,A)       
    671703    HKLs = []
     
    677709
    678710def getPeakProfile(dataType,parmDict,xdata,varyList,bakType):
     711    'needs a doc string'
    679712   
    680713    yb = getBackground('',parmDict,bakType,xdata)
     
    795828           
    796829def getPeakProfileDerv(dataType,parmDict,xdata,varyList,bakType):
     830    'needs a doc string'
    797831# needs to return np.array([dMdx1,dMdx2,...]) in same order as varylist = backVary,insVary,peakVary order
    798832    dMdv = np.zeros(shape=(len(varyList),len(xdata)))
     
    10061040   
    10071041def SetBackgroundParms(Background):
     1042    'needs a doc string'
    10081043    if len(Background) == 1:            # fix up old backgrounds
    10091044        BackGround.append({'nDebye':0,'debyeTerms':[]})
     
    10471082           
    10481083def DoPeakFit(FitPgm,Peaks,Background,Limits,Inst,Inst2,data,oneCycle=False,controls=None,dlg=None):
     1084    'needs a doc string'
    10491085   
    10501086       
     
    13471383
    13481384def calcIncident(Iparm,xdata):
     1385    'needs a doc string'
    13491386
    13501387    def IfunAdv(Iparm,xdata):
     
    14031440NeedTestData = True
    14041441def TestData():
     1442    'needs a doc string'
    14051443#    global NeedTestData
    14061444    NeedTestData = False
Note: See TracChangeset for help on using the changeset viewer.