Changeset 2681


Ignore:
Timestamp:
Jan 31, 2017 3:38:48 PM (5 years ago)
Author:
vondreele
Message:

fix missing 'Oblique' problem in G2imgGUI
fix inner 2-theta limit issue in OnTransferAngles?
PDF Peaks can now clear all peaks
PDF peak picking now gives pos,mag & sig=0.085 as default
calculated PDF peak fit curve now plotted on G(R) from PDF Peaks
fitting of PDF peaks implemented - works fine; needs text output

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIgrid.py

    r2675 r2681  
    149149] = [wx.NewId() for item in range(5)]
    150150
    151 [ wxID_PDFCOPYCONTROLS, wxID_PDFSAVECONTROLS, wxID_PDFLOADCONTROLS, wxID_PDFCOMPUTE, wxID_PDFCOMPUTEALL,
    152     wxID_PDFADDELEMENT, wxID_PDFDELELEMENT, wxID_PDFPKSFIT,wxID_PDFPKSFITALL,wxID_PDFCOPYPEAKS,
    153 ] = [wx.NewId() for item in range(10)]
     151[ wxID_PDFCOPYCONTROLS, wxID_PDFSAVECONTROLS, wxID_PDFLOADCONTROLS, wxID_PDFCOMPUTE,
     152    wxID_PDFCOMPUTEALL, wxID_PDFADDELEMENT, wxID_PDFDELELEMENT, wxID_PDFPKSFIT,
     153    wxID_PDFPKSFITALL,wxID_PDFCOPYPEAKS,wxID_CLEARPDFPEAKS,
     154] = [wx.NewId() for item in range(11)]
    154155
    155156[ wxID_MCRON,wxID_MCRLIST,wxID_MCRSAVE,wxID_MCRPLAY,
     
    21952196        self.PDFPksEdit.Append(help='Copy PDF peaks', id=wxID_PDFCOPYPEAKS, kind=wx.ITEM_NORMAL,
    21962197            text='Copy peaks')
    2197        
     2198        self.PDFPksEdit.Append(help='Clear PDF peaks', id=wxID_CLEARPDFPEAKS, kind=wx.ITEM_NORMAL,
     2199            text='Clear peaks')       
    21982200        self.PostfillDataMenu()
    21992201
  • trunk/GSASIIimgGUI.py

    r2677 r2681  
    307307        Source = G2frame.PatternTree.GetItemText(G2frame.Image)
    308308        # Assemble a list of item labels
    309         keyList = ['type','wavelength','calibrant','distance','center',
     309        keyList = ['type','wavelength','calibrant','distance','center','Oblique',
    310310                    'tilt','rotation','azmthOff','fullIntegrate','LRazimuth',
    311311                    'IOtth','outChannels','outAzimuths','invert_x','invert_y','DetDepth',
     
    358358    def WriteControls(filename,data):
    359359        File = open(filename,'w')
    360         keys = ['type','wavelength','calibrant','distance','center',
     360        keys = ['type','wavelength','calibrant','distance','center','Oblique',
    361361            'tilt','rotation','azmthOff','fullIntegrate','LRazimuth',
    362362            'IOtth','outChannels','outAzimuths','invert_x','invert_y','DetDepth',
     
    417417           
    418418    def OnLoadControls(event):
    419         cntlList = ['wavelength','distance','tilt','invert_x','invert_y','type',
     419        cntlList = ['wavelength','distance','tilt','invert_x','invert_y','type','Oblique',
    420420            'fullIntegrate','outChannels','outAzimuths','LRazimuth','IOtth','azmthOff','DetDepth',
    421421            'calibskip','pixLimit','cutoff','calibdmin','Flat Bkg','varyList',
     
    497497                    data = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Id,'Image Controls'))
    498498                    dist1 = data['distance']
    499                     data['IOtth'] = [xferAng(ttmin0,dist0,dist1),xferAng(ttmax0,dist0,dist1)]
     499                    if ttmin0 < 1.0:
     500                        data['IOtth'] = [ttmin0,xferAng(ttmax0,dist0,dist1)]
     501                    else:
     502                        data['IOtth'] = [xferAng(ttmin0,dist0,dist1),xferAng(ttmax0,dist0,dist1)]
    500503                    if extraopts["value_1"]:
    501504                        ang1 = xferAng(2.0*asind(wave0/(2.*dsp0)),dist0,dist1)
     
    20992102
    21002103###########################################################################
    2101 # Autointegration follows
     2104# Autointegration
     2105###########################################################################
    21022106def ReadMask(filename):
    21032107    'Read a mask (.immask) file'
     
    23382342            Should be called only when table is defined and active.
    23392343            '''
     2344            event.Skip()
    23402345            try:
    23412346                dlg = IntegParmTable(self.G2frame,self.ImgTblParms,self.IMfileList)
  • trunk/GSASIIplot.py

    r2672 r2681  
    24942494            if mouse.button == 1:
    24952495                El = data['ElList'].keys()[0]
    2496                 Peaks['Peaks'].append([xy[0],(xy[1]-Peaks['Background'][1][1]*xy[0])/.798,.5,'',El,El,0.])
     2496                Peaks['Peaks'].append([xy[0],(xy[1]-Peaks['Background'][1][1]*xy[0])/4.7,.085,'',El,El,0.])
    24972497                Peaks['Peaks'] = G2mth.sortArray(Peaks['Peaks'],0,reverse=False)
    24982498                PlotISFG(G2frame,data,peaks=Peaks,newPlot=False)
     
    26932693            Y = XYlist[0].T[1]
    26942694            Plot.plot(X,Y,color='b',picker=3)
     2695            if 'calc' in Peaks and len(Peaks['calc']):
     2696                XC,YC= Peaks['calc']
     2697                Plot.plot(XC,YC,color='g')
    26952698            G2frame.Lines.append(Plot.axvline(peaks['Limits'][0],color='g',dashes=(5,5),picker=2.))
    26962699            G2frame.Lines.append(Plot.axvline(peaks['Limits'][1],color='r',dashes=(5,5),picker=2.))
  • trunk/GSASIIpwd.py

    r2660 r2681  
    1818import os
    1919import subprocess as subp
     20import copy
    2021
    2122import numpy as np
     
    286287    '''
    287288    auxPlot = []
    288     import copy
    289289    import scipy.fftpack as ft
    290290    Ibeg = np.searchsorted(xydata['Sample'][1][0],limits[0])
     
    373373        xydata['GofR'][1][1] = np.where(xydata['GofR'][1][0]<0.5,0.,xydata['GofR'][1][1])
    374374    return auxPlot
     375   
     376def PDFPeakFit(peaks,data):
     377    rs2pi = 1./np.sqrt(2*np.pi)
     378   
     379    def MakeParms(peaks):
     380        varyList = []
     381        parmDict = {'slope':peaks['Background'][1][1]}
     382        if peaks['Background'][2]:
     383            varyList.append('slope')
     384        for i,peak in enumerate(peaks['Peaks']):
     385            parmDict[str(i)+':pos'] = peak[0]
     386            parmDict[str(i)+':mag'] = peak[1]
     387            parmDict[str(i)+':sig'] = peak[2]
     388            if 'P' in peak[3]:
     389                varyList.append(str(i)+':pos')
     390            if 'M' in peak[3]:
     391                varyList.append(str(i)+':mag')
     392            if 'S' in peak[3]:
     393                varyList.append(str(i)+':sig')
     394        return parmDict,varyList
     395       
     396    def SetParms(peaks,parmDict,varyList):
     397        if 'slope' in varyList:
     398            peaks['Background'][1][1] = parmDict['slope']
     399        for i,peak in enumerate(peaks['Peaks']):
     400            if str(i)+':pos' in varyList:
     401                peak[0] = parmDict[str(i)+':pos']
     402            if str(i)+':mag' in varyList:
     403                peak[1] = parmDict[str(i)+':mag']
     404            if str(i)+':sig' in varyList:
     405                peak[2] = parmDict[str(i)+':sig']
     406       
     407   
     408    def CalcPDFpeaks(parmdict,Xdata):
     409        Z = parmDict['slope']*Xdata
     410        ipeak = 0
     411        while True:
     412            try:
     413                pos = parmdict[str(ipeak)+':pos']
     414                mag = parmdict[str(ipeak)+':mag']
     415                wid = parmdict[str(ipeak)+':sig']
     416                wid2 = 2.*wid**2
     417                Z += mag*rs2pi*np.exp(-(Xdata-pos)**2/wid2)/wid
     418                ipeak += 1
     419            except KeyError:        #no more peaks to process
     420                return Z
     421               
     422    def errPDFProfile(values,xdata,ydata,parmdict,varylist):       
     423        parmdict.update(zip(varylist,values))
     424        M = CalcPDFpeaks(parmdict,xdata)-ydata
     425        return M
     426                               
     427           
     428    print 'Do PDF peak fitting'
     429    newpeaks = copy.copy(peaks)
     430    iBeg = np.searchsorted(data[1][0],newpeaks['Limits'][0])
     431    iFin = np.searchsorted(data[1][0],newpeaks['Limits'][1])
     432    X = data[1][0][iBeg:iFin]
     433    Y = data[1][1][iBeg:iFin]
     434    parmDict,varyList = MakeParms(peaks)
     435    if not len(varyList):
     436        print ' Nothing varied'
     437        return newpeaks
     438   
     439    begin = time.time()
     440    values =  np.array(Dict2Values(parmDict, varyList))
     441    result = so.leastsq(errPDFProfile,values,full_output=True,ftol=0.0001,
     442           args=(X,Y,parmDict,varyList))
     443    ncyc = int(result[2]['nfev']/2)
     444    runtime = time.time()-begin   
     445    print 'PDF fitpeak time = %8.3fs, %8.3fs/cycle'%(runtime,runtime/ncyc)
     446#    chisq = np.sum(result[2]['fvec']**2)
     447    Values2Dict(parmDict, varyList, result[0])
     448    SetParms(peaks,parmDict,varyList)
     449   
     450    Z = CalcPDFpeaks(parmDict,X)
     451    newpeaks['calc'] = [X,Z]
     452    return newpeaks   
    375453   
    376454def MakeRDF(RDFcontrols,background,inst,pwddata):
  • trunk/GSASIIpwdGUI.py

    r2676 r2681  
    657657        G2plt.PlotPatterns(G2frame,plotType='PWDR')
    658658        wx.CallAfter(UpdatePeakGrid,G2frame,newpeaks)
    659         return
    660659       
    661660    def OnResetSigGam(event):
     
    53235322       
    53245323        atms = ','.join(data['ElList'].keys())
    5325         colLabels = ['position','magnitude','width','refine','Atom A','Atom B','Cooord. No.']
    5326         Types = 3*[wg.GRID_VALUE_FLOAT+':10,3',]+[wg.GRID_VALUE_CHOICE+': ,P,M,W,PM,PW,MW,PMW',]+     \
     5324        colLabels = ['position','magnitude','sig','refine','Atom A','Atom B','Cooord. No.']
     5325        Types = 3*[wg.GRID_VALUE_FLOAT+':10,3',]+[wg.GRID_VALUE_CHOICE+': ,P,M,S,PM,PS,MS,PMS',]+     \
    53275326            2*[wg.GRID_VALUE_CHOICE+':'+atms,]+[wg.GRID_VALUE_FLOAT+':10,3',]
    53285327        rowLabels = range(len(peaks['Peaks']))
     
    53625361    def OnFitPDFpeaks(event):
    53635362        PatternId = G2frame.PatternId
    5364         data = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'PDF Controls'))['G(R)']
     5363        data = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'PDF Controls'))
    53655364        peaks = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'PDF Peaks'))
    53665365        if not peaks:
    53675366            G2frame.ErrorDialog('No peaks!','Nothing to fit!')
    53685367            return
    5369        
    5370         print 'fit peaks'
     5368        newpeaks = G2pwd.PDFPeakFit(peaks,data['G(R)'])
     5369        print 'PDF peak fit finished'
     5370        G2frame.PatternTree.SetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'PDF Peaks'),newpeaks)
     5371        G2plt.PlotISFG(G2frame,data,peaks=newpeaks,newPlot=False)
     5372        wx.CallAfter(UpdatePDFPeaks,G2frame,newpeaks,data)
    53715373       
    53725374    def OnFitAllPDFpeaks(event):
    53735375        print 'fit all pdf peaks'
     5376       
     5377    def OnClearPDFpeaks(event):
     5378        peaks['Peaks'] = []
     5379        G2plt.PlotISFG(G2frame,data,peaks=peaks,newPlot=False)
     5380        wx.CallAfter(UpdatePDFPeaks,G2frame,peaks,data)
     5381       
    53745382       
    53755383
     
    53835391    G2frame.dataFrame.Bind(wx.EVT_MENU, OnFitPDFpeaks, id=G2gd.wxID_PDFPKSFIT)
    53845392    G2frame.dataFrame.Bind(wx.EVT_MENU, OnFitAllPDFpeaks, id=G2gd.wxID_PDFPKSFITALL)
     5393    G2frame.dataFrame.Bind(wx.EVT_MENU, OnClearPDFpeaks, id=G2gd.wxID_CLEARPDFPEAKS)
    53855394    mainSizer = wx.BoxSizer(wx.VERTICAL)
    53865395    mainSizer.Add((5,5),0)
Note: See TracChangeset for help on using the changeset viewer.