Changeset 1496 for trunk/GSASIIpwdGUI.py


Ignore:
Timestamp:
Sep 14, 2014 7:48:39 PM (8 years ago)
Author:
vondreele
Message:

Add sequential peak fitting.
Change Back:n to Back;n for background parameters
Also DebyeA, etc.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIpwdGUI.py

    r1493 r1496  
    330330            data['peaks'].append(G2mth.setPeakparms(inst,inst2,pos,mag))
    331331        UpdatePeakGrid(G2frame,data)
    332         G2plt.PlotPatterns(G2frame,plotType='PWDR')       
     332        G2plt.PlotPatterns(G2frame,plotType='PWDR')
     333       
     334    def OnCopyPeaks(event):
     335        hst = G2frame.PatternTree.GetItemText(G2frame.PatternId)
     336        histList = GetHistsLikeSelected(G2frame)
     337        if not histList:
     338            G2frame.ErrorDialog('No match','No histograms match '+hst,G2frame.dataFrame)
     339            return
     340        copyList = []
     341        dlg = G2gd.G2MultiChoiceDialog(
     342            G2frame.dataFrame,
     343            'Copy peak list from\n'+str(hst[5:])+' to...',
     344            'Copy peaks', histList)
     345        try:
     346            if dlg.ShowModal() == wx.ID_OK:
     347                for i in dlg.GetSelections():
     348                    copyList.append(histList[i])
     349        finally:
     350            dlg.Destroy()
     351        for item in copyList:
     352            Id = G2gd.GetPatternTreeItemId(G2frame,G2frame.root,item)
     353            G2frame.PatternTree.SetItemPyData(
     354                G2gd.GetPatternTreeItemId(G2frame,Id,'Peak List'),copy.copy(data))
    333355   
    334356    def OnUnDo(event):
     
    368390    def OnOneCycle(event):
    369391        OnPeakFit('LSQ',oneCycle=True)
     392       
     393    def OnSeqPeakFit(event):
     394        hst = G2frame.PatternTree.GetItemText(G2frame.PatternId)
     395        histList = GetHistsLikeSelected(G2frame)
     396        if not histList:
     397            G2frame.ErrorDialog('No match','No histograms match '+hst,G2frame.dataFrame)
     398            return
     399        sel = []
     400        dlg = G2gd.G2MultiChoiceDialog(G2frame.dataFrame, 'Sequential peak fits',
     401             'Select dataset to include',histList)
     402        dlg.SetSelections(sel)
     403        names = []
     404        if dlg.ShowModal() == wx.ID_OK:
     405            for sel in dlg.GetSelections():
     406                names.append(histList[sel])
     407        dlg.Destroy()
     408        SeqResult = {'histNames':names}
     409        dlg.Destroy()
     410        dlg = wx.ProgressDialog('Sequential peak fit','Data set name = '+names[0],len(names),
     411            style = wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE|wx.PD_REMAINING_TIME|wx.PD_CAN_ABORT)
     412        controls = {'deriv type':'analytic','min dM/M':0.0001,}
     413        print 'Peak Fitting with '+controls['deriv type']+' derivatives:'
     414        oneCycle = False
     415        FitPgm = 'LSQ'
     416        try:
     417            for i,name in enumerate(names):
     418                print ' Sequential fit for ',name
     419                GoOn = dlg.Update(i,newmsg='Data set name = '+name)[0]
     420                if not GoOn:
     421                    break
     422                PatternId =  G2gd.GetPatternTreeItemId(G2frame,G2frame.root,name)
     423                peaks = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Peak List'))
     424                background = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Background'))
     425                limits = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Limits'))[1]
     426                inst,inst2 = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Instrument Parameters'))
     427                data = G2frame.PatternTree.GetItemPyData(PatternId)[1]
     428                wx.BeginBusyCursor()
     429                dlg2 = wx.ProgressDialog('Residual','Peak fit Rwp = ',101.0,
     430                    style = wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE|wx.PD_REMAINING_TIME|wx.PD_CAN_ABORT)
     431                screenSize = wx.ClientDisplayRect()
     432                Size = dlg.GetSize()
     433                dlg2.SetPosition(wx.Point(screenSize[2]-Size[0]-305,screenSize[1]+5))
     434                try:
     435                    peaks['sigDict'],result,sig,Rvals,varyList,parmDict = G2pwd.DoPeakFit(FitPgm,peaks['peaks'],
     436                        background,limits,inst,inst2,data,oneCycle,controls,dlg2)
     437                finally:
     438                    dlg2.Destroy()   
     439                G2frame.PatternTree.SetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Peak List'),peaks)
     440                SeqResult[name] = {'variables':result[0],'varyList':varyList,'sig':sig,'Rvals':Rvals,
     441                    'covMatrix':np.eye(len(result[0])),'title':name,'parmDict':parmDict}
     442            else:
     443                dlg.Destroy()
     444                print ' ***** Sequential peak fit successful *****'
     445        finally:
     446            wx.EndBusyCursor()   
     447        Id =  G2gd.GetPatternTreeItemId(G2frame,G2frame.root,'Sequential results')
     448        if Id:
     449            G2frame.PatternTree.SetItemPyData(Id,SeqResult)
     450        else:
     451            Id = G2frame.PatternTree.AppendItem(parent=G2frame.root,text='Sequential results')
     452            G2frame.PatternTree.SetItemPyData(Id,SeqResult)
     453        G2frame.PatternTree.SelectItem(Id)
    370454       
    371455    def OnClearPeaks(event):
     
    402486        dlg.SetPosition(wx.Point(screenSize[2]-Size[0]-305,screenSize[1]+5))
    403487        try:
    404             peaks['sigDict'] = G2pwd.DoPeakFit(FitPgm,peaks['peaks'],background,limits,inst,inst2,data,oneCycle,controls,dlg)
     488            peaks['sigDict'] = G2pwd.DoPeakFit(FitPgm,peaks['peaks'],background,limits,inst,inst2,data,oneCycle,controls,dlg)[0]
    405489        finally:
    406490            wx.EndBusyCursor()   
     
    502586    Status.SetStatusText('Global refine: select refine column & press Y or N')
    503587    G2frame.Bind(wx.EVT_MENU, OnAutoSearch, id=G2gd.wxID_AUTOSEARCH)
     588    G2frame.Bind(wx.EVT_MENU, OnCopyPeaks, id=G2gd.wxID_PEAKSCOPY)
    504589    G2frame.Bind(wx.EVT_MENU, OnUnDo, id=G2gd.wxID_UNDO)
    505590    G2frame.Bind(wx.EVT_MENU, OnLSQPeakFit, id=G2gd.wxID_LSQPEAKFIT)
    506591    G2frame.Bind(wx.EVT_MENU, OnOneCycle, id=G2gd.wxID_LSQONECYCLE)
     592    G2frame.Bind(wx.EVT_MENU, OnSeqPeakFit, id=G2gd.wxID_SEQPEAKFIT)
    507593    G2frame.Bind(wx.EVT_MENU, OnClearPeaks, id=G2gd.wxID_CLEARPEAKS)
    508594    G2frame.Bind(wx.EVT_MENU, OnResetSigGam, id=G2gd.wxID_RESETSIGGAM)
    509595    if data['peaks']:
    510596        G2frame.dataFrame.AutoSearch.Enable(False)
     597        G2frame.dataFrame.PeakCopy.Enable(True)
    511598        G2frame.dataFrame.PeakFit.Enable(True)
    512599        G2frame.dataFrame.PFOneCycle.Enable(True)
     600        G2frame.dataFrame.SeqPeakFit.Enable(True)
    513601    else:
    514602        G2frame.dataFrame.PeakFit.Enable(False)
     603        G2frame.dataFrame.PeakCopy.Enable(False)
    515604        G2frame.dataFrame.PFOneCycle.Enable(False)
    516605        G2frame.dataFrame.AutoSearch.Enable(True)
     606        G2frame.dataFrame.SeqPeakFit.Enable(False)
    517607    G2frame.PickTable = []
    518608    rowLabels = []
Note: See TracChangeset for help on using the changeset viewer.