Changeset 193


Ignore:
Timestamp:
Dec 22, 2010 2:29:41 PM (12 years ago)
Author:
vondreele
Message:

various fixes, but still bugs.
GSASII.py - add more sample parameters
GSASIIgrid.py - add save/load image controls; turn image plot back on
GSASIIimgGUI.py - load/save image controls
GSASIIIO.py - find 'Temp' in comments & load value as Temperature
GSASIIlattice.py - change 'laue' to 'SGLaue'
GSASIIphsGUI.py - change mustrain GUI
GSASIIplot.py - fix point picking in powder plots, add mustrain surface plotting
GSASIIspc.py - add conversion of isotropic to generalized mustrain converter (doesn't work yet)

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASII.py

    r186 r193  
    307307                self.dirname = dlg.GetDirectory()
    308308                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)
    310310                    if not Data:                                                    #if Data rejected by user - go to next one
    311311                        continue
     
    313313                    DataType = DataType.strip()[0:3]                                #just 1st 3 chars
    314314                    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}
    317319                    try:
    318320                        for Item in Data:
  • trunk/GSASIIIO.py

    r188 r193  
    4747        dlg.Destroy()
    4848    if result == wx.ID_NO: return (0,0)
     49    Temperature = 300
    4950       
    5051    self.IparmName = GetInstrumentFile(self,filename)
     
    7374            else:
    7475                Comments.append(S[:-1])
     76                if 'Temp' in S:
     77                    Temperature = float(S[:-1].split()[-1])
    7578        File.close()
    7679    finally:
     
    98101        finally:
    99102            dlg.Destroy()
    100     return FoundData,Iparm,Comments
     103    return FoundData,Iparm,Comments,Temperature
    101104
    102105def GetInstrumentFile(self,filename):
  • trunk/GSASIIgrid.py

    r187 r193  
    2323
    2424[ 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)]
    2727
    2828[ wxID_MASKCOPY,
     
    151151        parent.Append(help='Copy image controls to other images',
    152152            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
    153158                   
    154159    def _init_coll_Mask_Items(self,parent):
     
    716721        data = self.PatternTree.GetItemPyData(item)
    717722        G2imG.UpdateImageControls(self,data,masks)
    718 #        G2plt.PlotImage(self)
     723        G2plt.PlotImage(self)
    719724    elif self.PatternTree.GetItemText(item) == 'Masks':
    720725        self.dataFrame.SetTitle('Masks')
     
    723728        data = self.PatternTree.GetItemPyData(item)
    724729        G2imG.UpdateMasks(self,data)
    725 #        G2plt.PlotImage(self)
     730        G2plt.PlotImage(self)
    726731    elif self.PatternTree.GetItemText(item) == 'HKL Plot Controls':
    727732        self.PickId = item
  • trunk/GSASIIimgGUI.py

    r184 r193  
    267267            finally:
    268268                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()
    269309                                       
    270310    colorList = [m for m in mpl.cm.datad.keys() if not m.endswith("_r")]
     
    283323    self.dataFrame.Bind(wx.EVT_MENU, OnSaveIntegrate, id=G2gd.wxID_SAVEINTG)
    284324    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)
    285327    self.dataFrame.ImageEdit.Enable(id=G2gd.wxID_SAVEINTG,enable=False)   
    286328    self.dataDisplay = wx.Panel(self.dataFrame)
  • trunk/GSASIIlattice.py

    r189 r193  
    469469    return sortHKLd(HKL,True,False)
    470470   
    471 def GenHLaue(dmin,Laue,SGLatt,SGUniq,A):
     471def GenHLaue(dmin,SGLaue,SGLatt,SGUniq,A):
    472472    '''Generate the crystallographically unique powder diffraction reflections
    473473    for a lattice and Bravais type
    474474    '''
    475475# 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',
    477477#                            '3m1', '31m', '3', '3R', '3mR', 'm3', 'm3m'
    478478# SGLatt - lattice centering = 'P','A','B','C','I','F'
     
    483483    import math
    484484    #finds maximum allowed hkl for given A within dmin
    485     if Laue in ['3R','3mR']:        #Rhombohedral axes
     485    if SGLaue in ['3R','3mR']:        #Rhombohedral axes
    486486        Hmax = [0,0,0]
    487487        cell = A2cell(A)
     
    496496    dminsq = 1./(dmin**2)
    497497    HKL = []
    498     if Laue == '-1':                       #triclinic
     498    if SGLaue == '-1':                       #triclinic
    499499        for l in range(-Hmax[2],Hmax[2]+1):
    500500            for k in range(-Hmax[1],Hmax[1]+1):
     
    507507                    if 0 < rdsq <= dminsq:
    508508                        HKL.append([h,k,l,1/math.sqrt(rdsq)])
    509     elif Laue == '2/m':                #monoclinic
     509    elif SGLaue == '2/m':                #monoclinic
    510510        axisnum = 1 + ['a','b','c'].index(SGUniq)
    511511        Hmax = SwapIndx(axisnum,Hmax)
     
    523523                            HKL.append([h,k,l,1/math.sqrt(rdsq)])
    524524                    [h,k,l] = SwapIndx(axisnum,[h,k,l])
    525     elif Laue in ['mmm','4/m','6/m']:            #orthorhombic
     525    elif SGLaue in ['mmm','4/m','6/m']:            #orthorhombic
    526526        for l in range(Hmax[2]+1):
    527527            for h in range(Hmax[0]+1):
    528528                kmin = 1
    529                 if Laue == 'mmm' or h ==0: kmin = 0
     529                if SGLaue == 'mmm' or h ==0: kmin = 0
    530530                for k in range(kmin,Hmax[1]+1):
    531531                    H = []
     
    535535                        if 0 < rdsq <= dminsq:
    536536                            HKL.append([h,k,l,1/math.sqrt(rdsq)])
    537     elif Laue in ['4/mmm','6/mmm']:                  #tetragonal & hexagonal
     537    elif SGLaue in ['4/mmm','6/mmm']:                  #tetragonal & hexagonal
    538538        for l in range(Hmax[2]+1):
    539539            for h in range(Hmax[0]+1):
     
    545545                        if 0 < rdsq <= dminsq:
    546546                            HKL.append([h,k,l,1/math.sqrt(rdsq)])
    547     elif Laue in ['3m1','31m','3','3R','3mR']:                  #trigonals
     547    elif SGLaue in ['3m1','31m','3','3R','3mR']:                  #trigonals
    548548        for l in range(-Hmax[2],Hmax[2]+1):
    549549            hmin = 0
    550550            if l < 0: hmin = 1
    551551            for h in range(hmin,Hmax[0]+1):
    552                 if Laue in ['3R','3']:
     552                if SGLaue in ['3R','3']:
    553553                    kmax = h
    554554                    kmin = -int((h-1.)/2.)
     
    556556                    kmin = 0
    557557                    kmax = h
    558                     if Laue in ['3m1','3mR'] and l < 0: kmax = h-1
    559                     if Laue == '31m' and l < 0: kmin = 1
     558                    if SGLaue in ['3m1','3mR'] and l < 0: kmax = h-1
     559                    if SGLaue == '31m' and l < 0: kmin = 1
    560560                for k in range(kmin,kmax+1):
    561561                    H = []
    562562                    if CentCheck(SGLatt,[h,k,l]): H=[h,k,l]
    563                     if Laue in ['3R','3mR']:
     563                    if SGLaue in ['3R','3mR']:
    564564                        H = Hx2Rh(H)
    565565                    if H:
     
    572572                lmin = 0
    573573                lmax = k
    574                 if Laue =='m3':
     574                if SGLaue =='m3':
    575575                    lmax = h-1
    576576                    if h == k: lmax += 1
  • trunk/GSASIIphsGUI.py

    r190 r193  
    18491849        def OnSizeType(event):
    18501850            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()
    18531853            UpdateDData()
    18541854           
     
    18631863            try:
    18641864                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
    18671870            except ValueError:
    18681871                pass
    18691872            Obj.SetValue("%.1f"%(UseList[hist]['Size'][1][pid]))          #reset in case of error
    18701873           
    1871         def OnSizeAxis(event):
     1874        def OnSizeAxis(event):           
    18721875            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))
    18801887                       
    18811888        def OnStrainType(event):
    18821889            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)
    18851893            UpdateDData()
    18861894           
     
    18881896            Obj = event.GetEventObject()
    18891897            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()
    18911902           
    18921903        def OnStrainVal(event):
     1904            Snames = G2spc.MustrainNames(SGData)
    18931905            Obj = event.GetEventObject()
    18941906            hist,pid = Indx[Obj.GetId()]
    18951907            try:
    18961908                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
    18981918                    UseList[hist]['Mustrain'][1][pid] = strain
    18991919            except ValueError:
    19001920                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)
    19021926           
    19031927        def OnStrainAxis(event):
    19041928            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)
    19121941
    19131942        def OnMDRef(event):
     
    19291958        def OnMDAxis(event):
    19301959            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))
    19381971           
    19391972        def OnExtRef(event):
     
    20202053                    mainSizer.Add((0,5),0)
    20212054                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)
    20302062                    mainSizer.Add(sizeSizer)
    20312063                    mainSizer.Add((0,5),0)
     
    20712103                    mainSizer.Add((0,5),0)
    20722104                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)
    20812112                    mainSizer.Add(strainSizer)
    20822113                    mainSizer.Add((0,5),0)
     
    21042135                    Snames = G2spc.MustrainNames(SGData)
    21052136                    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))
    21102141                    strainSizer = wx.FlexGridSizer(numb%3+1,6,5,5)
    21112142                    for Pa,val,ref,id in parms:
     
    21342165                mdVal.Bind(wx.EVT_KILL_FOCUS,OnMDVal)
    21352166                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)
    21442174                mainSizer.Add(mdSizer)
    21452175                mainSizer.Add((0,5),0)
     
    21692199        Size[1] += 30                           #compensate for status bar
    21702200        DData.SetScrollbars(10,10,Size[0]/10-4,Size[1]/10-10)
     2201        dataDisplay.SetSize(Size)
    21712202        self.dataFrame.setSizePosLeft(Size)
    2172         dataDisplay.SetSize(Size)
    21732203       
    21742204    def OnHklfAdd(event):
     
    21972227       
    21982228    def OnPwdrAdd(event):
     2229        generalData = data['General']
     2230        SGData = generalData['SGData']
    21992231        UseList = data['Histograms']
     2232        NShkl = len(G2spc.MustrainNames(SGData))
    22002233        keyList = UseList.keys()
    22012234        TextList = []
     
    22162249                            'Scale':[1.0,False],'MDtexture':[1.0,False,[0,0,1]],
    22172250                            '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,]],                           
    22192253                            'Extinction':[0.0,False],'Cutoff':0.01}
    22202254                    data['Histograms'] = UseList
     
    22442278
    22452279    def FillPawleyReflectionsGrid():
    2246        
    2247            
    2248            
    22492280        if data['Histograms']:
    22502281            self.dataFrame.PawleyMenu.FindItemById(G2gd.wxID_PAWLEYLOAD).Enable(True)
     
    23752406            self.dataFrame.Bind(wx.EVT_MENU, OnDataDelete, id=G2gd.wxID_DATADELETE)
    23762407            UpdateDData()           
     2408            G2plt.PlotStrain(self,data)
    23772409        elif text == 'Draw Options':
    23782410            self.dataFrame.SetMenuBar(self.dataFrame.BlankMenu)
  • trunk/GSASIIplot.py

    r184 r193  
    22import time
    33import copy
     4import os.path
    45import numpy as np
    56import numpy.linalg as nl
     
    89import wx.glcanvas
    910import matplotlib as mpl
     11import mpl_toolkits.mplot3d.axes3d as mp3d
    1012import GSASIIpath
    1113import GSASIIgrid as G2gd
     
    3234atan2d = lambda x,y: 180.*math.atan2(y,x)/math.pi
    3335atand = lambda x: 180.*math.atan(x)/math.pi
     36# numpy versions
     37npsind = lambda x: np.sin(x*np.pi/180.)
     38npcosd = lambda x: np.cos(x*np.pi/180.)
     39npacosd = lambda x: 180.*np.arccos(x)/np.pi
    3440   
    3541class G2PlotMpl(wx.Panel):   
     
    5460        sizer=wx.BoxSizer(wx.VERTICAL)
    5561        sizer.Add(self.canvas,1,wx.EXPAND)
    56         self.SetSizer(sizer)           
     62        self.SetSizer(sizer)
     63       
     64class 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               
    5778               
    5879class G2PlotNoteBook(wx.Panel):
     
    7495    def addMpl(self,name=""):
    7596        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)
    76105        self.nb.AddPage(page,name)
    77106       
     
    252281        ypos = pick.get_ydata()
    253282        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]
    258284        if self.PatternTree.GetItemText(PickId) == 'Peak List':
    259285            if ind.all() != [0]:                                    #picked a data point
     
    432458            'i: interpolation method','s: color scheme','c: contour off')
    433459    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')
    435462    cb = wx.ComboBox(self.G2plotNB.status,style=wx.CB_DROPDOWN|wx.CB_READONLY,
    436463        choices=Choice)
     
    463490        Ymax = max(Ymax,max(xye[1]))
    464491    offset = self.Offset*Ymax/100.0
    465     Plot.set_title('Powder Patterns')
     492    Plot.set_title('Powder Patterns: '+os.path.split(self.GSASprojectfile)[1])
    466493    Plot.set_xlabel(r'$\mathsf{2\theta}$',fontsize=14)
    467494    Plot.set_ylabel('Intensity',fontsize=12)
     
    486513            Lines.append(Plot.axvline(limits[1][1],color='r',dashes=(5,5),picker=3.))                   
    487514        if self.Contour:
     515           
    488516            if lenX == len(X):
    489517                ContourY.append(N)
     
    527555        acolor = mpl.cm.get_cmap(self.ContourColor)
    528556        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')
    530558        Page.figure.colorbar(Img)
    531559    else:
     
    680708    Plot.plot(X,V,'+',color='k',label='G+L2 peak')
    681709    Plot.legend(loc='best')
     710    Page.canvas.draw()
     711   
     712def 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')
    682789    Page.canvas.draw()
    683790           
  • trunk/GSASIIspc.py

    r170 r193  
    555555        SHKL += ['S211','S121','S112']
    556556        return SHKL
    557        
     557
     558def 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   
     630def 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       
    558681def SytSym(XYZ,SGData):
    559682    '''
Note: See TracChangeset for help on using the changeset viewer.