Changeset 1585


Ignore:
Timestamp:
Nov 25, 2014 2:42:11 PM (7 years ago)
Author:
vondreele
Message:

remove Pwr from FitPeaksZ, SSZ & T - wasn't used
put in derivatives for FitPeaksZ, etc. - works better
reorder arrows & make the expand/shrink symmetric about view point
remove zero & refine? from SS Unit Cells display - not refinable with modulation coeff.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIindex.py

    r1582 r1585  
    4747npatand = lambda x: 180.*np.arctan(x)/np.pi
    4848npatan2d = lambda y,x: 180.*np.arctan2(y,x)/np.pi
     49rpd = np.pi/180.
    4950   
    5051def scaleAbyV(A,V):
     
    362363        return [values[0],values[1],values[2],0,values[3],0]
    363364    else:
    364         return list(values)
     365        return list(values[:6])
    365366       
    366367def A2values(ibrav,A):
     
    413414    return True,np.sum(errFit(result[0],ibrav,Peaks[7],Peaks[4:7],Pwr)**2),A,result
    414415           
    415 def errFitZ(values,ibrav,d,H,tth,wave,Z,Zref,Pwr):
     416def errFitZ(values,ibrav,d,H,tth,wave,Z,Zref):
    416417    Zero = Z
    417418    if Zref:   
    418419        Zero = values[-1]
    419     A = Values2A(ibrav,values[:6])
     420    A = Values2A(ibrav,values)
    420421    Qo = 1./d**2
    421422    Qc = G2lat.calc_rDsqZ(H,A,Zero,tth,wave)
    422     return (Qo-Qc)*d**Pwr
    423    
    424 def FitHKLZ(wave,ibrav,peaks,A,Z,Zref,Pwr):
     423    return (Qo-Qc)
     424   
     425def dervFitZ(values,ibrav,d,H,tth,wave,Z,Zref):
     426    if ibrav in [0,1,2]:
     427        derv = [H[0]*H[0]+H[1]*H[1]+H[2]*H[2],]
     428    elif ibrav in [3,4,]:
     429        derv = [H[0]*H[0]+H[1]*H[1]+H[0]*H[1],H[2]*H[2]]
     430    elif ibrav in [5,6]:
     431        derv = [H[0]*H[0]+H[1]*H[1],H[2]*H[2]]
     432    elif ibrav in [7,8,9,10]:
     433        derv = [H[0]*H[0],H[1]*H[1],H[2]*H[2]]
     434    elif ibrav in [11,12]:
     435        derv = [H[0]*H[0],H[1]*H[1],H[2]*H[2],H[0]*H[2]]
     436    else:
     437        derv = [H[0]*H[0],H[1]*H[1],H[2]*H[2],H[0]*H[1],H[0]*H[2],H[1]*H[2]]
     438    if Zref:
     439        derv.append(npsind(tth)*2.0*rpd/wave**2)
     440    derv = -np.array(derv)
     441    return derv.T
     442   
     443def FitHKLZ(wave,ibrav,peaks,A,Z,Zref):
    425444    'needs a doc string'
    426445   
     
    429448    if Zref:
    430449        values.append(Z)
    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))
     450    result = so.leastsq(errFitZ,values,Dfun=dervFitZ,full_output=True,ftol=0.0001,
     451        args=(ibrav,Peaks[7],Peaks[4:7],Peaks[0],wave,Z,Zref))
    433452    A = Values2A(ibrav,result[0][:6])
    434453    if Zref:
    435454        Z = result[0][-1]
    436     chisq = np.sum(errFitZ(result[0],ibrav,Peaks[7],Peaks[4:7],Peaks[0],wave,Z,Zref,Pwr)**2)
     455    chisq = np.sum(errFitZ(result[0],ibrav,Peaks[7],Peaks[4:7],Peaks[0],wave,Z,Zref)**2)
    437456    return True,chisq,A,Z,result
    438457   
    439 def errFitZSS(values,ibrav,d,H,tth,wave,vec,Vref,Z,Zref,Pwr):
     458def errFitZSS(values,ibrav,d,H,tth,wave,vec,Vref,Z,Zref):
    440459    Zero = Z
    441460    if Zref:   
    442461        Zero = values[-1]
    443     A = Values2A(ibrav,values[:6])
    444     vec = Values2Vec(ibrav,vec,Vref,values)
     462    A = Values2A(ibrav,values)
     463    Vec = Values2Vec(ibrav,vec,Vref,values)
    445464    Qo = 1./d**2
    446     Qc = G2lat.calc_rDsqZSS(H,A,vec,Zero,tth,wave)
    447     return (Qo-Qc)*d**Pwr
    448    
    449 def FitHKLZSS(wave,ibrav,peaks,A,V,Vref,Z,Zref,Pwr):
     465    Qc = G2lat.calc_rDsqZSS(H,A,Vec,Zero,tth,wave)
     466    return (Qo-Qc)
     467   
     468def dervFitZSS(values,ibrav,d,H,tth,wave,vec,Vref,Z,Zref):
     469    A = Values2A(ibrav,values)
     470    Vec = Values2Vec(ibrav,vec,Vref,values)
     471    HM = H[:3]+(H[3][:,np.newaxis]*Vec).T
     472    if ibrav in [3,4,]:
     473        derv = [HM[0]*HM[0]+HM[1]*HM[1]+HM[0]*HM[1],HM[2]*HM[2]]
     474    elif ibrav in [5,6]:
     475        derv = [HM[0]*HM[0]+HM[1]*HM[1],HM[2]*HM[2]]
     476    elif ibrav in [7,8,9,10]:
     477        derv = [HM[0]*HM[0],HM[1]*HM[1],HM[2]*HM[2]]
     478    elif ibrav in [11,12]:
     479        derv = [HM[0]*HM[0],HM[1]*HM[1],HM[2]*HM[2],HM[0]*HM[2]]
     480    else:
     481        derv = [HM[0]*HM[0],HM[1]*HM[1],HM[2]*HM[2],HM[0]*HM[1],HM[0]*HM[2],HM[1]*HM[2]]
     482    if Vref[0]:
     483        derv.append(2.*A[0]*HM[0]*H[3]+A[3]*HM[1]*H[3]+A[4]*HM[2]*H[3])
     484    if Vref[1]:
     485        derv.append(2.*A[1]*HM[1]*H[3]+A[3]*HM[0]*H[3]+A[5]*HM[2]*H[3])
     486    if Vref[2]:
     487        derv.append(2.*A[2]*HM[2]*H[3]+A[4]*HM[1]*H[3]+A[5]*HM[0]*H[3])   
     488    if Zref:
     489        derv.append(npsind(tth)*2.0*rpd/wave**2)
     490    derv = -np.array(derv)
     491    return derv.T
     492   
     493def FitHKLZSS(wave,ibrav,peaks,A,V,Vref,Z,Zref):
    450494    'needs a doc string'
    451495   
     
    457501    if Zref:
    458502        values.append(Z)
    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))
     503    result = so.leastsq(errFitZSS,values,Dfun=dervFitZSS,full_output=True,ftol=1.e-6,
     504        args=(ibrav,Peaks[8],Peaks[4:8],Peaks[0],wave,V,Vref,Z,Zref))
    461505    A = Values2A(ibrav,result[0])
    462506    Vec = Values2Vec(ibrav,V,Vref,result[0])
    463507    if Zref:
    464508        Z = result[0][-1]
    465     chisq = np.sum(errFitZSS(result[0],ibrav,Peaks[8],Peaks[4:8],Peaks[0],wave,Vec,Vref,Z,Zref,Pwr)**2)
     509    chisq = np.sum(errFitZSS(result[0],ibrav,Peaks[8],Peaks[4:8],Peaks[0],wave,Vec,Vref,Z,Zref)**2)
    466510    return True,chisq,A,Vec,Z,result
    467511   
    468 def errFitT(values,ibrav,d,H,tof,difC,Z,Zref,Pwr):
     512def errFitT(values,ibrav,d,H,tof,difC,Z,Zref):
    469513    Zero = Z
    470514    if Zref:   
    471515        Zero = values[-1]
    472     A = Values2A(ibrav,values[:6])
     516    A = Values2A(ibrav,values)
    473517    Qo = 1./d**2
    474518    Qc = G2lat.calc_rDsqT(H,A,Zero,tof,difC)
    475     return (Qo-Qc)*d**Pwr
    476    
    477 def FitHKLT(difC,ibrav,peaks,A,Z,Zref,Pwr):
     519    return (Qo-Qc)
     520   
     521def dervFitT(values,ibrav,d,H,tof,difC,Z,Zref):
     522    if ibrav in [0,1,2]:
     523        derv = [H[0]*H[0]+H[1]*H[1]+H[2]*H[2],]
     524    elif ibrav in [3,4,]:
     525        derv = [H[0]*H[0]+H[1]*H[1]+H[0]*H[1],H[2]*H[2]]
     526    elif ibrav in [5,6]:
     527        derv = [H[0]*H[0]+H[1]*H[1],H[2]*H[2]]
     528    elif ibrav in [7,8,9,10]:
     529        derv = [H[0]*H[0],H[1]*H[1],H[2]*H[2]]
     530    elif ibrav in [11,12]:
     531        derv = [H[0]*H[0],H[1]*H[1],H[2]*H[2],H[0]*H[2]]
     532    else:
     533        derv = [H[0]*H[0],H[1]*H[1],H[2]*H[2],H[0]*H[1],H[0]*H[2],H[1]*H[2]]
     534    if Zref:
     535        derv.append(np.ones_like(d)/difC)
     536    derv = -np.array(derv)
     537    return derv.T
     538   
     539def FitHKLT(difC,ibrav,peaks,A,Z,Zref):
    478540    'needs a doc string'
    479541   
     
    482544    if Zref:
    483545        values.append(Z)
    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))
    486     A = Values2A(ibrav,result[0][:6])
     546    result = so.leastsq(errFitT,values,Dfun=dervFitT,full_output=True,ftol=0.0001,
     547        args=(ibrav,Peaks[7],Peaks[4:7],Peaks[0],difC,Z,Zref))
     548    A = Values2A(ibrav,result[0])
    487549    if Zref:
    488550        Z = result[0][-1]
    489     chisq = np.sum(errFitT(result[0],ibrav,Peaks[7],Peaks[4:7],Peaks[0],difC,Z,Zref,Pwr)**2)
     551    chisq = np.sum(errFitT(result[0],ibrav,Peaks[7],Peaks[4:7],Peaks[0],difC,Z,Zref)**2)
    490552    return True,chisq,A,Z,result
    491553               
     
    539601    'needs a doc string'
    540602    dmin = getDmin(peaks)
    541     OK,smin,Aref,Z,result = FitHKLZ(wave,ibrav,peaks,A,Zero,ZeroRef,0)
     603    OK,smin,Aref,Z,result = FitHKLZ(wave,ibrav,peaks,A,Zero,ZeroRef)
    542604    Peaks = np.array(peaks).T
    543605    H = Peaks[4:7]
     
    551613    'needs a doc string'
    552614    dmin = getDmin(peaks)
    553     print Zero
    554     OK,smin,Aref,Vref,Z,result = FitHKLZSS(wave,ibrav,peaks,A,vec,vecRef,Zero,ZeroRef,0)
    555     print Z
     615    OK,smin,Aref,Vref,Z,result = FitHKLZSS(wave,ibrav,peaks,A,vec,vecRef,Zero,ZeroRef)
    556616    Peaks = np.array(peaks).T
    557617    H = Peaks[4:8]
     
    565625    'needs a doc string'
    566626    dmin = getDmin(peaks)
    567     OK,smin,Aref,Z,result = FitHKLT(difC,ibrav,peaks,A,Zero,ZeroRef,0)
     627    OK,smin,Aref,Z,result = FitHKLT(difC,ibrav,peaks,A,Zero,ZeroRef)
    568628    Peaks = np.array(peaks).T
    569629    H = Peaks[4:7]
  • trunk/GSASIIlattice.py

    r1581 r1585  
    424424        return wave/(2.0*sind((pos-Inst.get('Zero',[0,0])[1])/2.0))
    425425    else:   #'T'OF - ignore difB
     426#        return TOF2dsp(Inst,pos)
    426427        T = pos-Inst['Zero'][1]
    427428        T1 = Inst['difC'][1]**2-4.*Inst['difA'][1]*T
    428429        return 2.*T/(Inst['difC'][1]+np.sqrt(T1))
     430       
     431def TOF2dsp(Inst,Pos):
     432    import scipy.optimize as so
     433   
     434    def func(d,pos,Inst):
     435        return pos-Inst['difC'][1]*d-Inst['difA'][1]*d**2-Inst['Zero'][1]-Inst['difB'][1]/d
     436       
     437    return [so.brentq(func,.01,100.,args=(pos,Inst)) for pos in Pos]
    429438   
    430439def Dsp2pos(Inst,dsp):
  • trunk/GSASIIplot.py

    r1583 r1585  
    215215    arrows = {}
    216216    for direc in ('left','right','up','down','Expand X',
    217                   'Expand Y','Shrink X','Shrink Y'):
     217                  'Shrink X','Expand Y','Shrink Y'):
    218218        arrows[direc] = wx.NewId()
    219219    def __init__(self,plotCanvas):
     
    223223        POSITION_OF_CONFIGURE_SUBPLOTS_BTN = 6 # remove one button
    224224        self.DeleteToolByPos(POSITION_OF_CONFIGURE_SUBPLOTS_BTN)
    225         parent = self.GetParent()
     225        self.parent = self.GetParent()
    226226        key = os.path.join(os.path.split(__file__)[0],'key.ico')
    227227        self.AddSimpleTool(self.ON_MPL_KEY,_load_bitmap(key),'Key press','Select key press')
     
    236236            self.AddSimpleTool(self.arrows[direc],_load_bitmap(icon),
    237237                               'Shift '+direc,'Shift plot '+direc)
    238         for direc in ('Expand X','Expand Y','Shrink X','Shrink Y'):
     238        for direc in ('Expand X','Shrink X','Expand Y','Shrink Y'):
    239239            fil = ''.join([i[0].lower() for i in direc.split()]+['arrow.ico'])
    240240            wx.EVT_TOOL(self,self.arrows[direc],self.OnArrow)
     
    265265        elif event.Id == self.arrows['Expand X']:
    266266            delta = (xmax-xmin)/10.
    267             #xmin += delta
     267            xmin += delta
    268268            xmax -= delta
    269269        elif event.Id == self.arrows['Expand Y']:
    270270            delta = (ymax-ymin)/10.
    271             #ymin += delta
     271            ymin += delta
    272272            ymax -= delta
    273273        elif event.Id == self.arrows['Shrink X']:
    274274            delta = (xmax-xmin)/10.
    275             #xmin -= delta
     275            xmin -= delta
    276276            xmax += delta
    277277        elif event.Id == self.arrows['Shrink Y']:
    278278            delta = (ymax-ymin)/10.
    279             #ymin -= delta
     279            ymin -= delta
    280280            ymax += delta
    281281        else:
    282282            # should not happen!
    283283            GSASIIpath.IPyBreak()
     284        self.parent.toolbar.push_current()
    284285        ax.axis((xmin,xmax,ymin,ymax))
    285286        #print xmin,xmax,ymin,ymax
    286287        self.plotCanvas.figure.canvas.draw()
     288        self.parent.toolbar.draw()
     289#        self.parent.toolbar.push_current()
    287290       
    288291    def OnHelp(self,event):
  • trunk/GSASIIpwdGUI.py

    r1582 r1585  
    26682668    spcSel.Bind(wx.EVT_CHOICE,OnSpcSel)
    26692669    littleSizer.Add(spcSel,0,WACV)
    2670     littleSizer.Add(wx.StaticText(G2frame.dataDisplay,label=" Zero offset"),0,WACV)
    2671     zero = wx.TextCtrl(G2frame.dataDisplay,value="%.4f"%(controls[1]),style=wx.TE_PROCESS_ENTER)
    2672     zero.Bind(wx.EVT_TEXT_ENTER,OnZero)
    2673     zero.Bind(wx.EVT_KILL_FOCUS,OnZero)
    2674     littleSizer.Add(zero,0,WACV)
    2675     zeroVar = wx.CheckBox(G2frame.dataDisplay,label="Refine?")
    2676     zeroVar.SetValue(controls[0])
    2677     zeroVar.Bind(wx.EVT_CHECKBOX,OnZeroVar)
    2678     littleSizer.Add(zeroVar,0,WACV)
     2670    if ssopt.get('Use',False):        #zero for super lattice doesn't work!
     2671        controls[0] = False
     2672    else:
     2673        littleSizer.Add(wx.StaticText(G2frame.dataDisplay,label=" Zero offset"),0,WACV)
     2674        zero = wx.TextCtrl(G2frame.dataDisplay,value="%.4f"%(controls[1]),style=wx.TE_PROCESS_ENTER)
     2675        zero.Bind(wx.EVT_TEXT_ENTER,OnZero)
     2676        zero.Bind(wx.EVT_KILL_FOCUS,OnZero)
     2677        littleSizer.Add(zero,0,WACV)
     2678        zeroVar = wx.CheckBox(G2frame.dataDisplay,label="Refine?")
     2679        zeroVar.SetValue(controls[0])
     2680        zeroVar.Bind(wx.EVT_CHECKBOX,OnZeroVar)
     2681        littleSizer.Add(zeroVar,0,WACV)
    26792682    SSopt = wx.CheckBox(G2frame.dataDisplay,label="Super lattice?")
    26802683    SSopt.SetValue(ssopt.get('Use',False))
Note: See TracChangeset for help on using the changeset viewer.