Changeset 5084


Ignore:
Timestamp:
Nov 14, 2021 11:20:38 AM (6 months ago)
Author:
toby
Message:

update PWDR help btn formatting; compute changes to peak values immediately (as was already done for bkg); commented out Laue fitting work in progress

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIpwd.py

    r5075 r5084  
    13551355instrument parameters to be refined. When peakInstPrmMode=False, the instrument
    13561356parameters are not used and cannot be refined.
    1357 The default is peakFitMode=True.
     1357The default is peakFitMode=True. This is changed only in
     1358:func:`setPeakInstPrmMode`, which is called only from :mod:`GSASIIscriptable`.
    13581359'''
    13591360
     
    13631364    unless the individual parameter is refined. If normal=False,
    13641365    peak widths are used as supplied for each peak.
     1366    At present this is called only in G2scriptable.
    13651367
    13661368    Note that normal=True unless this routine is called. Also,
     
    13741376
    13751377def getPeakProfile(dataType,parmDict,xdata,fixback,varyList,bakType):
    1376     '''Computes the profile for a powder pattern for single peak fitting
     1378    '''Computes the profiles from multiple peaks for individual peak fitting
     1379    for powder patterns.
    13771380    NB: not used for Rietveld refinement
    13781381    '''
     
    19641967    InstPrint(Inst,sigDict)
    19651968    return True
    1966            
    1967 def DoPeakFit(FitPgm,Peaks,Background,Limits,Inst,Inst2,data,fixback=None,prevVaryList=[],oneCycle=False,controls=None,wtFactor=1.0,dlg=None):
     1969
     1970def DoPeakFit(FitPgm,Peaks,Background,Limits,Inst,Inst2,data,fixback=None,prevVaryList=[],oneCycle=False,controls=None,wtFactor=1.0,dlg=None,noFit=False):
    19681971    '''Called to perform a peak fit, refining the selected items in the peak
    19691972    table as well as selected items in the background.
     
    19921995    :param wx.Dialog dlg: A dialog box that is updated with progress from the fit.
    19931996      Defaults to None, which means no updates are done.
     1997    :param bool noFit: When noFit is True, a refinement is not performed. Default
     1998      is False.
     1999
    19942000    '''
    19952001    def GetBackgroundParms(parmList,Background):
     
    22332239               
    22342240    def devPeakProfile(values,xdata,ydata,fixback, weights,dataType,parmdict,varylist,bakType,dlg):
     2241        '''Computes a matrix where each row is the derivative of the calc-obs
     2242        values (see :func:`errPeakProfile`) with respect to each parameter
     2243        in backVary,insVary,peakVary. Used for peak fitting.
     2244        '''
    22352245        parmdict.update(zip(varylist,values))
    22362246        return np.sqrt(weights)*getPeakProfileDerv(dataType,parmdict,xdata,fixback,varylist,bakType)
    22372247           
    2238     def errPeakProfile(values,xdata,ydata,fixback,weights,dataType,parmdict,varylist,bakType,dlg):       
     2248    def errPeakProfile(values,xdata,ydata,fixback,weights,dataType,parmdict,varylist,bakType,dlg):
     2249        '''Computes a vector with the weighted calc-obs values differences
     2250        for peak fitting
     2251        '''
    22392252        parmdict.update(zip(varylist,values))
    22402253        M = np.sqrt(weights)*(getPeakProfile(dataType,parmdict,xdata,fixback,varylist,bakType)-ydata)
     
    22472260        return M
    22482261
    2249     # beginning of DoPeakFit
     2262    #---- beginning of DoPeakFit ----------------------------------------------
    22502263    if controls:
    22512264        Ftol = controls['min dM/M']
     
    22822295                raise Exception('Instrumental profile terms cannot be varied '+
    22832296                                    'after setPeakInstPrmMode(False) is used')
    2284     while True:
     2297    while not noFit:
    22852298        begin = time.time()
    22862299        values =  np.array(Dict2Values(parmDict, varyList))
     
    23182331                break
    23192332    if dlg: dlg.Destroy()
    2320     sigDict = dict(zip(varyList,sig))
    23212333    yb[xBeg:xFin] = getBackground('',parmDict,bakType,dataType,x[xBeg:xFin],fixback[xBeg:xFin])[0]
    23222334    yc[xBeg:xFin] = getPeakProfile(dataType,parmDict,x[xBeg:xFin],fixback[xBeg:xFin],varyList,bakType)
    23232335    yd[xBeg:xFin] = y[xBeg:xFin]-yc[xBeg:xFin]
     2336    if noFit:
     2337        return
     2338    sigDict = dict(zip(varyList,sig))
    23242339    GetBackgroundParms(parmDict,Background)
    23252340    if bakVary: BackgroundPrint(Background,sigDict)
  • trunk/GSASIIpwdGUI.py

    r5048 r5084  
    791791        if not G2frame.GSASprojectfile:            #force a save of the gpx file so SaveState can write in the same directory
    792792            G2frame.OnFileSaveas(event)
    793         wx.CallAfter(OnPeakFit,'LSQ')
     793        FitPgm = 'LSQ'
     794#        if data.get('FitPgm',0) == 1:
     795#            FitPgm = 'LaueFringe'
     796        wx.CallAfter(OnPeakFit,FitPgm)
    794797       
    795798    def OnOneCycle(event):
     
    797800            reflGrid.HideCellEditControl()
    798801            reflGrid.DisableCellEditControl()
    799         wx.CallAfter(OnPeakFit,'LSQ',oneCycle=True)
     802        FitPgm = 'LSQ'
     803#        if data.get('FitPgm',0) == 1:
     804#            FitPgm = 'LaueFringe'
     805        wx.CallAfter(OnPeakFit,FitPgm,oneCycle=True)
    800806       
    801807    def OnSeqPeakFit(event):
     
    825831        oneCycle = False
    826832        FitPgm = 'LSQ'
     833#        if data.get('FitPgm',0) == 1:
     834#            FitPgm = 'LaueFringe'
    827835        prevVaryList = []
    828836        peaks = None
     
    878886        G2plt.PlotPatterns(G2frame,plotType='PWDR')
    879887       
    880     def OnPeakFit(FitPgm,oneCycle=False):
     888    def OnPeakFit(FitPgm,oneCycle=False,noFit=False):
    881889        SaveState()
    882890        controls = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.root, 'Controls'))
     
    896904        wtFactor = Pattern[0]['wtFactor']
    897905        bxye = GetFileBackground(G2frame,data,background,scale=False)
    898         dlg = wx.ProgressDialog('Residual','Peak fit Rwp = ',101.0,
     906#======================================================================
     907#        print('Debug: reload G2pwd')  # TODO: remove me
     908#        import imp
     909#        imp.reload(G2pwd)
     910#        # TODO: remove ^^^^
     911#======================================================================
     912        if noFit:
     913            results = G2pwd.DoPeakFit(FitPgm,peaks['peaks'],background,limits,inst,inst2,data,bxye,[],oneCycle,controls,wtFactor,noFit=True)
     914            G2plt.PlotPatterns(G2frame,plotType='PWDR')
     915            return
     916        dlg = wx.ProgressDialog('Residual','Peak fit Rwp = ',101.0,
     917            parent=G2frame,
    899918            style = wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE|wx.PD_REMAINING_TIME|wx.PD_CAN_ABORT)
    900919        screenSize = wx.ClientDisplayRect()
     
    902921        if 50 < Size[0] < 500: # sanity check on size, since this fails w/Win & wx3.0
    903922            dlg.SetSize((int(Size[0]*1.2),Size[1])) # increase size a bit along x
    904             dlg.SetPosition(wx.Point(screenSize[2]-Size[0]-305,screenSize[1]+5))
     923            dlg.CenterOnParent()
    905924        try:
    906925            results = G2pwd.DoPeakFit(FitPgm,peaks['peaks'],background,limits,inst,inst2,data,bxye,[],oneCycle,controls,wtFactor,dlg)
     
    908927            text = 'Peak fit: Rwp=%.2f%% Nobs= %d Nparm= %d Npeaks= %d'%(results[3]['Rwp'],results[1][2]['fjac'].shape[1],len(results[0]),len(peaks['peaks']))
    909928        finally:
    910 #            dlg.Destroy()
    911             print ('finished')
     929            dlg.Destroy()
    912930        newpeaks = copy.copy(peaks)
    913931        G2frame.GPXtree.SetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Peak List'),newpeaks)
     
    10651083                    for row in range(reflGrid.GetNumberRows()): data['peaks'][row][c]=False
    10661084            wx.CallAfter(UpdatePeakGrid,G2frame,data)
    1067                  
     1085
     1086    def updateMe(*args):
     1087        'Redraw the peak listings after the mode changes'
     1088        wx.CallAfter(UpdatePeakGrid,G2frame,data)
     1089
     1090    def RefreshPeakGrid(event):
     1091        'recompute & plot the peaks any time a value in the table is edited'
     1092        FitPgm = 'LSQ'
     1093#        if data.get('FitPgm',0) == 1:
     1094#            FitPgm = 'LaueFringe'
     1095        OnPeakFit(FitPgm,noFit=True)
     1096       
    10681097    #======================================================================
    10691098    # beginning of UpdatePeakGrid init
    10701099    #======================================================================
     1100#    data['FitPgm'] = data.get('FitPgm',0)
    10711101    G2frame.GetStatusBar().SetStatusText('Global refine: select refine column & press Y or N',1)
    10721102    G2gd.SetDataMenuBar(G2frame,G2frame.dataWindow.PeakMenu)
     
    11001130    Inst = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Instrument Parameters'))[0]
    11011131    for i in range(len(data['peaks'])): rowLabels.append(str(i+1))
     1132#    if data.get('FitPgm',0) == 1:
     1133#        colLabels = ['position','refine','intensity','refine','cells','refine']
     1134#        Types = [wg.GRID_VALUE_FLOAT+':10,4',wg.GRID_VALUE_BOOL,
     1135#            wg.GRID_VALUE_FLOAT+':10,3',wg.GRID_VALUE_BOOL,
     1136#            wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_BOOL]
     1137#        # TODO: note gamma values can still be set as refined
     1138#    elif 'C' in Inst['Type'][0]:
    11021139    if 'C' in Inst['Type'][0]:
    11031140        colLabels = ['position','refine','intensity','refine','sigma','refine','gamma','refine']
     
    11421179    reflGrid.SetTable(G2frame.PeakTable, True)
    11431180    setBackgroundColors()                         
    1144 #    reflGrid.Bind(wg.EVT_GRID_CELL_CHANGE, RefreshPeakGrid)
     1181    reflGrid.Bind(wg.EVT_GRID_CELL_CHANGED, RefreshPeakGrid)
    11451182    reflGrid.Bind(wx.EVT_KEY_DOWN, KeyEditPeakGrid)
    11461183#    reflGrid.Bind(wg.EVT_GRID_LABEL_LEFT_CLICK, onCellListSClick)
     
    11521189    G2frame.reflGrid = reflGrid
    11531190    topSizer = wx.BoxSizer(wx.HORIZONTAL)
    1154     topSizer.Add((-1,-1),1,wx.EXPAND)
    11551191    topSizer.Add(wx.StaticText(G2frame.dataWindow,label='List of peaks to fit individually'),0,WACV)
    11561192    topSizer.Add((-1,-1),1,wx.EXPAND)   
    11571193    topSizer.Add(G2G.HelpButton(G2frame.dataWindow,helpIndex=G2frame.dataWindow.helpKey))
    11581194    mainSizer.Add(topSizer,0,wx.EXPAND)
    1159     mainSizer.Add(reflGrid)
     1195    G2G.HorizontalLine(mainSizer,G2frame.dataWindow)
     1196#    if 'C' in Inst['Type'][0]:
     1197#        topSizer = wx.BoxSizer(wx.HORIZONTAL)
     1198#        topSizer.Add(wx.StaticText(G2frame.dataWindow,label=' Fitting mode: '),0,WACV)
     1199#        pkType = G2G.G2ChoiceButton(G2frame.dataWindow,('Powder diffraction','Laue fringes'),
     1200#                    indLoc=data,indKey='FitPgm',
     1201#                    onChoice=updateMe)
     1202#        topSizer.Add(pkType)
     1203#        mainSizer.Add(topSizer)
     1204    mainSizer.Add(reflGrid,0,wx.ALL,10)
    11601205    G2frame.dataWindow.SetSizer(mainSizer)
    11611206    G2frame.dataWindow.SetDataSize()
     
    17171762    mainSizer = wx.BoxSizer(wx.VERTICAL)
    17181763    topSizer = wx.BoxSizer(wx.HORIZONTAL)
    1719     topSizer.Add((-1,-1),1,wx.EXPAND)
    17201764    topSizer.Add(wx.StaticText(G2frame.dataWindow,label='Background used in refinement'),0,WACV)
    17211765    # add help button to bring up help web page - at right side of window
     
    17231767    topSizer.Add(G2G.HelpButton(G2frame.dataWindow,helpIndex=G2frame.dataWindow.helpKey))
    17241768    mainSizer.Add(topSizer,0,wx.EXPAND)
     1769    G2G.HorizontalLine(mainSizer,G2frame.dataWindow)
    17251770    mainSizer.Add(BackSizer())
    17261771    mainSizer.Add((0,5),0)
     
    18071852        mainSizer = wx.BoxSizer(wx.VERTICAL)
    18081853        topSizer = wx.BoxSizer(wx.HORIZONTAL)
    1809         topSizer.Add((-1,-1),1,wx.EXPAND)
    18101854        topSizer.Add(wx.StaticText(G2frame.dataWindow,label=' Data range to be used in fits'),0,WACV)
    18111855        # add help button to bring up help web page - at right side of window
     
    18131857        topSizer.Add(G2G.HelpButton(G2frame.dataWindow,helpIndex=G2frame.dataWindow.helpKey))
    18141858        mainSizer.Add(topSizer,0,wx.EXPAND)
     1859        G2G.HorizontalLine(mainSizer,G2frame.dataWindow)
    18151860        mainSizer.Add((5,5))
    18161861        mainSizer.Add(LimitSizer())
     
    29553000    mainSizer = wx.BoxSizer(wx.VERTICAL)
    29563001    topSizer = wx.BoxSizer(wx.HORIZONTAL)
    2957     topSizer.Add((-1,-1),1,wx.EXPAND)
    29583002    topSizer.Add(wx.StaticText(G2frame.dataWindow,label=' Sample and Experimental Parameters'))
    29593003    # add help button to bring up help web page - at right side of window
     
    29613005    topSizer.Add(G2G.HelpButton(G2frame.dataWindow,helpIndex=G2frame.dataWindow.helpKey))
    29623006    mainSizer.Add(topSizer,0,wx.EXPAND)
     3007    G2G.HorizontalLine(mainSizer,G2frame.dataWindow)
    29633008    nameSizer = wx.BoxSizer(wx.HORIZONTAL)
    29643009    nameSizer.Add(wx.StaticText(G2frame.dataWindow,wx.ID_ANY,' Instrument Name '),0,WACV)
     
    44284473    mainSizer = wx.BoxSizer(wx.VERTICAL)
    44294474    topSizer = wx.BoxSizer(wx.HORIZONTAL)
    4430     topSizer.Add((-1,-1),1,wx.EXPAND)
    44314475    topSizer.Add(wx.StaticText(parent=G2frame.dataWindow,label='Indexing controls'),0,WACV)
    44324476    # add help button to bring up help web page - at right side of window
     
    44344478    topSizer.Add(G2G.HelpButton(G2frame.dataWindow,helpIndex=G2frame.dataWindow.helpKey))
    44354479    mainSizer.Add(topSizer,0,wx.EXPAND)
     4480    G2G.HorizontalLine(mainSizer,G2frame.dataWindow)
    44364481    mainSizer.Add((5,5),0)
    44374482    littleSizer = wx.FlexGridSizer(0,5,5,5)
Note: See TracChangeset for help on using the changeset viewer.