Changeset 4654 for trunk


Ignore:
Timestamp:
Nov 10, 2020 11:24:39 AM (3 years ago)
Author:
toby
Message:

new video tutorial; misc minor RB GUI fixes for Windows; option to show GPX sizes; remove use of deprecated imp module

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIIO.py

    r4635 r4654  
    677677    wx.BeginBusyCursor()
    678678    try:
     679        if GSASIIpath.GetConfigValue('show_gpxSize'):
     680            posPrev = 0
     681            sizeList = {}
    679682        while True:
    680683            try:
     
    683686                break
    684687            datum = data[0]
     688            if GSASIIpath.GetConfigValue('show_gpxSize'):
     689                sizeList[datum[0]] = filep.tell()-posPrev
     690                posPrev = filep.tell()
    685691            # scan the GPX file for unexpected objects
    686692            if GSASIIpath.GetConfigValue('debug'):
     
    761767        else:
    762768            print('project load successful')
     769        if GSASIIpath.GetConfigValue('show_gpxSize'):
     770            print(50*'=')
     771            print('File section sizes (Kb)')
     772            for item in sizeList:
     773                print('  {:20s} {:10.3f}'.format(
     774                    item[:20],sizeList[item]/1024.))
     775            print(50*'=')
    763776        G2frame.NewPlot = True
    764777    except Exception as errmsg:
  • trunk/GSASIIctrlGUI.py

    r4647 r4654  
    12781278        if self.onChoice:
    12791279            self.onChoice()
     1280    def setByString(self,string):
     1281        'Find an entry matching string and select it'
     1282        num = self.FindString(string)
     1283        if num >= 0: self.SetSelection(num)
    12801284
    12811285##############################################################
  • trunk/GSASIIfiles.py

    r4635 r4654  
    2828import inspect
    2929import numpy as np
    30 import imp
    3130
    3231import GSASIIpath
     
    388387
    389388    readerlist = []
    390     pathlist = sys.path[:]
    391     if '.' not in pathlist:
    392         pathlist.append('.')
    393 
    394     potential_files = []
    395     for path in pathlist:
     389    import_files = {}
     390    if '.' not in sys.path: sys.path.append('.')
     391    for path in sys.path:
    396392        for filename in glob.iglob(os.path.join(path, 'G2'+prefix+'*.py')):
    397             potential_files.append(filename)
    398 
    399     potential_files = sorted(list(set(potential_files)))
    400     for filename in potential_files:
    401         path, rootname = os.path.split(filename)
    402         pkg = os.path.splitext(rootname)[0]
    403 
     393            pkg = os.path.splitext(os.path.split(filename)[1])[0]
     394            if pkg in import_files:
     395                G2Print('Warning: file {} hidden by {}'
     396                                  .format(os.path.abspath(filename),import_files[pkg]))
     397            else:
     398                import_files[pkg] = filename           
     399
     400    for pkg in sorted(import_files.keys()):
    404401        try:
    405             fp = None
    406             fp, fppath, desc = imp.find_module(pkg, [path])
    407             pkg = imp.load_module(pkg, fp, fppath, desc)
    408             for name, value in inspect.getmembers(pkg):
     402            exec('import '+pkg)
     403            for name, value in inspect.getmembers(eval(pkg)):
    409404                if name.startswith('_'):
    410405                    continue
     
    420415                            readerlist.append(reader)
    421416        except AttributeError:
    422             G2Print ('Import_' + errprefix + ': Attribute Error ' + filename)
     417            G2Print ('Import_' + errprefix + ': Attribute Error ' + import_files[pkg])
    423418            if traceback:
    424419                traceback.print_exc(file=sys.stdout)
    425420        except Exception as exc:
    426             G2Print ('\nImport_' + errprefix + ': Error importing file ' + filename)
     421            G2Print ('\nImport_' + errprefix + ': Error importing file ' + import_files[pkg])
    427422            G2Print (u'Error message: {}\n'.format(exc))
    428423            if traceback:
    429424                traceback.print_exc(file=sys.stdout)
    430         finally:
    431             if fp:
    432                 fp.close()
    433 
    434425    return readerlist
    435426
     
    438429    '''
    439430    exporterlist = []
    440     pathlist = sys.path
    441     filelist = []
    442     for path in pathlist:
     431    import_files = {}
     432    if '.' not in sys.path: sys.path.append('.')
     433    for path in sys.path:
    443434        for filename in glob.iglob(os.path.join(path,"G2export*.py")):
    444                     filelist.append(filename)   
    445     filelist = sorted(list(set(filelist))) # remove duplicates
     435            pkg = os.path.splitext(os.path.split(filename)[1])[0]
     436            if pkg in import_files:
     437                G2Print('Warning: file {} hidden by {}'
     438                                  .format(os.path.abspath(filename),import_files[pkg]))
     439            else:
     440                import_files[pkg] = filename           
    446441    # go through the routines and import them, saving objects that
    447442    # have export routines (method Exporter)
    448     for filename in filelist:
    449         path,rootname = os.path.split(filename)
    450         pkg = os.path.splitext(rootname)[0]
     443    for pkg in sorted(import_files.keys()):
    451444        try:
    452             fp = None
    453             fp, fppath,desc = imp.find_module(pkg,[path,])
    454             pkg = imp.load_module(pkg,fp,fppath,desc)
    455             for clss in inspect.getmembers(pkg): # find classes defined in package
     445            exec('import '+pkg)
     446            for clss in inspect.getmembers(eval(pkg)): # find classes defined in package
    456447                if clss[0].startswith('_'): continue
    457448                if not inspect.isclass(clss[1]): continue
     
    484475            if traceback:
    485476                traceback.print_exc(file=sys.stdout)
    486         finally:
    487             if fp:
    488                 fp.close()
    489477    return exporterlist
    490478
  • trunk/GSASIIobj.py

    r4643 r4654  
    12431243import platform
    12441244import re
    1245 import imp
    12461245import random as ran
    12471246import sys
     
    28842883            df = f.split('.')
    28852884            pkgdict = {}
    2886             # no listed package, try in current namespace
     2885            # no listed module name, try in current namespace
    28872886            if len(df) == 1:
    28882887                try:
     
    28912890                except (AttributeError, NameError):
    28922891                    return None,None
    2893             else:
    2894                 try:
    2895                     fxnobj = eval(f)
    2896                     pkgdict[df[0]] = eval(df[0])
    2897                     return pkgdict,fxnobj
    2898                 except (AttributeError, NameError):
    2899                     pass
    2900             # includes a package, lets try to load the packages
    2901             pkgname = ''
    2902             path = sys.path+['./',]
    2903             for pkg in f.split('.')[:-1]: # if needed, descend down the tree
    2904                 if pkgname:
    2905                     pkgname += '.' + pkg
    2906                 else:
    2907                     pkgname = pkg
    2908                 fp = None
    2909                 try:
    2910                     fp, fppath,desc = imp.find_module(pkg,path)
    2911                     pkgobj = imp.load_module(pkg,fp,fppath,desc)
    2912                     pkgdict[pkgname] = pkgobj
    2913                     path = [fppath]
    2914                 except Exception as msg:
    2915                     print('load of '+pkgname+' failed with error='+str(msg))
    2916                     return {},None
    2917                 finally:
    2918                     if fp: fp.close()
    2919                 try:
    2920                     #print 'before',pkgdict.keys()
    2921                     fxnobj = eval(f,globals(),pkgdict)
    2922                     #print 'after 1',pkgdict.keys()
    2923                     #fxnobj = eval(f,pkgdict)
    2924                     #print 'after 2',pkgdict.keys()
    2925                     return pkgdict,fxnobj
    2926                 except:
    2927                     continue
    2928             return None # not found
     2892
     2893            # includes a package, see if package is already imported
     2894            pkgnam = '.'.join(df[:-1])
     2895            try:
     2896                fxnobj = eval(f)
     2897                pkgdict[pkgnam] = eval(pkgnam)
     2898                return pkgdict,fxnobj
     2899            except (AttributeError, NameError):
     2900                pass
     2901            # package not yet imported, so let's try
     2902            if '.' not in sys.path: sys.path.append('.')
     2903            pkgnam = '.'.join(df[:-1])
     2904            #for pkg in f.split('.')[:-1]: # if needed, descend down the tree
     2905            #    if pkgname:
     2906            #        pkgname += '.' + pkg
     2907            #    else:
     2908            #        pkgname = pkg
     2909            try:
     2910                exec('import '+pkgnam)
     2911                pkgdict[pkgnam] = eval(pkgnam)
     2912                fxnobj = eval(f)
     2913            except Exception as msg:
     2914                print('load of '+pkgnam+' failed with error='+str(msg))
     2915                return {},None
     2916            # can we access the function? I am not exactly sure what
     2917            #    I intended this to test originally (BHT)
     2918            try:
     2919                fxnobj = eval(f,globals(),pkgdict)
     2920                return pkgdict,fxnobj
     2921            except Exception as msg:
     2922                print('call to',f,' failed with error=',str(msg))
     2923                return None,None # not found
    29292924        def ASTtransverse(node,fxn=False):
    29302925            '''Transverse a AST-parsed expresson, compiling a list of variables
  • trunk/GSASIIphsGUI.py

    r4647 r4654  
    77707770            drawingData['selectedAtoms'] = drawAtoms.GetSelectedRows()
    77717771            G2plt.PlotStructure(G2frame,data)
    7772 
     7772            G2frame.Raise()
     7773           
    77737774        def RowSelect(event):
    77747775            r,c =  event.GetRow(),event.GetCol()
     
    1066610667                    i for i,a in enumerate(data['Atoms']) if a[0] == cryatom]
    1066710668                G2plt.PlotStructure(G2frame,data,False,UpdateTable)
    10668                 misc['showSelect'].SetLabelText(cryatom)
     10669                misc['showSelect'].setByString(cryatom)
     10670                G2frame.Raise()
     10671                #RigidBodies.atomsGrid.SetFocus()
    1066910672               
    1067010673            def OnSymRadioSet(event):
     
    1294012943    def rbKeyPress(event):
    1294112944        '''Respond to a Tab to highlight the next RB or crystal atom
     12945        TODO: this is not getting called in Windows. Is a bind needed elsewhere?
    1294212946        '''
    1294312947        if 'testRBObj' not in data: return
     
    1298112985                if data['Atoms'][I][0] in data['testRBObj']['availAtoms']:
    1298212986                    data['testRBObj']['CRYhighLight'] = [I]
    12983                     misc['showSelect'].SetLabelText(data['Atoms'][I][0])
     12987                    misc['showSelect'].setByString(data['Atoms'][I][0])
    1298412988                    break
    1298512989        G2plt.PlotStructure(G2frame,data,False,misc['UpdateTable'])
     12990        G2frame.Raise()
     12991        return
     12992   
    1298612993    if data['General']['Type'] not in ['faulted',] and not data['General']['Modulated']:
    1298712994        RigidBodies = wx.ScrolledWindow(G2frame.phaseDisplay)
    1298812995        G2frame.phaseDisplay.AddPage(RigidBodies,'RB Models')
     12996        # note the bind is here so that it is only done once, but
     12997        # TODO: might need to be on a different widget for Windows
    1298912998        RigidBodies.Bind(wx.EVT_CHAR,rbKeyPress)
    1299012999        Pages.append('RB Models')
  • trunk/GSASIIscriptable.py

    r4636 r4654  
    13451345        file.close()
    13461346    G2fil.G2Print('gpx file saved as %s'%ProjFile)
    1347 
    1348 # def ImportPowder(reader,filename):
    1349 #     '''Use a reader to import a powder diffraction data file
    1350 
    1351 #     :param str reader: a scriptable reader
    1352 #     :param str filename: full name of powder data file; can be "multi-Bank" data
    1353 
    1354 #     :returns: list rdlist: list of reader objects containing powder data, one for each
    1355 #         "Bank" of data encountered in file. Items in reader object of interest are:
    1356 
    1357 #           * rd.comments: list of str: comments found on powder file
    1358 #           * rd.dnames: list of str: data nammes suitable for use in GSASII data tree NB: duplicated in all rd entries in rdlist
    1359 #           * rd.powderdata: list of numpy arrays: pos,int,wt,zeros,zeros,zeros as needed for a PWDR entry in  GSASII data tree.
    1360 #     '''
    1361 #     rdfile,rdpath,descr = imp.find_module(reader)
    1362 #     rdclass = imp.load_module(reader,rdfile,rdpath,descr)
    1363 #     rd = rdclass.GSAS_ReaderClass()
    1364 #     if not rd.scriptable:
    1365 #         G2fil.G2Print(u'**** ERROR: '+reader+u' is not a scriptable reader')
    1366 #         return None
    1367 #     rdlist = []
    1368 #     if rd.ContentsValidator(filename):
    1369 #         repeat = True
    1370 #         rdbuffer = {} # create temporary storage for file reader
    1371 #         block = 0
    1372 #         while repeat: # loop if the reader asks for another pass on the file
    1373 #             block += 1
    1374 #             repeat = False
    1375 #             rd.objname = ospath.basename(filename)
    1376 #             flag = rd.Reader(filename,None,buffer=rdbuffer,blocknum=block,)
    1377 #             if flag:
    1378 #                 rdlist.append(copy.deepcopy(rd)) # save the result before it is written over
    1379 #                 if rd.repeat:
    1380 #                     repeat = True
    1381 #         return rdlist
    1382 #     G2fil.G2Print(rd.errors)
    1383 #     return None
    13841347
    13851348def SetDefaultDData(dType,histoName,NShkl=0,NDij=0):
  • trunk/config_example.py

    r4617 r4654  
    234234'''
    235235
     236show_gpxSize = False
     237'''When True, the sizes of the sections of the GPX file are listed
     238when the GPX file is opened. Default is False.
     239'''
  • trunk/help/Tutorials.html

    r4632 r4654  
    4848<blockquote><I>Shows how to set lower and upper limits on selected parameters to keep refinements from refining unreasonably.</I></blockquote>
    4949<LI><A href="https://subversion.xray.aps.anl.gov/pyGSAS/Tutorials/RigidBody/RigidBodyRef.html">Rietveld Fitting with Rigid Bodies</A>
    50  [link: <A href="https://subversion.xray.aps.anl.gov/pyGSAS/Tutorials/RigidBody/data">Exercise files</A>].
     50 [links: <A href="https://anl.box.com/v/RigidBodyRef">video</A>, <A href="https://subversion.xray.aps.anl.gov/pyGSAS/Tutorials/RigidBody/data">Exercise files</A>].
    5151<blockquote><I>Shows how to set up and refine with rigid bodies to simplify and improve the crystal structure model.</I></blockquote>
    5252</UL><h4>Magnetic Structure Analysis</H4><UL>
     
    222222<LI><A href="https://anl.box.com/v/SimTutorial-">Simulating Powder Diffraction with GSAS-II</A></LI>
    223223<LI><A href="https://anl.box.com/v/FitBkgTut---">Fitting the Starting Background using Fixed Points</A></LI>
     224<LI><A href="https://anl.box.com/v/RigidBodyRef">Rietveld Fitting with Rigid Bodies</A></LI>
    224225<LI><A href="https://anl.box.com/v/SimpleMagnetic">Simple Magnetic Structure Analysis</A></LI>
    225226<LI><A href="https://anl.box.com/v/SequentialTutorial">Sequential refinement of multiple datasets</A></LI>
  • trunk/makeTutorial.py

    r4131 r4654  
    5252onlineVideos.append('https://anl.box.com/v/Textureanalysisof2DdatainGSAS-')
    5353onlineVideos.append('https://anl.box.com/v/TOFSequentialSinglePeakFit')
     54onlineVideos.append('https://anl.box.com/v/RigidBodyRef')
    5455#onlineVideos.append('
    5556
Note: See TracChangeset for help on using the changeset viewer.