Changeset 429


Ignore:
Timestamp:
Nov 28, 2011 10:32:08 AM (10 years ago)
Author:
vondreele
Message:

set 'browser' as default help display
fix zero & zero offset to be consistent in peak fitting/indexing/cell refinement

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIgrid.py

    r427 r429  
    3030htmlFrame = None
    3131helpMode = 'internal'    # need a global control to set this
    32 #helpMode = 'browser'    # need a global control to set this
     32helpMode = 'browser'    # need a global control to set this
    3333htmlFirstUse = True
    3434
  • trunk/GSASIIindex.py

    r428 r429  
    289289    return True,np.sum(errFit(result[0],ibrav,Peaks[7],Peaks[4:7],Pwr)**2),A,result
    290290           
    291 def FitHKLZ(wave,ibrav,peaks,A,Z,Pwr):
    292    
    293     def errFit(values,ibrav,d,H,tth,wave,Pwr):
    294         A = Values2A(ibrav,values[:-1])
    295         Z = values[-1]
     291def FitHKLZ(wave,ibrav,peaks,A,Z,Zref,Pwr):
     292   
     293    def errFit(values,ibrav,d,H,tth,wave,Zref,Pwr):
     294        Zero = Z
     295        if Zref:   
     296            Zero = values[-1]
     297        A = Values2A(ibrav,values[:6])
    296298        Qo = 1./d**2
    297         Qc = G2lat.calc_rDsqZ(H,A,Z,tth,wave)
     299        Qc = G2lat.calc_rDsqZ(H,A,Zero,tth,wave)
    298300        return (Qo-Qc)*d**Pwr
    299301   
     
    301303   
    302304    values = A2values(ibrav,A)
    303     values.append(Z)
    304     result = so.leastsq(errFit,values,full_output=True,ftol=0.001,
    305         args=(ibrav,Peaks[7],Peaks[4:7],Peaks[0],wave,Pwr))
    306     A = Values2A(ibrav,result[0][:-1])
    307     Z = result[0][-1]
    308    
    309     return True,np.sum(errFit(result[0],ibrav,Peaks[7],Peaks[4:7],Peaks[0],wave,Pwr)**2),A,Z,result
     305    if Zref:
     306        values.append(Z)
     307    result = so.leastsq(errFit,values,full_output=True,ftol=0.0001,factor=0.001,
     308        args=(ibrav,Peaks[7],Peaks[4:7],Peaks[0],wave,Zref,Pwr))
     309    A = Values2A(ibrav,result[0][:6])
     310    if Zref:
     311        Z = result[0][-1]
     312   
     313    return True,np.sum(errFit(result[0],ibrav,Peaks[7],Peaks[4:7],Peaks[0],wave,Zref,Pwr)**2),A,Z,result
    310314               
    311315def rotOrthoA(A):
     
    349353    return peaks[0][7]
    350354   
    351 def refinePeaksZ(peaks,wave,ibrav,A,Zero):
     355def refinePeaksZ(peaks,wave,ibrav,A,Zero,ZeroRef):
    352356    dmin = getDmin(peaks)
    353     OK,smin,Aref,Z,result = FitHKLZ(wave,ibrav,peaks,A,Zero,2)
     357    OK,smin,Aref,Z,result = FitHKLZ(wave,ibrav,peaks,A,Zero,ZeroRef,0)
    354358    Peaks = np.array(peaks).T
    355359    H = Peaks[4:7]
    356360    Peaks[8] = 1./np.sqrt(G2lat.calc_rDsqZ(H,Aref,Z,Peaks[0],wave))
    357     peaks = Peaks.T
    358    
     361    peaks = Peaks.T   
    359362    HKL = G2lat.GenHBravais(dmin,ibrav,Aref)
    360363    M20,X20 = calc_M20(peaks,HKL)
     
    501504    Nobs = len(peaks)
    502505    wave = inst[1]
    503     if len(inst) > 10:
    504         zero = inst[3]
    505     else:
    506         zero = inst[2]
    507     print "%s %8.5f %6.3f" % ('wavelength, zero =',wave,zero)
     506    zero,ncno = controls[1:3]
     507    ncMax = Nobs*ncno
    508508    print "%s %8.3f %8.3f" % ('lattice parameter range = ',amin,amax)
    509     ifzero,maxzero,ncno = controls[:3]
    510     ncMax = Nobs*ncno
    511     print "%s %d %s %d %s %d" % ('change zero =',ifzero,'Nc/No max =',ncno,' Max Nc =',ncno*Nobs)
     509    print "%s %8.5f %s %.4f %s %d %s %d" % ('Wavelength =',wave,'Zero =',zero,'Nc/No max =',ncno,' Max Nc =',ncno*Nobs)
    512510    cells = []
    513511    for ibrav in range(14):
  • trunk/GSASIIpwd.py

    r411 r429  
    730730        try:
    731731            pos = parmDict['pos'+str(iPeak)]
     732            theta = (pos-parmDict['Zero'])/2.0
    732733            intens = parmDict['int'+str(iPeak)]
    733734            sigName = 'sig'+str(iPeak)
     
    735736                sig = parmDict[sigName]
    736737            else:
    737                 sig = U*tand(pos/2.0)**2+V*tand(pos/2.0)+W
     738                sig = U*tand(theta)**2+V*tand(theta)+W
    738739            sig = max(sig,0.001)          #avoid neg sigma
    739740            gamName = 'gam'+str(iPeak)
     
    741742                gam = parmDict[gamName]
    742743            else:
    743                 gam = X/cosd(pos/2.0)+Y*tand(pos/2.0)
     744                gam = X/cosd(theta)+Y*tand(theta)
    744745            gam = max(gam,0.001)             #avoid neg gamma
    745746            Wd,fmin,fmax = getWidths(pos,sig,gam,shl)
     
    792793        try:
    793794            pos = parmDict['pos'+str(iPeak)]
     795            theta = (pos-parmDict['Zero'])/2.0
    794796            intens = parmDict['int'+str(iPeak)]
    795797            sigName = 'sig'+str(iPeak)
    796             tanth = tand(pos/2.0)
    797             costh = cosd(pos/2.0)
     798            tanth = tand(theta)
     799            costh = cosd(theta)
    798800            if sigName in varyList:
    799801                sig = parmDict[sigName]
  • trunk/GSASIIpwdGUI.py

    r428 r429  
    619619                    instSizer.Add((5,5),0)
    620620            for item in ['Zero','Polariz.']:
    621                 fmt = '%10.3f'
     621                fmt = '%10.4f'
    622622                Fmt = ' %s: ('+fmt+')'
    623623                if item in insDef:
     
    850850def UpdateIndexPeaksGrid(self, data):
    851851    IndexId = G2gd.GetPatternTreeItemId(self,self.PatternId, 'Index Peak List')
     852    inst = self.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(self,self.PatternId, 'Instrument Parameters'))
     853    Inst = dict(zip(inst[3],inst[1]))
     854    try:
     855        wave = Inst['Lam']
     856    except KeyError:
     857        wave = Inst['Lam1']
    852858   
    853859    def RefreshIndexPeaksGrid(event):
     
    867873        peaks = self.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(self,self.PatternId, 'Peak List'))
    868874        for peak in peaks:
    869             dsp = inst[1]/(2.0*sind(peak[0]/2.0))
     875            dsp = wave/(2.0*sind((peak[0]-Inst['Zero'])/2.0))
    870876            data.append([peak[0],peak[2],True,False,0,0,0,dsp,0.0])
    871877        self.PatternTree.SetItemPyData(IndexId,data)
     
    899905        self.dataFrame.SetMenuBar(self.dataFrame.IndPeaksMenu)
    900906        self.Bind(wx.EVT_MENU, OnReload, id=G2gd.wxID_INDXRELOAD)
    901     inst = self.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(self,self.PatternId, 'Instrument Parameters'))[1]
    902907    self.dataFrame.IndexPeaks.Enable(False)
    903908    self.IndexPeaksTable = []
     
    916921                    G2indx.IndexPeaks(data,self.HKL)
    917922                    for hkl in self.HKL:
    918                         hkl.append(2.0*asind(inst[1]/(2.*hkl[3])))             
     923                        hkl.append(2.0*asind(wave/(2.*hkl[3]))+Inst['Zero'])             
    919924    rowLabels = []
    920925    for i in range(len(data)): rowLabels.append(str(i+1))
     
    946951    spaceGroups = ['F m 3 m','I m 3 m','P m 3 m','R -3 H','P 6/m m m','I 4/m m m',
    947952        'P 4/m m m','F m m m','I m m m','C m m m','P m m m','C 2/m','P 2/m','P -1']
     953    inst = self.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(self,self.PatternId, 'Instrument Parameters'))
     954    Inst = dict(zip(inst[3],inst[1]))
     955    if 'Lam' in Inst:
     956        wave = Inst['Lam']
     957    else:
     958        wave = Inst['Lam1']
    948959       
    949960    def SetLattice(controls):
     
    984995    def OnZero(event):
    985996        try:
    986             Zero = min(0.1,max(-0.1,float(zero.GetValue())))
     997            Zero = min(5.0,max(-5.0,float(zero.GetValue())))
    987998        except ValueError:
    988999            Zero = 0.0
     
    10511062        A = G2lat.cell2A(cell)
    10521063        ibrav = bravaisSymb.index(controls[5])
    1053         inst = self.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(self,PatternId, 'Instrument Parameters'))
    1054         inst = dict(zip(inst[3],inst[1]))
    1055         if 'Lam' in inst:
    1056             wave = inst['Lam']
    1057         else:
    1058             wave = inst['Lam1']
    10591064        dmin = wave/(2.0*sind(limits[1]/2.0))
    10601065        self.HKL = G2lat.GenHBravais(dmin,ibrav,A)
    10611066        for hkl in self.HKL:
    1062             hkl.append(2.0*asind(wave/(2.*hkl[3]))+controls[1])             
     1067            hkl.append(2.0*asind(wave/(2.*hkl[3]))+controls[1]+Inst['Zero'])             
    10631068        if 'PKS' in self.PatternTree.GetItemText(self.PatternId):
    10641069            G2plt.PlotPowderLines(self)
     
    11181123            return       
    11191124        print 'Refine cell'
    1120         inst = self.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(self,PatternId, 'Instrument Parameters'))[1]
    11211125        controls,bravais,cells,dmin = self.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(self,PatternId, 'Unit Cells List'))
    11221126        cell = controls[6:12]
     
    11261130        self.HKL = G2lat.GenHBravais(dmin,ibrav,A)
    11271131        G2indx.IndexPeaks(peaks,self.HKL)
    1128         if controls[0]:
    1129             Lhkl,M20,X20,Aref,Zero = G2indx.refinePeaksZ(peaks,inst[1],ibrav,A,controls[1])           
    1130             controls[1] = Zero
    1131         else:
    1132             Lhkl,M20,X20,Aref = G2indx.refinePeaks(peaks,ibrav,A)
     1132        Lhkl,M20,X20,Aref,Zero = G2indx.refinePeaksZ(peaks,wave,ibrav,A,controls[1],controls[0])           
     1133        controls[1] = Zero
    11331134        controls[6:12] = G2lat.A2cell(Aref)
    11341135        controls[12] = G2lat.calc_V(Aref)
     
    11451146        cellPrint(ibrav,Aref)
    11461147        for hkl in self.HKL:
    1147             hkl.append(2.0*asind(inst[1]/(2.*hkl[3]))+controls[1])             
     1148            hkl.append(2.0*asind(wave/(2.*hkl[3]))+controls[1]+Inst['Zero'])             
    11481149        if 'PKS' in self.PatternTree.GetItemText(self.PatternId):
    11491150            G2plt.PlotPowderLines(self)
     
    11531154    def IndexPeaks(event):
    11541155        PatternId = self.PatternId   
    1155 #        peaks = self.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(self,PatternId, 'Index Peak List'))
    1156 #        if not peaks:
    1157 #            self.ErrorDialog('No peaks!', 'Nothing to index!')
    1158 #            return
    1159         inst = self.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(self,PatternId, 'Instrument Parameters'))[1]
    11601156        print 'Peak Indexing'
    11611157        try:
     
    11701166        self.dataFrame.CopyCell.Enable(False)
    11711167        self.dataFrame.RefineCell.Enable(False)
    1172         OK,dmin,cells = G2indx.DoIndexPeaks(peaks,inst,controls,bravais)
     1168        OK,dmin,cells = G2indx.DoIndexPeaks(peaks,inst[1],controls,bravais)
    11731169        if OK:
    11741170            data = [controls,bravais,cells,dmin]
     
    11791175                self.HKL = G2lat.GenHBravais(dmin,bestCell[2],G2lat.cell2A(bestCell[3:9]))
    11801176                for hkl in self.HKL:
    1181                     hkl.append(2.0*asind(inst[1]/(2.*hkl[3])))             
     1177                    hkl.append(2.0*asind(wave/(2.*hkl[3]))+controls[1]+Inst['Zero'])             
    11821178                if 'PKS' in self.PatternTree.GetItemText(self.PatternId):
    11831179                    G2plt.PlotPowderLines(self)
     
    12041200                self.HKL = G2lat.GenHBravais(dmin,ibrav,A)
    12051201                for hkl in self.HKL:
    1206                     hkl.append(2.0*asind(inst[1]/(2.*hkl[3])))
     1202                    hkl.append(2.0*asind(wave/(2.*hkl[3]))+controls[1]+Inst['Zero'])             
    12071203                if 'PKS' in self.PatternTree.GetItemText(self.PatternId):
    12081204                    G2plt.PlotPowderLines(self)
     
    12501246        controls.append(G2lat.calc_V(G2lat.cell2A(controls[6:12])))
    12511247    self.PatternTree.SetItemPyData(UnitCellsId,data)            #update with volume
    1252     inst = self.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(self,self.PatternId, 'Instrument Parameters'))[1]
    12531248    bravaisNames = ['Cubic-F','Cubic-I','Cubic-P','Trigonal-R','Trigonal/Hexagonal-P',
    12541249        'Tetragonal-I','Tetragonal-P','Orthorhombic-F','Orthorhombic-I','Orthorhombic-C',
     
    13301325    zeroVar.Bind(wx.EVT_CHECKBOX,OnZeroVar)
    13311326    littleSizer.Add(zeroVar,0,wx.ALIGN_CENTER_VERTICAL)
    1332     hklShow = wx.Button(self.dataDisplay,label="  Show hkl positions")
     1327    hklShow = wx.Button(self.dataDisplay,label="Show refined hkl positions + Zero offset")
    13331328    hklShow.Bind(wx.EVT_BUTTON,OnHklShow)
    13341329    littleSizer.Add(hklShow,0,wx.ALIGN_CENTER_VERTICAL)
     
    13651360        else:
    13661361            topSize[1] += 200
    1367     self.dataFrame.setSizePosLeft(topSize)
    1368    
     1362    self.dataFrame.setSizePosLeft(topSize)   
    13691363   
    13701364    if cells:
     
    13891383                self.HKL = G2lat.GenHBravais(dmin,cell[2],A)
    13901384                for hkl in self.HKL:
    1391                     hkl.append(2.0*asind(inst[1]/(2.*hkl[3])))
     1385                    hkl.append(2.0*asind(wave/(2.*hkl[3]))+controls[1]+Inst['Zero'])             
    13921386            table.append(row)
    13931387        UnitCellsTable = G2gd.Table(table,rowLabels=rowLabels,colLabels=colLabels,types=Types)
  • trunk/GSASIIstruct.py

    r425 r429  
    11111111                    continue
    11121112                if 'C' in inst['Type']:
    1113                     pos = 2.0*asind(wave/(2.0*d))
     1113                    pos = 2.0*asind(wave/(2.0*d))+Zero
    11141114                    if limits[0] < pos < limits[1]:
    11151115                        refList.append([h,k,l,mul,d,pos,0.0,0.0,0.0,0.0,0.0,Uniq,phi,0.0])
     
    19731973    dsq = 1./G2lat.calc_rDsq2(np.array([h,k,l]),G)
    19741974    d = np.sqrt(dsq)
     1975
    19751976    refl[4] = d
    19761977    pos = 2.0*asind(wave/(2.0*d))+parmDict[hfx+'Zero']
Note: See TracChangeset for help on using the changeset viewer.