Changeset 3906 for trunk/GSASIIpwd.py


Ignore:
Timestamp:
Apr 16, 2019 9:39:40 PM (3 years ago)
Author:
toby
Message:

implement fixed backgound file in Riteveld Fit; show Rietveld & peak fits with bkg file added to calc bkg, not subtracted

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIpwd.py

    r3848 r3906  
    716716    return intens*Df(xdata)*DX/dx
    717717
    718 def getBackground(pfx,parmDict,bakType,dataType,xdata):
    719     'needs a doc string'
     718def getBackground(pfx,parmDict,bakType,dataType,xdata,fixedBkg={}):
     719    '''Computes the background from vars pulled from gpx file or tree.
     720    '''
    720721    if 'T' in dataType:
    721722        q = 2.*np.pi*parmDict[pfx+'difC']/xdata
     
    837838        except ValueError:
    838839            print ('**** WARNING - backround peak '+str(iD)+' sigma is negative; fix & try again ****')
    839             break       
     840            break
     841    # fixed background from file
     842    if len(fixedBkg) >= 3:
     843        mult = fixedBkg.get('_fixedMult',0.0)
     844        if len(fixedBkg.get('_fixedValues',[])) != len(yb):
     845            print('Lengths of backgrounds do not agree: yb={}, fixed={}'.format(
     846                len(yb),len(fixedBkg.get('_fixedValues',[]))))
     847        elif mult:
     848            yb -= mult*fixedBkg.get('_fixedValues',[]) # N.B. mult is negative
     849            sumBk[0] = sum(yb)
    840850    return yb,sumBk
    841851   
     
    10871097
    10881098def getPeakProfile(dataType,parmDict,xdata,varyList,bakType):
    1089     'needs a doc string'
     1099    'Computes the profile for a powder pattern'
    10901100   
    10911101    yb = getBackground('',parmDict,bakType,dataType,xdata)[0]
     
    14041414   
    14051415def SetBackgroundParms(Background):
    1406     'needs a doc string'
     1416    'Loads background parameters into dicts/lists to create varylist & parmdict'
    14071417    if len(Background) == 1:            # fix up old backgrounds
    14081418        Background.append({'nDebye':0,'debyeTerms':[]})
     
    14421452            peaksVary.append(item[0])
    14431453    backDict.update(peaksDict)
    1444     backVary += peaksVary   
     1454    backVary += peaksVary
    14451455    return bakType,backDict,backVary
    14461456   
     
    18671877    if dlg: dlg.Destroy()
    18681878    sigDict = dict(zip(varyList,sig))
    1869     yb[xBeg:xFin] = getBackground('',parmDict,bakType,dataType,x[xBeg:xFin])[0]
    1870     yc[xBeg:xFin] = getPeakProfile(dataType,parmDict,x[xBeg:xFin],varyList,bakType)
    1871     yd[xBeg:xFin] = (y+fixback)[xBeg:xFin]-yc[xBeg:xFin]
     1879    yb[xBeg:xFin] = getBackground('',parmDict,bakType,dataType,x[xBeg:xFin])[0]-fixback[xBeg:xFin]
     1880    yc[xBeg:xFin] = getPeakProfile(dataType,parmDict,x[xBeg:xFin],varyList,bakType)-fixback[xBeg:xFin]
     1881    yd[xBeg:xFin] = y[xBeg:xFin]-yc[xBeg:xFin]
    18721882    GetBackgroundParms(parmDict,Background)
    18731883    if bakVary: BackgroundPrint(Background,sigDict)
     
    28482858    fplot.plot(xdata,getBackground('',parmDict1,bakType,'PXC',xdata)[0])   
    28492859    fplot.plot(xdata,getPeakProfile(parmDict1,xdata,varyList,bakType))
    2850     
     2860   
    28512861def test1():
    28522862    if NeedTestData: TestData()
Note: See TracChangeset for help on using the changeset viewer.