Changeset 4785 for trunk/G2compare.py


Ignore:
Timestamp:
Jan 27, 2021 3:27:25 PM (2 years ago)
Author:
toby
Message:

new table for text w/sorting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/G2compare.py

    r4364 r4785  
    1818#TODO:
    1919# Prince-test next
    20 # Make PWDR unique? (use histlist)
     20# Make Phase unique? (need a phaselist)
    2121# more graphics
    2222# display more in datawindow
     
    2525import os
    2626import platform
     27import glob
    2728if '2' in platform.python_version_tuple()[0]:
    2829    import cPickle
     
    4748import GSASIIfiles as G2fil
    4849import GSASIIplot as G2plt
     50import GSASIIdataGUI as G2gd
    4951import GSASIIctrlGUI as G2G
    5052import GSASIIobj as G2obj
     
    105107def main(application):
    106108    '''Start up the GSAS-II GUI'''                       
    107     knownVersions = ['2.7','3.6','3.7','3.8']
     109    knownVersions = ['3.6','3.7','3.8','3.9']
    108110    if platform.python_version()[:3] not in knownVersions:
    109111        dlg = wx.MessageDialog(None,
    110                 'GSAS-II requires Python 2.7.x or 3.6+\n Yours is '+sys.version.split()[0],
     112                'GSAS-II requires Python 3.6+\n Yours is '+sys.version.split()[0],
    111113                'Python version error',  wx.OK)
    112114        try:
     
    158160        File = wx.Menu(title='')
    159161        self.MenuBar.Append(menu=File, title='&File')
    160         item = File.Append(wx.ID_ANY,'&Import project...\tCtrl+O','Open a GSAS-II project file (*.gpx)')           
     162        item = File.Append(wx.ID_ANY,'&Import single project...\tCtrl+O','Open a GSAS-II project file (*.gpx)')           
    161163        self.Bind(wx.EVT_MENU, self.onLoadGPX, id=item.GetId())
     164        item = File.Append(wx.ID_ANY,'&Import multiple projects...\tCtrl+M','Open a GSAS-II project file (*.gpx)')           
     165        self.Bind(wx.EVT_MENU, self.onLoadMultGPX, id=item.GetId())
     166        item = File.Append(wx.ID_ANY,'&Wildcard import of projects...\tCtrl+W','Open a GSAS-II project file (*.gpx)')           
     167        self.Bind(wx.EVT_MENU, self.onLoadWildGPX, id=item.GetId())
    162168#        item = File.Append(wx.ID_ANY,'&Import selected...','Open a GSAS-II project file (*.gpx)')
    163169#        self.Bind(wx.EVT_MENU, self.onLoadSel, id=item.GetId())
     
    166172        self.MenuBar.Append(menu=self.Mode, title='&Mode')
    167173        self.wxID_Mode = {}
    168         for m in "Histogram","Phase","Project":
    169             i = self.wxID_Mode[m] = wx.NewId()
    170             item = self.Mode.AppendRadioItem(i,m,'Display {}s'.format(m))
     174        for i,m in enumerate(("Histogram","Phase","Project")):
     175            self.wxID_Mode[m] = i+1
     176            item = self.Mode.AppendRadioItem(i+1,m+'\tCtrl+{}'.format(i+1),
     177                                                 'Display {}s'.format(m))
    171178            self.Bind(wx.EVT_MENU, self.onRefresh, id=item.GetId())
    172179        item = self.Mode.Append(wx.ID_ANY,'Set histogram filter','Set a filter for histograms to display')
     
    198205        self.GPXtree = G2G.G2TreeCtrl(id=wx.ID_ANY,
    199206            parent=self.treePanel, size=self.treePanel.GetClientSize(),style=wx.TR_DEFAULT_STYLE )
    200         TreeId = self.GPXtree.Id
     207        #TreeId = self.GPXtree.Id
    201208
    202209        treeSizer.Add(self.GPXtree,1,wx.EXPAND|wx.ALL,0)
     
    221228        self.fileList = []  # list of files read for use in Reload
    222229        self.histList = []  # list of histograms loaded for unique naming
     230        self.projList = []
    223231
    224232        self.PWDRfilter = None
     
    229237                if type(pos) is str: pos = eval(pos)
    230238                win.SetPosition(pos)
    231                 if GetDisplay(pos) is None: win.Center()
     239                if G2gd.GetDisplay(pos) is None: win.Center()
    232240            except:
    233241                if GSASIIpath.GetConfigValue(var):
     
    247255            dlg.Destroy()
    248256        if os.path.exists(fil):
    249             self.fileList.append([fil,'GPX'])
     257            #self.fileList.append([fil,'GPX'])
    250258            return fil
    251259        else:
    252260            print('File {} not found, skipping'.format(fil))
    253261            return
     262
     263    def SelectMultGPX(self):
     264        '''Select multiple .GPX files to be read
     265        '''
     266        dlg = wx.FileDialog(self, 'Choose GSAS-II project file',
     267                wildcard='GSAS-II project file (*.gpx)|*.gpx',
     268                style=wx.FD_OPEN|wx.FD_MULTIPLE)
     269        try:
     270            if dlg.ShowModal() != wx.ID_OK: return
     271            files = dlg.GetPaths()
     272        finally:
     273            dlg.Destroy()
     274        fileList = []
     275        for f in files:
     276            fil = os.path.splitext(f)[0]+'.gpx'
     277            if os.path.exists(fil):
     278                if fil not in fileList:
     279                    fileList.append(fil)
     280            else:
     281                print('File {} not found, skipping'.format(fil))
     282        return fileList
    254283       
    255284    def getMode(self):
     
    269298        self.GPXtree.DeleteChildren(self.root)  # delete tree contents
    270299        self.histList = []  # clear list of loaded histograms
     300        self.projList = []
    271301        for fil,mode in self.fileList:
    272302            self.loadFile(fil)
     303        self.doneLoad()
    273304        self.SetModeMenu()
    274305           
     
    300331            print("mode not implemented")
    301332            #raise Exception("mode not implemented")
    302        
     333
     334    def doneLoad(self):
     335        self.GPXtree.Expand(self.root)
     336        if self.getMode() == "Project":
     337            overId = self.GPXtree.InsertItem(pos=0,parent=self.root,text='Project Overview')
     338            self.GPXtree.SelectItem(overId)
     339
    303340    def onLoadGPX(self,event):
    304341        '''Initial load of GPX file in response to a menu command
     
    309346        self.fileList.append([fil,'GPX'])
    310347        self.loadFile(fil)
     348        self.doneLoad()
     349
     350    def onLoadMultGPX(self,event):
     351        '''Initial load of multiple GPX files in response to a menu command
     352        '''
     353        for fil in self.SelectMultGPX():
     354            if not os.path.exists(fil): continue
     355            self.fileList.append([fil,'GPX'])
     356            self.loadFile(fil)
     357        self.doneLoad()
     358
     359    def onLoadWildGPX(self,event,wildcard=None):
     360        '''Initial load of GPX file in response to a menu command
     361        '''
     362        home = os.path.abspath(os.getcwd())
     363        hlp = '''Enter a wildcard version of a file name.
     364The directory is assumed to be "{}" unless specified otherwise.
     365Extensions will be set to .gpx and .bak files will be ignored unless
     366the wildcard string includes "bak". For example, "*abc*" will match any
     367.gpx file in that directory containing "abc". String "/tmp/A*" will match
     368files in "/tmp" beginning with "A". Supplying two strings, "A*" and "B*bak*"
     369will match files names beginning with "A" or "B", but ".bak" files will
     370be included for the files beginning with "B" only.
     371'''.format(home)
     372        if wildcard is None:
     373            dlg = G2G.MultiStringDialog(self, 'Enter wildcard file names',
     374                    ['wild-card 1'] , values=['*'],
     375                    lbl='Provide string(s) with "*" to find matching files',
     376                    addRows=True, hlp=hlp)
     377            res = dlg.Show()
     378            wl = dlg.GetValues()
     379            dlg.Destroy()
     380            if not res: return
     381        else:
     382            wl = [wildcard]
     383        for w in wl:
     384            if not os.path.split(w)[0]:
     385                w = os.path.join(home,w)
     386            w = os.path.splitext(w)[0] + '.gpx'
     387            for fil in glob.glob(w):
     388                if not os.path.exists(fil): continue
     389                if '.bak' in fil and 'bak' not in w: continue
     390                if fil in [i for i,j in self.fileList]: continue
     391                self.fileList.append([fil,'GPX'])
     392                self.loadFile(fil)
     393        self.doneLoad()
    311394
    312395    def LoadPwdr(self,fil):
     
    369452                G2frame.GPXtree.SetItemPyData(sub,datus[1])
    370453        if datum: # was anything loaded?
    371             print('project load successful for {}'.format(datum[0]))
     454            print('data load successful for {}'.format(datum[0]))
    372455    #        G2frame.Status.SetStatusText('Mouse RB drag/drop to reorder',0)
    373456    #    G2frame.SetTitleByGPX()
     
    449532        if datum: # was anything loaded?
    450533            self.GPXtree.Expand(Id)
    451             print('project load successful for {}'.format(datum[0]))
     534            print('Phase load successful for {}'.format(datum[0]))
    452535    #        G2frame.Status.SetStatusText('Mouse RB drag/drop to reorder',0)
    453536    #    G2frame.SetTitleByGPX()
     
    458541        see :func:`GSASIIIO.ProjFileOpen`
    459542        '''
     543        import datetime
    460544        G2frame = self
    461545        filep = open(fil,'rb')
     546        saved = datetime.datetime.fromtimestamp(os.path.getmtime(fil)).strftime("%Y-%h-%d %H:%M")
    462547        shortname = os.path.splitext(os.path.split(fil)[1])[0]
    463 
     548        projInfo = [shortname,saved]
    464549        wx.BeginBusyCursor()
    465         Phases = None
     550        #Phases = None
     551        #G2frame.GPXtree.SetItemPyData(Id,Covar[1])
    466552        try:
    467553            while True:
     
    470556                except EOFError:
    471557                    break
     558                #if data[0][0] == 'Controls' and 'LastSavedUsing' in data[0][1]:
    472559                if not data[0][0].startswith('Covariance'): continue
    473560                Covar = data[0]
     561                f = '{:d}'
     562                if 'varyList' in data[0][1]:
     563                    projInfo += [f.format(len(data[0][1]['varyList']))]
     564                else:
     565                    projInfo += ['?']
     566                for v in 'Nobs','GOF':
     567                    if 'Rvals' in data[0][1] and v in data[0][1]['Rvals']:
     568                        projInfo += [f.format(data[0][1]['Rvals'][v])]
     569                    else:
     570                        projInfo += ['?']
     571                    f = '{:6.2f}'
    474572                #GSASIIpath.IPyBreak_base()
    475573                #if self.PWDRfilter is not None: # implement filter
    476574                #    if self.PWDRfilter not in data[0][0]: continue
    477                 Covar[0] = shortname + ' Covariance'
     575                Covar[0] = shortname # + ' Covariance'
    478576                Id = G2frame.GPXtree.AppendItem(parent=G2frame.root,text=Covar[0])
    479577                G2frame.GPXtree.SetItemPyData(Id,Covar[1])
     578                self.projList.append(projInfo)
    480579                break
    481580            else:
     
    493592            filep.close()
    494593            wx.EndBusyCursor()
    495         self.GPXtree.Expand(self.root)
    496594
    497595    def OnDataTreeSelChanged(self,event):
     
    510608        item = event.GetItem()
    511609        #print('selected',item)
    512         if self.getMode() == "Project":
     610        lbl = G2frame.GPXtree.GetItemText(item)
     611        if self.getMode() == "Project" and lbl == 'Project Overview':
     612            ClearData(G2frame.dataWindow)
     613            #import imp
     614            #imp.reload(G2G)
     615            pnl = G2G.SortableLstCtrl(G2frame.dataWindow)
     616            h = ["File", "last saved", "vars", "Nobs", "GOF"]
     617            j = [ 0,       0,           1,      1,      1]
     618            pnl.PopulateHeader(h,j)
     619            for i,line in enumerate(self.projList):
     620                pnl.PopulateLine(i,line)
     621            G2frame.dataWindow.GetSizer().Add(pnl,1,wx.EXPAND)
     622            pnl.SetColWidth(0,maxwidth=170)
     623            for i in range(1,len(h)):
     624                pnl.SetColWidth(i,minwidth=50)
     625            G2frame.dataWindow.SendSizeEvent()
     626        elif self.getMode() == "Project":
    513627            ClearData(G2frame.dataWindow)
    514628            data = G2frame.GPXtree.GetItemPyData(item)
     
    528642                if 'lamMax' in Rvals:
    529643                    text += '\n\tlog10 MaxLambda = {:.1f}'.format(np.log10(Rvals['lamMax']))
     644                text += '\n\tReduced χ**2 = {:.2f}'.format(Rvals['GOF']**2)
    530645                G2frame.dataWindow.GetSizer().Add(
    531646                    wx.StaticText(G2frame.dataWindow,wx.ID_ANY,text)
     
    722837            G2G.G2MessageBox(self,'Unable to use test: "X" values differ','Comparison not valid')
    723838            return
    724         X = data0[3] - data1[3]
    725         #Z = np.sqrt(data0[3]) * (data0[1] - (data0[3] + data1[3])/2)
    726         X = (data0[3] - data1[3]) / np.sqrt(data0[1])
    727         Z = (data0[1] - (data0[3] + data1[3])/2) / np.sqrt(data0[1])
    728         lam = np.sum(X*Z) / np.sum(X)
    729         sig = np.sqrt(
    730             (np.sum(Z*Z) - lam*lam*np.sum(X*X)) /
    731             ((len(data0[0]) - 1) * np.sum(X*X))
    732             )
     839        # X = data0[3] - data1[3]
     840        # #Z = np.sqrt(data0[3]) * (data0[1] - (data0[3] + data1[3])/2)
     841        # X = (data0[3] - data1[3]) / np.sqrt(data0[1])
     842        # Z = (data0[1] - (data0[3] + data1[3])/2) / np.sqrt(data0[1])
     843        # lam = np.sum(X*Z) / np.sum(X)
     844        # sig = np.sqrt(
     845        #     (np.sum(Z*Z) - lam*lam*np.sum(X*X)) /
     846        #     ((len(data0[0]) - 1) * np.sum(X*X))
     847        #     )
    733848           
    734849#    0 the x-postions (two-theta in degrees),
     
    752867        print('Unable to run with current setup, do you want to update to the')
    753868        try:
    754             if '2' in platform.python_version_tuple()[0]:           
    755                 ans = raw_input("latest GSAS-II version? Update ([Yes]/no): ")
    756             else:
     869#            if '2' in platform.python_version_tuple()[0]:           
     870#                ans = raw_input("latest GSAS-II version? Update ([Yes]/no): ")
     871#            else:
    757872                ans = input("latest GSAS-II version? Update ([Yes]/no): ")               
    758873        except:
    759874            ans = 'no'
    760875        if ans.strip().lower() == "no":
    761             import sys
    762876            print('Exiting')
    763877            sys.exit()
     
    774888        else:
    775889            print('File {} not found. Skipping'.format(fil))
    776 
    777     # debug code to select in initial mode
    778     #self=Frame
    779     #self.Mode.FindItemById(self.wxID_Mode['Project']).Check(True)
    780     #self.onRefresh(None)
     890    Frame.doneLoad()
     891    # debug code to select Project in initial mode
     892    #Frame.onLoadWildGPX(None,wildcard='*')
     893    #Frame.Mode.FindItemById(Frame.wxID_Mode['Project']).Check(True)
     894    #Frame.onRefresh(None)
    781895   
    782896    application.MainLoop()
Note: See TracChangeset for help on using the changeset viewer.