Changeset 2172


Ignore:
Timestamp:
Mar 15, 2016 3:07:56 PM (8 years ago)
Author:
vondreele
Message:

add new dialog for DIFFaX controls (now empty)
fix layer pair plotting - allow shifting of one layer vs the reference
updates plot & Transitions values
fix hard copy plot error - structure drawings were flipped up/down!

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIgrid.py

    r2166 r2172  
    489489        parent = self.GetParent()
    490490        parent.Raise()
    491         self.EndModal(wx.ID_CANCEL)       
     491        self.EndModal(wx.ID_CANCEL)     
     492       
     493################################################################################
     494class DIFFaXcontrols(wx.Dialog):
     495    ''' Solicit items needed to prepare DIFFaX control.dif file
     496    '''
     497    def __init__(self,parent,ctrls):
     498        wx.Dialog.__init__(self,parent,wx.ID_ANY,'DIFFaX controls',
     499            pos=wx.DefaultPosition,style=wx.DEFAULT_DIALOG_STYLE)
     500        self.panel = wx.Panel(self)         #just a dummy - gets destroyed in Draw!
     501        self.ctrls = ctrls
     502        self.Draw()
     503       
     504    def Draw(self):
     505       
     506       
     507       
     508        self.panel.Destroy()
     509        self.panel = wx.Panel(self)
     510        mainSizer = wx.BoxSizer(wx.VERTICAL)
     511        mainSizer.Add(wx.StaticText(self.panel,label=' Controls for DIFFaX'),0,WACV)
     512       
     513
     514        OkBtn = wx.Button(self.panel,-1,"Ok")
     515        OkBtn.Bind(wx.EVT_BUTTON, self.OnOk)
     516        cancelBtn = wx.Button(self.panel,-1,"Cancel")
     517        cancelBtn.Bind(wx.EVT_BUTTON, self.OnCancel)
     518        btnSizer = wx.BoxSizer(wx.HORIZONTAL)
     519        btnSizer.Add((20,20),1)
     520        btnSizer.Add(OkBtn)
     521        btnSizer.Add((20,20),1)
     522        btnSizer.Add(cancelBtn)
     523        btnSizer.Add((20,20),1)
     524       
     525        mainSizer.Add(btnSizer,0,wx.EXPAND|wx.BOTTOM|wx.TOP, 10)
     526        self.panel.SetSizer(mainSizer)
     527        self.panel.Fit()
     528        self.Fit()
     529       
     530    def GetSelection(self):
     531        return self.ctrls
     532
     533    def OnOk(self,event):
     534        parent = self.GetParent()
     535        parent.Raise()
     536        self.EndModal(wx.ID_OK)
     537
     538    def OnCancel(self,event):
     539        parent = self.GetParent()
     540        parent.Raise()
     541        self.EndModal(wx.ID_CANCEL)
     542           
    492543       
    493544################################################################################
  • trunk/GSASIIphsGUI.py

    r2170 r2172  
    6767acosd = lambda x: 180.*np.arccos(x)/np.pi
    6868atan2d = lambda x,y: 180.*np.arctan2(y,x)/np.pi
    69 
     69   
    7070def SetPhaseWindow(mainFrame,phasePage,mainSizer,Scroll=0):
    7171    phasePage.SetSizer(mainSizer)
     
    25842584            def OnDrawLayer(event):
    25852585                drawLayer.SetValue(False)
    2586                 if len(Layers['Layers'][il]['Atoms']) == 0:
    2587                     wx.MessageBox('No atoms in this layer to plot',caption='Data error',style=wx.ICON_EXCLAMATION)
    2588                     return
    25892586                G2plt.PlotLayers(G2frame,Layers,[il,],plotDefaults)
    25902587               
     
    26482645                Obj = event.GetEventObject()
    26492646                Yi = Indx[Obj.GetId()]               
    2650                 if len(Layers['Layers'][Yi]['Atoms']) == 0:
    2651                     wx.MessageBox('No atoms in this layer to plot',caption='Data error',style=wx.ICON_EXCLAMATION)
    2652                     return
    26532647                Xi,c =  event.GetRow(),event.GetCol()
    26542648                if Xi >= 0 and c == 5:   #plot column
    2655                     if len(Layers['Layers'][Xi]['Atoms']) == 0:
    2656                         wx.MessageBox('No atoms in this layer to plot',caption='Data error',style=wx.ICON_EXCLAMATION)
    2657                         return
    26582649                    Obj.SetCellValue(Xi,5,'')
    26592650                    G2plt.PlotLayers(G2frame,Layers,[Yi,Xi,],plotDefaults)
     
    26642655            transArray = Layers['Transitions']
    26652656            Indx = {}
     2657            layerData.transGrids = []
    26662658            if not Names or not transArray:
    26672659                return transSizer
     
    26862678                transGrid.AutoSizeColumns(True)
    26872679                transSizer.Add(transGrid)
     2680                layerData.transGrids.append(transGrid)
    26882681            return transSizer
    26892682           
     
    29042897            wx.MessageBox("Can't simulate neutron TOF patterns yet",caption='Data error',style=wx.ICON_EXCLAMATION)
    29052898            return           
    2906         profile = G2frame.PatternTree.GetItemPyData(G2frame.PatternId)[1]           
     2899        profile = G2frame.PatternTree.GetItemPyData(G2frame.PatternId)[1]
     2900        ctrls = {}
     2901        dlg = G2gd.DIFFaXcontrols(G2frame,ctrls)
     2902        if dlg.ShowModal() == wx.ID_OK:
     2903            ctrls = dlg.GetSelection()
     2904        else:
     2905            return
     2906        dlg.Destroy()       
    29072907        G2pwd.StackSim(data['Layers'],HistName,scale,background,limits,inst,profile)
    29082908        G2plt.PlotPatterns(G2frame,plotType='PWDR')
  • trunk/GSASIIplot.py

    r2167 r2172  
    582582                im = Im.new("RGB", (size[0],size[1]))
    583583            im.fromstring(Pix)
     584            im = im.transpose(Im.FLIP_TOP_BOTTOM)
    584585            im.save(Fname,mode)
    585586            cb.SetValue(' save as/key:')
     
    45234524                im = Im.new("RGB", (size[0],size[1]))
    45244525            im.fromstring(Pix)
     4526            im = im.transpose(Im.FLIP_TOP_BOTTOM)
    45254527            im.save(Fname,mode)
    45264528            cb.SetValue(' save as/key:')
     
    57725774    '''
    57735775
     5776    global AtNames,AtTypes,XYZ,Bonds
    57745777    def FindBonds(atTypes,XYZ):
    57755778        Radii = []
     
    57895792                Bonds[j].append(-Dx[j]*Radii[j]/sumR[j])
    57905793        return Bonds
     5794       
     5795    def getAtoms():
     5796        global AtNames,AtTypes,XYZ,Bonds
     5797        AtNames = []
     5798        AtTypes = []
     5799        newXYZ = np.zeros((0,3))
     5800        TX = np.zeros(3)
     5801        for il in range(len(laySeq)):
     5802            layer = laySeq[il]     
     5803            if Layers['Layers'][layer]['SameAs']:
     5804                layer = Names.index(Layers['Layers'][layer]['SameAs'])
     5805            atNames = [atom[0] for atom in Layers['Layers'][layer]['Atoms']]
     5806            atTypes = [atom[1] for atom in Layers['Layers'][layer]['Atoms']]
     5807            XYZ = np.array([atom[2:5] for atom in Layers['Layers'][layer]['Atoms']])
     5808            if '-1' in Layers['Layers'][layer]['Symm']:
     5809                atNames += atNames
     5810                atTypes += atTypes
     5811                XYZ = np.concatenate((XYZ,-XYZ))
     5812            if il:
     5813                TX += np.array(Trans[laySeq[il-1]][layer][1:4])
     5814            XYZ += TX
     5815            XYZT = XYZ.T
     5816            XYZT[0] = XYZT[0]%1.
     5817            XYZT[1] = XYZT[1]%1.
     5818            XYZ = XYZT.T
     5819            AtNames += atNames
     5820            AtTypes += atTypes
     5821            newXYZ = np.concatenate((newXYZ,XYZ))
     5822        XYZ = newXYZ
     5823        na = int(8./cell[0])
     5824        nb = int(8./cell[1])
     5825        nunit = [na,nb,0]
     5826        indA = range(-na,na)
     5827        indB = range(-nb,nb)
     5828        Units = np.array([[h,k,0] for h in indA for k in indB])
     5829        newXYZ = np.zeros((0,3))
     5830        for unit in Units:
     5831            newXYZ = np.concatenate((newXYZ,unit+XYZ))
     5832        if len(Units):
     5833            AtNames *= len(Units)
     5834            AtTypes *= len(Units)
     5835        XYZ = newXYZ
     5836        Bonds = FindBonds(AtTypes,XYZ)
    57915837                       
    57925838    cell = Layers['Cell'][1:7]
     
    58045850    AtInfo = Layers['AtInfo']
    58055851    Names = [layer['Name'] for layer in Layers['Layers']]
    5806     AtNames = []
    5807     AtTypes = []
    5808     newXYZ = np.zeros((0,3))
    5809     TX = np.zeros(3)
    5810     for il in range(len(laySeq)):
    5811         layer = laySeq[il]     
    5812         if Layers['Layers'][layer]['SameAs']:
    5813             alayer = Names.index(Layers['Layers'][layer]['SameAs'])
    5814         atNames = [atom[0] for atom in Layers['Layers'][layer]['Atoms']]
    5815         atTypes = [atom[1] for atom in Layers['Layers'][layer]['Atoms']]
    5816         XYZ = np.array([atom[2:5] for atom in Layers['Layers'][layer]['Atoms']])
    5817         if '-1' in Layers['Layers'][layer]['Symm']:
    5818             atNames += atNames
    5819             atTypes += atTypes
    5820             XYZ = np.concatenate((XYZ,-XYZ))
    5821         if il:
    5822             TX += np.array(Trans[laySeq[il-1]][layer][1:4])
    5823         XYZ += TX
    5824         XYZT = XYZ.T
    5825         XYZT[0] = XYZT[0]%1.
    5826         XYZT[1] = XYZT[1]%1.
    5827         XYZ = XYZT.T
    5828         AtNames += atNames
    5829         AtTypes += atTypes
    5830         newXYZ = np.concatenate((newXYZ,XYZ))
    5831     XYZ = newXYZ
    5832     na = int(8./cell[0])
    5833     nb = int(8./cell[1])
    5834     nunit = [na,nb,0]
    5835     indA = range(-na,na)
    5836     indB = range(-nb,nb)
    5837     Units = np.array([[h,k,0] for h in indA for k in indB])
    5838     newXYZ = np.zeros((0,3))
    5839     for unit in Units:
    5840         newXYZ = np.concatenate((newXYZ,unit+XYZ))
    5841     if len(Units):
    5842         AtNames *= len(Units)
    5843         AtTypes *= len(Units)
    5844     XYZ = newXYZ
    5845     Bonds = FindBonds(AtTypes,XYZ)
     5852    getAtoms()
    58465853   
     5854    def OnKeyBox(event):
     5855        mode = cb.GetValue()
     5856        if mode in ['jpeg','bmp','tiff',]:
     5857            try:
     5858                import Image as Im
     5859            except ImportError:
     5860                try:
     5861                    from PIL import Image as Im
     5862                except ImportError:
     5863                    print "PIL/pillow Image module not present. Cannot save images without this"
     5864                    raise Exception("PIL/pillow Image module not found")
     5865            projFile = G2frame.GSASprojectfile
     5866            Fname = os.path.splitext(projFile)[0]+'.'+mode
     5867            size = Page.canvas.GetSize()
     5868            glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
     5869            if mode in ['jpeg',]:
     5870                Pix = glReadPixels(0,0,size[0],size[1],GL_RGBA, GL_UNSIGNED_BYTE)
     5871                im = Im.new("RGBA", (size[0],size[1]))
     5872            else:
     5873                Pix = glReadPixels(0,0,size[0],size[1],GL_RGB, GL_UNSIGNED_BYTE)
     5874                im = Im.new("RGB", (size[0],size[1]))
     5875            im.fromstring(Pix)
     5876            im = im.transpose(Im.FLIP_TOP_BOTTOM)
     5877            im.save(Fname,mode)
     5878            cb.SetValue(' save as:')
     5879            G2frame.G2plotNB.status.SetStatusText('Drawing saved to: '+Fname,1)
     5880
    58475881    def OnPlotKeyPress(event):
     5882        global AtNames,AtTypes,XYZ,Bonds
    58485883        if event.GetKeyCode() > 255:
    58495884            return
     
    58605895        Trans = Layers['Transitions']
    58615896        Yi,Xi = laySeq
     5897        dxyz = 0.01
    58625898        if keyCode == 'X':
    5863             dx = 0.001
     5899            dx = dxyz
    58645900            if event.shiftDown:
    58655901                dx *= -1.
     5902            Trans[Yi][Xi][1] += dx
     5903            SetTransText(Yi,Xi,Trans[Yi][Xi],1)
    58665904        elif keyCode == 'Y':
    5867             dy = 0.001
     5905            dy = dxyz
    58685906            if event.shiftDown:
    58695907                dy *= -1.
     5908            Trans[Yi][Xi][2] += dy
     5909            SetTransText(Yi,Xi,Trans[Yi][Xi],2)
    58705910        elif keyCode == 'Z':
    5871             dz = 0.001
     5911            dz = dxyz
    58725912            if event.shiftDown:
    58735913                dz *= -1.
    5874         Trans[Yi][Xi][1] += dx
    5875         Trans[Yi][Xi][2] += dy
    5876         Trans[Yi][Xi][3] += dz
     5914            Trans[Yi][Xi][3] += dz
     5915            SetTransText(Yi,Xi,Trans[Yi][Xi],3)
     5916        getAtoms()
    58775917        Draw('shift')
     5918       
     5919    def SetTransText(Yi,Xi,XYZ,id):
     5920        page = G2frame.dataDisplay.GetSelection()
     5921        if page:
     5922            if G2frame.dataDisplay.GetPageText(page) == 'Layers':
     5923                G2frame.dataDisplay.GetPage(page).transGrids[Yi].Refresh()
    58785924           
    58795925    def OnMouseDown(event):
     
    60406086#            print caller
    60416087# end of useful debug
     6088        global AtNames,AtTypes,XYZ,Bonds
    60426089        cPos = defaults['cameraPos']
    60436090        VS = np.array(Page.canvas.GetSize())
     
    60916138        view = False
    60926139        altDown = False
    6093     Page.Choice = (' key press','l: shift left','r: shift right','d: shift down','u: shift up',
    6094             't: toggle labels',)
     6140    choice = [' save as:','jpeg','tiff','bmp']
    60956141    Page.keyPress = OnPlotKeyPress
    60966142    Page.SetFocus()
    60976143    Font = Page.GetFont()
     6144    cb = wx.ComboBox(G2frame.G2plotNB.status,style=wx.CB_DROPDOWN|wx.CB_READONLY,choices=choice)
     6145    cb.Bind(wx.EVT_COMBOBOX, OnKeyBox)
     6146    if len(laySeq) == 2:
     6147        G2frame.G2plotNB.status.SetStatusText('Shift layer +/-XYZ key: X/shift-X, Y/shift-Y, Z/shift-Z; key: L - toggle atom labels',1)
     6148    else:
     6149        G2frame.G2plotNB.status.SetStatusText('L - toggle atom labels',1)
    60986150    Page.canvas.Bind(wx.EVT_MOUSEWHEEL, OnMouseWheel)
    60996151    Page.canvas.Bind(wx.EVT_LEFT_DOWN, OnMouseDown)
  • trunk/GSASIIpwd.py

    r2170 r2172  
    5656npT2stl = lambda tth, wave: 2.0*npsind(tth/2.0)/wave
    5757npT2q = lambda tth,wave: 2.0*np.pi*npT2stl(tth,wave)
     58forln2 = 4.0*math.log(2.0)
    5859   
    5960#GSASII pdf calculation routines
     
    17471748    param: background dict: background parameters
    17481749    param: limits list: min/max 2-theta to be calculated
    1749     param: inst dict: instrumnet parameters dictionary
     1750    param: inst dict: instrument parameters dictionary
    17501751    param: profile list: powder pattern data
    17511752   
     
    17821783    iFin = np.searchsorted(x0,limits[1])
    17831784    if iFin-iBeg > 20000:
    1784         iFin = iBeg+19999
    1785     x = x0[iBeg:iFin]
    1786     dx = x0[iBeg+1]-x0[iBeg]
     1785        iFin = iBeg+20000
     1786    Dx = (x0[iFin]-x0[iBeg])/(iFin-iBeg)
    17871787    cf = open('control.dif','w')
    17881788    cf.write('GSASII-DIFFaX.dat\n0\n0\n3\n')
    1789     cf.write('%.3f %.3f %.3f\n1\n1\nend\n'%(x0[iBeg],x0[iFin],dx))
     1789    cf.write('%.6f %.6f %.6f\n1\n1\nend\n'%(x0[iBeg],x0[iFin],Dx))
    17901790    cf.close()
    17911791    #make DIFFaX data file
     
    17971797        df.write('NEUTRON\n')
    17981798    df.write('%.4f\n'%(G2mth.getMeanWave(inst)))
    1799 #    df.write('GAUSSIAN 0.1 TRIM\n')     #fast option - might not really matter
    1800     df.write('PSEUDO-VOIGT 0.1 -0.036 0.009 0.6 TRIM\n')    #slow - make a GUI option?
     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?
    18011807    df.write('STRUCTURAL\n')
    18021808    a,b,c = Layers['Cell'][1:4]
     
    18541860    subp.call(DIFFaX)
    18551861    print 'DIFFaX time = %.2fs'%(time.time()-time0)
    1856     X = np.loadtxt('GSASII-DIFFaX.spc')
     1862    Xpat = np.loadtxt('GSASII-DIFFaX.spc').T
     1863    iFin = iBeg+Xpat.shape[1]
    18571864    bakType,backDict,backVary = SetBackgroundParms(background)
    18581865    backDict['Lam1'] = G2mth.getWave(inst)
    18591866#    GSASIIpath.IPyBreak()
    1860     iB = np.searchsorted(profile[0],X.T[0])[0]
    1861     iF = np.searchsorted(profile[0],X.T[-1])[0]
    1862     if not iF:
    1863         iF = -1
    1864     profile[4][iB:iF] = getBackground('',backDict,bakType,inst['Type'][0],X.T[0])[0]   
    1865     profile[3][iB:iF] = X.T[1]*scale+profile[4][iB:iF]
     1867    profile[4][iBeg:iFin] = getBackground('',backDict,bakType,inst['Type'][0],profile[0][iBeg:iFin])[0]   
     1868    profile[3][iBeg:iFin] = Xpat[2]*scale+profile[4][iBeg:iFin]
    18661869    if not np.any(profile[1]):                   #fill dummy data x,y,w,yc,yb,yd
    1867         rv = st.poisson(profile[3][iB:iF])
    1868         profile[1][iB:iF] = rv.rvs()
    1869         Z = np.ones_like(profile[3][iB:iF])
     1870        rv = st.poisson(profile[3][iBeg:iFin])
     1871        profile[1][iBeg:iFin] = rv.rvs()
     1872        Z = np.ones_like(profile[3][iBeg:iFin])
    18701873        Z[1::2] *= -1
    1871         profile[1][iB:iF] = profile[3][iB:iF]+np.abs(profile[1][iB:iF]-profile[3][iB:iF])*Z
    1872         profile[2][iB:iF] = np.where(profile[1][iB:iF]>0.,1./profile[1][iB:iF],1.0)
    1873     profile[5][iB:iF] = profile[1][iB:iF]-profile[3][iB:iF]
     1874        profile[1][iBeg:iFin] = profile[3][iBeg:iFin]+np.abs(profile[1][iBeg:iFin]-profile[3][iBeg:iFin])*Z
     1875        profile[2][iBeg:iFin] = np.where(profile[1][iBeg:iFin]>0.,1./profile[1][iBeg:iFin],1.0)
     1876    profile[5][iBeg:iFin] = profile[1][iBeg:iFin]-profile[3][iBeg:iFin]
    18741877
    18751878
Note: See TracChangeset for help on using the changeset viewer.