Changeset 1617


Ignore:
Timestamp:
Dec 25, 2014 2:27:10 PM (7 years ago)
Author:
toby
Message:

add tabs to reflection page

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIpwdGUI.py

    r1613 r1617  
    28492849       
    28502850def UpdateReflectionGrid(G2frame,data,HKLF=False,Name=''):
    2851     '''respond to selection of PWDR Reflections data tree item.
     2851    '''respond to selection of PWDR Reflections data tree item by displaying
     2852    a table of reflections in the data window.
    28522853    '''
    28532854    def OnPlotHKL(event):
     2855        '''Plots a layer of reflections
     2856        '''
    28542857        FoMax = np.max(refList.T[8+Super])
    28552858        Hmin = np.array([int(np.min(refList.T[0])),int(np.min(refList.T[1])),int(np.min(refList.T[2]))])
     
    28602863       
    28612864    def OnPlot3DHKL(event):
     2865        '''Plots the reflections in 3D
     2866        '''
    28622867        FoMax = np.max(refList.T[8+Super])
    28632868        Hmin = np.array([int(np.min(refList.T[0])),int(np.min(refList.T[1])),int(np.min(refList.T[2]))])
     
    28702875        G2plt.Plot3DSngl(G2frame,newPlot=True,Data=controls,hklRef=refList,Title=phaseName)
    28712876       
     2877    def MakeReflectionTable(phaseName):
     2878        '''Returns a wx.grid table (G2gd.Table) containing a list of all reflections
     2879        for a phase.       
     2880        '''
     2881        if phaseName:
     2882            pId = G2gd.GetPatternTreeItemId(G2frame,G2frame.root,'Phases')
     2883            phaseId =  G2gd.GetPatternTreeItemId(G2frame,pId,phaseName)
     2884            General = G2frame.PatternTree.GetItemPyData(phaseId)['General']
     2885            Super = General.get('Super',0)
     2886            SuperVec = General.get('SuperVec',[])
     2887        else:
     2888            Super = 0
     2889            SuperVec = []       
     2890        rowLabels = []
     2891        if HKLF:
     2892            refList = data[1]['RefList']
     2893            refs = refList
     2894        else:
     2895            if len(data) > 1:
     2896                G2frame.dataFrame.SelectPhase.Enable(True)
     2897            try:            #patch for old reflection lists
     2898                refList = np.array(data[phaseName]['RefList'])
     2899                I100 = refList.T[8+Super]*refList.T[11+Super]
     2900            except TypeError:
     2901                refList = np.array([refl[:11+Super] for refl in data[phaseName]])
     2902                I100 = refList.T[8+Super]*np.array([refl[11+Super] for refl in data[phaseName]])
     2903            Imax = np.max(I100)
     2904            if Imax:
     2905                I100 *= 100.0/Imax
     2906            if 'C' in Inst['Type'][0]:
     2907                refs = np.vstack((refList.T[:15+Super],I100)).T
     2908            elif 'T' in Inst['Type'][0]:
     2909                refs = np.vstack((refList.T[:18+Super],I100)).T
     2910        for i in range(len(refs)): rowLabels.append(str(i))
     2911        Types = (4+Super)*[wg.GRID_VALUE_LONG,]+4*[wg.GRID_VALUE_FLOAT+':10,4',]+ \
     2912            2*[wg.GRID_VALUE_FLOAT+':10,2',]+[wg.GRID_VALUE_FLOAT+':10,3',]+ \
     2913            [wg.GRID_VALUE_FLOAT+':10,3',]
     2914        if HKLF:
     2915            colLabels = ['H','K','L','mul','d','Fosq','sig','Fcsq','FoTsq','FcTsq','phase','ExtC',]
     2916            if 'T' in Inst['Type'][0]:
     2917                colLabels = ['H','K','L','mul','d','Fosq','sig','Fcsq','FoTsq','FcTsq','phase','ExtC','wave','tbar']
     2918                Types += 2*[wg.GRID_VALUE_FLOAT+':10,3',]
     2919            if Super:
     2920                colLabels.insert(3,'M')
     2921        else:
     2922            if 'C' in Inst['Type'][0]:
     2923                colLabels = ['H','K','L','mul','d','pos','sig','gam','Fosq','Fcsq','phase','Icorr','Prfo','Trans','ExtP','I100']
     2924                Types += 4*[wg.GRID_VALUE_FLOAT+':10,3',]
     2925            elif 'T' in Inst['Type'][0]:
     2926                colLabels = ['H','K','L','mul','d','pos','sig','gam','Fosq','Fcsq','phase','Icorr','alp','bet','wave','Prfo','Abs','Ext','I100']
     2927                Types += 7*[wg.GRID_VALUE_FLOAT+':10,3',]
     2928            if Super:
     2929                colLabels.insert(3,'M')
     2930        return G2gd.Table(refs,rowLabels=rowLabels,colLabels=colLabels,types=Types)
     2931    def ShowReflTable(phaseName):
     2932        '''Posts a table of reflections for a phase, creating the table
     2933        if needed using MakeReflectionTable
     2934        '''
     2935        G2frame.RefList = phaseName
     2936        G2frame.dataFrame.SetLabel('Reflection List for '+phaseName)
     2937        # has this table already been displayed?
     2938        if G2frame.refTable[phaseName].GetTable() is None:
     2939            PeakTable = MakeReflectionTable(phaseName)
     2940            G2frame.refTable[phaseName].SetTable(PeakTable, True)
     2941            G2frame.refTable[phaseName].EnableEditing(False)
     2942            G2frame.refTable[phaseName].SetMargins(0,0)
     2943            G2frame.refTable[phaseName].AutoSizeColumns(False)
     2944        # raise the tab (needed for 1st use and from OnSelectPhase)
     2945        for PageNum in range(G2frame.dataDisplay.GetPageCount()):
     2946            if phaseName == G2frame.dataDisplay.GetPageText(PageNum):
     2947                G2frame.dataDisplay.SetSelection(PageNum)
     2948                break
     2949        else:
     2950            print phaseName
     2951            print phases
     2952            raise Exception("how did we not find a phase name?")
     2953        G2plt.PlotPatterns(G2frame) # replot, to activate phase's reflection tooltips
     2954       
     2955    def OnPageChanged(event):
     2956        '''Respond to a press on a phase tab by displaying the reflections. This
     2957        routine is needed because the reflection table may not have been created yet.
     2958        '''
     2959        page = event.GetSelection()
     2960        phaseName = G2frame.dataDisplay.GetPageText(page)
     2961        ShowReflTable(phaseName)
     2962
    28722963    def OnSelectPhase(event):
     2964        '''For PWDR, selects a phase with a selection box. Called from menu.
     2965        '''
     2966        if len(phases) < 2: return
    28732967        dlg = wx.SingleChoiceDialog(G2frame,'Select','Phase',phases)
    28742968        try:
    28752969            if dlg.ShowModal() == wx.ID_OK:
    28762970                sel = dlg.GetSelection()
    2877                 G2frame.RefList = phases[sel]
    2878                 UpdateReflectionGrid(G2frame,data)
     2971                ShowReflTable(phases[sel])
    28792972        finally:
    28802973            dlg.Destroy()
    2881         G2plt.PlotPatterns(G2frame)
    28822974           
    28832975    if not data:
     
    28872979        G2frame.RefList = 1
    28882980        phaseName = IsHistogramInAnyPhase(G2frame,Name)
     2981        phases = [phaseName]
    28892982    else:
    28902983        phaseName = G2frame.RefList
     
    28932986        G2frame.dataFrame.Clear()
    28942987    Inst = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId, 'Instrument Parameters'))[0]
    2895     if phaseName:
    2896         pId = G2gd.GetPatternTreeItemId(G2frame,G2frame.root,'Phases')
    2897         phaseId =  G2gd.GetPatternTreeItemId(G2frame,pId,phaseName)
    2898         General = G2frame.PatternTree.GetItemPyData(phaseId)['General']
    2899         Super = General.get('Super',0)
    2900         SuperVec = General.get('SuperVec',[])
    2901     else:
    2902         Super = 0
    2903         SuperVec = []       
    2904     rowLabels = []
    29052988    if HKLF:
    29062989        G2gd.SetDataMenuBar(G2frame)
    2907         refList = data[1]['RefList']
    29082990        G2gd.SetDataMenuBar(G2frame,G2frame.dataFrame.ReflMenu)
    29092991        if not G2frame.dataFrame.GetStatusBar():
     
    29122994        G2frame.Bind(wx.EVT_MENU, OnPlot3DHKL, id=G2gd.wxID_PWD3DHKLPLOT)
    29132995        G2frame.dataFrame.SelectPhase.Enable(False)
    2914         refs = refList
    29152996    else:
    29162997        G2gd.SetDataMenuBar(G2frame,G2frame.dataFrame.ReflMenu)
     
    29213002        G2frame.Bind(wx.EVT_MENU, OnPlot3DHKL, id=G2gd.wxID_PWD3DHKLPLOT)
    29223003        G2frame.dataFrame.SelectPhase.Enable(False)
    2923         if len(data) > 1:
    2924             G2frame.dataFrame.SelectPhase.Enable(True)
    2925         try:            #patch for old reflection lists
    2926             refList = np.array(data[G2frame.RefList]['RefList'])
    2927             I100 = refList.T[8+Super]*refList.T[11+Super]
    2928         except TypeError:
    2929             refList = np.array([refl[:11+Super] for refl in data[G2frame.RefList]])
    2930             I100 = refList.T[8+Super]*np.array([refl[11+Super] for refl in data[G2frame.RefList]])
    2931         Imax = np.max(I100)
    2932         if Imax:
    2933             I100 *= 100.0/Imax
    2934         if 'C' in Inst['Type'][0]:
    2935             refs = np.vstack((refList.T[:15+Super],I100)).T
    2936         elif 'T' in Inst['Type'][0]:
    2937             refs = np.vstack((refList.T[:18+Super],I100)).T
    29383004           
    2939     for i in range(len(refs)): rowLabels.append(str(i))
    2940     Types = (4+Super)*[wg.GRID_VALUE_LONG,]+4*[wg.GRID_VALUE_FLOAT+':10,4',]+ \
    2941         2*[wg.GRID_VALUE_FLOAT+':10,2',]+[wg.GRID_VALUE_FLOAT+':10,3',]+ \
    2942         [wg.GRID_VALUE_FLOAT+':10,3',]
    2943     if HKLF:
    2944         colLabels = ['H','K','L','mul','d','Fosq','sig','Fcsq','FoTsq','FcTsq','phase','ExtC',]
    2945         if 'T' in Inst['Type'][0]:
    2946             colLabels = ['H','K','L','mul','d','Fosq','sig','Fcsq','FoTsq','FcTsq','phase','ExtC','wave','tbar']
    2947             Types += 2*[wg.GRID_VALUE_FLOAT+':10,3',]
    2948         if Super:
    2949             colLabels.insert(3,'M')
    2950     else:
    2951         if 'C' in Inst['Type'][0]:
    2952             colLabels = ['H','K','L','mul','d','pos','sig','gam','Fosq','Fcsq','phase','Icorr','Prfo','Trans','ExtP','I100']
    2953             Types += 4*[wg.GRID_VALUE_FLOAT+':10,3',]
    2954         elif 'T' in Inst['Type'][0]:
    2955             colLabels = ['H','K','L','mul','d','pos','sig','gam','Fosq','Fcsq','phase','Icorr','alp','bet','wave','Prfo','Abs','Ext','I100']
    2956             Types += 7*[wg.GRID_VALUE_FLOAT+':10,3',]
    2957         if Super:
    2958             colLabels.insert(3,'M')
    2959            
    2960     G2frame.PeakTable = G2gd.Table(refs,rowLabels=rowLabels,colLabels=colLabels,types=Types)
    2961     G2frame.dataFrame.SetLabel('Reflection List for '+phaseName)
    2962     G2frame.dataDisplay = G2gd.GSGrid(parent=G2frame.dataFrame)
    2963     G2frame.dataDisplay.SetTable(G2frame.PeakTable, True)
    2964     G2frame.dataDisplay.EnableEditing(False)
    2965     G2frame.dataDisplay.SetMargins(0,0)
    2966     G2frame.dataDisplay.AutoSizeColumns(False)
    2967     G2frame.dataDisplay.Fit()
    2968     size = G2frame.dataDisplay.GetSize()
    2969     G2frame.dataFrame.setSizePosLeft([size[0]+32,350])
     3005    G2frame.dataDisplay = G2gd.GSNoteBook(parent=G2frame.dataFrame,size=G2frame.dataFrame.GetClientSize())
     3006    G2frame.refTable = {}
     3007    for tabnum,phase in enumerate(phases):
     3008        G2frame.refTable[phase] = G2gd.GSGrid(parent=G2frame.dataDisplay)
     3009        G2frame.dataDisplay.AddPage(G2frame.refTable[phase],phase)
     3010    if phaseName not in G2frame.refTable:
     3011        print phaseName
     3012        print phases
     3013        raise Exception("how did we get a invalid phase name?")   
     3014    ShowReflTable(phaseName)
     3015    G2frame.refTable[phaseName].Fit()
     3016    size = G2frame.refTable[phaseName].GetSize()
     3017    G2frame.dataFrame.setSizePosLeft([size[0]+32,350])       
     3018    G2frame.dataDisplay.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGED, OnPageChanged)
    29703019   
    29713020################################################################################
Note: See TracChangeset for help on using the changeset viewer.