Changeset 1474


Ignore:
Timestamp:
Aug 21, 2014 1:31:59 PM (7 years ago)
Author:
vondreele
Message:

1st MC/SA tutorial
various MC/SA fixes
fix to background peak fitting for CW & TOF

Location:
trunk
Files:
61 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIImath.py

    r1464 r1474  
    29422942        cosTable = np.array(cosTable)**2
    29432943        nRef = len(refs)
    2944         if covData['freshCOV'] and generalData['doPawley'] and MCSA.get('newDmin',True):
     2944        if generalData['doPawley'] and (covData['freshCOV'] or  MCSA['newDmin']):
    29452945            vList = covData['varyList']
    29462946            covMatrix = covData['covMatrix']
  • trunk/GSASIIphsGUI.py

    r1470 r1474  
    122122            'MCSA controls' not in generalData:
    123123            generalData['MCSA controls'] = {'Data source':'','Annealing':[50.,0.001,50],
    124             'dmin':2.0,'Algorithm':'fast','Jump coeff':[0.95,0.5],'boltzmann':1.0,
    125             'fast parms':[1.0,1.0,1.0],'log slope':0.9,'Cycles':1,'Results':[]}
     124            'dmin':2.0,'Algorithm':'log','Jump coeff':[0.95,0.5],'boltzmann':1.0,
     125            'fast parms':[1.0,1.0,1.0],'log slope':0.9,'Cycles':1,'Results':[],'newDmin':True}
    126126        if 'AtomPtrs' not in generalData:
    127127            generalData['AtomPtrs'] = [3,1,7,9]
  • trunk/GSASIIplot.py

    r1473 r1474  
    38493849    MCSA = data.get('MCSA',{})
    38503850    mcsaModels = MCSA.get('Models',[])
    3851     if mcsaModels:
     3851    if len(mcsaModels) > 1:
    38523852        XYZs,Types = G2mth.UpdateMCSAxyz(Bmat,MCSA)
    38533853        mcsaXYZ = []
  • trunk/GSASIIpwd.py

    r1464 r1474  
    519519    return intens*Df(xdata)*DX/dx
    520520
    521 def getBackground(pfx,parmDict,bakType,xdata):
     521def getBackground(pfx,parmDict,bakType,dataType,xdata):
    522522    'needs a doc string'
    523523    yb = np.zeros_like(xdata)
     
    589589            pkS = parmDict[pfx+'BkPksig;'+str(iD)]
    590590            pkG = parmDict[pfx+'BkPkgam;'+str(iD)]
    591             shl = 0.002
    592             Wd,fmin,fmax = getWidthsCW(pkP,pkS,pkG,shl)
     591            if 'C' in dataType:
     592                Wd,fmin,fmax = getWidthsCW(pkP,pkS,pkG,.002)
     593            else: #'T'OF
     594                Wd,fmin,fmax = getWidthsTOF(pkP,1.,1.,pkS,pkG)
    593595            iBeg = np.searchsorted(xdata,pkP-fmin)
    594596            iFin = np.searchsorted(xdata,pkP+fmax)
    595             yb[iBeg:iFin] += pkI*getFCJVoigt3(pkP,pkS,pkG,shl,xdata[iBeg:iFin])
     597            lenX = len(xdata)
     598            if not iBeg:
     599                iFin = np.searchsorted(xdata,pkP+fmax)
     600            elif iBeg == lenX:
     601                iFin = iBeg
     602            else:
     603                iFin = np.searchsorted(xdata,pkP+fmax)
     604            if 'C' in dataType:
     605                yb[iBeg:iFin] += pkI*getFCJVoigt3(pkP,pkS,pkG,0.002,xdata[iBeg:iFin])
     606            else:   #'T'OF
     607                yb[iBeg:iFin] += pkI*getEpsVoigt(pkP,1.,1.,pkS,pkG,xdata[iBeg:iFin])
    596608            iD += 1       
    597609        except KeyError:
     
    602614    return yb
    603615   
    604 def getBackgroundDerv(hfx,parmDict,bakType,xdata):
     616def getBackgroundDerv(hfx,parmDict,bakType,dataType,xdata):
    605617    'needs a doc string'
    606618    nBak = 0
     
    685697            pkS = parmDict[hfx+'BkPksig;'+str(iD)]
    686698            pkG = parmDict[hfx+'BkPkgam;'+str(iD)]
    687             shl = 0.002
    688             Wd,fmin,fmax = getWidthsCW(pkP,pkS,pkG,shl)
     699            if 'C' in dataType:
     700                Wd,fmin,fmax = getWidthsCW(pkP,pkS,pkG,.002)
     701            else: #'T'OF
     702                Wd,fmin,fmax = getWidthsTOF(pkP,1.,1.,pkS,pkG)
    689703            iBeg = np.searchsorted(xdata,pkP-fmin)
    690704            iFin = np.searchsorted(xdata,pkP+fmax)
    691             Df,dFdp,dFds,dFdg,dFdsh = getdFCJVoigt3(pkP,pkS,pkG,shl,xdata[iBeg:iFin])
    692             dydpk[4*iD][iBeg:iFin] += 100.*cw[iBeg:iFin]*pkI*dFdp
    693             dydpk[4*iD+1][iBeg:iFin] += 100.*cw[iBeg:iFin]*Df
    694             dydpk[4*iD+2][iBeg:iFin] += 100.*cw[iBeg:iFin]*pkI*dFds
    695             dydpk[4*iD+3][iBeg:iFin] += 100.*cw[iBeg:iFin]*pkI*dFdg
     705            lenX = len(xdata)
     706            if not iBeg:
     707                iFin = np.searchsorted(xdata,pkP+fmax)
     708            elif iBeg == lenX:
     709                iFin = iBeg
     710            else:
     711                iFin = np.searchsorted(xdata,pkP+fmax)
     712            if 'C' in dataType:
     713                Df,dFdp,dFds,dFdg,x = getdFCJVoigt3(pkP,pkS,pkG,.002,xdata[iBeg:iFin])
     714                dydpk[4*iD][iBeg:iFin] += 100.*cw[iBeg:iFin]*pkI*dFdp
     715                dydpk[4*iD+1][iBeg:iFin] += 100.*cw[iBeg:iFin]*Df
     716                dydpk[4*iD+2][iBeg:iFin] += 100.*cw[iBeg:iFin]*pkI*dFds
     717                dydpk[4*iD+3][iBeg:iFin] += 100.*cw[iBeg:iFin]*pkI*dFdg
     718            else:   #'T'OF
     719                Df,dFdp,x,x,dFds,dFdg = getdEpsVoigt(pkP,1.,1.,pkS,pkG,xdata[iBeg:iFin])
     720                dydpk[4*iD][iBeg:iFin] += pkI*dFdp
     721                dydpk[4*iD+1][iBeg:iFin] += Df
     722                dydpk[4*iD+2][iBeg:iFin] += pkI*dFds
     723                dydpk[4*iD+3][iBeg:iFin] += pkI*dFdg
    696724            iD += 1       
    697725        except KeyError:
     
    778806    'needs a doc string'
    779807   
    780     yb = getBackground('',parmDict,bakType,xdata)
     808    yb = getBackground('',parmDict,bakType,dataType,xdata)
    781809    yc = np.zeros_like(yb)
    782810    cw = np.diff(xdata)
     
    886914# needs to return np.array([dMdx1,dMdx2,...]) in same order as varylist = backVary,insVary,peakVary order
    887915    dMdv = np.zeros(shape=(len(varyList),len(xdata)))
    888     dMdb,dMddb,dMdpk = getBackgroundDerv('',parmDict,bakType,xdata)
     916    dMdb,dMddb,dMdpk = getBackgroundDerv('',parmDict,bakType,dataType,xdata)
    889917    if 'Back:0' in varyList:            #background derivs are in front if present
    890918        dMdv[0:len(dMdb)] = dMdb
     
    898926    for name in varyList:
    899927        if 'BkPk' in name:
    900             parm,id = name.split(':')
     928            parm,id = name.split(';')
    901929            ip = names.index(parm)
    902930            dMdv[varyList.index(name)] = dMdpk[4*int(id)+ip]
     
    11171145    peaksList = []
    11181146    for i in range(Debye['nPeaks']):
    1119         peaksNames = ['BkPkpos:'+str(i),'BkPkint:'+str(i),'BkPksig:'+str(i),'BkPkgam:'+str(i)]
     1147        peaksNames = ['BkPkpos;'+str(i),'BkPkint;'+str(i),'BkPksig;'+str(i),'BkPkgam;'+str(i)]
    11201148        peaksDict.update(dict(zip(peaksNames,Debye['peaksList'][i][::2])))
    11211149        peaksList += zip(peaksNames,Debye['peaksList'][i][1::2])
     
    12381266        iDb = 0
    12391267        while True:
    1240             names = ['BkPkpos:','BkPkint:','BkPksig:','BkPkgam:']
     1268            names = ['BkPkpos;','BkPkint;','BkPksig;','BkPkgam;']
    12411269            try:
    12421270                for i,name in enumerate(names):
     
    12801308            parms = ['BkPkpos','BkPkint','BkPksig','BkPkgam']
    12811309            print 'Peaks in background coefficients'
    1282             ptfmt = "%12.5f"
     1310            ptfmt = "%15.3f"
    12831311            names =   'names :'
    12841312            ptstr =  'values:'
     
    12861314            for item in sigDict:
    12871315                if 'BkPk' in item:
    1288                     names += '%12s'%(item)
     1316                    names += '%15s'%(item)
    12891317                    sigstr += ptfmt%(sigDict[item])
    1290                     parm,id = item.split(':')
     1318                    parm,id = item.split(';')
    12911319                    ip = parms.index(parm)
    12921320                    ptstr += ptfmt%(Background[1]['peaksList'][int(id)][2*ip])
     
    15041532       
    15051533    sigDict = dict(zip(varyList,sig))
    1506     yb[xBeg:xFin] = getBackground('',parmDict,bakType,x[xBeg:xFin])
     1534    yb[xBeg:xFin] = getBackground('',parmDict,bakType,dataType,x[xBeg:xFin])
    15071535    yc[xBeg:xFin] = getPeakProfile(dataType,parmDict,x[xBeg:xFin],varyList,bakType)
    15081536    yd[xBeg:xFin] = y[xBeg:xFin]-yc[xBeg:xFin]
     
    16151643    msg = 'test '
    16161644    gplot = plotter.add('FCJ-Voigt, 11BM').gca()
    1617     gplot.plot(xdata,getBackground('',parmDict0,bakType,xdata))   
     1645    gplot.plot(xdata,getBackground('',parmDict0,bakType,'PXC',xdata))   
    16181646    gplot.plot(xdata,getPeakProfile(parmDict0,xdata,varyList,bakType))
    16191647    fplot = plotter.add('FCJ-Voigt, Ka1+2').gca()
    1620     fplot.plot(xdata,getBackground('',parmDict1,bakType,xdata))   
     1648    fplot.plot(xdata,getBackground('',parmDict1,bakType,'PXC',xdata))   
    16211649    fplot.plot(xdata,getPeakProfile(parmDict1,xdata,varyList,bakType))
    16221650   
  • trunk/GSASIIstrMain.py

    r1462 r1474  
    5656        Ftol = Controls['min dM/M']
    5757        Factor = Controls['shift factor']
    58         maxCyc = Controls['max cyc']
    5958        if 'Jacobian' in Controls['deriv type']:           
    6059            result = so.leastsq(G2stMth.errRefine,values,Dfun=G2stMth.dervRefine,full_output=True,
     
    6362            ncyc = int(result[2]['nfev']/2)
    6463        elif 'Hessian' in Controls['deriv type']:
     64            maxCyc = Controls['max cyc']
    6565            result = G2mth.HessianLSQ(G2stMth.errRefine,values,Hess=G2stMth.HessRefine,ftol=Ftol,maxcyc=maxCyc,Print=ifPrint,
    6666                args=([Histograms,Phases,restraintDict,rigidbodyDict],parmDict,varyList,calcControls,pawleyLookup,dlg))
  • trunk/GSASIIstrMath.py

    r1466 r1474  
    15971597    hfx = ':%d:'%(hId)
    15981598    bakType = calcControls[hfx+'bakType']
    1599     yb = G2pwd.getBackground(hfx,parmDict,bakType,x)
     1599    yb = G2pwd.getBackground(hfx,parmDict,bakType,calcControls[hfx+'histType'],x)
    16001600    yc = np.zeros_like(yb)
    16011601    cw = np.diff(x)
     
    17301730    bakType = calcControls[hfx+'bakType']
    17311731    dMdv = np.zeros(shape=(len(varylist),len(x)))
    1732     dMdb,dMddb,dMdpk = G2pwd.getBackgroundDerv(hfx,parmDict,bakType,x)
     1732    dMdb,dMddb,dMdpk = G2pwd.getBackgroundDerv(hfx,parmDict,bakType,calcControls[hfx+'histType'],x)
    17331733    if hfx+'Back:0' in varylist: # for now assume that Back:x vars to not appear in constraints
    17341734        bBpos =varylist.index(hfx+'Back:0')
     
    17811781            h,k,l = refl[:3]
    17821782            Uniq = np.inner(refl[:3],SGMT)
     1783            if 'T' in calcControls[hfx+'histType']:
     1784                wave = refl[14]
    17831785            dIdsh,dIdsp,dIdpola,dIdPO,dFdODF,dFdSA,dFdAb,dFdEx = GetIntensityDerv(refl,wave,Uniq,G,g,pfx,phfx,hfx,SGData,calcControls,parmDict)
    17841786            if 'C' in calcControls[hfx+'histType']:        #CW powder
Note: See TracChangeset for help on using the changeset viewer.