Changeset 1696


Ignore:
Timestamp:
Mar 11, 2015 11:30:57 PM (7 years ago)
Author:
toby
Message:

more work on seq. ref. with differing variables; rework svn interface; fix tutorial downloads

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASII.py

    r1694 r1696  
    20122012            self._init_Macro()
    20132013        HelpMenu=G2G.MyHelp(self,helpType='Data tree',
    2014             morehelpitems=[('&Tutorials','Tutorials')])
    2015         menubar.Append(menu=HelpMenu,title='&Help')
    2016         # this will eventually go away
    2017         HelpMenu=G2G.MyHelp(self,helpType='Data tree',
    2018             morehelpitems=[('&New Tutorials','NewTutorials')])
     2014            morehelpitems=[('&Tutorials','Tutorials'),
     2015                           ('&New Tutorials','NewTutorials'), # this will eventually go away
     2016                           ])
    20192017        menubar.Append(menu=HelpMenu,title='&Help')
    20202018
  • trunk/GSASIIctrls.py

    r1692 r1696  
    19621962    ['TOF Charge Flipping', 'TOF Charge Flipping', 'Charge Flipping with TOF single crystal data in GSASII.htm',
    19631963     'Charge flipping with neutron TOF single crystal data'],
     1964    ['TOF-CW Joint Refinement', 'TOF-CW Joint Refinement', 'TOF combined XN Rietveld refinement in GSAS.htm', 'Combined XN Rietveld refinement with TOF data'],
    19641965    ['TOF Sequential Single Peak Fit', 'TOF Sequential Single Peak Fit', '', ''],
    19651966    ['TOF Single Crystal Refinement', 'TOF Single Crystal Refinement', '', ''],
    1966     ['TOF-CW Joint Refinement', 'TOF-CW Joint Refinement', '', ''],
    19671967    )
    19681968if GSASIIpath.GetConfigValue('Tutorial_location'):
     
    19701970else:
    19711971    tutorialPath = GSASIIpath.path2GSAS2
    1972    
     1972
    19731973class OpenTutorial(wx.Dialog):
    19741974    '''Open a tutorial, optionally copying it to the local disk. Always copy
     
    20622062        '''
    20632063        self.BrowseMode = self.mode.GetSelection()
    2064         #self.FillListBox()
    2065     #def FillListBox(self):
    20662064        if self.BrowseMode == 3:
    20672065            import glob
    2068             filelist = glob.glob(tutorialPath+'/help/*/*.htm')
     2066            filelist = glob.glob(os.path.join(tutorialPath,'help','*','*.htm'))
    20692067            taillist = [os.path.split(f)[1] for f in filelist]
    20702068            itemlist = [tut[-1] for tut in tutorialCatalog if tut[2] in taillist]
     
    20952093                return
    20962094        self.dataLoc.SetLabel(tutorialPath)
     2095        self.EndModal(wx.ID_OK)
    20972096        if self.BrowseMode == 0:
    20982097            # xfer data & web page locally, then open web page
     
    21162115        else:
    21172116            raise Exception("How did this happen!")
    2118         self.EndModal(wx.ID_OK)
    21192117    def ValidateTutorialDir(self,fullpath=tutorialPath,baseURL=G2BaseURL):
    21202118        '''Load help to new directory or make sure existing directory looks correctly set up
     
    21392137    def LoadTutorial(self,tutorialname,fullpath=tutorialPath,baseURL=G2BaseURL):
    21402138        'Load a Tutorial to the selected location'
    2141         if GSASIIpath.svnSwitchDir("help/"+tutorialname,baseURL+"/Tutorials/"+tutorialname,fullpath):
     2139        if GSASIIpath.svnSwitchDir("help",tutorialname,baseURL+"/Tutorials",fullpath):
    21422140            return True
    21432141        raise Exception("Problem transferring Tutorial from web")
     
    21452143    def LoadExercise(self,tutorialname,fullpath=tutorialPath,baseURL=G2BaseURL):
    21462144        'Load Exercise file(s) for a Tutorial to the selected location'
    2147         if GSASIIpath.svnSwitchDir("Exercises/"+tutorialname,baseURL+"/Exercises/"+tutorialname,fullpath):
     2145        if GSASIIpath.svnSwitchDir("Exercises",tutorialname,baseURL+"/Exercises",fullpath):
    21482146            return True
    21492147        raise Exception("Problem transferring Exercise from web")
  • trunk/GSASIIgrid.py

    r1688 r1696  
    35113511    VaryListChanges = [] # histograms where there is a change
    35123512    combinedVaryList = []
    3513     firstValueList = []
     3513    firstValueDict = {}
    35143514    vallookup = {}
    35153515    posdict = {}
     3516    prevVaryList = []
    35163517    for i,name in enumerate(histNames):
    3517         newval = False
    3518         for var,val in zip(data[name]['varyList'],data[name]['variables']):
    3519             svar = striphist(var,'*')
    3520             if svar in combinedVaryList: continue
    3521             # add variables to list as they appear
    3522             combinedVaryList.append(svar)
    3523             firstValueList.append(val)
    3524             newval = True
    3525         if newval:
     3518        for var,val,sig in zip(data[name]['varyList'],data[name]['variables'],data[name]['sig']):
     3519            svar = striphist(var,'*') # wild-carded
     3520            if svar not in combinedVaryList:
     3521                # add variables to list as they appear
     3522                combinedVaryList.append(svar)
     3523                firstValueDict[svar] = (val,sig)
     3524        if prevVaryList != data[name]['varyList']: # this refinement has a different refinement list from previous
     3525            prevVaryList = data[name]['varyList']
    35263526            vallookup[name] = dict(zip(data[name]['varyList'],data[name]['variables']))
    35273527            posdict[name] = {}
     
    36173617        if name in posdict:
    36183618            varsellist = [posdict[name].get(i) for i in range(varcols)]
    3619             #sellist = [data[name]['varyList'].index(v) if v is not None else None for v in varsellist]
    3620             sellist = [i if striphist(v,'*') in varsellist else None for i,v in enumerate(data[name]['varyList'])]
     3619            # translate variable names to how they will be used in the headings
     3620            vs = [striphist(v,'*') for v in data[name]['varyList']]
     3621            # determine the index for each column (or None) in the data[]['variables'] and ['sig'] lists
     3622            sellist = [vs.index(v) if v is not None else None for v in varsellist]
     3623            #sellist = [i if striphist(v,'*') in varsellist else None for i,v in enumerate(data[name]['varyList'])]
    36213624        if not varsellist: raise Exception()
    36223625        vals.append([data[name]['variables'][s] if s is not None else None for s in sellist])
    36233626        esds.append([data[name]['sig'][s] if s is not None else None for s in sellist])
     3627        #GSASIIpath.IPyBreak()
    36243628    colList += zip(*vals)
    36253629    colSigs += zip(*esds)
    3626     # add the variables that were refined; change from rows to columns
    3627     #colList += zip(*[data[name]['variables'] for name in histNames])
    3628     #colLabels += data[histNames[0]]['varyList']
    3629     #Types += len(data[histNames[0]]['varyList'])*[wg.GRID_VALUE_FLOAT]
    3630     #colSigs += zip(*[data[name]['sig'] for name in histNames])
    3631 
    3632     # for var in combinedVaryList:
    3633     #     colLabels += [var]
    3634     #     Types += [wg.GRID_VALUE_FLOAT]
    3635     #     vals = []
    3636     #     sigs = []
    3637     #     for name in histNames:
    3638     #         try:
    3639     #             i = data[name]['varyList'].index(var)
    3640     #             vals.append(data[name]['variables'][i])
    3641     #             sigs.append(data[name]['sig'][i])
    3642     #         except ValueError: # var not in list
    3643     #             vals.append(None)
    3644     #             sigs.append(None)
    3645     #     colList += [vals]
    3646     #     colSigs += [sigs]
    36473630               
    36483631    # tabulate constrained variables, removing histogram numbers if needed
     
    37293712
    37303713    #******************************************************************************
     3714    # create a set of values for example evaluation of pseudovars and
    37313715    # this does not work for refinements that have differing numbers of variables.
    37323716    #raise Exception
    3733     indepVarDict = {     #  values in table w/o ESDs
    3734         var:colList[i][0] for i,var in enumerate(colLabels) if colSigs[i] is None
    3735         }
    3736     # make dict of dependent vars (w/ESDs) that are not converted (Dij to Ak or dAx to Ax)
    3737     depVarDict = {
    3738         var:colList[i][0] for i,var in enumerate(colLabels)
    3739         if colSigs[i] is not None and striphist(var) not in Dlookup
    3740         }
     3717    indepVarDict = {}     #  values in table w/o ESDs
     3718    depVarDict = {}
     3719    for i,var in enumerate(colLabels):
     3720        if var == 'Use': continue
     3721        if colList[i][0] is None:
     3722            val,sig = firstValueDict.get(var,[None,None])
     3723        elif colSigs[i]:
     3724            val,sig = colList[i][0],colSigs[i][0]
     3725        else:
     3726            val,sig = colList[i][0],None
     3727        if val is None:
     3728            continue
     3729        elif sig is None:
     3730            indepVarDict[var] = val
     3731        elif striphist(var) not in Dlookup:
     3732            depVarDict[var] = val
    37413733    # add recip cell coeff. values
    37423734    depVarDict.update({var:val for var,val in data[name].get('newCellDict',{}).values()})
  • trunk/GSASIIpath.py

    r1688 r1696  
    153153            return os.path.abspath(exe_file)
    154154
     155def svnVersion():
     156    '''Get the version number of the current subversion executable
     157
     158    :returns: a string with a version number such as "1.6.6" or None if
     159      subversion is not found.
     160
     161    '''
     162    import subprocess
     163    svn = whichsvn()
     164    if not svn: return
     165
     166    cmd = [svn,'--version','--quiet']
     167    s = subprocess.Popen(cmd,
     168                         stdout=subprocess.PIPE,stderr=subprocess.PIPE)
     169    out,err = s.communicate()
     170    if err:
     171        print 'subversion error!\nout=',out
     172        print 'err=',err
     173        return None
     174    return out.strip()
     175
     176def svnVersionNumber():
     177    '''Get the version number of the current subversion executable
     178
     179    :returns: a fractional version number such as 1.6 or None if
     180      subversion is not found.
     181
     182    '''
     183    ver = svnVersion()
     184    if not ver: return
     185    M,m = svnVersion().split('.')[:2]
     186    return int(M)+int(m)/10.
     187
    155188def svnGetLog(fpath=os.path.split(__file__)[0],version=None):
    156     '''Get the revision log information for a specific version of the
     189    '''Get the revision log information for a specific version of the specified package
    157190
    158191    :param str fpath: path to repository dictionary, defaults to directory where
     
    213246    else:
    214247        cmd = [svn,'info',fpath,'--xml','-rHEAD']
    215     s = subprocess.Popen(cmd+['--non-interactive', '--trust-server-cert'],
    216                          stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    217     out,err = s.communicate()
    218     if err:
    219         print 'svn failed, retry w/o --trust...\nout=',out
     248    if svnVersionNumber() >= 1.6:
     249        cmd += ['--non-interactive', '--trust-server-cert']
     250    s = subprocess.Popen(cmd, stdout=subprocess.PIPE,stderr=subprocess.PIPE)
     251    out,err = s.communicate()
     252    if err:
     253        print 'svn failed\n',out
    220254        print 'err=',err
    221         s = subprocess.Popen(cmd,
    222                             stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    223         out,err = s.communicate()
    224         if err:
    225             print 'out=',out
    226             print 'err=',err
    227             return None
     255        return None
    228256    x = ET.fromstring(out)
    229257    for i in x.iter('entry'):
     
    278306           '--non-interactive',
    279307           '--accept','theirs-conflict','--force']
    280     s = subprocess.Popen(cmd+['--trust-server-cert'],
    281                          stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    282     out,err = s.communicate()
    283     print out
    284     if err:
    285         s = subprocess.Popen(cmd,
    286                          stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    287         out,err = s.communicate()
    288         if err:
    289             print(60*"=")
    290             print ("****** An error was noted, see below *********")
    291             print(60*"=")
    292             print err
    293             sys.exit()
    294 
     308    if svnVersionNumber() >= 1.6:
     309        cmd += ['--trust-server-cert']
     310    s = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
     311    out,err = s.communicate()
     312    if err:
     313        print(60*"=")
     314        print ("****** An error was noted, see below *********")
     315        print(60*"=")
     316        print err
     317        sys.exit()
     318
     319def svnUpgrade(fpath=os.path.split(__file__)[0]):
     320    '''This reformats subversion files, which may be needed if an upgrade of subversion is
     321    done.
     322
     323    :param str fpath: path to repository dictionary, defaults to directory where
     324       the current file is located
     325    '''
     326    import subprocess
     327    svn = whichsvn()
     328    if not svn: return
     329    cmd = [svn,'upgrade',fpath,'--non-interactive']
     330    s = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
     331    out,err = s.communicate()
     332    if err:
     333        print("svn upgrade did not happen (this is probably OK). Messages:")
     334        print err
     335           
    295336def svnUpdateProcess(version=None,projectfile=None):
    296337    '''perform an update of GSAS-II in a separate python process'''
     
    309350    sys.exit()
    310351
    311 def svnSwitchDir(rpath,URL,loadpath=None):
     352def svnSwitchDir(rpath,filename,baseURL,loadpath=None):
    312353    '''This performs a switch command to move files between subversion trees.
    313354
     
    324365    svn = whichsvn()
    325366    if not svn: return
     367    URL = baseURL[:]
     368    if baseURL[-1] != '/':
     369        URL = baseURL + '/' + filename
     370    else:
     371        URL = baseURL + filename
    326372    if loadpath:
    327         fpath = os.path.join(loadpath,rpath)
    328     else:
    329         fpath = os.path.join(path2GSAS2,rpath)
    330     cmd = [svn,'switch','--ignore-ancestry',URL,fpath,
    331            '--non-interactive',
     373        fpath = os.path.join(loadpath,rpath,filename)
     374    else:
     375        fpath = os.path.join(path2GSAS2,rpath,filename)
     376    cmd = [svn,'switch',URL,fpath,
     377           '--non-interactive','--trust-server-cert',
    332378           '--accept','theirs-conflict','--force']
     379    if svnVersionNumber() > 1.6: cmd += ['--ignore-ancestry']
    333380    print("Loading files from "+URL)
    334     s = subprocess.Popen(cmd+['--trust-server-cert'],
    335                          stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    336     out,err = s.communicate()
    337     if err:
    338         s = subprocess.Popen(cmd,
    339                          stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    340         out,err = s.communicate()
    341         if err:
    342             print(60*"=")
    343             print ("****** An error was noted, see below *********")
    344             print(60*"=")
    345             print err
    346             return False
     381    s = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
     382    out,err = s.communicate()
     383    if err:
     384        print(60*"=")
     385        print ("****** An error was noted, see below *********")
     386        print(60*"=")
     387        print 'out=',out
     388        print 'err=',err
     389        return False
    347390    return True
    348391
     
    360403        raise Exception("Error: Attempting to create existing directory "+loadpath)
    361404    cmd = [svn,'co',URL,loadpath,'--non-interactive']
     405    if svnVersionNumber() >= 1.6: cmd += ['--trust-server-cert']
    362406    print("Loading files from "+URL)
    363     s = subprocess.Popen(cmd+['--trust-server-cert'],
    364                          stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    365     out,err = s.communicate()
    366     if err:
    367         print out
    368         s = subprocess.Popen(cmd,
    369                          stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    370         out,err = s.communicate()
    371         if err:
    372             print(60*"=")
    373             print ("****** An error was noted, see below *********")
    374             print(60*"=")
    375             print err
    376             return False
     407    s = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
     408    out,err = s.communicate()
     409    if err:
     410        print(60*"=")
     411        print ("****** An error was noted, see below *********")
     412        print(60*"=")
     413        print err
     414        return False
    377415    return True
    378 
    379416           
    380417def IPyBreak_base():
  • trunk/config_example.py

    r1688 r1696  
    4242G2 is installed by an administrator, it is a good idea to use something like this:
    4343    import os.path
    44     Tutorial_location = os.path.expanduser('~/G2tutorials')
     44    Tutorial_location = os.path.join(os.path.expanduser('~'),'G2tutorials')
    4545This will allow users to download tutorial files into their own file space.
    4646'''
Note: See TracChangeset for help on using the changeset viewer.