Changeset 3447


Ignore:
Timestamp:
Jun 23, 2018 7:46:31 PM (3 years ago)
Author:
toby
Message:

fix seq ref constraint numbering bug; fix use if HAP vars in PSvars & equations; complete RepaintHistogramInfo? w/Py3 + misc Py3 fixes; improve initialization after project read

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIIO.py

    r3438 r3447  
    11991199            outfile = os.path.join(zloc, efil)
    12001200            fpin = z.open(zinfo[zindex])
    1201             fpout = file(outfile, "wb")
     1201            fpout = open(outfile, "wb")
    12021202            shutil.copyfileobj(fpin, fpout)
    12031203            fpin.close()
  • trunk/GSASIIctrlGUI.py

    r3445 r3447  
    110110import os
    111111import sys
     112import platform
    112113try:
    113114    import wx
     
    33883389        # make lists of variables of different types along with lists of parameter names, histogram #s, phase #s,...
    33893390        self.parmNames = sorted(list(parmDict.keys()))
     3391        if '2' not in platform.python_version_tuple()[0]: basestring = str
    33903392        splitNames = [item.split(':') for item in self.parmNames if len(item) > 3 and not isinstance(self.parmDict[item],basestring)]
    33913393        globNames = [':'.join(item) for item in splitNames if not item[0] and not item[1]]
     
    34273429        for name in self.choiceDict[self.parmChoice]:
    34283430            # skip entries without numerical values
     3431            if '2' not in platform.python_version_tuple()[0]: basestring = str
    34293432            if isinstance(self.parmDict[name],basestring): continue
    34303433            if 'Refined' in self.listSel and (name not in self.fullVaryList
  • trunk/GSASIIdataGUI.py

    r3446 r3447  
    26462646                    win.Center()
    26472647
    2648     def __init__(self, parent):
    2649         self.ExportLookup = {}
    2650         self.exporterlist = []
    2651         self._init_ctrls(parent)
    2652         self.Image = wx.Image(
    2653             os.path.join(GSASIIpath.path2GSAS2,'gsas2.ico'),
    2654             wx.BITMAP_TYPE_ICO)
    2655         if "wxMSW" in wx.PlatformInfo:
    2656             img = self.Image.Scale(16, 16).ConvertToBitmap()
    2657         elif "wxGTK" in wx.PlatformInfo:
    2658             img = self.Image.Scale(22, 22).ConvertToBitmap()
    2659         else:
    2660             img = self.Image.ConvertToBitmap()
    2661         if 'phoenix' in wx.version():
    2662             self.SetIcon(wx.Icon(img))
    2663         else:
    2664             self.SetIcon(wx.IconFromBitmap(img))
    2665         self.Bind(wx.EVT_CLOSE, self.ExitMain)
     2648    def init_vars(self):
    26662649        # initialize default values for GSAS-II "global" variables (saved in main Frame)
    26672650        self.oldFocus = None
    2668         self.GSASprojectfile = ''
    26692651        self.undofile = ''
    26702652        self.TreeItemDelete = False
     
    27192701        self.EnablePlot = True
    27202702        self.hist = ''              # selected histogram in Phase/Data tab
     2703        self.dataDisplayPhaseText = ''
     2704        self.lastTreeSetting = [] # used to track the selected Tree item before a refinement
     2705        self.ExpandingAll = False
     2706        self.SeqTblHideList = None
     2707        self.lastSelectedPhaseTab = None # track the last tab pressed on a phase window
     2708       
     2709    def __init__(self, parent):
     2710        self.ExportLookup = {}
     2711        self.exporterlist = []
     2712        self._init_ctrls(parent)
     2713        self.Image = wx.Image(
     2714            os.path.join(GSASIIpath.path2GSAS2,'gsas2.ico'),
     2715            wx.BITMAP_TYPE_ICO)
     2716        if "wxMSW" in wx.PlatformInfo:
     2717            img = self.Image.Scale(16, 16).ConvertToBitmap()
     2718        elif "wxGTK" in wx.PlatformInfo:
     2719            img = self.Image.Scale(22, 22).ConvertToBitmap()
     2720        else:
     2721            img = self.Image.ConvertToBitmap()
     2722        if 'phoenix' in wx.version():
     2723            self.SetIcon(wx.Icon(img))
     2724        else:
     2725            self.SetIcon(wx.IconFromBitmap(img))
     2726        self.Bind(wx.EVT_CLOSE, self.ExitMain)
     2727        self.GSASprojectfile = ''
    27212728        self.dirname = os.path.abspath(os.path.expanduser('~'))       #start in the users home directory by default; may be meaningless
    27222729        self.TutorialImportDir = None  # location to read tutorial files, set when a tutorial is viewed
     
    27252732        self.LastExportDir = None  # the last directory used for exports, if any.
    27262733        self.dataDisplay = None
    2727         self.dataDisplayPhaseText = ''
    2728         self.lastTreeSetting = [] # used to track the selected Tree item before a refinement
    2729         self.ExpandingAll = False
    2730         self.SeqTblHideList = None
    2731         self.lastSelectedPhaseTab = None # track the last tab pressed on a phase window
    2732                
     2734        self.init_vars()
     2735                       
    27332736        arg = sys.argv
    27342737        if len(arg) > 1 and arg[1]:
     
    36423645            self.dirname = os.path.split(filename)[0]
    36433646
     3647        self.init_vars()
    36443648        try:
    36453649            self.StartProject()         #open the file if possible
     
    63886392                data['SeqParFitEqList'][selected],depVarDict=VarDict,
    63896393                header="Edit the formula for this minimization function",
    6390                 ExtraButton=['Fit',SingleParEqFit])
     6394                ExtraButton=['Fit',SingleParEqFit],wildCard=False)
    63916395            newobj = dlg.Show(True)
    63926396            if newobj:
     
    64066410        dlg = G2exG.ExpressionDialog(G2frame.dataDisplay,VarDict,depVarDict=VarDict,
    64076411            header='Define an equation to minimize in the parametric fit',
    6408             ExtraButton=['Fit',SingleParEqFit],usedVars=usedvarlist)
     6412            ExtraButton=['Fit',SingleParEqFit],usedVars=usedvarlist,wildCard=False)
    64096413        obj = dlg.Show(True)
    64106414        dlg.Destroy()
     
    64376441                G2frame.dataDisplay,VarDict,newEqn,depVarDict=VarDict,
    64386442                header="Edit the formula for this minimization function",
    6439                 ExtraButton=['Fit',SingleParEqFit])
     6443                ExtraButton=['Fit',SingleParEqFit],wildCard=False)
    64406444            newobj = dlg.Show(True)
    64416445            if newobj:
  • trunk/GSASIIddataGUI.py

    r3436 r3447  
    796796    def RepaintHistogramInfo(Scroll=0):
    797797        if 'phoenix' in wx.version():
    798 #            if DData.__class__ is  not wx._core.ScrolledWindow:
    799 #                # How to determine window is closed in Phoenix?
    800 #                return
    801798            G2frame.bottomSizer.Clear(True)
     799            # deal with case where this is called after another tree item has been selected
     800            try:
     801                DData.Shown
     802            except RuntimeError:
     803                if GSASIIpath.GetConfigValue('debug'):
     804                    print('DBG: DData window deleted. Ignoring RepaintHistogramInfo, forcing redraw')
     805                # Repaint called while DData window deleted, force redraw of entire window
     806                import GSASIIdataGUI
     807                G2frame.PickIdText = ''
     808                wx.CallLater(100,GSASIIdataGUI.SelectDataTreeItem,G2frame,G2frame.GPXtree.Selection)
     809                return
    802810        else:
     811            # deal with case where this is called after another tree item has been selected
    803812            if DData.__class__ is  not wx._windows.ScrolledWindow:
    804813                # fix bug where this is called after the Window is deleted
  • trunk/GSASIIexprGUI.py

    r3136 r3447  
    2525from __future__ import division, print_function
    2626import re
     27import platform
    2728import wx
    2829import wx.lib.scrolledpanel as wxscroll
     
    127128      will not be reused as defaults for new free variables.
    128129      (The default is an empty list).
     130    :param bool wildCard: If True (default), histogram names are converted to wildcard
     131      values, as is appropriate for the sequential refinement table
    129132    '''
    130133    def __init__(self, parent, parmDict, exprObj=None,
     
    132135                 wintitle='Expression Editor',
    133136                 fit=True,VarLabel=None,depVarDict=None,
    134                  ExtraButton=None,usedVars=[]):
     137                 ExtraButton=None,usedVars=[],
     138                 wildCard=True):
    135139        self.fit = fit
    136140        self.depVarDict = depVarDict
     
    168172        self.usedVars = usedVars
    169173        'variable names that have been used and should not be reused by default'
     174        self.wildCard = wildCard
    170175        defSize = (620,340) # seems like a good size
    171176        'Starting size for dialog'
     
    179184            except (TypeError,IndexError):
    180185                val = parmDict[key]
     186            if '2' not in platform.python_version_tuple()[0]: basestring = str
    181187            if isinstance(val, basestring): continue
    182188            try:
     
    380386                if msg: msg += "; "
    381387                msg += 'No variable for '+str(v)
    382             elif self.varSelect.get(v) > 0:
    383                if '*' in varname:
     388            elif self.varSelect.get(v,0) > 0:
     389                if varname in self.parmDict:
     390                    pass
     391                elif '*' in varname:
    384392                   l = G2obj.LookupWildCard(varname,list(self.parmDict.keys()))
    385393                   if len(l) == 0:
     
    387395                       if msg: msg += "; "
    388396                       msg += 'No variables match '+str(varname)
    389                elif varname not in self.parmDict.keys():
     397                elif varname not in self.parmDict:
    390398                   invalid += 1
    391399                   if msg: msg += "; "
     
    458466        :returns: a variable name or None (if Cancel is pressed)
    459467        '''
     468        def wildHist(var):
     469            '''Replace a histogram number with a wild card
     470            '''
     471            slst = var.split(':')
     472            if len(slst) > 2 and slst[1]:
     473                slst[1] = '*'
     474                return ':'.join(slst)
     475            return var
     476
    460477        if not parmList:
    461478            return None
    462479        l2 = l1 = 1
    463         for i in parmList:
     480        if self.wildCard:
     481            wildList = [wildHist(i) for i in parmList]
     482        else:
     483            wildList = parmList
     484        for i in wildList:
    464485            l1 = max(l1,len(i))
    465486            loc,desc = G2obj.VarDescr(i)
    466487            l2 = max(l2,len(loc))
    467488        fmt = u"{:"+str(l1)+"s} {:"+str(l2)+"s} {:s}"
    468         varListlbl = [fmt.format(i,*G2obj.VarDescr(i)) for i in parmList]
    469 
     489        varListlbl = [fmt.format(i,*G2obj.VarDescr(i)) for i in wildList]
    470490        dlg = G2G.G2SingleChoiceDialog(
    471491            self,'Select GSAS-II variable for '+str(var)+':',
     
    477497        if dlg.ShowModal() == wx.ID_OK:
    478498            i = dlg.GetSelection()
    479             var = parmList[i]
     499            var = wildList[i]
    480500        dlg.Destroy()
    481501        return var
     
    608628            else:
    609629                var = self.varName[v]
    610                 if '*' in var:
     630                if var in self.parmDict:
     631                    val = self.parmDict[var]
     632                    s = G2py3.FormatSigFigs(val).rstrip('0')
     633                elif '*' in var:
    611634                    vs = G2obj.LookupWildCard(var,self.parmDict.keys())
    612635                    s = '('+str(len(vs))+' values)'
    613                 elif var in self.parmDict:
    614                     val = self.parmDict[var]
    615                     s = G2py3.FormatSigFigs(val).rstrip('0')
    616636                else:
    617637                    s = '?'
     
    951971    #app.MainLoop()
    952972
    953     import platform
    954973    if '2' in platform.python_version_tuple()[0]:
    955974        import cPickle
  • trunk/GSASIIobj.py

    r3345 r3447  
    16351635        v = []
    16361636        for i in var.split(':'):
     1637            if i == '':
     1638                v.append(-1)
     1639                continue
    16371640            try:
    16381641                v.append(int(i))
     
    25592562        '''
    25602563        # Patch: for old-style expressions with a (now removed step size)
     2564        if '2' not in platform.python_version_tuple()[0]: basestring = str
    25612565        for v in self.eObj.assgnVars:
    25622566            if not isinstance(self.eObj.assgnVars[v], basestring):
     
    25782582        # look at first value in parmDict to determine its type
    25792583        parmsInList = True
     2584        if '2' not in platform.python_version_tuple()[0]: basestring = str
    25802585        for key in parmDict:
    25812586            val = parmDict[key]
     
    26052610        for v in self.eObj.assgnVars:
    26062611            varname = self.eObj.assgnVars[v]
    2607             if '*' in varname:
     2612            if varname in parmDict:
     2613                self.lblLookup[varname] = v
     2614                self.varLookup[v] = varname
     2615                if parmsInList:
     2616                    self.exprDict[v] = parmDict[varname][0]
     2617                else:
     2618                    self.exprDict[v] = parmDict[varname]
     2619            elif '*' in varname:
    26082620                varlist = LookupWildCard(varname,list(parmDict.keys()))
    26092621                if len(varlist) == 0:
     
    26162628                    self.exprDict[v] = np.array([parmDict[var] for var in varlist])
    26172629                self.varLookup[v] = [var for var in varlist]
    2618             elif varname in parmDict:
    2619                 self.lblLookup[varname] = v
    2620                 self.varLookup[v] = varname
    2621                 if parmsInList:
    2622                     self.exprDict[v] = parmDict[varname][0]
    2623                 else:
    2624                     self.exprDict[v] = parmDict[varname]
    26252630            else:
    26262631                self.exprDict[v] = None
  • trunk/GSASIIstrMain.py

    r3413 r3447  
    368368            continue
    369369    #TODO - implement "Fix FXU" for seq refinement here - done?
     370        hId = Histograms[histogram]['hId']
    370371        redphaseVary = phaseCheck(phaseVary,Phases,histogram)
    371372        Histo = {histogram:Histograms[histogram],}
     
    405406        try:
    406407            groups,parmlist = G2mv.GroupConstraints(constrDict)
    407             G2mv.GenerateConstraints(groups,parmlist,varyList,constrDict,fixedList,parmDict,SeqHist=ihst)
    408             #print (G2mv.VarRemapShow(varyList,True))
     408            G2mv.GenerateConstraints(groups,parmlist,varyList,constrDict,fixedList,parmDict,SeqHist=hId)
     409#            if GSASIIpath.GetConfigValue('debug'): print("DBG_"+
     410#                G2mv.VarRemapShow(varyList,True))
    409411            constraintInfo = (groups,parmlist,constrDict,fixedList,ihst)
    410412        except G2mv.ConstraintException:
Note: See TracChangeset for help on using the changeset viewer.