Changeset 1889 for trunk/GSASIIpwdGUI.py


Ignore:
Timestamp:
Jun 15, 2015 3:00:17 PM (7 years ago)
Author:
toby
Message:

Add fixed background points; animate dragging points and lines; add fixed bkg fit routine (bkg peaks buggy\!)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIpwdGUI.py

    r1881 r1889  
    789789            G2frame.PatternTree.SetItemPyData(
    790790                G2gd.GetPatternTreeItemId(G2frame,Id,'Background'),copy.copy(data))
    791                
     791
     792    def OnBkgFit(event):
     793        def SetInstParms(Inst):
     794            dataType = Inst['Type'][0]
     795            insVary = []
     796            insNames = []
     797            insVals = []
     798            for parm in Inst:
     799                insNames.append(parm)
     800                insVals.append(Inst[parm][1])
     801                if parm in ['U','V','W','X','Y','SH/L','I(L2)/I(L1)','alpha',
     802                    'beta-0','beta-1','beta-q','sig-0','sig-1','sig-2','sig-q',] and Inst[parm][2]:
     803                        insVary.append(parm)
     804            instDict = dict(zip(insNames,insVals))
     805            instDict['X'] = max(instDict['X'],0.01)
     806            instDict['Y'] = max(instDict['Y'],0.01)
     807            if 'SH/L' in instDict:
     808                instDict['SH/L'] = max(instDict['SH/L'],0.002)
     809            return dataType,instDict,insVary
     810   
     811        PatternId = G2frame.PatternId       
     812        controls = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.root, 'Controls'))
     813        background = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Background'))
     814        limits = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Limits'))[1]
     815        inst,inst2 = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Instrument Parameters'))
     816       
     817        X = [x for x,y in background[1]['FixedPoints'] if limits[0] <= x <= limits[1]]
     818        Y = [y for x,y in background[1]['FixedPoints'] if limits[0] <= x <= limits[1]]
     819        W = [1]*len(X)
     820        Z = [0]*len(X)
     821
     822        # load instrument and background params
     823        dataType,insDict,insVary = SetInstParms(inst)
     824        bakType,bakDict,bakVary = G2pwd.SetBackgroundParms(background)
     825        # how many background parameters are refined?
     826        if len(bakVary)*1.5 > len(X):
     827            msg = ("You are attempting to vary "+str(len(bakVary))+
     828                   " background terms with only "+str(len(X))+" background points"+
     829                    "\nAdd more points or reduce the number of terms")
     830            print msg
     831            G2frame.ErrorDialog('Too few points',msg)
     832            return
     833       
     834        wx.BeginBusyCursor()
     835        try:
     836            G2pwd.DoPeakFit('LSQ',[],background,limits,inst,inst2,
     837                            np.array((X,Y,W,Z,Z,Z)),bakVary,False,controls)
     838        finally:
     839            wx.EndBusyCursor()
     840        # compute the background values and plot them
     841        pwddata = G2frame.PatternTree.GetItemPyData(PatternId)[1]
     842        x = pwddata[0]
     843        xBeg = np.searchsorted(x,limits[0])
     844        xFin = np.searchsorted(x,limits[1])
     845        parmDict = {}
     846        bakType,bakDict,bakVary = G2pwd.SetBackgroundParms(background)
     847        parmDict.update(bakDict)
     848        parmDict.update(insDict)
     849        pwddata[3] *= 0
     850        pwddata[5] *= 0
     851        pwddata[4][xBeg:xFin] = G2pwd.getBackground(
     852            '',parmDict,bakType,dataType,x[xBeg:xFin])[0]
     853        G2plt.PlotPatterns(G2frame,plotType='PWDR')
     854        # show the updated background values
     855        wx.CallLater(100,UpdateBackground,G2frame,data)
     856   
    792857    def OnPeaksMove(event):
    793858        if not data[1]['nPeaks']:
     
    9921057    G2frame.Bind(wx.EVT_MENU,OnBackFlagCopy,id=G2gd.wxID_BACKFLAGCOPY)
    9931058    G2frame.Bind(wx.EVT_MENU,OnPeaksMove,id=G2gd.wxID_PEAKSMOVE)
     1059    G2frame.Bind(wx.EVT_MENU,OnBkgFit,id=G2frame.dataFrame.wxID_BackPts['Fit'])
    9941060    BackId = G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId, 'Background')
    9951061    Choices = ['chebyschev','cosine','Q^2 power series','Q^-2 powder series','lin interpolate','inv interpolate','log interpolate']
Note: See TracChangeset for help on using the changeset viewer.