# Changeset 1585

Ignore:
Timestamp:
Nov 25, 2014 2:42:11 PM (9 years ago)
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

Unmodified
Removed
• ## trunk/GSASIIindex.py

 r1582 npatand = lambda x: 180.*np.arctan(x)/np.pi npatan2d = lambda y,x: 180.*np.arctan2(y,x)/np.pi rpd = np.pi/180. def scaleAbyV(A,V): return [values[0],values[1],values[2],0,values[3],0] else: return list(values) return list(values[:6]) def A2values(ibrav,A): return True,np.sum(errFit(result[0],ibrav,Peaks[7],Peaks[4:7],Pwr)**2),A,result def errFitZ(values,ibrav,d,H,tth,wave,Z,Zref,Pwr): def errFitZ(values,ibrav,d,H,tth,wave,Z,Zref): Zero = Z if Zref: Zero = values[-1] A = Values2A(ibrav,values[:6]) A = Values2A(ibrav,values) Qo = 1./d**2 Qc = G2lat.calc_rDsqZ(H,A,Zero,tth,wave) return (Qo-Qc)*d**Pwr def FitHKLZ(wave,ibrav,peaks,A,Z,Zref,Pwr): return (Qo-Qc) def dervFitZ(values,ibrav,d,H,tth,wave,Z,Zref): if ibrav in [0,1,2]: derv = [H[0]*H[0]+H[1]*H[1]+H[2]*H[2],] elif ibrav in [3,4,]: derv = [H[0]*H[0]+H[1]*H[1]+H[0]*H[1],H[2]*H[2]] elif ibrav in [5,6]: derv = [H[0]*H[0]+H[1]*H[1],H[2]*H[2]] elif ibrav in [7,8,9,10]: derv = [H[0]*H[0],H[1]*H[1],H[2]*H[2]] elif ibrav in [11,12]: derv = [H[0]*H[0],H[1]*H[1],H[2]*H[2],H[0]*H[2]] else: 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]] if Zref: derv.append(npsind(tth)*2.0*rpd/wave**2) derv = -np.array(derv) return derv.T def FitHKLZ(wave,ibrav,peaks,A,Z,Zref): 'needs a doc string' if Zref: values.append(Z) result = so.leastsq(errFitZ,values,full_output=True,ftol=0.0001,factor=10., args=(ibrav,Peaks[7],Peaks[4:7],Peaks[0],wave,Z,Zref,Pwr)) result = so.leastsq(errFitZ,values,Dfun=dervFitZ,full_output=True,ftol=0.0001, args=(ibrav,Peaks[7],Peaks[4:7],Peaks[0],wave,Z,Zref)) A = Values2A(ibrav,result[0][:6]) if Zref: Z = result[0][-1] chisq = np.sum(errFitZ(result[0],ibrav,Peaks[7],Peaks[4:7],Peaks[0],wave,Z,Zref,Pwr)**2) chisq = np.sum(errFitZ(result[0],ibrav,Peaks[7],Peaks[4:7],Peaks[0],wave,Z,Zref)**2) return True,chisq,A,Z,result def errFitZSS(values,ibrav,d,H,tth,wave,vec,Vref,Z,Zref,Pwr): def errFitZSS(values,ibrav,d,H,tth,wave,vec,Vref,Z,Zref): Zero = Z if Zref: Zero = values[-1] A = Values2A(ibrav,values[:6]) vec = Values2Vec(ibrav,vec,Vref,values) A = Values2A(ibrav,values) Vec = Values2Vec(ibrav,vec,Vref,values) Qo = 1./d**2 Qc = G2lat.calc_rDsqZSS(H,A,vec,Zero,tth,wave) return (Qo-Qc)*d**Pwr def FitHKLZSS(wave,ibrav,peaks,A,V,Vref,Z,Zref,Pwr): Qc = G2lat.calc_rDsqZSS(H,A,Vec,Zero,tth,wave) return (Qo-Qc) def dervFitZSS(values,ibrav,d,H,tth,wave,vec,Vref,Z,Zref): A = Values2A(ibrav,values) Vec = Values2Vec(ibrav,vec,Vref,values) HM = H[:3]+(H[3][:,np.newaxis]*Vec).T if ibrav in [3,4,]: derv = [HM[0]*HM[0]+HM[1]*HM[1]+HM[0]*HM[1],HM[2]*HM[2]] elif ibrav in [5,6]: derv = [HM[0]*HM[0]+HM[1]*HM[1],HM[2]*HM[2]] elif ibrav in [7,8,9,10]: derv = [HM[0]*HM[0],HM[1]*HM[1],HM[2]*HM[2]] elif ibrav in [11,12]: derv = [HM[0]*HM[0],HM[1]*HM[1],HM[2]*HM[2],HM[0]*HM[2]] else: 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]] if Vref[0]: derv.append(2.*A[0]*HM[0]*H[3]+A[3]*HM[1]*H[3]+A[4]*HM[2]*H[3]) if Vref[1]: derv.append(2.*A[1]*HM[1]*H[3]+A[3]*HM[0]*H[3]+A[5]*HM[2]*H[3]) if Vref[2]: derv.append(2.*A[2]*HM[2]*H[3]+A[4]*HM[1]*H[3]+A[5]*HM[0]*H[3]) if Zref: derv.append(npsind(tth)*2.0*rpd/wave**2) derv = -np.array(derv) return derv.T def FitHKLZSS(wave,ibrav,peaks,A,V,Vref,Z,Zref): 'needs a doc string' if Zref: values.append(Z) result = so.leastsq(errFitZSS,values,full_output=True,ftol=1.e-6,factor=10., args=(ibrav,Peaks[8],Peaks[4:8],Peaks[0],wave,V,Vref,Z,Zref,Pwr)) result = so.leastsq(errFitZSS,values,Dfun=dervFitZSS,full_output=True,ftol=1.e-6, args=(ibrav,Peaks[8],Peaks[4:8],Peaks[0],wave,V,Vref,Z,Zref)) A = Values2A(ibrav,result[0]) Vec = Values2Vec(ibrav,V,Vref,result[0]) if Zref: Z = result[0][-1] chisq = np.sum(errFitZSS(result[0],ibrav,Peaks[8],Peaks[4:8],Peaks[0],wave,Vec,Vref,Z,Zref,Pwr)**2) chisq = np.sum(errFitZSS(result[0],ibrav,Peaks[8],Peaks[4:8],Peaks[0],wave,Vec,Vref,Z,Zref)**2) return True,chisq,A,Vec,Z,result def errFitT(values,ibrav,d,H,tof,difC,Z,Zref,Pwr): def errFitT(values,ibrav,d,H,tof,difC,Z,Zref): Zero = Z if Zref: Zero = values[-1] A = Values2A(ibrav,values[:6]) A = Values2A(ibrav,values) Qo = 1./d**2 Qc = G2lat.calc_rDsqT(H,A,Zero,tof,difC) return (Qo-Qc)*d**Pwr def FitHKLT(difC,ibrav,peaks,A,Z,Zref,Pwr): return (Qo-Qc) def dervFitT(values,ibrav,d,H,tof,difC,Z,Zref): if ibrav in [0,1,2]: derv = [H[0]*H[0]+H[1]*H[1]+H[2]*H[2],] elif ibrav in [3,4,]: derv = [H[0]*H[0]+H[1]*H[1]+H[0]*H[1],H[2]*H[2]] elif ibrav in [5,6]: derv = [H[0]*H[0]+H[1]*H[1],H[2]*H[2]] elif ibrav in [7,8,9,10]: derv = [H[0]*H[0],H[1]*H[1],H[2]*H[2]] elif ibrav in [11,12]: derv = [H[0]*H[0],H[1]*H[1],H[2]*H[2],H[0]*H[2]] else: 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]] if Zref: derv.append(np.ones_like(d)/difC) derv = -np.array(derv) return derv.T def FitHKLT(difC,ibrav,peaks,A,Z,Zref): 'needs a doc string' if Zref: values.append(Z) result = so.leastsq(errFitT,values,full_output=True,ftol=0.0001,factor=0.001, args=(ibrav,Peaks[7],Peaks[4:7],Peaks[0],difC,Z,Zref,Pwr)) A = Values2A(ibrav,result[0][:6]) result = so.leastsq(errFitT,values,Dfun=dervFitT,full_output=True,ftol=0.0001, args=(ibrav,Peaks[7],Peaks[4:7],Peaks[0],difC,Z,Zref)) A = Values2A(ibrav,result[0]) if Zref: Z = result[0][-1] chisq = np.sum(errFitT(result[0],ibrav,Peaks[7],Peaks[4:7],Peaks[0],difC,Z,Zref,Pwr)**2) chisq = np.sum(errFitT(result[0],ibrav,Peaks[7],Peaks[4:7],Peaks[0],difC,Z,Zref)**2) return True,chisq,A,Z,result 'needs a doc string' dmin = getDmin(peaks) OK,smin,Aref,Z,result = FitHKLZ(wave,ibrav,peaks,A,Zero,ZeroRef,0) OK,smin,Aref,Z,result = FitHKLZ(wave,ibrav,peaks,A,Zero,ZeroRef) Peaks = np.array(peaks).T H = Peaks[4:7] 'needs a doc string' dmin = getDmin(peaks) print Zero OK,smin,Aref,Vref,Z,result = FitHKLZSS(wave,ibrav,peaks,A,vec,vecRef,Zero,ZeroRef,0) print Z OK,smin,Aref,Vref,Z,result = FitHKLZSS(wave,ibrav,peaks,A,vec,vecRef,Zero,ZeroRef) Peaks = np.array(peaks).T H = Peaks[4:8] 'needs a doc string' dmin = getDmin(peaks) OK,smin,Aref,Z,result = FitHKLT(difC,ibrav,peaks,A,Zero,ZeroRef,0) OK,smin,Aref,Z,result = FitHKLT(difC,ibrav,peaks,A,Zero,ZeroRef) Peaks = np.array(peaks).T H = Peaks[4:7]
• ## trunk/GSASIIlattice.py

 r1581 return wave/(2.0*sind((pos-Inst.get('Zero',[0,0])[1])/2.0)) else:   #'T'OF - ignore difB #        return TOF2dsp(Inst,pos) T = pos-Inst['Zero'][1] T1 = Inst['difC'][1]**2-4.*Inst['difA'][1]*T return 2.*T/(Inst['difC'][1]+np.sqrt(T1)) def TOF2dsp(Inst,Pos): import scipy.optimize as so def func(d,pos,Inst): return pos-Inst['difC'][1]*d-Inst['difA'][1]*d**2-Inst['Zero'][1]-Inst['difB'][1]/d return [so.brentq(func,.01,100.,args=(pos,Inst)) for pos in Pos] def Dsp2pos(Inst,dsp):
• ## trunk/GSASIIplot.py

 r1583 arrows = {} for direc in ('left','right','up','down','Expand X', 'Expand Y','Shrink X','Shrink Y'): 'Shrink X','Expand Y','Shrink Y'): arrows[direc] = wx.NewId() def __init__(self,plotCanvas): POSITION_OF_CONFIGURE_SUBPLOTS_BTN = 6 # remove one button self.DeleteToolByPos(POSITION_OF_CONFIGURE_SUBPLOTS_BTN) parent = self.GetParent() self.parent = self.GetParent() key = os.path.join(os.path.split(__file__)[0],'key.ico') self.AddSimpleTool(self.ON_MPL_KEY,_load_bitmap(key),'Key press','Select key press') self.AddSimpleTool(self.arrows[direc],_load_bitmap(icon), 'Shift '+direc,'Shift plot '+direc) for direc in ('Expand X','Expand Y','Shrink X','Shrink Y'): for direc in ('Expand X','Shrink X','Expand Y','Shrink Y'): fil = ''.join([i[0].lower() for i in direc.split()]+['arrow.ico']) wx.EVT_TOOL(self,self.arrows[direc],self.OnArrow) elif event.Id == self.arrows['Expand X']: delta = (xmax-xmin)/10. #xmin += delta xmin += delta xmax -= delta elif event.Id == self.arrows['Expand Y']: delta = (ymax-ymin)/10. #ymin += delta ymin += delta ymax -= delta elif event.Id == self.arrows['Shrink X']: delta = (xmax-xmin)/10. #xmin -= delta xmin -= delta xmax += delta elif event.Id == self.arrows['Shrink Y']: delta = (ymax-ymin)/10. #ymin -= delta ymin -= delta ymax += delta else: # should not happen! GSASIIpath.IPyBreak() self.parent.toolbar.push_current() ax.axis((xmin,xmax,ymin,ymax)) #print xmin,xmax,ymin,ymax self.plotCanvas.figure.canvas.draw() self.parent.toolbar.draw() #        self.parent.toolbar.push_current() def OnHelp(self,event):