Changeset 1284
- Timestamp:
- Apr 18, 2014 12:38:47 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIgrid.py
r1283 r1284 1435 1435 Sizer = wx.BoxSizer(wx.VERTICAL) 1436 1436 topSizer = wx.BoxSizer(wx.HORIZONTAL) 1437 topSizer.Add(wx.StaticText(self,wx.ID_ANY,title,size=(-1,35)),1,wx.ALL|wx.EXPAND|WACV,1) 1437 topSizer.Add( 1438 wx.StaticText(self,wx.ID_ANY,title,size=(-1,35)), 1439 1,wx.ALL|wx.EXPAND|WACV,1) 1438 1440 if filterBox: 1439 1441 self.timer = wx.Timer() … … 1584 1586 Sizer = wx.BoxSizer(wx.VERTICAL) 1585 1587 topSizer = wx.BoxSizer(wx.HORIZONTAL) 1586 topSizer.Add(wx.StaticText(self,wx.ID_ANY,title),1,wx.ALL|wx.EXPAND,0) 1588 topSizer.Add( 1589 wx.StaticText(self,wx.ID_ANY,title,size=(-1,35)), 1590 1,wx.ALL|wx.EXPAND|WACV,1) 1587 1591 if filterBox: 1588 1592 self.timer = wx.Timer() … … 3507 3511 * 'title' - histogram name; same as dict item name 3508 3512 * 'newAtomDict' - new atom parameters after shifts applied 3509 * 'newCellDict' - new cell parameters after shifts to A0-A5applied'3513 * 'newCellDict' - refined cell parameters after shifts to A0-A5 from Dij terms applied' 3510 3514 """ 3511 3515 … … 3528 3532 return sampleParm 3529 3533 3530 def GetColumnVals(col): 3531 'returns lists of values and errors (or None) for each column in the table' 3532 return colList[col],colSigs[col] 3534 def GetColumnInfo(col): 3535 '''returns column label, lists of values and errors (or None) for each column in the table. 3536 label is reformatted from Unicode to MatPlotLib 3537 ''' 3538 plotName = plotSpCharFix(G2frame.SeqTable.GetColLabelValue(col)) 3539 return plotName,colList[col],colSigs[col] 3533 3540 3534 3541 def PlotSelect(event): … … 3537 3544 rows = G2frame.dataDisplay.GetSelectedRows() 3538 3545 if cols: 3539 for col in cols: 3540 plotName = plotSpCharFix(G2frame.SeqTable.GetColLabelValue(col)) 3541 data,sigs = GetColumnVals(col) 3542 G2plt.PlotSeq(G2frame,[data],[sigs],[plotName]) 3543 break # stop after 1st 3546 G2plt.PlotSelectedSequence(G2frame,cols,GetColumnInfo,SelectXaxis) 3544 3547 elif rows: 3545 3548 name = histNames[rows[0]] #only does 1st one selected 3546 3549 G2plt.PlotCovariance(G2frame,data[name]) 3547 3550 else: 3551 G2frame.ErrorDialog( 3552 'Select row or columns', 3553 'Nothing selected in table. Click on column or row label(s) to plot. N.B. Grid selection can be a bit funky.' 3554 ) 3555 3548 3556 def OnPlotSelSeq(event): 3549 'plot the selected columns from menu command'3557 'plot the selected columns or row from menu command' 3550 3558 cols = sorted(G2frame.dataDisplay.GetSelectedCols()) # ignore selection order 3551 print cols 3552 nrows = G2frame.SeqTable.GetNumberRows() 3553 if not cols: 3559 rows = G2frame.dataDisplay.GetSelectedRows() 3560 if cols: 3561 G2plt.PlotSelectedSequence(G2frame,cols,GetColumnInfo,SelectXaxis) 3562 elif rows: 3563 name = histNames[rows[0]] #only does 1st one selected 3564 G2plt.PlotCovariance(G2frame,data[name]) 3565 else: 3554 3566 G2frame.ErrorDialog( 3555 3567 'Select columns', 3556 'No columns selected in table. Click on column labels to select fields for output.'3568 'No columns or rows selected in table. Click on row or column labels to select fields for plotting.' 3557 3569 ) 3558 return3559 #saveNames = [G2frame.SeqTable.GetRowLabelValue(r) for r in range(nrows)]3560 saveData = []3561 saveSigs = []3562 plotNames = [plotSpCharFix(G2frame.SeqTable.GetColLabelValue(col)) for col in cols]3563 for col in cols:3564 vals,sigs = GetColumnVals(col)3565 saveData.append(vals)3566 saveSigs.append(sigs)3567 G2plt.PlotSeq(G2frame,saveData,saveSigs,plotNames)3568 3570 3569 3571 def OnSaveSelSeqCSV(event): … … 3626 3628 havesig = [] 3627 3629 for col in cols: 3628 vals,sigs = GetColumnVals(col)3630 name,vals,sigs = GetColumnInfo(col) 3629 3631 saveData[col] = vals 3630 3632 if sigs: … … 3662 3664 [['-1'],(0,1,2,3,4,5)], 3663 3665 ] 3664 def striphist(var): 3666 # cell labels 3667 cellUlbl = ('a','b','c',u'\u03B1',u'\u03B2',u'\u03b3') # unicode a,b,c,alpha,beta,gamma 3668 def striphist(var,insChar=''): 3665 3669 'strip a histogram number from a var name' 3666 3670 sv = var.split(':') 3667 sv[1] = ''3671 sv[1] = insChar 3668 3672 return ':'.join(sv) 3669 3673 def plotSpCharFix(lbl): … … 3677 3681 lbl = lbl.replace(u,p) 3678 3682 return lbl 3679 3683 3684 def SelectXaxis(): 3685 'returns a selected column number (or None) as the X-axis selection' 3686 ncols = G2frame.SeqTable.GetNumberCols() 3687 colNames = [G2frame.SeqTable.GetColLabelValue(r) for r in range(ncols)] 3688 dlg = G2SingleChoiceDialog( 3689 G2frame.dataDisplay, 3690 'Select x-axis parameter for plot or Cancel for sequence number', 3691 'Select X-axis', 3692 colNames) 3693 try: 3694 if dlg.ShowModal() == wx.ID_OK: 3695 col = dlg.GetSelection() 3696 else: 3697 col = None 3698 finally: 3699 dlg.Destroy() 3700 return col 3680 3701 #====================================================================== 3681 3702 # start processing sequential results here … … 3706 3727 3707 3728 # get unit cell & symmetry for all phases 3708 cellUlbl = ('a','b','c',u'\u03B1',u'\u03B2',u'\u03b3') # unicode a,b,c,alpha,beta,gamma3709 #cellUlbl = ('a','b','c',r'$\alpha$',r'$\beta$',r'$\gamma$') # matplotlib a,b,c,alpha,beta,gamma3710 3729 Phases = G2frame.GetPhaseData() 3711 3730 Alist = {} … … 3746 3765 colLabels += ['Rwp'] 3747 3766 Types += [wg.GRID_VALUE_FLOAT,] 3748 # add Converged flag3767 # add % change in Chi^2 in last cycle 3749 3768 colList += [[100.*data[name]['Rvals'].get('DelChi2',-1) for name in histNames]] 3750 3769 colSigs += [None] … … 3752 3771 Types += [wg.GRID_VALUE_FLOAT,] 3753 3772 3773 # adds checkbox for converged (Bob wants to change color of previous instead) 3754 3774 # colList += [[data[name]['Rvals']['converged'] for name in histNames]] 3755 3775 # colSigs += [None] 3756 3776 # colLabels += ['Cnvg'] 3757 3777 # Types += [wg.GRID_VALUE_BOOL,] 3778 3758 3779 # add sample parameters 3759 3780 for key in sampleParms: … … 3800 3821 3801 3822 # process the dependent constrained variables, removing histogram numbers if needed 3823 # from parameter label 3802 3824 depValDict = {} 3803 3825 depSigDict = {} … … 3805 3827 for var in data[name].get('depParmDict',{}): 3806 3828 val,sig = data[name]['depParmDict'][var] 3807 sv = var.split(':') 3808 if sv[1] != '': sv[1] = '*' 3809 svar = ':'.join(sv) 3829 svar = striphist(var,'*') 3810 3830 if svar not in depValDict: 3811 3831 depValDict[svar] = [val] … … 3814 3834 depValDict[svar].append(val) 3815 3835 depSigDict[svar].append(sig) 3836 3816 3837 # add the dependent constrained variables 3817 3838 for var in sorted(depValDict): … … 3831 3852 G2frame.SeqTable = Table(rowList,colLabels=colLabels,rowLabels=histNames,types=Types) 3832 3853 3854 # old Table contents generator, keep for comparison for right now. 3833 3855 # Rwps = [data[name]['Rvals']['Rwp'] for name in histNames] 3834 3856 # seqList = [[Rwps[i],]+list(data[name]['variables']) for i,name in enumerate(histNames)] … … 3851 3873 G2frame.dataDisplay.AutoSizeColumns(True) 3852 3874 G2frame.dataFrame.setSizePosLeft([700,350]) 3875 3853 3876 ################################################################################ 3854 3877 ##### Main PWDR panel -
trunk/GSASIIplot.py
r1282 r1284 2248 2248 ##### PlotSeq 2249 2249 ################################################################################ 2250 2251 def PlotSeq(G2frame,SeqData,SeqSig,SeqNames): 2250 def PlotSelectedSequence(G2frame,ColumnList,TableGet,SelectX): 2252 2251 '''Plot a result from a sequential refinement 2253 ''' 2254 # def OnKeyPress(event): 2255 # if event.key == 's' and sampleParm: 2256 # G2frame.xAxis = not G2frame.xAxis 2257 # Draw(False) 2252 2253 :param wx.Frame G2frame: The main GSAS-II tree "window" 2254 :param list ColumnList: list of int values corresponding to columns 2255 selected as y values 2256 :param function TableGet: a function that takes a column number 2257 as argument and returns the column label, the values and there ESDs (or None) 2258 :param function SelectX: a function that returns a selected column 2259 number (or None) as the X-axis selection 2260 ''' 2261 G2frame.seqYaxisList = ColumnList 2262 G2frame.seqTableGet = TableGet 2263 G2frame.seqXselect = SelectX 2264 try: 2265 G2frame.seqXaxis 2266 except: 2267 G2frame.seqXaxis = None 2268 def OnKeyPress(event): 2269 if event.key == 's': 2270 G2frame.seqXaxis = G2frame.seqXselect() 2271 Draw() 2258 2272 try: 2259 2273 plotNum = G2frame.G2plotNB.plotList.index('Sequential refinement') … … 2267 2281 plotNum = G2frame.G2plotNB.plotList.index('Sequential refinement') 2268 2282 Page = G2frame.G2plotNB.nb.GetPage(plotNum) 2269 #Page.canvas.mpl_connect('key_press_event', OnKeyPress) 2270 G2frame.xAxis = False 2271 Page.Choice = [] 2272 #Page.Choice = ['s to toggle x-axis = sample environment parameter'] 2273 #Page.keyPress = OnKeyPress 2274 2275 def Draw(newPlot): 2283 Page.canvas.mpl_connect('key_press_event', OnKeyPress) 2284 Page.Choice = ['s to select plot x-axis'] 2285 Page.keyPress = OnKeyPress 2286 2287 def Draw(): 2276 2288 Page.SetFocus() 2277 #G2frame.G2plotNB.status.SetFields(['','press ']) 2278 if len(SeqData): 2279 Plot.clear() 2280 # if G2frame.xAxis: 2281 # xName = sampleParm.keys()[0] 2282 # X = sampleParm[xName] 2283 # else: 2284 X = np.arange(0,len(SeqData[0]),1) 2289 G2frame.G2plotNB.status.SetFields(['press s to select X axis']) 2290 Plot.clear() 2291 if G2frame.seqXaxis is not None: 2292 xName,X,Xsig = G2frame.seqTableGet(G2frame.seqXaxis) 2293 else: 2294 X = np.arange(0,G2frame.SeqTable.GetNumberRows(),1) 2285 2295 xName = 'Data sequence number' 2286 for Y,sig,name in zip(SeqData,SeqSig,SeqNames): 2287 if sig: 2288 Plot.errorbar(X,Y,yerr=sig,label=name) 2289 else: 2290 Plot.errorbar(X,Y,label=name) 2291 Plot.legend(loc='best') 2292 Plot.set_ylabel('Parameter values') 2293 Plot.set_xlabel(xName) 2294 Page.canvas.draw() 2295 Draw(True) 2296 2296 for col in G2frame.seqYaxisList: 2297 name,Y,sig = G2frame.seqTableGet(col) 2298 if sig: 2299 Plot.errorbar(X,Y,yerr=sig,label=name) 2300 else: 2301 Plot.errorbar(X,Y,label=name) 2302 Plot.legend(loc='best') 2303 Plot.set_ylabel('Parameter values') 2304 Plot.set_xlabel(xName) 2305 Page.canvas.draw() 2306 Draw() 2307 2297 2308 ################################################################################ 2298 2309 ##### PlotExposedImage & PlotImage
Note: See TracChangeset
for help on using the changeset viewer.