Changeset 2175


Ignore:
Timestamp:
Mar 17, 2016 1:52:26 PM (6 years ago)
Author:
vondreele
Message:

modify DIFFaXDialog - more parameters
add selected are plot as a pylab plot

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIgrid.py

    r2172 r2175  
    500500        self.panel = wx.Panel(self)         #just a dummy - gets destroyed in Draw!
    501501        self.ctrls = ctrls
     502        self.calcType = 'powder pattern'
     503        self.plane = 'h0l'
     504        self.planeChoice = ['h0l','0kl','hhl','h-hl',]
     505        self.lmax = '2'
     506        self.lmaxChoice = ['1','2','3','4','5',]
     507        self.mult = '2'
     508        self.multChoice = ['1','2','3','4','5','6','7','8','9',]
    502509        self.Draw()
    503510       
    504511    def Draw(self):
    505512       
    506        
     513        def OnCalcType(event):
     514            self.calcType = calcType.GetValue()
     515            self.Draw()
     516           
     517        def OnPlane(event):
     518            self.plane = plane.GetValue()
     519           
     520        def OnMaxL(event):
     521            self.lmax = lmax.GetValue()
     522           
     523        def OnMult(event):
     524            self.mult = mult.GetValue()
    507525       
    508526        self.panel.Destroy()
     
    510528        mainSizer = wx.BoxSizer(wx.VERTICAL)
    511529        mainSizer.Add(wx.StaticText(self.panel,label=' Controls for DIFFaX'),0,WACV)
    512        
    513 
     530        calcChoice = ['powder pattern','selected area']
     531        calcSizer = wx.BoxSizer(wx.HORIZONTAL)
     532        calcSizer.Add(wx.StaticText(self.panel,label=' Select calculation type: '),0,WACV)
     533        calcType = wx.ComboBox(self.panel,value=self.calcType,choices=calcChoice,
     534            style=wx.CB_READONLY|wx.CB_DROPDOWN)
     535        calcType.Bind(wx.EVT_COMBOBOX,OnCalcType)
     536        calcSizer.Add(calcType,0,WACV)
     537        mainSizer.Add(calcSizer)
     538        if 'selected' in self.calcType:
     539            planeSizer = wx.BoxSizer(wx.HORIZONTAL)
     540            planeSizer.Add(wx.StaticText(self.panel,label=' Select plane: '),0,WACV)
     541            plane = wx.ComboBox(self.panel,value=self.plane,choices=self.planeChoice,
     542                style=wx.CB_READONLY|wx.CB_DROPDOWN)
     543            plane.Bind(wx.EVT_COMBOBOX,OnPlane)
     544            planeSizer.Add(plane,0,WACV)
     545            planeSizer.Add(wx.StaticText(self.panel,label=' Max. l index: '),0,WACV)
     546            lmax = wx.ComboBox(self.panel,value=self.lmax,choices=self.lmaxChoice,
     547                style=wx.CB_READONLY|wx.CB_DROPDOWN)
     548            lmax.Bind(wx.EVT_COMBOBOX,OnMaxL)
     549            planeSizer.Add(lmax,0,WACV)           
     550            mainSizer.Add(planeSizer)
     551            multSizer = wx.BoxSizer(wx.HORIZONTAL)
     552            multSizer.Add(wx.StaticText(self.panel,label=' Image scale: '),0,WACV)
     553            mult = wx.ComboBox(self.panel,value=self.mult,choices=self.multChoice,
     554                style=wx.CB_READONLY|wx.CB_DROPDOWN)
     555            mult.Bind(wx.EVT_COMBOBOX,OnMult)
     556            multSizer.Add(mult,0,WACV)
     557            mainSizer.Add(multSizer)
    514558        OkBtn = wx.Button(self.panel,-1,"Ok")
    515559        OkBtn.Bind(wx.EVT_BUTTON, self.OnOk)
     
    529573       
    530574    def GetSelection(self):
    531         return self.ctrls
     575        if 'powder' in self.calcType:
     576            return '0\n0\n3\n',''
     577        elif 'selected' in self.calcType:
     578            return '0\n0\n4\n1\n%d\n%d\n16\n1\n%d\n0\nend\n'%    \
     579                (self.planeChoice.index(self.plane)+1,self.lmaxChoice.index(self.lmax)+1,
     580                self.multChoice.index(self.mult)+1),self.plane
    532581
    533582    def OnOk(self,event):
     
    16901739        self.LayerDataEdit.Append(id=wxID_LOADDIFFAX, kind=wx.ITEM_NORMAL,text='Load from DIFFaX file',
    16911740            help='Load layer info from DIFFaX file')
    1692         self.LayerDataEdit.Append(id=wxID_LAYERSIMULATE, kind=wx.ITEM_NORMAL,text='Simulate PWDR pattern',
    1693             help='Simulate powder pattern from layer stacking')
     1741        self.LayerDataEdit.Append(id=wxID_LAYERSIMULATE, kind=wx.ITEM_NORMAL,text='Simulate pattern',
     1742            help='Simulate diffraction pattern from layer stacking')
    16941743        self.PostfillDataMenu()
    16951744                 
  • trunk/GSASIIphsGUI.py

    r2174 r2175  
    24212421            toler.SetValue('%.3f'%(Layers['Toler']))
    24222422           
     2423        def OnSadpPlot(event):
     2424            sadpPlot.SetValue(False)
     2425            import pylab as pl
     2426            pl.clf()
     2427            pl.imshow(Layers['Sadp']['Img'],aspect='equal')
     2428            pl.title(Layers['Sadp']['Plane'])
     2429            pl.show()
     2430           
    24232431        def CellSizer():
    24242432           
     
    28162824            toler.Bind(wx.EVT_KILL_FOCUS,OnToler)
    28172825            laueSizer.Add(toler,0,WACV)
     2826        if 'Sadp' in Layers:
     2827            sadpPlot = wx.CheckBox(layerData,label=' Plot selected area diffraction?')
     2828            sadpPlot.Bind(wx.EVT_CHECKBOX,OnSadpPlot)
     2829            laueSizer.Add(sadpPlot,0,WACV)
    28182830        topSizer.Add(laueSizer,0,WACV)
    28192831        topSizer.Add(wx.StaticText(layerData,label=' Reference unit cell for all layers:'),0,WACV)
     
    28632875       
    28642876    def OnSimulate(event):
    2865         UseList = []
    2866         for item in data['Histograms']:
    2867             if 'PWDR' in item:
    2868                 UseList.append(item)
    2869         if not UseList:
    2870             wx.MessageBox('No PWDR data for this phase to simulate',caption='Data error',style=wx.ICON_EXCLAMATION)
    2871             return
    2872         dlg = wx.SingleChoiceDialog(G2frame,'Data to simulate','Select',UseList)
     2877        ctrls = ''
     2878        dlg = G2gd.DIFFaXcontrols(G2frame,ctrls)
    28732879        if dlg.ShowModal() == wx.ID_OK:
    2874             sel = dlg.GetSelection()
    2875             HistName = UseList[sel]
     2880            ctrls,plane = dlg.GetSelection()
     2881            data['Layers']['Sadp'] = {}
     2882            data['Layers']['Sadp']['Plane'] = plane
    28762883        else:
    28772884            return
    2878         dlg.Destroy()
    2879         PWDR = data['Histograms'][HistName]
    2880         G2frame.PatternId = G2gd.GetPatternTreeItemId(G2frame,G2frame.root,HistName)
    2881         sample = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(
    2882             G2frame,G2frame.PatternId, 'Sample Parameters'))
    2883         scale = sample['Scale'][0]
    2884         background = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(
    2885             G2frame,G2frame.PatternId, 'Background'))       
    2886         limits = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(
    2887             G2frame,G2frame.PatternId, 'Limits'))[1]
    2888         inst = G2frame.PatternTree.GetItemPyData(
    2889             G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId, 'Instrument Parameters'))[0]
    2890         if 'T' in inst['Type'][0]:
    2891             wx.MessageBox("Can't simulate neutron TOF patterns yet",caption='Data error',style=wx.ICON_EXCLAMATION)
    2892             return           
    2893         profile = G2frame.PatternTree.GetItemPyData(G2frame.PatternId)[1]
    2894         ctrls = {}
    2895         dlg = G2gd.DIFFaXcontrols(G2frame,ctrls)
    2896         if dlg.ShowModal() == wx.ID_OK:
    2897             ctrls = dlg.GetSelection()
    2898         else:
    2899             return
    2900         dlg.Destroy()       
    2901         G2pwd.StackSim(data['Layers'],HistName,scale,background,limits,inst,profile)
    2902         G2plt.PlotPatterns(G2frame,plotType='PWDR')
     2885        if ctrls == '0\n0\n3\n':    #powder pattern
     2886            UseList = []
     2887            for item in data['Histograms']:
     2888                if 'PWDR' in item:
     2889                    UseList.append(item)
     2890            if not UseList:
     2891                wx.MessageBox('No PWDR data for this phase to simulate',caption='Data error',style=wx.ICON_EXCLAMATION)
     2892                return
     2893            dlg = wx.SingleChoiceDialog(G2frame,'Data to simulate','Select',UseList)
     2894            if dlg.ShowModal() == wx.ID_OK:
     2895                sel = dlg.GetSelection()
     2896                HistName = UseList[sel]
     2897            else:
     2898                return
     2899            dlg.Destroy()
     2900            PWDR = data['Histograms'][HistName]
     2901            G2frame.PatternId = G2gd.GetPatternTreeItemId(G2frame,G2frame.root,HistName)
     2902            sample = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(
     2903                G2frame,G2frame.PatternId, 'Sample Parameters'))
     2904            scale = sample['Scale'][0]
     2905            background = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(
     2906                G2frame,G2frame.PatternId, 'Background'))       
     2907            limits = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(
     2908                G2frame,G2frame.PatternId, 'Limits'))[1]
     2909            inst = G2frame.PatternTree.GetItemPyData(
     2910                G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId, 'Instrument Parameters'))[0]
     2911            if 'T' in inst['Type'][0]:
     2912                wx.MessageBox("Can't simulate neutron TOF patterns yet",caption='Data error',style=wx.ICON_EXCLAMATION)
     2913                return           
     2914            profile = G2frame.PatternTree.GetItemPyData(G2frame.PatternId)[1]
     2915            dlg.Destroy()       
     2916            G2pwd.StackSim(data['Layers'],ctrls,HistName,scale,background,limits,inst,profile)
     2917            G2plt.PlotPatterns(G2frame,plotType='PWDR')
     2918        else:   #selected area
     2919            G2pwd.StackSim(data['Layers'],ctrls)
     2920        wx.CallAfter(UpdateLayerData)
    29032921       
    29042922################################################################################
  • trunk/GSASIIpwd.py

    r2174 r2175  
    17381738################################################################################
    17391739
    1740 def StackSim(Layers,HistName,scale,background,limits,inst,profile):
     1740def StackSim(Layers,ctrls,HistName='',scale=0.,background={},limits=[],inst={},profile=[]):
    17411741    '''Simulate powder pattern from stacking faults using DIFFaX
    17421742   
     
    17791779    sf.close()
    17801780    #make DIFFaX control.dif file - future use GUI to set some of these flags
    1781     x0 = profile[0]
    1782     iBeg = np.searchsorted(x0,limits[0])
    1783     iFin = np.searchsorted(x0,limits[1])
    1784     if iFin-iBeg > 20000:
    1785         iFin = iBeg+20000
    1786     Dx = (x0[iFin]-x0[iBeg])/(iFin-iBeg)
    17871781    cf = open('control.dif','w')
    1788     cf.write('GSASII-DIFFaX.dat\n0\n0\n3\n')
    1789     cf.write('%.6f %.6f %.6f\n1\n1\nend\n'%(x0[iBeg],x0[iFin],Dx))
     1782    if ctrls == '0\n0\n3\n':
     1783        x0 = profile[0]
     1784        iBeg = np.searchsorted(x0,limits[0])
     1785        iFin = np.searchsorted(x0,limits[1])
     1786        if iFin-iBeg > 20000:
     1787            iFin = iBeg+20000
     1788        Dx = (x0[iFin]-x0[iBeg])/(iFin-iBeg)
     1789        cf.write('GSASII-DIFFaX.dat\n'+ctrls)
     1790        cf.write('%.6f %.6f %.6f\n1\n1\nend\n'%(x0[iBeg],x0[iFin],Dx))
     1791    else:
     1792        cf.write('GSASII-DIFFaX.dat\n'+ctrls)
     1793        inst = {'Type':['XSC','XSC',]}
    17901794    cf.close()
    17911795    #make DIFFaX data file
     
    17961800    elif 'N' in inst['Type'][0]:
    17971801        df.write('NEUTRON\n')
    1798     df.write('%.4f\n'%(G2mth.getMeanWave(inst)))
    1799     U = forln2*inst['U'][1]/10000.
    1800     V = forln2*inst['V'][1]/10000.
    1801     W = forln2*inst['W'][1]/10000.
    1802     HWHM = U*nptand(x0[iBeg:iFin]/2.)**2+V*nptand(x0[iBeg:iFin]/2.)+W
    1803     HW = np.mean(HWHM)
    1804 #    df.write('PSEUDO-VOIGT 0.015 -0.0036 0.009 0.605 TRIM\n')
    1805 #    df.write('GAUSSIAN %.6f TRIM\n'%(HW))     #fast option - might not really matter
    1806     df.write('GAUSSIAN %.6f %.6f %.6f TRIM\n'%(U,V,W))    #slow - make a GUI option?
     1802    if ctrls == '0\n0\n3\n':
     1803        df.write('%.4f\n'%(G2mth.getMeanWave(inst)))
     1804        U = forln2*inst['U'][1]/10000.
     1805        V = forln2*inst['V'][1]/10000.
     1806        W = forln2*inst['W'][1]/10000.
     1807        HWHM = U*nptand(x0[iBeg:iFin]/2.)**2+V*nptand(x0[iBeg:iFin]/2.)+W
     1808        HW = np.mean(HWHM)
     1809    #    df.write('PSEUDO-VOIGT 0.015 -0.0036 0.009 0.605 TRIM\n')
     1810    #    df.write('GAUSSIAN %.6f TRIM\n'%(HW))     #fast option - might not really matter
     1811        df.write('GAUSSIAN %.6f %.6f %.6f TRIM\n'%(U,V,W))    #slow - make a GUI option?
     1812    else:
     1813        df.write('0.10\nNone\n')
    18071814    df.write('STRUCTURAL\n')
    18081815    a,b,c = Layers['Cell'][1:4]
     
    18931900    #cleanup files..
    18941901        os.remove('GSASII-DIFFaX.spc')
     1902    elif os.path.exists('GSASII-DIFFaX.sadp'):
     1903        Sadp = np.fromfile('GSASII-DIFFaX.sadp','>u2')
     1904        Sadp = np.reshape(Sadp,(256,-1))
     1905        Layers['Sadp']['Img'] = Sadp
     1906        os.remove('GSASII-DIFFaX.sadp')
    18951907    os.remove('data.sfc')
    18961908    os.remove('control.dif')
Note: See TracChangeset for help on using the changeset viewer.