Changeset 1582


Ignore:
Timestamp:
Nov 24, 2014 3:36:56 PM (7 years ago)
Author:
vondreele
Message:

revamp cell refinement in Unit Celle List
fix peak indexing in plots & bug in sqrt plot
put in error trap if indexing is tried with no peaks

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIindex.py

    r1581 r1582  
    413413    return True,np.sum(errFit(result[0],ibrav,Peaks[7],Peaks[4:7],Pwr)**2),A,result
    414414           
     415def errFitZ(values,ibrav,d,H,tth,wave,Z,Zref,Pwr):
     416    Zero = Z
     417    if Zref:   
     418        Zero = values[-1]
     419    A = Values2A(ibrav,values[:6])
     420    Qo = 1./d**2
     421    Qc = G2lat.calc_rDsqZ(H,A,Zero,tth,wave)
     422    return (Qo-Qc)*d**Pwr
     423   
    415424def FitHKLZ(wave,ibrav,peaks,A,Z,Zref,Pwr):
    416425    'needs a doc string'
    417426   
    418     def errFit(values,ibrav,d,H,tth,wave,Zref,Pwr):
    419         Zero = Z
    420         if Zref:   
    421             Zero = values[-1]
    422         A = Values2A(ibrav,values[:6])
    423         Qo = 1./d**2
    424         Qc = G2lat.calc_rDsqZ(H,A,Zero,tth,wave)
    425         return (Qo-Qc)*d**Pwr
    426    
    427     Peaks = np.array(peaks).T
    428    
     427    Peaks = np.array(peaks).T   
    429428    values = A2values(ibrav,A)
    430429    if Zref:
    431430        values.append(Z)
    432     result = so.leastsq(errFit,values,full_output=True,ftol=0.0001,factor=0.001,
    433         args=(ibrav,Peaks[7],Peaks[4:7],Peaks[0],wave,Zref,Pwr))
     431    result = so.leastsq(errFitZ,values,full_output=True,ftol=0.0001,factor=10.,
     432        args=(ibrav,Peaks[7],Peaks[4:7],Peaks[0],wave,Z,Zref,Pwr))
    434433    A = Values2A(ibrav,result[0][:6])
    435434    if Zref:
    436435        Z = result[0][-1]
    437        
    438     return True,np.sum(errFit(result[0],ibrav,Peaks[7],Peaks[4:7],Peaks[0],wave,Zref,Pwr)**2),A,Z,result
     436    chisq = np.sum(errFitZ(result[0],ibrav,Peaks[7],Peaks[4:7],Peaks[0],wave,Z,Zref,Pwr)**2)
     437    return True,chisq,A,Z,result
     438   
     439def errFitZSS(values,ibrav,d,H,tth,wave,vec,Vref,Z,Zref,Pwr):
     440    Zero = Z
     441    if Zref:   
     442        Zero = values[-1]
     443    A = Values2A(ibrav,values[:6])
     444    vec = Values2Vec(ibrav,vec,Vref,values)
     445    Qo = 1./d**2
     446    Qc = G2lat.calc_rDsqZSS(H,A,vec,Zero,tth,wave)
     447    return (Qo-Qc)*d**Pwr
    439448   
    440449def FitHKLZSS(wave,ibrav,peaks,A,V,Vref,Z,Zref,Pwr):
    441450    'needs a doc string'
    442451   
    443     def errFit(values,ibrav,d,H,tth,wave,vec,Vref,Zref,Pwr):
    444         Zero = Z
    445         if Zref:   
    446             Zero = values[-1]
    447         A = Values2A(ibrav,values[:6])
    448         vec = Values2Vec(ibrav,vec,Vref,values)
    449         Qo = 1./d**2
    450         Qc = G2lat.calc_rDsqZSS(H,A,vec,Zero,tth,wave)
    451         return (Qo-Qc)*d**Pwr
    452    
    453     Peaks = np.array(peaks).T
    454    
     452    Peaks = np.array(peaks).T   
    455453    values = A2values(ibrav,A)
    456454    for v,r in zip(V,Vref):
     
    459457    if Zref:
    460458        values.append(Z)
    461     result = so.leastsq(errFit,values,full_output=True,ftol=1.e-6,factor=1.,
    462         args=(ibrav,Peaks[8],Peaks[4:8],Peaks[0],wave,V,Vref,Zref,Pwr))
     459    result = so.leastsq(errFitZSS,values,full_output=True,ftol=1.e-6,factor=10.,
     460        args=(ibrav,Peaks[8],Peaks[4:8],Peaks[0],wave,V,Vref,Z,Zref,Pwr))
    463461    A = Values2A(ibrav,result[0])
    464462    Vec = Values2Vec(ibrav,V,Vref,result[0])
    465463    if Zref:
    466464        Z = result[0][-1]
    467     chisq = np.sum(errFit(result[0],ibrav,Peaks[8],Peaks[4:8],Peaks[0],wave,Vec,Vref,Zref,Pwr)**2)
    468     return True,A,Vec,Z,chisq,result
     465    chisq = np.sum(errFitZSS(result[0],ibrav,Peaks[8],Peaks[4:8],Peaks[0],wave,Vec,Vref,Z,Zref,Pwr)**2)
     466    return True,chisq,A,Vec,Z,result
     467   
     468def errFitT(values,ibrav,d,H,tof,difC,Z,Zref,Pwr):
     469    Zero = Z
     470    if Zref:   
     471        Zero = values[-1]
     472    A = Values2A(ibrav,values[:6])
     473    Qo = 1./d**2
     474    Qc = G2lat.calc_rDsqT(H,A,Zero,tof,difC)
     475    return (Qo-Qc)*d**Pwr
    469476   
    470477def FitHKLT(difC,ibrav,peaks,A,Z,Zref,Pwr):
    471478    'needs a doc string'
    472479   
    473     def errFit(values,ibrav,d,H,tof,difC,Zref,Pwr):
    474         Zero = Z
    475         if Zref:   
    476             Zero = values[-1]
    477         A = Values2A(ibrav,values[:6])
    478         Qo = 1./d**2
    479         Qc = G2lat.calc_rDsqT(H,A,Zero,tof,difC)
    480         return (Qo-Qc)*d**Pwr
    481    
    482     Peaks = np.array(peaks).T
    483    
     480    Peaks = np.array(peaks).T   
    484481    values = A2values(ibrav,A)
    485482    if Zref:
    486483        values.append(Z)
    487     result = so.leastsq(errFit,values,full_output=True,ftol=0.0001,factor=0.001,
    488         args=(ibrav,Peaks[7],Peaks[4:7],Peaks[0],difC,Zref,Pwr))
     484    result = so.leastsq(errFitT,values,full_output=True,ftol=0.0001,factor=0.001,
     485        args=(ibrav,Peaks[7],Peaks[4:7],Peaks[0],difC,Z,Zref,Pwr))
    489486    A = Values2A(ibrav,result[0][:6])
    490487    if Zref:
    491488        Z = result[0][-1]
    492    
    493     return True,np.sum(errFit(result[0],ibrav,Peaks[7],Peaks[4:7],Peaks[0],difC,Zref,Pwr)**2),A,Z,result
     489    chisq = np.sum(errFitT(result[0],ibrav,Peaks[7],Peaks[4:7],Peaks[0],difC,Z,Zref,Pwr)**2)
     490    return True,chisq,A,Z,result
    494491               
    495492def rotOrthoA(A):
     
    554551    'needs a doc string'
    555552    dmin = getDmin(peaks)
    556     OK,Aref,Vref,Z,smin,result = FitHKLZSS(wave,ibrav,peaks,A,vec,vecRef,Zero,ZeroRef,0)
     553    print Zero
     554    OK,smin,Aref,Vref,Z,result = FitHKLZSS(wave,ibrav,peaks,A,vec,vecRef,Zero,ZeroRef,0)
     555    print Z
    557556    Peaks = np.array(peaks).T
    558557    H = Peaks[4:8]
  • trunk/GSASIIplot.py

    r1579 r1582  
    999999                if G2frame.PickId:
    10001000                    found = []
    1001                     if G2frame.PatternTree.GetItemText(G2frame.PickId) in ['Index Peak List','Unit Cells List','Reflection Lists'] or \
     1001                    pickIdText = G2frame.PatternTree.GetItemText(G2frame.PickId)
     1002                    if pickIdText in ['Index Peak List','Unit Cells List','Reflection Lists'] or \
    10021003                        'PWDR' in G2frame.PatternTree.GetItemText(PickId):
     1004                        indx = -1
     1005                        if pickIdText in ['Index Peak List','Unit Cells List',]:
     1006                            indx = -2
    10031007                        if len(HKL):
    10041008                            view = Page.toolbar._views.forward()[0][:2]
    10051009                            wid = view[1]-view[0]
    1006                             found = HKL[np.where(np.fabs(HKL.T[-2]-xpos) < 0.002*wid)]
     1010                            found = HKL[np.where(np.fabs(HKL.T[indx]-xpos) < 0.002*wid)]
    10071011                        if len(found):
    10081012                            if len(found[0]) > 6:   #SS reflections
     
    12771281            Phases = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId,'Reflection Lists'))
    12781282            HKL = []
    1279             if Phases:
     1283            if Phases:  #will be trouble for SS reflection lists - will need peak[:7]
    12801284                try:
    12811285                    for peak in Phases[G2frame.RefList]['RefList']:
    12821286                        HKL.append(peak[:6])
    1283                 except TypeError:
     1287                except TypeError:   #old style patch
    12841288                    for peak in Phases[G2frame.RefList]:
    12851289                        HKL.append(peak[:6])                   
     
    14101414            if ifpicked:
    14111415                if G2frame.SqrtPlot:
     1416                    olderr = np.seterr(invalid='ignore') #get around sqrt(-ve) error
    14121417                    Z = np.where(xye[3]>=0.,np.sqrt(xye[3]),-np.sqrt(-xye[3]))
     1418                    np.seterr(invalid=olderr['invalid'])
    14131419                else:
    14141420                    Z = xye[3]+offset*N
     
    15321538            peaks = np.array((G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Index Peak List'))))[0]
    15331539            for peak in peaks:
     1540#                print 'peak',peak
    15341541                if G2frame.qPlot:
    15351542                    Plot.axvline(2.*np.pi/G2lat.Pos2dsp(Parms,peak[0]),color='b')
  • trunk/GSASIIpwdGUI.py

    r1581 r1582  
    24992499            G2frame.ErrorDialog('Error','No Bravais lattices selected')
    25002500            return
     2501        if not peaks[0]:
     2502            G2frame.ErrorDialog('Error','Index Peak List is empty')
     2503            return
    25012504        G2frame.dataFrame.CopyCell.Enable(False)
    25022505        G2frame.dataFrame.RefineCell.Enable(False)
     
    25792582    if G2frame.dataDisplay:
    25802583        G2frame.dataFrame.DestroyChildren()
    2581 #    G2frame.dataDisplay = wx.Panel(G2frame.dataFrame)
    25822584    G2frame.dataDisplay = wxscroll.ScrolledPanel(G2frame.dataFrame)
    25832585    G2gd.SetDataMenuBar(G2frame,G2frame.dataFrame.IndexMenu)
Note: See TracChangeset for help on using the changeset viewer.