# Changeset 264

Ignore:
Timestamp:
Mar 31, 2011 4:41:13 PM (12 years ago)
Message:

begin implementation of pdf generation - work in progress
modify image to have azimuth=0 as vertical "up"
add textctrls for max and min image intensity
fix to some lattice parameter defaults for some Laue groups

Location:
trunk
Files:
10 edited

Unmodified
Removed

• ## trunk/GSASIIElem.py

 r230 import sys import os.path import  wx.lib.colourselect as wscs import wx.lib.colourselect as wscs import GSASIIpath import numpy as np t = -fb*SQ return np.sum(fa*np.exp(t))+FormFac['fc'] def ComptonFac(ComptonCoeff,SQ): """compute Compton scattering factor @param ComptonCoeff: list [Z, a1:a5, b1:b5] @param SQ: (sin-theta/lambda)**2 @return: comp: compton scattering factor """ ca = np.array(ComptonCoeff[1:6]) cb = np.array(ComptonCoeff[6:11]) t = -cb*SQ return ComptonCoeff[0]-np.sum(ca*np.exp(t)) def FPcalc(Orbs, KEv): "Makes periodic table widget for picking element - caller maintains element list" Elem=None def _init_ctrls(self, prnt): def _init_ctrls(self, prnt,oneOnly): wx.Dialog.__init__(self, id=-1, name='PickElement', parent=prnt, pos=wx.DefaultPosition, i=0 for E in ET.ElTable: if oneOnly: color=E[4] else: color=E[6] PickElement.ElButton(self,name=E[0], #            pos=wx.Point(E[1]*40+25,E[2]*24+24),tip=E[3],color=E[4]) pos=wx.Point(E[1]*40+25,E[2]*24+24),tip=E[3],color=E[6]) pos=wx.Point(E[1]*40+25,E[2]*24+24),tip=E[3],color=color,oneOnly=oneOnly) i+=1 def __init__(self, parent): self._init_ctrls(parent) def ElButton(self, name, pos, tip, color): def __init__(self, parent,oneOnly=False): self._init_ctrls(parent,oneOnly) def ElButton(self, name, pos, tip, color, oneOnly): Black = wx.Colour(0,0,0) El = wx.ComboBox(choices=name, parent=self, pos=pos, size=wx.Size(40,23), style=wx.CB_READONLY, value=name[0]) if oneOnly: El = wscs.ColourSelect(label=name[0], parent=self,colour=color, pos=pos, size=wx.Size(40,23), style=wx.RAISED_BORDER) #            El.SetLabel(name) El.Bind(wx.EVT_BUTTON, self.OnElButton) else: El = wx.ComboBox(choices=name, parent=self, pos=pos, size=wx.Size(40,23), style=wx.CB_READONLY, value=name[0]) El.Bind(wx.EVT_COMBOBOX,self.OnElButton) El.SetBackgroundColour(color) El.SetToolTipString(tip) El.Bind(wx.EVT_COMBOBOX, self.OnElButton) def OnElButton(self, event): El = event.GetEventObject().GetLabel() self.Elem = (El) self.Elem = El self.EndModal(wx.ID_OK)

• ## trunk/GSASIIimage.py

 r263 B = np.array(-(x**2+y**2)) bb,err = fel.fellipse(len(x),x,y,1.E-7) #    print nl.lstsq(M.T,B)[0] #    print bb return err,makeParmsEllipse(bb) ring = [] if azm: aR = azm[0],azm[1],1 aR = azm[0]-90,azm[1]-90,1 if azm[1]-azm[0] > 180: aR[2] = 2 tth = npatand(np.sqrt(dx**2+dy**2-Z**2)/(dist-Z)) dsp = wave/(2.*npsind(tth/2.)) azm = npatan2d(dy,dx)+azmthoff azm = npatan2d(dx,-dy)+azmthoff return tth,azm,dsp data['center'] = copy.copy(ellipse[0])           #not right!! (but useful for now) data['ellipses'].append(ellipse[:]+('r',)) G2plt.PlotImage(self,newImage=False) G2plt.PlotImage(self,newImage=True) #setup for calibration else: ellipse = newellipse #                if abs((radii[1]/radii[0]-ratio)/ratio) > 0.1: #                    print 'Bad fit for ring # %i. Try reducing Pixel search range'%(i) #                    return False zdis,cosB = calcZdisCosB(radius,tth,radii) Tilt = acosd(cosB)          # 0 <= tilt <= 90 tiltSum += numZ*abs(Tilt) if not np.all(checkEllipse(Zsum,distSum,xSum,ySum,dist,data['center'][0],data['center'][1])): print 'Bad ellipse. Try reducing Pixel search range' print 'Bad fit for ring # %i. Try reducing Pixel search range'%(i) cent = data['center'] print ('for ring # %2i @ d-space %.4f: dist %.3f rotate %6.2f tilt %6.2f Xcent %.3f Ycent %.3f Npts %d' %(i,dsp,dist,phi,Tilt,cent[0],cent[1],numZ)) %(i,dsp,dist,phi-90.,Tilt,cent[0],cent[1],numZ)) data['ellipses'].append(copy.deepcopy(ellipse+('r',))) else:

• ## trunk/GSASIIlattice.py

 r230 else: return [0,0,0] def CellAbsorption(ElList,Volume): # ElList = dictionary of element contents including mu muT = 0 for El in ElList: muT += ElList[El]['mu']*ElList[El]['FormulaNo'] return muT/Volume def qRebin(x,y,nQbins): #Rebin data from x to qx #   input: #   X - array of q-values in increasing order #   y - array of intensities for the x array #   nQbins - number of q-bins desired #   returns: #   qx - array of q-values #   qy - array of rebinned intensities dQ = (x[-1]-x[0])/nQbins dQ2 = dQ/2. Qmin = x[0] yf = y[0] frac = 0.0 jch = 0 kch = 0 qy = [] for i in range(nQbins): Q = Qmin+dQ*i rom = Q rop = rom+dQ sdq = (1.-frac)*dQ qy.append(1-frac)*yf*dQ #      DELQ = (XT(NCHANS)-XT(1))/FLOAT(MCHANS) #      DELQ2 = DELQ/2.0 #      QMIN = XT(1) #      JCH = 1 #      KCH = 0 #      YF = YT(1) #      FRAC = 0.0 #      DQ = XT(2)-QMIN #      DO ICH = 1,MCHANS #        Q = QMIN+DELQ*FLOAT(ICH-1) !Front end interpolation #        ROM = Q #        ROP = ROM+DELQ #        SDQ = (1.0-FRAC)*DQ #        RY(ICH) = (1.0-FRAC)*YF*DQ !Sum intervening channels #        DO WHILE ( ROP.GT.XT(KCH+1) .AND. KCH.NE.NCHANS-1 ) #          KCH = MIN(KCH+1,NCHANS-1) #        END DO #        DO LCH=JCH+1,KCH #          DQ = XT(LCH+1)-XT(LCH) #          SDQ = SDQ+DQ #          RY(ICH) = RY(ICH)+DQ*YT(LCH) #        END DO !Tail end interpolation #        XF = XT(MAX(1,KCH)) #        YF = YT(MAX(1,KCH)) #        DQ = XT(KCH+1)-XF #        DY = YT(KCH+1)-YF #        FRAC = (ROP-XF)/DQ #        SDQ = SDQ+DQ*FRAC #        RY(ICH) = RY(ICH)+YF*FRAC*DQ !Reset lower limit #        JCH = KCH #        RY(ICH) = RY(ICH)/SDQ #      END DO #      RETURN #      END #Permutations and Combinations
• ## trunk/GSASIIpeak.py

 r243 #GSASII peak fitting module #GSASII powder calculation module ########### SVN repository information ################### # \$Date\$ plist.append(p) return plist def Transmission(Geometry,Abs,Diam): #Calculate sample transmission #   Geometry: one of 'Cylinder','Bragg-Brentano','Tilting Flat Plate in transmission','Fixed flat plate' #   Abs: absorption coeff in cm-1 #   Diam: sample thickness/diameter in mm if 'Cylinder' in Geometry:      #Lobanov & Alte da Veiga for 2-theta = 0; beam fully illuminates sample MuR = Abs*Diam/5.0 if MuR <= 3.0: T0 = 16/(3.*math.pi) T1 = -0.045780 T2 = -0.02489 T3 = 0.003045 T = -T0*MuR-T1*MuR**2-T2*MuR**3-T3*MuR**4 if T < -20.: return 2.06e-9 else: return math.exp(T) else: T1 = 1.433902 T2 = 0.013869+0.337894 T3 = 1.933433+1.163198 T4 = 0.044365-0.04259 T = (T1-T4)/(1.0+T2*(MuR-3.0))**T3+T4 return T/100. def Absorb(Geometry,Abs,Diam,Tth,Phi=0,Psi=0): #Calculate sample absorption #   Geometry: one of 'Cylinder','Bragg-Brentano','Tilting Flat Plate in transmission','Fixed flat plate' #   Abs: absorption coeff in cm-1 #   Diam: sample thickness/diameter in mm #   Tth: 2-theta scattering angle - can be numpy array #   Phi: flat plate tilt angle - future #   Psi: flat plate tilt axis - future MuR = Abs*Diam/5.0 Sth2 = npsind(Tth/2.0)**2 Cth2 = 1.-Sth2 if 'Cylinder' in Geometry:      #Lobanov & Alte da Veiga for 2-theta = 0; beam fully illuminates sample if MuR < 3.0: T0 = 16.0/(3*np.pi) T1 = (25.99978-0.01911*Sth2**0.25)*np.exp(-0.024551*Sth2)+ \ 0.109561*np.sqrt(Sth2)-26.04556 T2 = -0.02489-0.39499*Sth2+1.219077*Sth2**1.5- \ 1.31268*Sth2**2+0.871081*Sth2**2.5-0.2327*Sth2**3 T3 = 0.003045+0.018167*Sth2-0.03305*Sth2**2 Trns = -T0*MuR-T1*MuR**2-T2*MuR**3-T3*MuR**4 return np.exp(Trns) else: T1 = 1.433902+11.07504*Sth2-8.77629*Sth2*Sth2+ \ 10.02088*Sth2**3-3.36778*Sth2**4 T2 = (0.013869-0.01249*Sth2)*np.exp(3.27094*Sth2)+ \ (0.337894+13.77317*Sth2)/(1.0+11.53544*Sth2)**1.555039 T3 = 1.933433/(1.0+23.12967*Sth2)**1.686715- \ 0.13576*np.sqrt(Sth2)+1.163198 T4 = 0.044365-0.04259/(1.0+0.41051*Sth2)**148.4202 Trns = (T1-T4)/(1.0+T2*(MuR-3.0))**T3+T4 return Trns/100. elif 'Bragg' in Geometry: return 1.0 elif 'Fixed' in Geometry: #assumes sample plane is perpendicular to incident beam # and only defined for 2theta < 90 T1 = np.exp(-MuR) T2 = np.exp(-MuR/(1.-2.*Sth2)) Tb = -2.*Abs*Sth2 return (T1-T2)/Tb elif 'Tilting' in Geometry: #assumes symmetric tilt so sample plane is parallel to diffraction vector cth = npcosd(Tth/2.0) return (Diam/cth)*np.exp(-MuR/cth) def Polarization(Pola,Azm,Tth): #   Calculate x-ray polarization correction #   Pola: polarization coefficient e.g 1.0 fully polarized, 0.5 unpolarized #   Azm: azimuthal angle e.g. 0.0 in plane of polarization(?) #   Tth: 2-theta scattering angle - can be numpy array pass def ValEsd(value,esd=0,nTZ=False):                  #NOT complete - don't use data = [x,y,w,yc,yb,yd] return True,smin,Rwp,runtime,GoOn def ComputePDF(data,xydata): for key in data: print key,data[key] #subtract backgrounds - if any xydata['Sample corrected'] = xydata['Sample'] if 'Sample Bkg.' in xydata: xydata['Sample corrected'][1][1] -= (xydata['Sample Bkg.'][1][1]+ data['Sample Bkg.']['Add'])*data['Sample Bkg.']['Mult'] if 'Container' in xydata: xydata['Sample corrected'][1][1] -= (xydata['Container'][1][1]+ data['Container']['Add'])*data['Container']['Mult'] if 'Container Bkg.' in xydata: xydata['Sample corrected'][1][1] += (xydata['Container Bkg.'][1][1]+ data['Container Bkg.']['Add'])*data['Container Bkg.']['Mult'] return xydata['Sample corrected'],[]
• ## trunk/GSASIIphsGUI.py

 r242 Obj.SetValue("%.5f"%(cell[4])) elif laue in ['3','3m1','31m','6/m','6/mmm','4/m','4/mmm']: cell[4] = cell[5] = 90. cell[6] = 120. if ObjId == 0: cell[1] = cell[2] = value elif laue in ['mmm']: cell[ObjId+1] = value cell[4] = cell[5] = cell[6] = 90. Obj.SetValue("%.5f"%(cell[ObjId+1])) elif laue in ['2/m'+'a']: cell[5] = cell[6] = 90. if ObjId != 3: cell[ObjId+1] = value Obj.SetValue("%.3f"%(cell[4])) elif laue in ['2/m'+'b']: cell[4] = cell[6] = 90. if ObjId != 3: cell[ObjId+1] = value Obj.SetValue("%.3f"%(cell[5])) elif laue in ['2/m'+'c']: cell[5] = cell[6] = 90. if ObjId != 3: cell[ObjId+1] = value