Changeset 1617
 Timestamp:
 Dec 25, 2014 2:27:10 PM (8 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/GSASIIpwdGUI.py
r1613 r1617 2849 2849 2850 2850 def 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. 2852 2853 ''' 2853 2854 def OnPlotHKL(event): 2855 '''Plots a layer of reflections 2856 ''' 2854 2857 FoMax = np.max(refList.T[8+Super]) 2855 2858 Hmin = np.array([int(np.min(refList.T[0])),int(np.min(refList.T[1])),int(np.min(refList.T[2]))]) … … 2860 2863 2861 2864 def OnPlot3DHKL(event): 2865 '''Plots the reflections in 3D 2866 ''' 2862 2867 FoMax = np.max(refList.T[8+Super]) 2863 2868 Hmin = np.array([int(np.min(refList.T[0])),int(np.min(refList.T[1])),int(np.min(refList.T[2]))]) … … 2870 2875 G2plt.Plot3DSngl(G2frame,newPlot=True,Data=controls,hklRef=refList,Title=phaseName) 2871 2876 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 2872 2963 def OnSelectPhase(event): 2964 '''For PWDR, selects a phase with a selection box. Called from menu. 2965 ''' 2966 if len(phases) < 2: return 2873 2967 dlg = wx.SingleChoiceDialog(G2frame,'Select','Phase',phases) 2874 2968 try: 2875 2969 if dlg.ShowModal() == wx.ID_OK: 2876 2970 sel = dlg.GetSelection() 2877 G2frame.RefList = phases[sel] 2878 UpdateReflectionGrid(G2frame,data) 2971 ShowReflTable(phases[sel]) 2879 2972 finally: 2880 2973 dlg.Destroy() 2881 G2plt.PlotPatterns(G2frame)2882 2974 2883 2975 if not data: … … 2887 2979 G2frame.RefList = 1 2888 2980 phaseName = IsHistogramInAnyPhase(G2frame,Name) 2981 phases = [phaseName] 2889 2982 else: 2890 2983 phaseName = G2frame.RefList … … 2893 2986 G2frame.dataFrame.Clear() 2894 2987 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 = 02903 SuperVec = []2904 rowLabels = []2905 2988 if HKLF: 2906 2989 G2gd.SetDataMenuBar(G2frame) 2907 refList = data[1]['RefList']2908 2990 G2gd.SetDataMenuBar(G2frame,G2frame.dataFrame.ReflMenu) 2909 2991 if not G2frame.dataFrame.GetStatusBar(): … … 2912 2994 G2frame.Bind(wx.EVT_MENU, OnPlot3DHKL, id=G2gd.wxID_PWD3DHKLPLOT) 2913 2995 G2frame.dataFrame.SelectPhase.Enable(False) 2914 refs = refList2915 2996 else: 2916 2997 G2gd.SetDataMenuBar(G2frame,G2frame.dataFrame.ReflMenu) … … 2921 3002 G2frame.Bind(wx.EVT_MENU, OnPlot3DHKL, id=G2gd.wxID_PWD3DHKLPLOT) 2922 3003 G2frame.dataFrame.SelectPhase.Enable(False) 2923 if len(data) > 1:2924 G2frame.dataFrame.SelectPhase.Enable(True)2925 try: #patch for old reflection lists2926 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/Imax2934 if 'C' in Inst['Type'][0]:2935 refs = np.vstack((refList.T[:15+Super],I100)).T2936 elif 'T' in Inst['Type'][0]:2937 refs = np.vstack((refList.T[:18+Super],I100)).T2938 3004 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) 2970 3019 2971 3020 ################################################################################
Note: See TracChangeset
for help on using the changeset viewer.