Changeset 1284 for trunk/GSASIIgrid.py


Ignore:
Timestamp:
Apr 18, 2014 12:38:47 PM (8 years ago)
Author:
toby
Message:

Redo plot to allow column selection; some cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIgrid.py

    r1283 r1284  
    14351435        Sizer = wx.BoxSizer(wx.VERTICAL)
    14361436        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)
    14381440        if filterBox:
    14391441            self.timer = wx.Timer()
     
    15841586        Sizer = wx.BoxSizer(wx.VERTICAL)
    15851587        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)
    15871591        if filterBox:
    15881592            self.timer = wx.Timer()
     
    35073511              * 'title' - histogram name; same as dict item name
    35083512              * 'newAtomDict' - new atom parameters after shifts applied
    3509               * 'newCellDict' - new cell parameters after shifts to A0-A5 applied'
     3513              * 'newCellDict' - refined cell parameters after shifts to A0-A5 from Dij terms applied'
    35103514    """
    35113515
     
    35283532        return sampleParm
    35293533
    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]
    35333540           
    35343541    def PlotSelect(event):
     
    35373544        rows = G2frame.dataDisplay.GetSelectedRows()
    35383545        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)
    35443547        elif rows:
    35453548            name = histNames[rows[0]]       #only does 1st one selected
    35463549            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           
    35483556    def OnPlotSelSeq(event):
    3549         'plot the selected columns from menu command'
     3557        'plot the selected columns or row from menu command'
    35503558        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:
    35543566            G2frame.ErrorDialog(
    35553567                '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.'
    35573569                )
    3558             return
    3559         #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)
    35683570           
    35693571    def OnSaveSelSeqCSV(event):
     
    36263628        havesig = []
    36273629        for col in cols:
    3628             vals,sigs = GetColumnVals(col)
     3630            name,vals,sigs = GetColumnInfo(col)
    36293631            saveData[col] = vals
    36303632            if sigs:
     
    36623664        [['-1'],(0,1,2,3,4,5)],
    36633665        ]
    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=''):
    36653669        'strip a histogram number from a var name'
    36663670        sv = var.split(':')
    3667         sv[1] = ''
     3671        sv[1] = insChar
    36683672        return ':'.join(sv)
    36693673    def plotSpCharFix(lbl):
     
    36773681            lbl = lbl.replace(u,p)
    36783682        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
    36803701    #======================================================================
    36813702    # start processing sequential results here
     
    37063727
    37073728    # get unit cell & symmetry for all phases
    3708     cellUlbl = ('a','b','c',u'\u03B1',u'\u03B2',u'\u03b3') # unicode a,b,c,alpha,beta,gamma
    3709     #cellUlbl = ('a','b','c',r'$\alpha$',r'$\beta$',r'$\gamma$') # matplotlib a,b,c,alpha,beta,gamma
    37103729    Phases = G2frame.GetPhaseData()
    37113730    Alist = {}
     
    37463765    colLabels += ['Rwp']
    37473766    Types += [wg.GRID_VALUE_FLOAT,]
    3748     # add Converged flag
     3767    # add % change in Chi^2 in last cycle
    37493768    colList += [[100.*data[name]['Rvals'].get('DelChi2',-1) for name in histNames]]
    37503769    colSigs += [None]
     
    37523771    Types += [wg.GRID_VALUE_FLOAT,]
    37533772
     3773    # adds checkbox for converged (Bob wants to change color of previous instead)
    37543774    # colList += [[data[name]['Rvals']['converged'] for name in histNames]]
    37553775    # colSigs += [None]
    37563776    # colLabels += ['Cnvg']
    37573777    # Types += [wg.GRID_VALUE_BOOL,]
     3778
    37583779    # add sample parameters
    37593780    for key in sampleParms:
     
    38003821   
    38013822    # process the dependent constrained variables, removing histogram numbers if needed
     3823    # from parameter label
    38023824    depValDict = {}
    38033825    depSigDict = {}
     
    38053827        for var in data[name].get('depParmDict',{}):
    38063828            val,sig = data[name]['depParmDict'][var]
    3807             sv = var.split(':')
    3808             if sv[1] != '': sv[1] = '*'
    3809             svar = ':'.join(sv)
     3829            svar = striphist(var,'*')
    38103830            if svar not in depValDict:
    38113831               depValDict[svar] = [val]
     
    38143834               depValDict[svar].append(val)
    38153835               depSigDict[svar].append(sig)
     3836               
    38163837    # add the dependent constrained variables
    38173838    for var in sorted(depValDict):
     
    38313852    G2frame.SeqTable = Table(rowList,colLabels=colLabels,rowLabels=histNames,types=Types)
    38323853
     3854    # old Table contents generator, keep for comparison for right now.
    38333855    # Rwps = [data[name]['Rvals']['Rwp'] for name in histNames]
    38343856    # seqList = [[Rwps[i],]+list(data[name]['variables']) for i,name in enumerate(histNames)]
     
    38513873    G2frame.dataDisplay.AutoSizeColumns(True)
    38523874    G2frame.dataFrame.setSizePosLeft([700,350])
     3875
    38533876################################################################################
    38543877#####  Main PWDR panel
Note: See TracChangeset for help on using the changeset viewer.