Changeset 1287


Ignore:
Timestamp:
Apr 19, 2014 10:28:10 AM (8 years ago)
Author:
toby
Message:

Seq Ref: add pseudo var; open Seq Ref after refinement; highlight unconverged; reset Copy Next after ref.; Also: remove annoying wx.FRAME_FLOAT_ON_PARENT

Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASII.py

    r1283 r1287  
    32623262                    self.G2plotNB.clear()
    32633263                G2IO.ProjFileOpen(self)
    3264                 item, cookie = self.PatternTree.GetFirstChild(self.root)
    3265                 while item and not Id:
    3266                     name = self.PatternTree.GetItemText(item)
    3267                     if name[:4] in ['PWDR','HKLF']:
    3268                         Id = item
    3269                     item, cookie = self.PatternTree.GetNextChild(self.root, cookie)               
    3270                 if Id:
    3271                     self.PatternTree.SelectItem(Id)
     3264                # (BHT) what does this next section of code do?
     3265                #item, cookie = self.PatternTree.GetFirstChild(self.root)
     3266                #while item and not Id:
     3267                #    name = self.PatternTree.GetItemText(item)
     3268                #    if name[:4] in ['PWDR','HKLF']:
     3269                #        Id = item
     3270                #    item, cookie = self.PatternTree.GetNextChild(self.root, cookie)
     3271                #if Id:
     3272                #    self.PatternTree.SelectItem(Id)
     3273
     3274                # Open the sequential results tree entry
     3275                Id = G2gd.GetPatternTreeItemId(self,self.root,'Sequential results')
     3276                self.PatternTree.SelectItem(Id)
     3277                G2gd.MovePatternTreeToGrid(self,Id)
     3278
    32723279        finally:
    32733280            dlg.Destroy()
  • trunk/GSASIIgrid.py

    r1286 r1287  
    4343import GSASIIpy3 as G2py3
    4444import GSASIIobj as G2obj
     45import GSASIIexprGUI as G2exG
    4546
    4647# trig functions in degrees
     
    134135
    135136[ wxID_SAVESEQSEL,wxID_SAVESEQSELCSV,wxID_PLOTSEQSEL,
    136 ] = [wx.NewId() for item in range(3)]
     137  wxADDSEQVAR,wxDELSEQVAR,wxEDITSEQVAR,
     138] = [wx.NewId() for item in range(6)]
    137139
    138140[ wxID_MODELCOPY,wxID_MODELFIT,wxID_MODELADD,wxID_ELEMENTADD,wxID_ELEMENTDELETE,
     
    24612463        self.SequentialFile.Append(id=wxID_PLOTSEQSEL, kind=wx.ITEM_NORMAL,text='Plot selected',
    24622464            help='Plot selected sequential refinement results')
     2465        self.SequentialPvars = wx.Menu(title='')
     2466        self.SequentialMenu.Append(menu=self.SequentialPvars, title='Pseudo Vars')
     2467        self.SequentialPvars.Append(
     2468            id=wxADDSEQVAR, kind=wx.ITEM_NORMAL,text='Add',
     2469            help='Add a new pseudo-variable')
     2470        self.SequentialPvars.Append(
     2471            id=wxDELSEQVAR, kind=wx.ITEM_NORMAL,text='Delete',
     2472            help='Delete an existing pseudo-variable')
     2473        self.SequentialPvars.Append(
     2474            id=wxEDITSEQVAR, kind=wx.ITEM_NORMAL,text='Edit',
     2475            help='Edit an existing pseudo-variable')
    24632476        self.PostfillDataMenu()
    24642477           
     
    29612974       
    29622975    def _init_ctrls(self, parent,name=None,size=None,pos=None):
    2963         wx.Frame.__init__(self,parent=parent,
    2964             style=wx.DEFAULT_FRAME_STYLE ^ wx.CLOSE_BOX | wx.FRAME_FLOAT_ON_PARENT ,
     2976        wx.Frame.__init__(
     2977            self,parent=parent,
     2978            #style=wx.DEFAULT_FRAME_STYLE ^ wx.CLOSE_BOX | wx.FRAME_FLOAT_ON_PARENT ,
     2979            style=wx.DEFAULT_FRAME_STYLE ^ wx.CLOSE_BOX,
    29652980            size=size,pos=pos,title='GSAS-II data display')
    29662981        self._init_menus()
     
    34873502           
    34883503################################################################################
    3489 #####  Sequential Results
     3504#####  Display of Sequential Results
    34903505################################################################################           
    34913506       
    3492 def UpdateSeqResults(G2frame,data):
     3507def UpdateSeqResults(G2frame,data,prevSize=None):
    34933508    """
    34943509    Called when the Sequential Results data tree entry is selected
     
    36653680        ]
    36663681    # cell labels
    3667     cellUlbl = ('a','b','c',u'\u03B1',u'\u03B2',u'\u03b3') # unicode a,b,c,alpha,beta,gamma
     3682    cellUlbl = ('a','b','c',u'\u03B1',u'\u03B2',u'\u03B3') # unicode a,b,c,alpha,beta,gamma
    36683683    def striphist(var,insChar=''):
    36693684        'strip a histogram number from a var name'
     
    36763691            (u'\u03B1',r'$\alpha$'),
    36773692            (u'\u03B2',r'$\beta$'),
    3678             (u'\u03b3',r'$\gamma$'),
     3693            (u'\u03B3',r'$\gamma$'),
    36793694            (u'\u0394\u03C7',r'$\Delta\chi$'),
    36803695            ]:
     
    36993714            dlg.Destroy()
    37003715        return col
     3716   
     3717    def EnableSeqExpressionMenus():
     3718        'Enables or disables the PseudoVar menu items that require existing defs'
     3719        if Controls['SeqPseudoVars']:
     3720            val = True
     3721        else:
     3722            val = False
     3723        G2frame.dataFrame.SequentialPvars.Enable(wxDELSEQVAR,val)
     3724        G2frame.dataFrame.SequentialPvars.Enable(wxEDITSEQVAR,val)
     3725
     3726    def DelSeqExpression(event):
     3727        'Ask the user to select expression to delete'
     3728        choices = Controls['SeqPseudoVars'].keys()
     3729        selected = ItemSelector(
     3730            choices,G2frame.dataFrame,
     3731            multiple=True,
     3732            title='Select expressions to remove',
     3733            header='Delete expression')
     3734        for item in selected:
     3735            del Controls['SeqPseudoVars'][choices[item]]
     3736        if selected:
     3737            UpdateSeqResults(G2frame,data,G2frame.dataDisplay.GetSize()) # redisplay variables
     3738
     3739    def EditSeqExpression(event):
     3740        'Edit an existing expression'
     3741        choices = Controls['SeqPseudoVars'].keys()
     3742        selected = ItemSelector(
     3743            choices,G2frame.dataFrame,
     3744            multiple=False,
     3745            title='Select an expression to edit',
     3746            header='Edit expression')
     3747        if selected is not None:
     3748            dlg = G2exG.ExpressionDialog(G2frame.dataDisplay,parmDict,
     3749                                         Controls['SeqPseudoVars'][choices[selected]],
     3750                                         header='Edit this expression formula',
     3751                                         fit=False)
     3752            newobj = dlg.Show(True)
     3753            if newobj:
     3754                calcobj = G2obj.ExpressionCalcObj(newobj)
     3755                del Controls['SeqPseudoVars'][choices[selected]]
     3756                Controls['SeqPseudoVars'][calcobj.eObj.expression] = newobj
     3757                UpdateSeqResults(G2frame,data,G2frame.dataDisplay.GetSize()) # redisplay variables
     3758       
     3759    def AddNewSeqExpression(event):
     3760        'Create a new expression'
     3761        parmDict = dict(zip(colLabels,zip(*colList)[0]))
     3762        dlg = G2exG.ExpressionDialog(G2frame.dataDisplay,parmDict,
     3763                                     header='Enter an expression formula here',
     3764                                     fit=False)
     3765        obj = dlg.Show(True)
     3766        dlg.Destroy()
     3767        if obj:
     3768            calcobj = G2obj.ExpressionCalcObj(obj)
     3769            Controls['SeqPseudoVars'][calcobj.eObj.expression] = obj
     3770            UpdateSeqResults(G2frame,data,G2frame.dataDisplay.GetSize()) # redisplay variables
     3771
    37013772    #======================================================================
    37023773    # start processing sequential results here
     
    37043775        print 'No sequential refinement results'
    37053776        return
     3777    Histograms,Phases = G2frame.GetUsedHistogramsAndPhasesfromTree()
     3778    Controls = G2frame.PatternTree.GetItemPyData(GetPatternTreeItemId(G2frame,G2frame.root,'Controls'))
     3779    if 'SeqPseudoVars' not in Controls: # create a place to store Pseudo Vars, if needed
     3780        Controls['SeqPseudoVars'] = {}
    37063781    histNames = data['histNames']
    37073782    if G2frame.dataDisplay:
     
    37103785        Status = G2frame.dataFrame.CreateStatusBar()
    37113786        Status.SetStatusText("Select column to export; Double click on column to plot data; on row for Covariance")
     3787    sampleParms = GetSampleParms()
    37123788    # make dict of varied atom coords keyed by absolute position
    37133789    newAtomDict = data[histNames[0]]['newAtomDict'] # dict with atom positions; relative & absolute
     
    37273803
    37283804    # get unit cell & symmetry for all phases
    3729     Phases = G2frame.GetPhaseData()
    37303805    Alist = {}
    37313806    SGdata = {}
     
    37473822            uniqCellParms[pId] = range(6)
    37483823
    3749     sampleParms = GetSampleParms()
    37503824    SetDataMenuBar(G2frame,G2frame.dataFrame.SequentialMenu)
    37513825    G2frame.dataFrame.SetLabel('Sequential refinement results')
     
    37543828    G2frame.dataFrame.Bind(wx.EVT_MENU, OnSaveSelSeqCSV, id=wxID_SAVESEQSELCSV)
    37553829    G2frame.dataFrame.Bind(wx.EVT_MENU, OnPlotSelSeq, id=wxID_PLOTSEQSEL)
    3756     # build up the table one column at a time
     3830    G2frame.dataFrame.Bind(wx.EVT_MENU, AddNewSeqExpression, id=wxADDSEQVAR)
     3831    G2frame.dataFrame.Bind(wx.EVT_MENU, DelSeqExpression, id=wxDELSEQVAR)
     3832    G2frame.dataFrame.Bind(wx.EVT_MENU, EditSeqExpression, id=wxEDITSEQVAR)
     3833    EnableSeqExpressionMenus()
     3834
     3835    # build up the data table one column at a time
    37573836    colList = []
    37583837    colSigs = []
     
    37703849    colLabels += [u'\u0394\u03C7\u00B2 (%)']
    37713850    Types += [wg.GRID_VALUE_FLOAT,]
     3851    deltaChiCol = len(colLabels)-1
    37723852
    37733853    # adds checkbox for converged (Bob wants to change color of previous instead)
     
    38483928    for parm in atomList:
    38493929        colList += [[data[name]['newAtomDict'][atomList[parm]][1] for name in histNames]]
     3930    # add Pseudovars
     3931    for exp in Controls['SeqPseudoVars']:
     3932        obj = Controls['SeqPseudoVars'][exp]
     3933        calcobj = G2obj.ExpressionCalcObj(obj)
     3934        valList = []
     3935        for row in zip(*colList):
     3936            parmDict = dict(zip(colLabels,row))
     3937            calcobj.SetupCalc(parmDict)
     3938            valList.append(calcobj.EvalExpression())
     3939        colList += [valList]
     3940        colSigs += [None]
     3941        colLabels += [exp]
     3942        Types += [wg.GRID_VALUE_FLOAT,]
    38503943
    38513944    rowList = [c for c in zip(*colList)]     # convert from columns to rows
     
    38653958    # G2frame.SeqTable = Table(seqList,colLabels=colLabels,rowLabels=histNames,types=Types
    38663959    #                         )
     3960   
    38673961    G2frame.dataDisplay = GSGrid(parent=G2frame.dataFrame)
     3962    # colSigs += [None]
     3963    # colLabels += ['Cnvg']
     3964    # Types += [wg.GRID_VALUE_BOOL,]
    38683965    G2frame.dataDisplay.SetTable(G2frame.SeqTable, True)
    38693966    G2frame.dataDisplay.EnableEditing(False)
     
    38723969    G2frame.dataDisplay.SetMargins(0,0)
    38733970    G2frame.dataDisplay.AutoSizeColumns(True)
    3874     G2frame.dataFrame.setSizePosLeft([700,350])
    3875 
     3971    if prevSize:
     3972        G2frame.dataDisplay.SetSize(prevSize)
     3973    else:
     3974        G2frame.dataFrame.setSizePosLeft([700,350])
     3975    # highlight unconverged shifts
     3976    for row,name in enumerate(histNames):
     3977        if not data[name]['Rvals']['converged']:
     3978            G2frame.dataDisplay.SetCellStyle(row,deltaChiCol,color=wx.Color(255,255,0))
     3979        # colList += [[data[name]['Rvals']['converged'] for name in histNames]]
     3980   
    38763981################################################################################
    38773982#####  Main PWDR panel
  • trunk/GSASIIobj.py

    r1282 r1287  
    11191119    '''
    11201120   
     1121    # special handling for parameter names without a colons
     1122    # for now, assume self-defining
     1123    if varname.find(':') == -1:
     1124        return "Global",varname
     1125       
    11211126    l = getVarDescr(varname)
    11221127    if not l:
    1123         return "invalid variable name ("+str(varname)+")!"
     1128        #return ("invalid variable name ("+str(varname)+")!"),""
     1129        return "invalid variable name!",""
    11241130
    11251131    if not l[-1]:
     
    11431149            hlbl = 'Hist='+hlbl
    11441150        s = "Ph="+str(lbl)+" * "+str(hlbl)
     1151    elif l[2] == 'Back': # background parameters are "special", alas
     1152        s = 'Hist='+ShortHistNames.get(l[1],'? #'+str(l[1]))
     1153        l[-1] += ' #'+str(l[3])
    11451154    elif l[4] is not None: # rigid body parameter
    11461155        lbl = ShortPhaseNames.get(l[0],'phase?')
     
    12221231    if reVarDesc: return # already done
    12231232    for key,value in {
     1233        # derived or other sequential vars
     1234        '([abc])$' : 'Lattice parameter, \\1, from Ai and Djk', # N.B. '$' prevents match if any characters follow
     1235        u'\u03B1' : u'Lattice parameter, \u03B1, from Ai and Djk',
     1236        u'\u03B2' : u'Lattice parameter, \u03B2, from Ai and Djk',
     1237        u'\u03B3' : u'Lattice parameter, \u03B3, from Ai and Djk',
    12241238        # ambiguous, alas:
    12251239        'Scale' : 'Phase or Histogram scale factor',
     
    12331247        'Afrac': 'Atomic occupancy parameter',
    12341248        # Hist & Phase (HAP) vars (p:h:<var>)
     1249        'Back': 'Background term',
     1250        'BkPkint;(.*)':'Background peak #\\1 intensity',
     1251        'BkPkpos;(.*)':'Background peak #\\1 position',
     1252        'BkPksig;(.*)':'Background peak #\\1 Gaussian width',
     1253        'BkPkgam;(.*)':'Background peak #\\1 Cauchy width',
    12351254        'Bab([AU])': 'Babinet solvent scattering coef. \\1',
    12361255        'D([123][123])' : 'Anisotropic strain coef. \\1',
     
    12581277        'RBR([TLS])([123AB][123AB])' : 'Residue rigid body group disp. param.',
    12591278        # Global vars (::<var>)
     1279        'constr([0-9]*)' : 'Parameter from constraint',
    12601280        }.items():
    12611281        VarDesc[key] = value
  • trunk/GSASIIstrIO.py

    r1253 r1287  
    516516        if datum[0] == 'Sequential results':
    517517            data[0][1] = SeqResult
     518        # reset the Copy Next flag, since it should not be needed twice in a row
     519        if datum[0] == 'Controls':
     520            data[0][1]['Copy2Next'] = False
    518521        try:
    519522            histogram = Histograms[datum[0]]
Note: See TracChangeset for help on using the changeset viewer.