Changeset 193
- Timestamp:
- Dec 22, 2010 2:29:41 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASII.py
r186 r193 307 307 self.dirname = dlg.GetDirectory() 308 308 for filename in filenames: 309 Data,Iparm,Comments = G2IO.SelectPowderData(self, filename) #Data: list of tuples (filename,Pos,Bank)309 Data,Iparm,Comments,Temperature = G2IO.SelectPowderData(self, filename) #Data: list of tuples (filename,Pos,Bank) 310 310 if not Data: #if Data rejected by user - go to next one 311 311 continue … … 313 313 DataType = DataType.strip()[0:3] #just 1st 3 chars 314 314 wx.BeginBusyCursor() 315 Sample = {'Scale':[1.0,True],'Type':'Debye-Scherrer','Absorption':[0.0,False],'DisplaceX':[0.0,False], 316 'DisplaceY':[0.0,False],'Diffuse':[]} 315 Sample = {'Scale':[1.0,True],'Type':'Debye-Scherrer','Absorption':[0.0,False], 316 'DisplaceX':[0.0,False],'DisplaceY':[0.0,False],'Diffuse':[], 317 'Temperature':Temperature,'Pressure':1.0,'Humidity':0.0,'Voltage':0.0, 318 'Force':0.0} 317 319 try: 318 320 for Item in Data: -
trunk/GSASIIIO.py
r188 r193 47 47 dlg.Destroy() 48 48 if result == wx.ID_NO: return (0,0) 49 Temperature = 300 49 50 50 51 self.IparmName = GetInstrumentFile(self,filename) … … 73 74 else: 74 75 Comments.append(S[:-1]) 76 if 'Temp' in S: 77 Temperature = float(S[:-1].split()[-1]) 75 78 File.close() 76 79 finally: … … 98 101 finally: 99 102 dlg.Destroy() 100 return FoundData,Iparm,Comments 103 return FoundData,Iparm,Comments,Temperature 101 104 102 105 def GetInstrumentFile(self,filename): -
trunk/GSASIIgrid.py
r187 r193 23 23 24 24 [ wxID_IMCALIBRATE, wxID_IMINTEGRATE, wxID_IMCLEARCALIB, wxID_SAVEINTG, 25 wxID_IMCOPYCONTROLS, wxID_INTEGRATEALL, 26 ] = [wx.NewId() for _init_coll_IMAGE_Items in range( 6)]25 wxID_IMCOPYCONTROLS, wxID_INTEGRATEALL, wxID_IMSAVECONTROLS, wxID_IMLOADCONTROLS, 26 ] = [wx.NewId() for _init_coll_IMAGE_Items in range(8)] 27 27 28 28 [ wxID_MASKCOPY, … … 151 151 parent.Append(help='Copy image controls to other images', 152 152 id=wxID_IMCOPYCONTROLS, kind=wx.ITEM_NORMAL,text='Copy Controls') 153 parent.Append(help='Save image controls to file', 154 id=wxID_IMSAVECONTROLS, kind=wx.ITEM_NORMAL,text='Save Controls') 155 parent.Append(help='Load image controls from file', 156 id=wxID_IMLOADCONTROLS, kind=wx.ITEM_NORMAL,text='Load Controls') 157 153 158 154 159 def _init_coll_Mask_Items(self,parent): … … 716 721 data = self.PatternTree.GetItemPyData(item) 717 722 G2imG.UpdateImageControls(self,data,masks) 718 #G2plt.PlotImage(self)723 G2plt.PlotImage(self) 719 724 elif self.PatternTree.GetItemText(item) == 'Masks': 720 725 self.dataFrame.SetTitle('Masks') … … 723 728 data = self.PatternTree.GetItemPyData(item) 724 729 G2imG.UpdateMasks(self,data) 725 #G2plt.PlotImage(self)730 G2plt.PlotImage(self) 726 731 elif self.PatternTree.GetItemText(item) == 'HKL Plot Controls': 727 732 self.PickId = item -
trunk/GSASIIimgGUI.py
r184 r193 267 267 finally: 268 268 dlg.Destroy() 269 270 def OnSaveControls(event): 271 dlg = wx.FileDialog(self, 'Choose image controls file', '.', '', 272 'image control files (*.imctrl)|*.imctrl',wx.OPEN) 273 if self.dirname: 274 dlg.SetDirectory(self.dirname) 275 try: 276 if dlg.ShowModal() == wx.ID_OK: 277 filename = dlg.GetPath() 278 File = open(filename,'wb') 279 save = {} 280 keys = ['wavelength','calibrant','distance','center','tilt','rotation'] 281 for key in keys: 282 save[key] = data[key] 283 cPickle.dump(save,File,1) 284 File.close() 285 finally: 286 dlg.Destroy() 287 288 def OnLoadControls(event): 289 dlg = wx.FileDialog(self, 'Choose image controls file', '.', '', 290 'image control files (*.imctrl)|*.imctrl',wx.OPEN) 291 if self.dirname: 292 dlg.SetDirectory(self.dirname) 293 try: 294 if dlg.ShowModal() == wx.ID_OK: 295 filename = dlg.GetPath() 296 File = open(filename,'rb') 297 save = cPickle.load(File) 298 data.update(save) 299 calSel.SetValue(data['calibrant']) 300 waveSel.SetValue("%6.5f" % (data['wavelength'])) 301 cent = data['center'] 302 centText.SetValue(("%8.3f,%8.3f" % (cent[0],cent[1]))) 303 distSel.SetValue("%8.3f"%(data['distance'])) 304 tiltSel.SetValue("%9.3f"%(data['tilt'])) 305 rotSel.SetValue("%9.3f"%(data['rotation'])) 306 File.close() 307 finally: 308 dlg.Destroy() 269 309 270 310 colorList = [m for m in mpl.cm.datad.keys() if not m.endswith("_r")] … … 283 323 self.dataFrame.Bind(wx.EVT_MENU, OnSaveIntegrate, id=G2gd.wxID_SAVEINTG) 284 324 self.dataFrame.Bind(wx.EVT_MENU, OnCopyControls, id=G2gd.wxID_IMCOPYCONTROLS) 325 self.dataFrame.Bind(wx.EVT_MENU, OnSaveControls, id=G2gd.wxID_IMSAVECONTROLS) 326 self.dataFrame.Bind(wx.EVT_MENU, OnLoadControls, id=G2gd.wxID_IMLOADCONTROLS) 285 327 self.dataFrame.ImageEdit.Enable(id=G2gd.wxID_SAVEINTG,enable=False) 286 328 self.dataDisplay = wx.Panel(self.dataFrame) -
trunk/GSASIIlattice.py
r189 r193 469 469 return sortHKLd(HKL,True,False) 470 470 471 def GenHLaue(dmin, Laue,SGLatt,SGUniq,A):471 def GenHLaue(dmin,SGLaue,SGLatt,SGUniq,A): 472 472 '''Generate the crystallographically unique powder diffraction reflections 473 473 for a lattice and Bravais type 474 474 ''' 475 475 # dmin - minimum d-spacing 476 # Laue - Laue group symbol = '-1','2/m','mmm','4/m','6/m','4/mmm','6/mmm',476 # SGLaue - Laue group symbol = '-1','2/m','mmm','4/m','6/m','4/mmm','6/mmm', 477 477 # '3m1', '31m', '3', '3R', '3mR', 'm3', 'm3m' 478 478 # SGLatt - lattice centering = 'P','A','B','C','I','F' … … 483 483 import math 484 484 #finds maximum allowed hkl for given A within dmin 485 if Laue in ['3R','3mR']: #Rhombohedral axes485 if SGLaue in ['3R','3mR']: #Rhombohedral axes 486 486 Hmax = [0,0,0] 487 487 cell = A2cell(A) … … 496 496 dminsq = 1./(dmin**2) 497 497 HKL = [] 498 if Laue == '-1': #triclinic498 if SGLaue == '-1': #triclinic 499 499 for l in range(-Hmax[2],Hmax[2]+1): 500 500 for k in range(-Hmax[1],Hmax[1]+1): … … 507 507 if 0 < rdsq <= dminsq: 508 508 HKL.append([h,k,l,1/math.sqrt(rdsq)]) 509 elif Laue == '2/m': #monoclinic509 elif SGLaue == '2/m': #monoclinic 510 510 axisnum = 1 + ['a','b','c'].index(SGUniq) 511 511 Hmax = SwapIndx(axisnum,Hmax) … … 523 523 HKL.append([h,k,l,1/math.sqrt(rdsq)]) 524 524 [h,k,l] = SwapIndx(axisnum,[h,k,l]) 525 elif Laue in ['mmm','4/m','6/m']: #orthorhombic525 elif SGLaue in ['mmm','4/m','6/m']: #orthorhombic 526 526 for l in range(Hmax[2]+1): 527 527 for h in range(Hmax[0]+1): 528 528 kmin = 1 529 if Laue == 'mmm' or h ==0: kmin = 0529 if SGLaue == 'mmm' or h ==0: kmin = 0 530 530 for k in range(kmin,Hmax[1]+1): 531 531 H = [] … … 535 535 if 0 < rdsq <= dminsq: 536 536 HKL.append([h,k,l,1/math.sqrt(rdsq)]) 537 elif Laue in ['4/mmm','6/mmm']: #tetragonal & hexagonal537 elif SGLaue in ['4/mmm','6/mmm']: #tetragonal & hexagonal 538 538 for l in range(Hmax[2]+1): 539 539 for h in range(Hmax[0]+1): … … 545 545 if 0 < rdsq <= dminsq: 546 546 HKL.append([h,k,l,1/math.sqrt(rdsq)]) 547 elif Laue in ['3m1','31m','3','3R','3mR']: #trigonals547 elif SGLaue in ['3m1','31m','3','3R','3mR']: #trigonals 548 548 for l in range(-Hmax[2],Hmax[2]+1): 549 549 hmin = 0 550 550 if l < 0: hmin = 1 551 551 for h in range(hmin,Hmax[0]+1): 552 if Laue in ['3R','3']:552 if SGLaue in ['3R','3']: 553 553 kmax = h 554 554 kmin = -int((h-1.)/2.) … … 556 556 kmin = 0 557 557 kmax = h 558 if Laue in ['3m1','3mR'] and l < 0: kmax = h-1559 if Laue == '31m' and l < 0: kmin = 1558 if SGLaue in ['3m1','3mR'] and l < 0: kmax = h-1 559 if SGLaue == '31m' and l < 0: kmin = 1 560 560 for k in range(kmin,kmax+1): 561 561 H = [] 562 562 if CentCheck(SGLatt,[h,k,l]): H=[h,k,l] 563 if Laue in ['3R','3mR']:563 if SGLaue in ['3R','3mR']: 564 564 H = Hx2Rh(H) 565 565 if H: … … 572 572 lmin = 0 573 573 lmax = k 574 if Laue =='m3':574 if SGLaue =='m3': 575 575 lmax = h-1 576 576 if h == k: lmax += 1 -
trunk/GSASIIphsGUI.py
r190 r193 1849 1849 def OnSizeType(event): 1850 1850 Obj = event.GetEventObject() 1851 UseList[Indx[Obj.GetId()]]['Size'][0] = Obj.GetValue()1852 dataDisplay.Destroy()1851 hist = Indx[Obj.GetId()] 1852 UseList[hist]['Size'][0] = Obj.GetValue() 1853 1853 UpdateDData() 1854 1854 … … 1863 1863 try: 1864 1864 size = float(Obj.GetValue()) 1865 if size > 0: 1866 UseList[hist]['Size'][1][pid] = size 1865 if pid == 0 and size <= 0: 1866 raise ValueError 1867 elif pid == 1 and size <= -UseList[hist]['Size'][1][0]: 1868 raise ValueError 1869 UseList[hist]['Size'][1][pid] = size 1867 1870 except ValueError: 1868 1871 pass 1869 1872 Obj.SetValue("%.1f"%(UseList[hist]['Size'][1][pid])) #reset in case of error 1870 1873 1871 def OnSizeAxis(event): 1874 def OnSizeAxis(event): 1872 1875 Obj = event.GetEventObject() 1873 hist,pid = Indx[Obj.GetId()] 1874 axis = np.array(UseList[hist]['Size'][3]) 1875 UseList[hist]['Size'][3][pid] = Obj.GetValue() 1876 new = np.array(UseList[hist]['Size'][3]) 1877 if not np.any(new): 1878 UseList[hist]['Size'][3] += new-axis 1879 Obj.SetValue(UseList[hist]['Size'][3][pid]) 1876 hist = Indx[Obj.GetId()] 1877 Saxis = Obj.GetValue().split() 1878 try: 1879 hkl = [int(Saxis[i]) for i in range(3)] 1880 except (ValueError,IndexError): 1881 hkl = UseList[hist]['Size'][3] 1882 if not np.any(np.array(hkl)): 1883 hkl = UseList[hist]['Size'][3] 1884 UseList[hist]['Size'][3] = hkl 1885 h,k,l = hkl 1886 Obj.SetValue('%3d %3d %3d'%(h,k,l)) 1880 1887 1881 1888 def OnStrainType(event): 1882 1889 Obj = event.GetEventObject() 1883 UseList[Indx[Obj.GetId()]]['Mustrain'][0] = Obj.GetValue() 1884 dataDisplay.Destroy() 1890 hist = Indx[Obj.GetId()] 1891 UseList[hist]['Mustrain'][0] = Obj.GetValue() 1892 G2plt.PlotStrain(self,data) 1885 1893 UpdateDData() 1886 1894 … … 1888 1896 Obj = event.GetEventObject() 1889 1897 hist,pid = Indx[Obj.GetId()] 1890 UseList[hist]['Mustrain'][2][pid] = Obj.GetValue() 1898 if UseList[hist]['Mustrain'][0] == 'generalized': 1899 UseList[hist]['Mustrain'][5][pid] = Obj.GetValue() 1900 else: 1901 UseList[hist]['Mustrain'][2][pid] = Obj.GetValue() 1891 1902 1892 1903 def OnStrainVal(event): 1904 Snames = G2spc.MustrainNames(SGData) 1893 1905 Obj = event.GetEventObject() 1894 1906 hist,pid = Indx[Obj.GetId()] 1895 1907 try: 1896 1908 strain = float(Obj.GetValue()) 1897 if strain >= 0: 1909 if UseList[hist]['Mustrain'][0] == 'generalized': 1910 if '4' in Snames[pid] and strain < 0: 1911 raise ValueError 1912 UseList[hist]['Mustrain'][4][pid] = strain 1913 else: 1914 if pid == 0 and strain < 0: 1915 raise ValueError 1916 elif pid == 1 and strain < -UseList[hist]['Mustrain'][1][0]: 1917 raise ValueError 1898 1918 UseList[hist]['Mustrain'][1][pid] = strain 1899 1919 except ValueError: 1900 1920 pass 1901 Obj.SetValue("%.5f"%(UseList[hist]['Mustrain'][1][pid])) #reset in case of error 1921 if UseList[hist]['Mustrain'][0] == 'generalized': 1922 Obj.SetValue("%.5f"%(UseList[hist]['Mustrain'][4][pid])) #reset in case of error 1923 else: 1924 Obj.SetValue("%.5f"%(UseList[hist]['Mustrain'][1][pid])) #reset in case of error 1925 G2plt.PlotStrain(self,data) 1902 1926 1903 1927 def OnStrainAxis(event): 1904 1928 Obj = event.GetEventObject() 1905 hist,pid = Indx[Obj.GetId()] 1906 axis = np.array(UseList[hist]['Mustrain'][3]) 1907 UseList[hist]['Mustrain'][3][pid] = Obj.GetValue() 1908 new = np.array(UseList[hist]['Mustrain'][3]) 1909 if not np.any(new): 1910 UseList[hist]['Mustrain'][3] += new-axis 1911 Obj.SetValue(UseList[hist]['Mustrain'][3][pid]) 1929 hist = Indx[Obj.GetId()] 1930 Saxis = Obj.GetValue().split() 1931 try: 1932 hkl = [int(Saxis[i]) for i in range(3)] 1933 except (ValueError,IndexError): 1934 hkl = UseList[hist]['Mustrain'][3] 1935 if not np.any(np.array(hkl)): 1936 hkl = UseList[hist]['Mustrain'][3] 1937 UseList[hist]['Mustrain'][3] = hkl 1938 h,k,l = hkl 1939 Obj.SetValue('%3d %3d %3d'%(h,k,l)) 1940 G2plt.PlotStrain(self,data) 1912 1941 1913 1942 def OnMDRef(event): … … 1929 1958 def OnMDAxis(event): 1930 1959 Obj = event.GetEventObject() 1931 hist,pid = Indx[Obj.GetId()] 1932 axis = np.array(UseList[hist]['MDtexture'][2]) 1933 UseList[hist]['MDtexture'][2][pid] = Obj.GetValue() 1934 new = np.array(UseList[hist]['MDtexture'][2]) 1935 if not np.any(new): 1936 UseList[hist]['MDtexture'][2] += new-axis 1937 Obj.SetValue(UseList[hist]['MDtexture'][2][pid]) 1960 hist = Indx[Obj.GetId()] 1961 Saxis = Obj.GetValue().split() 1962 try: 1963 hkl = [int(Saxis[i]) for i in range(3)] 1964 except (ValueError,IndexError): 1965 hkl = UseList[hist]['MDtexture'][2] 1966 if not np.any(np.array(hkl)): 1967 hkl = UseList[hist]['MDtexture'][2] 1968 UseList[hist]['MDtexture'][2] = hkl 1969 h,k,l = hkl 1970 Obj.SetValue('%3d %3d %3d'%(h,k,l)) 1938 1971 1939 1972 def OnExtRef(event): … … 2020 2053 mainSizer.Add((0,5),0) 2021 2054 elif UseList[item]['Size'][0] == 'uniaxial': 2022 sizeSizer.Add(wx.StaticText(dataDisplay,-1,' Unique axis: '),0,wx.ALIGN_CENTER_VERTICAL) 2023 axes = zip(['H:','K:','L:'],UseList[item]['Size'][3],range(3)) 2024 for ax,H,i in axes: 2025 Axis = wx.SpinCtrl(dataDisplay,wx.ID_ANY,ax,min=-3,max=3,size=wx.Size(40,20)) 2026 Axis.SetValue(H) 2027 Indx[Axis.GetId()] = [item,i] 2028 sizeSizer.Add(Axis) 2029 Axis.Bind(wx.EVT_SPINCTRL, OnSizeAxis) 2055 sizeSizer.Add(wx.StaticText(dataDisplay,-1,' Unique axis, H K L: '),0,wx.ALIGN_CENTER_VERTICAL) 2056 h,k,l = UseList[item]['Size'][3] 2057 sizeAxis = wx.TextCtrl(dataDisplay,-1,'%3d %3d %3d'%(h,k,l),style=wx.TE_PROCESS_ENTER) 2058 Indx[sizeAxis.GetId()] = item 2059 sizeAxis.Bind(wx.EVT_TEXT_ENTER,OnSizeAxis) 2060 sizeAxis.Bind(wx.EVT_KILL_FOCUS,OnSizeAxis) 2061 sizeSizer.Add(sizeAxis,0,wx.ALIGN_CENTER_VERTICAL) 2030 2062 mainSizer.Add(sizeSizer) 2031 2063 mainSizer.Add((0,5),0) … … 2071 2103 mainSizer.Add((0,5),0) 2072 2104 elif UseList[item]['Mustrain'][0] == 'uniaxial': 2073 strainSizer.Add(wx.StaticText(dataDisplay,-1,' Unique axis: '),0,wx.ALIGN_CENTER_VERTICAL) 2074 axes = zip(['H:','K:','L:'],UseList[item]['Mustrain'][3],range(3)) 2075 for ax,H,i in axes: 2076 Axis = wx.SpinCtrl(dataDisplay,wx.ID_ANY,ax,min=-3,max=3,size=wx.Size(40,20)) 2077 Axis.SetValue(H) 2078 Indx[Axis.GetId()] = [item,i] 2079 strainSizer.Add(Axis) 2080 Axis.Bind(wx.EVT_SPINCTRL, OnStrainAxis) 2105 strainSizer.Add(wx.StaticText(dataDisplay,-1,' Unique axis, H K L: '),0,wx.ALIGN_CENTER_VERTICAL) 2106 h,k,l = UseList[item]['Mustrain'][3] 2107 strAxis = wx.TextCtrl(dataDisplay,-1,'%3d %3d %3d'%(h,k,l),style=wx.TE_PROCESS_ENTER) 2108 Indx[strAxis.GetId()] = item 2109 strAxis.Bind(wx.EVT_TEXT_ENTER,OnStrainAxis) 2110 strAxis.Bind(wx.EVT_KILL_FOCUS,OnStrainAxis) 2111 strainSizer.Add(strAxis,0,wx.ALIGN_CENTER_VERTICAL) 2081 2112 mainSizer.Add(strainSizer) 2082 2113 mainSizer.Add((0,5),0) … … 2104 2135 Snames = G2spc.MustrainNames(SGData) 2105 2136 numb = len(Snames) 2106 if len(UseList[item]['Mustrain'][ 1]) < numb:2107 UseList[item]['Mustrain'][ 1] = numb*[0.0,]2108 UseList[item]['Mustrain'][ 2] = numb*[False,]2109 parms = zip(Snames,UseList[item]['Mustrain'][ 1],UseList[item]['Mustrain'][2],range(numb))2137 if len(UseList[item]['Mustrain'][4]) < numb: 2138 UseList[item]['Mustrain'][4] = numb*[0.0,] 2139 UseList[item]['Mustrain'][5] = numb*[False,] 2140 parms = zip(Snames,UseList[item]['Mustrain'][4],UseList[item]['Mustrain'][5],range(numb)) 2110 2141 strainSizer = wx.FlexGridSizer(numb%3+1,6,5,5) 2111 2142 for Pa,val,ref,id in parms: … … 2134 2165 mdVal.Bind(wx.EVT_KILL_FOCUS,OnMDVal) 2135 2166 mdSizer.Add(mdVal,0,wx.ALIGN_CENTER_VERTICAL) 2136 mdSizer.Add(wx.StaticText(dataDisplay,-1,' Unique axis: '),0,wx.ALIGN_CENTER_VERTICAL) 2137 axes = zip(['H:','K:','L:'],UseList[item]['MDtexture'][2],range(3)) 2138 for ax,H,i in axes: 2139 Axis = wx.SpinCtrl(dataDisplay,wx.ID_ANY,ax,min=-3,max=3,size=wx.Size(40,20)) 2140 Axis.SetValue(H) 2141 Indx[Axis.GetId()] = [item,i] 2142 mdSizer.Add(Axis) 2143 Axis.Bind(wx.EVT_SPINCTRL, OnMDAxis) 2167 mdSizer.Add(wx.StaticText(dataDisplay,-1,' Unique axis, H K L: '),0,wx.ALIGN_CENTER_VERTICAL) 2168 h,k,l = UseList[item]['MDtexture'][2] 2169 mdAxis = wx.TextCtrl(dataDisplay,-1,'%3d %3d %3d'%(h,k,l),style=wx.TE_PROCESS_ENTER) 2170 Indx[mdAxis.GetId()] = item 2171 mdAxis.Bind(wx.EVT_TEXT_ENTER,OnMDAxis) 2172 mdAxis.Bind(wx.EVT_KILL_FOCUS,OnMDAxis) 2173 mdSizer.Add(mdAxis,0,wx.ALIGN_CENTER_VERTICAL) 2144 2174 mainSizer.Add(mdSizer) 2145 2175 mainSizer.Add((0,5),0) … … 2169 2199 Size[1] += 30 #compensate for status bar 2170 2200 DData.SetScrollbars(10,10,Size[0]/10-4,Size[1]/10-10) 2201 dataDisplay.SetSize(Size) 2171 2202 self.dataFrame.setSizePosLeft(Size) 2172 dataDisplay.SetSize(Size)2173 2203 2174 2204 def OnHklfAdd(event): … … 2197 2227 2198 2228 def OnPwdrAdd(event): 2229 generalData = data['General'] 2230 SGData = generalData['SGData'] 2199 2231 UseList = data['Histograms'] 2232 NShkl = len(G2spc.MustrainNames(SGData)) 2200 2233 keyList = UseList.keys() 2201 2234 TextList = [] … … 2216 2249 'Scale':[1.0,False],'MDtexture':[1.0,False,[0,0,1]], 2217 2250 'Size':['isotropic',[10000.,0,],[False,False],[0,0,1]], 2218 'Mustrain':['isotropic',[0.0,0,],[False,False],[0,0,1]], 2251 'Mustrain':['isotropic',[1.0,0.0],[False,False],[0,0,1], 2252 NShkl*[0.01,],NShkl*[False,]], 2219 2253 'Extinction':[0.0,False],'Cutoff':0.01} 2220 2254 data['Histograms'] = UseList … … 2244 2278 2245 2279 def FillPawleyReflectionsGrid(): 2246 2247 2248 2249 2280 if data['Histograms']: 2250 2281 self.dataFrame.PawleyMenu.FindItemById(G2gd.wxID_PAWLEYLOAD).Enable(True) … … 2375 2406 self.dataFrame.Bind(wx.EVT_MENU, OnDataDelete, id=G2gd.wxID_DATADELETE) 2376 2407 UpdateDData() 2408 G2plt.PlotStrain(self,data) 2377 2409 elif text == 'Draw Options': 2378 2410 self.dataFrame.SetMenuBar(self.dataFrame.BlankMenu) -
trunk/GSASIIplot.py
r184 r193 2 2 import time 3 3 import copy 4 import os.path 4 5 import numpy as np 5 6 import numpy.linalg as nl … … 8 9 import wx.glcanvas 9 10 import matplotlib as mpl 11 import mpl_toolkits.mplot3d.axes3d as mp3d 10 12 import GSASIIpath 11 13 import GSASIIgrid as G2gd … … 32 34 atan2d = lambda x,y: 180.*math.atan2(y,x)/math.pi 33 35 atand = lambda x: 180.*math.atan(x)/math.pi 36 # numpy versions 37 npsind = lambda x: np.sin(x*np.pi/180.) 38 npcosd = lambda x: np.cos(x*np.pi/180.) 39 npacosd = lambda x: 180.*np.arccos(x)/np.pi 34 40 35 41 class G2PlotMpl(wx.Panel): … … 54 60 sizer=wx.BoxSizer(wx.VERTICAL) 55 61 sizer.Add(self.canvas,1,wx.EXPAND) 56 self.SetSizer(sizer) 62 self.SetSizer(sizer) 63 64 class G2Plot3D(wx.Panel): 65 def __init__(self,parent,id=-1,dpi=None,**kwargs): 66 wx.Panel.__init__(self,parent,id=id,**kwargs) 67 self.figure = mpl.figure.Figure(dpi=dpi,figsize=(6,6)) 68 self.canvas = Canvas(self,-1,self.figure) 69 self.toolbar = Toolbar(self.canvas) 70 71 self.toolbar.Realize() 72 73 sizer=wx.BoxSizer(wx.VERTICAL) 74 sizer.Add(self.canvas,1,wx.EXPAND) 75 sizer.Add(self.toolbar,0,wx.LEFT|wx.EXPAND) 76 self.SetSizer(sizer) 77 57 78 58 79 class G2PlotNoteBook(wx.Panel): … … 74 95 def addMpl(self,name=""): 75 96 page = G2PlotMpl(self.nb) 97 self.nb.AddPage(page,name) 98 99 self.plotList.append(name) 100 101 return page.figure 102 103 def add3D(self,name=""): 104 page = G2Plot3D(self.nb) 76 105 self.nb.AddPage(page,name) 77 106 … … 252 281 ypos = pick.get_ydata() 253 282 ind = event.ind 254 view = Page.toolbar._views.forward() 255 if view and 'line2' in str(pick): #apply offset only for picked powder pattern points 256 ind += np.searchsorted(xye[0],view[0][0]) 257 xy = zip(xpos[ind],ypos[ind])[0] 283 xy = zip(np.take(xpos,ind),np.take(ypos,ind))[0] 258 284 if self.PatternTree.GetItemText(PickId) == 'Peak List': 259 285 if ind.all() != [0]: #picked a data point … … 432 458 'i: interpolation method','s: color scheme','c: contour off') 433 459 else: 434 Choice = (' key press','d: offset down','u: offset up','c: contour on','s: toggle single plot','+: no selection') 460 Choice = (' key press','d: offset down','u: offset up','c: contour on', 461 's: toggle single plot','+: no selection') 435 462 cb = wx.ComboBox(self.G2plotNB.status,style=wx.CB_DROPDOWN|wx.CB_READONLY, 436 463 choices=Choice) … … 463 490 Ymax = max(Ymax,max(xye[1])) 464 491 offset = self.Offset*Ymax/100.0 465 Plot.set_title('Powder Patterns ')492 Plot.set_title('Powder Patterns: '+os.path.split(self.GSASprojectfile)[1]) 466 493 Plot.set_xlabel(r'$\mathsf{2\theta}$',fontsize=14) 467 494 Plot.set_ylabel('Intensity',fontsize=12) … … 486 513 Lines.append(Plot.axvline(limits[1][1],color='r',dashes=(5,5),picker=3.)) 487 514 if self.Contour: 515 488 516 if lenX == len(X): 489 517 ContourY.append(N) … … 527 555 acolor = mpl.cm.get_cmap(self.ContourColor) 528 556 Img = Plot.imshow(ContourZ,cmap=acolor,vmin=0,vmax=Ymax*self.Cmax,interpolation=self.Interpolate, 529 extent=[ContourX[0],ContourX[-1],ContourY[0],ContourY[-1]],aspect='auto' )557 extent=[ContourX[0],ContourX[-1],ContourY[0],ContourY[-1]],aspect='auto',origin='lower') 530 558 Page.figure.colorbar(Img) 531 559 else: … … 680 708 Plot.plot(X,V,'+',color='k',label='G+L2 peak') 681 709 Plot.legend(loc='best') 710 Page.canvas.draw() 711 712 def PlotStrain(self,data): 713 # in this instance data is for a phase 714 PatternId = self.PatternId 715 generalData = data['General'] 716 SGData = generalData['SGData'] 717 MuStrKeys = G2spc.MustrainNames(SGData) 718 cell = generalData['Cell'][1:] 719 A,B = G2lat.cell2AB(cell[:6]) 720 Vol = cell[6] 721 useList = data['Histograms'] 722 numPlots = len(useList) 723 724 try: 725 plotNum = self.G2plotNB.plotList.index('Microstrain') 726 Page = self.G2plotNB.nb.GetPage(plotNum) 727 Page.figure.clf() 728 Plot = mp3d.Axes3D(Page.figure) 729 except ValueError,error: 730 Plot = mp3d.Axes3D(self.G2plotNB.add3D('Microstrain')) 731 plotNum = self.G2plotNB.plotList.index('Microstrain') 732 Page = self.G2plotNB.nb.GetPage(plotNum) 733 Page.SetFocus() 734 self.G2plotNB.status.SetStatusText('Adjust frame size to get desired aspect ratio',1) 735 736 for item in useList: 737 if useList[item]['Show']: 738 muStrain = useList[item]['Mustrain'] 739 PHI = np.linspace(0.,360.,30,True) 740 PSI = np.linspace(0.,180.,30,True) 741 X = np.outer(npsind(PHI),npsind(PSI)) 742 Y = np.outer(npcosd(PHI),npsind(PSI)) 743 Z = np.outer(np.ones(np.size(PHI)),npcosd(PSI)) 744 if muStrain[0] == 'isotropic': 745 muiso = muStrain[1][0]*math.pi/0.018 746 X *= muiso 747 Y *= muiso 748 Z *= muiso 749 750 elif muStrain[0] == 'uniaxial': 751 def uniaxMustrain(xyz,muiso,muaniso,axes): 752 cp = abs(np.dot(xyz,axes)) 753 S = muiso+muaniso*cp 754 return S*xyz*math.pi/0.018 755 muiso,muaniso = muStrain[1][:2] 756 axes = np.inner(A,np.array(muStrain[3])) 757 axes /= nl.norm(axes) 758 Shkl = np.array(muStrain[1]) 759 Shape = X.shape[0] 760 XYZ = np.dstack((X,Y,Z)) 761 XYZ = np.nan_to_num(np.apply_along_axis(uniaxMustrain,2,XYZ,muiso,muaniso,axes)) 762 X,Y,Z = np.dsplit(XYZ,3) 763 X = X[:,:,0] 764 Y = Y[:,:,0] 765 Z = Z[:,:,0] 766 767 elif muStrain[0] == 'generalized': 768 def genMustrain(xyz,SGData,A,Shkl): 769 uvw = np.inner(A.T,xyz) 770 Strm = np.array(G2spc.MustrainCoeff(uvw,SGData)) 771 sum = np.sqrt(np.sum(np.multiply(Shkl,Strm)))*math.pi/0.018 772 return sum*xyz 773 Shkl = np.array(muStrain[4]) 774 if np.any(Shkl): 775 Shape = X.shape[0] 776 XYZ = np.dstack((X,Y,Z)) 777 XYZ = np.nan_to_num(np.apply_along_axis(genMustrain,2,XYZ,SGData,A,Shkl)) 778 X,Y,Z = np.dsplit(XYZ,3) 779 X = X[:,:,0] 780 Y = Y[:,:,0] 781 Z = Z[:,:,0] 782 783 if np.any(X) and np.any(Y) and np.any(Z): 784 Plot.plot_surface(X,Y,Z,rstride=1,cstride=1,color='g') 785 786 Plot.set_xlabel('X') 787 Plot.set_ylabel('Y') 788 Plot.set_zlabel('Z') 682 789 Page.canvas.draw() 683 790 -
trunk/GSASIIspc.py
r170 r193 555 555 SHKL += ['S211','S121','S112'] 556 556 return SHKL 557 557 558 def MustrainCoeff(HKL,SGData): 559 #NB: order of terms is the same as returned by MustrainNames 560 laue = SGData['SGLaue'] 561 uniq = SGData['SGUniq'] 562 h,k,l = HKL 563 Strm = [] 564 if laue in ['m3','m3m']: 565 Strm.append(h**4+k**4+l**4) 566 Strm.append(3.0*((h*k)**2+(h*l)**2+(k*l)**2)) 567 elif laue in ['6/m','6/mmm','3m1']: 568 Strm.append(h**4+k**4+2.0*k*h**3+2.0*h*k**3+3.0*(h*k)**2) 569 Strm.append(l**4) 570 Strm.append(3.0*((h*l)**2+(k*l)**2+h*k*l**2)) 571 elif laue in ['31m','3']: 572 Strm.append(h**4+k**4+2.0*k*h**3+2.0*h*k**3+3.0*(h*k)**2) 573 Strm.append(l**4) 574 Strm.append(3.0*((h*l)**2+(k*l)**2+h*k*l**2)) 575 Strm.append(4.0*h*k*l*(h+k)) 576 elif laue in ['3R','3mR']: 577 Strm.append(h**4+k**4+l**4) 578 Strm.append(3.0*((h*k)**2+(h*l)**2+(k*l)**2)) 579 Strm.append(2.0*(h*l**3+l*k**3+k*h**3)+2.0*(l*h**3+k*l**3+l*k**3)) 580 Strm.append(4.0*(k*l*h**2+h*l*k**2+h*k*l**2)) 581 elif laue in ['4/m','4/mmm']: 582 Strm.append(h**4+k**4) 583 Strm.append(l**4) 584 Strm.append(3.0*(h*k)**2) 585 Strm.append(3.0*((h*l)**2+(k*l)**2)) 586 elif laue in ['mmm']: 587 Strm.append(h**4) 588 Strm.append(k**4) 589 Strm.append(l**4) 590 Strm.append(3.0*(h*k)**2) 591 Strm.append(3.0*(h*l)**2) 592 Strm.append(3.0*(k*l)**2) 593 elif laue in ['2/m']: 594 Strm.append(h**4) 595 Strm.append(k**4) 596 Strm.append(l**4) 597 Strm.append(3.0*(h*k)**2) 598 Strm.append(3.0*(h*l)**2) 599 Strm.append(3.0*(k*l)**2) 600 if uniq == 'a': 601 Strm.append(2.0*k*l**3) 602 Strm.append(2.0*l*k**3) 603 Strm.append(4.0*k*l*h**2) 604 elif uniq == 'b': 605 Strm.append(2.0*l*h**3) 606 Strm.append(2.0*h*l**3) 607 Strm.append(4.0*h*l*k**2) 608 elif uniq == 'c': 609 Strm.append(2.0*h*k**3) 610 Strm.append(2.0*k*h**3) 611 Strm.append(4.0*h*k*l**2) 612 else: 613 Strm.append(h**4) 614 Strm.append(k**4) 615 Strm.append(l**4) 616 Strm.append(3.0*(h*k)**2) 617 Strm.append(3.0*(h*l)**2) 618 Strm.append(3.0*(k*l)**2) 619 Strm.append(2.0*k*h**3) 620 Strm.append(2.0*h*l**3) 621 Strm.append(2.0*l*k**3) 622 Strm.append(2.0*h*k**3) 623 Strm.append(2.0*l*h**3) 624 Strm.append(2.0*k*l**3) 625 Strm.append(4.0*k*l*h**2) 626 Strm.append(4.0*h*l*k**2) 627 Strm.append(4.0*k*h*l**2) 628 return Strm 629 630 def Muiso2Shkl(muiso,SGData,cell): 631 #this is to convert isotropic mustrain to generalized Shkls - doesn't work just now 632 import GSASIIlattice as G2lat 633 from scipy.optimize import fmin 634 A = G2lat.cell2AB(cell)[0] 635 def minMus(Shkl,H,muiso,SGData,A): 636 U = np.inner(A.T,H) 637 S = np.array(MustrainCoeff(H.T,SGData)) 638 sum = np.sqrt(np.sum(np.multiply(S,Shkl))) 639 return abs(muiso-sum*H) 640 laue = SGData['SGLaue'] 641 if laue in ['m3','m3m']: 642 H = [[1,0,0],[1,1,0]] 643 S0 = [0.01,0.01] 644 elif laue in ['6/m','6/mmm','3m1']: 645 H = [[1,0,0],[0,0,1],[1,0,1]] 646 S0 = [0.01,0.01,0.01] 647 elif laue in ['31m','3']: 648 H = [[1,0,0],[0,0,1],[1,0,1],[1,1,1]] 649 S0 = [0.01,0.01,0.01,0.01] 650 elif laue in ['3R','3mR']: 651 H = [[1,0,0],[1,1,0],[1,0,1],[1,1,1]] 652 S0 = [0.01,0.01,0.01,0.01] 653 elif laue in ['4/m','4/mmm']: 654 H = [[1,0,0],[0,0,1],[1,1,0],[1,0,1]] 655 S0 = [0.01,0.01,0.01,0.01] 656 elif laue in ['mmm']: 657 H = [[1,0,0],[0,1,0],[0,0,1],[1,1,0],[1,0,1],[0,1,1]] 658 S0 = [0.01,0.01,0.01,0.01,0.01,0.01] 659 elif laue in ['2/m']: 660 H = [[1,0,0],[0,1,0],[0,0,1],[1,1,0],[1,0,1],[0,1,1]] 661 if uniq == 'a': 662 H.append([0,1,-1]) 663 H.append([0,-2,1]) 664 elif uniq == 'b': 665 H.append([1,0,-1]) 666 H.append([-2,0,1]) 667 elif uniq == 'c': 668 H.append([1,-1,0]) 669 H.append([-2,1,0]) 670 H.append([1,1,1]) 671 S0 = [9*[0.01,]] 672 else: 673 H = [[1,0,0],[0,1,0],[0,0,1],[1,1,0],[1,0,1],[0,1,1], 674 [-1,1,0],[1,0,-1],[0,-1,1],[1,-2,0],[-2,0,1],[0,1,-2], 675 [1,-1,1],[-1, 1, 1],[1,-1,1]] 676 S0 = [15*[0.01,]] 677 H = np.array(H) 678 S0 = np.array(S0) 679 return fmin(minMus,S0,(H,muiso,SGData,A)) 680 558 681 def SytSym(XYZ,SGData): 559 682 '''
Note: See TracChangeset
for help on using the changeset viewer.