Changeset 1582 for trunk/GSASIIindex.py


Ignore:
Timestamp:
Nov 24, 2014 3:36:56 PM (8 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

File:
1 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]
Note: See TracChangeset for help on using the changeset viewer.