Changeset 3070


Ignore:
Timestamp:
Sep 13, 2017 8:53:49 AM (4 years ago)
Author:
vondreele
Message:

implement use of background pattern for PWDR data.
Used for plot & peak fitting; not Rietveld refinement
fix background parm copy issue - needed deepcopy

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIplot.py

    r3066 r3070  
    19711971        Pattern.append(G2frame.GPXtree.GetItemText(PatternId))
    19721972        PlotList = [Pattern,]
     1973        Pattern[0]['BackFile'] =  G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId, 'Background'))[1].get('background PWDR',['',-1.0])
    19731974        Parms,Parms2 = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,
    19741975            G2frame.PatternId, 'Instrument Parameters'))
     
    19941995                Ymax = max(Pattern[1][1])
    19951996                Pattern[0].update({'Offset':[0.0,0.0],'delOffset':0.02*Ymax,'refOffset':-0.1*Ymax,'refDelt':0.1*Ymax,})
     1997            Pattern[0]['BackFile'] =  G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId, 'Background'))[1].get('background PWDR',['',-1.0])
    19961998            PlotList.append(Pattern)
    19971999            ParmList.append(G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,
     
    20032005    for Pattern in PlotList:
    20042006        xye = Pattern[1]
     2007        bxye = G2pdG.GetFileBackground(G2frame,xye,Pattern)
    20052008        if xye[1] is None: continue
    2006         if Ymax is None: Ymax = max(xye[1])
    2007         Ymax = max(Ymax,max(xye[1]))
     2009        if Ymax is None: Ymax = max(xye[1]+bxye)
     2010        Ymax = max(Ymax,max(xye[1]+bxye))
    20082011    if Ymax is None: return # nothing to plot
    20092012    offsetX = Pattern[0]['Offset'][1]
     
    20622065        LimitId = 0
    20632066        if Pattern[1] is None: continue # skip over uncomputed simulations
    2064         xye = ma.array(ma.getdata(Pattern[1]))
     2067#        xye = ma.array(ma.getdata(Pattern[1]))
     2068        xye = np.array(ma.getdata(Pattern[1]))
     2069        bxye = G2pdG.GetFileBackground(G2frame,xye,Pattern)
    20652070        if PickId:
    20662071            ifpicked = Pattern[2] == G2frame.GPXtree.GetItemText(PatternId)
     
    20812086            if G2frame.plotStyle['sqrtPlot']:
    20822087                olderr = np.seterr(invalid='ignore') #get around sqrt(-ve) error
    2083                 Y = np.where(xye[1]>=0.,np.sqrt(xye[1]),-np.sqrt(-xye[1]))
     2088                Y = np.where(xye[1]+bxye>=0.,np.sqrt(xye[1]+bxye),-np.sqrt(-xye[1]-bxye))
    20842089                np.seterr(invalid=olderr['invalid'])
    20852090            else:
    2086                 Y = xye[1]+offsetY*N*Ymax/100.0
     2091                Y = xye[1]+bxye+offsetY*N*Ymax/100.0
    20872092        elif plottype in ['SASD','REFD']:
    20882093            if plottype == 'SASD':
  • trunk/GSASIIpwd.py

    r3000 r3070  
    15011501    return True
    15021502           
    1503 def DoPeakFit(FitPgm,Peaks,Background,Limits,Inst,Inst2,data,prevVaryList=[],oneCycle=False,controls=None,dlg=None):
     1503def DoPeakFit(FitPgm,Peaks,Background,Limits,Inst,Inst2,data,fixback,prevVaryList=[],oneCycle=False,controls=None,dlg=None):
    15041504    '''Called to perform a peak fit, refining the selected items in the peak
    15051505    table as well as selected items in the background.
     
    15191519      data[1] is the y-values, data[2] are weight values, data[3], [4] and [5] are
    15201520      calc, background and difference intensities, respectively.
     1521    :param array fixback: fixed background values
    15211522    :param list prevVaryList: Used in sequential refinements to override the
    15221523      variable list. Defaults as an empty list.
     
    18011802        badVary = []
    18021803        result = so.leastsq(errPeakProfile,values,Dfun=devPeakProfile,full_output=True,ftol=Ftol,col_deriv=True,
    1803                args=(x[xBeg:xFin],y[xBeg:xFin],w[xBeg:xFin],dataType,parmDict,varyList,bakType,dlg))
     1804               args=(x[xBeg:xFin],(y+fixback)[xBeg:xFin],w[xBeg:xFin],dataType,parmDict,varyList,bakType,dlg))
    18041805        ncyc = int(result[2]['nfev']/2)
    18051806        runtime = time.time()-begin   
    18061807        chisq = np.sum(result[2]['fvec']**2)
    18071808        Values2Dict(parmDict, varyList, result[0])
    1808         Rvals['Rwp'] = np.sqrt(chisq/np.sum(w[xBeg:xFin]*y[xBeg:xFin]**2))*100.      #to %
     1809        Rvals['Rwp'] = np.sqrt(chisq/np.sum(w[xBeg:xFin]*(y+fixback)[xBeg:xFin]**2))*100.      #to %
    18091810        Rvals['GOF'] = chisq/(xFin-xBeg-len(varyList))       #reduced chi^2
    18101811        print 'Number of function calls:',result[2]['nfev'],' Number of observations: ',xFin-xBeg,' Number of parameters: ',len(varyList)
     
    18341835    yb[xBeg:xFin] = getBackground('',parmDict,bakType,dataType,x[xBeg:xFin])[0]
    18351836    yc[xBeg:xFin] = getPeakProfile(dataType,parmDict,x[xBeg:xFin],varyList,bakType)
    1836     yd[xBeg:xFin] = y[xBeg:xFin]-yc[xBeg:xFin]
     1837    yd[xBeg:xFin] = (y+fixback)[xBeg:xFin]-yc[xBeg:xFin]
    18371838    GetBackgroundParms(parmDict,Background)
    18381839    if bakVary: BackgroundPrint(Background,sigDict)
  • trunk/GSASIIpwdGUI.py

    r3063 r3070  
    138138##### Setup routines
    139139################################################################################
     140
     141def GetFileBackground(G2frame,xye,Pattern):
     142    backfile,mult = Pattern[0]['BackFile']
     143    bxye = np.zeros(len(xye[1]))
     144    if backfile:
     145        bxye = mult*G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.root,backfile))[1][1]
     146    return bxye
    140147   
    141148def IsHistogramInAnyPhase(G2frame,histoName):
     
    426433        limits = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Limits'))[1]
    427434        inst,inst2 = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Instrument Parameters'))
    428         profile = G2frame.GPXtree.GetItemPyData(PatternId)[1]
     435        Pattern = G2frame.GPXtree.GetItemPyData(PatternId)
     436        profile = Pattern[1]
     437        bxye = GetFileBackground(G2frame,profile,Pattern)
    429438        x0 = profile[0]
    430439        iBeg = np.searchsorted(x0,limits[0])
    431440        iFin = np.searchsorted(x0,limits[1])
    432441        x = x0[iBeg:iFin]
    433         y0 = profile[1][iBeg:iFin]
     442        y0 = (profile[1]+bxye)[iBeg:iFin]
    434443        ysig = 1.0*np.std(y0)
    435444        offset = [-1,1]
     
    567576                limits = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Limits'))[1]
    568577                inst,inst2 = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Instrument Parameters'))
    569                 data = G2frame.GPXtree.GetItemPyData(PatternId)[1]
     578                Pattern = G2frame.GPXtree.GetItemPyData(PatternId)
     579                data = Pattern[1]
     580                fixback = GetFileBackground(G2frame,data,Pattern)
    570581                peaks['sigDict'],result,sig,Rvals,varyList,parmDict,fullvaryList,badVary = G2pwd.DoPeakFit(FitPgm,peaks['peaks'],
    571                     background,limits,inst,inst2,data,prevVaryList,oneCycle,controls)
     582                    background,limits,inst,inst2,data,fixback,prevVaryList,oneCycle,controls)
    572583                if len(result[0]) != len(fullvaryList):
    573584                    dlg.Destroy()
     
    611622        limits = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Limits'))[1]
    612623        inst,inst2 = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Instrument Parameters'))
    613         data = G2frame.GPXtree.GetItemPyData(PatternId)[1]
     624        Pattern = G2frame.GPXtree.GetItemPyData(PatternId)
     625        data = Pattern[1]
     626        bxye = GetFileBackground(G2frame,data,Pattern)
    614627        dlg = wx.ProgressDialog('Residual','Peak fit Rwp = ',101.0,
    615628            style = wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE|wx.PD_REMAINING_TIME|wx.PD_CAN_ABORT)
     
    620633            dlg.SetPosition(wx.Point(screenSize[2]-Size[0]-305,screenSize[1]+5))
    621634        try:
    622             peaks['sigDict'] = G2pwd.DoPeakFit(FitPgm,peaks['peaks'],background,limits,inst,inst2,data,[],oneCycle,controls,dlg)[0]
     635            peaks['sigDict'] = G2pwd.DoPeakFit(FitPgm,peaks['peaks'],background,limits,inst,inst2,data,bxye,[],oneCycle,controls,dlg)[0]
    623636        finally:
    624637            print 'finished'
     
    933946            Id = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,item)
    934947            G2frame.GPXtree.SetItemPyData(
    935                 G2gd.GetGPXtreeItemId(G2frame,Id,'Background'),copy.copy(data))
     948                G2gd.GetGPXtreeItemId(G2frame,Id,'Background'),copy.deepcopy(data))
    936949
    937950    def OnBkgFit(event):
     
    12311244            peaksSizer.Add(peaksGrid)       
    12321245        return peaksSizer
     1246   
     1247    def BackFileSizer():
     1248       
     1249        def OnBackPWDR(event):
     1250            data[1]['background PWDR'][0] = back.GetValue()
     1251            G2plt.PlotPatterns(G2frame,plotType='PWDR')
     1252       
     1253        fileSizer = wx.BoxSizer(wx.VERTICAL)
     1254        fileSizer.Add(wx.StaticText(G2frame.dataWindow,-1,' Fixed background file:'),0,WACV)
     1255        if 'background PWDR' not in data[1]:
     1256            data[1]['background PWDR'] = ['',-1.]
     1257        backSizer = wx.BoxSizer(wx.HORIZONTAL)
     1258        Choices = ['',]+G2gd.GetGPXtreeDataNames(G2frame,['PWDR',])
     1259        Source = G2frame.GPXtree.GetItemText(G2frame.PatternId)
     1260        Choices.pop(Choices.index(Source))
     1261        back = wx.ComboBox(parent=G2frame.dataWindow,value=data[1]['background PWDR'][0],choices=Choices,
     1262            style=wx.CB_READONLY|wx.CB_DROPDOWN)
     1263        back.Bind(wx.EVT_COMBOBOX,OnBackPWDR)
     1264        backSizer.Add(back)
     1265        backSizer.Add(wx.StaticText(G2frame.dataWindow,-1,' multiplier'),0,WACV)
     1266        backMult = G2G.ValidatedTxtCtrl(G2frame.dataWindow,data[1]['background PWDR'],1,nDig=(10,3))
     1267        backSizer.Add(backMult,0,WACV)
     1268        fileSizer.Add(backSizer)
     1269        return fileSizer
    12331270
    12341271    # UpdateBackground execution starts here
     
    12541291    mainSizer.Add((0,5),0)
    12551292    mainSizer.Add(PeaksSizer())
     1293    mainSizer.Add((0,5),0)
     1294    mainSizer.Add(BackFileSizer())
    12561295    G2frame.dataWindow.SetDataSize()
    12571296       
Note: See TracChangeset for help on using the changeset viewer.