Changeset 5236 for trunk


Ignore:
Timestamp:
Mar 18, 2022 11:33:37 AM (3 years ago)
Author:
vondreele
Message:

fix formatting issue in Covariance window
document stuff in G2dataGUI, remove some dead/commented out code, remove excessive tabs
Add doc to GetFileList? in G2pwdrGUI

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/GSASIIdataGUI.py

    r5233 r5236  
    121121
    122122def SetDefaultDData(dType,histoName,NShkl=0,NDij=0):
     123    ''' Sets default values for various histogram parameters
     124    param: str dType: 3 letter histogram type, e.g. 'PNT'
     125    param: str histoName: histogram name as it aoears in tree
     126    param: NShkl int: number of generalized mustrain coefficients - depends on symmetry
     127    param: NDij int: number of hydrostatic strain coefficients - depends on symmetry
     128   
     129    returns dict: default data for histogram - found in data tab for phase/histogram
     130    '''
    123131    if dType in ['SXC','SNC']:
    124132        return {'Histogram':histoName,'Show':False,'Scale':[1.0,True],'Type':dType,
     
    337345
    338346def convVersion(version):
    339     '''Convert a version string ("x", "x.y", "x.y.z") into a series of
    340     ints.
     347    '''Convert a version string ("x", "x.y", "x.y.z") into a series of ints.
    341348
    342349    :returns: [i0, i1, i2] where None is used if a value is not specified
     
    651658    application.GetTopWindow().Show(True)
    652659
    653 #### Create main frame (window) for GUI #######################################
     660#### Create main frame (window) for GUI; main menu items here #######################################
    654661class GSASII(wx.Frame):
    655662    '''Define the main GSAS-II frame and its associated menu items.
     
    663670        log.InvokeMenuCommand(event.GetId(),self,event)
    664671           
    665 #    def Bind(self,eventtype,handler,*args,**kwargs):
    666 #        '''Override the Bind function so that we can wrap calls that will be logged.
    667 #       
    668 #        N.B. This is a bit kludgy. Menu bindings with an id are wrapped and
    669 #        menu bindings with an object and no id are not.
    670 #        '''
    671 #        if eventtype == wx.EVT_MENU and 'id' in kwargs:
    672 #            menulabels = log.SaveMenuCommand(kwargs['id'],self,handler)
    673 #            if menulabels:
    674 #                wx.Frame.Bind(self,eventtype,self.MenuBinding,*args,**kwargs)
    675 #                return
    676 #        wx.Frame.Bind(self,eventtype,handler,*args,**kwargs)     
    677    
    678672    def _Add_FileMenuItems(self, parent):
    679673        '''Add items to File menu
     
    714708        '''Add items to Data menu
    715709        '''
    716         # item = parent.Append(
    717         #     help='',id=wx.ID_ANY,
    718         #     kind=wx.ITEM_NORMAL,
    719         #     text='Read image data...')
    720         # self.Bind(wx.EVT_MENU, self.OnImageRead, id=item.GetId())
    721710        item = parent.Append(wx.ID_ANY,'Read Powder Pattern Peaks...','')
    722711        self.Bind(wx.EVT_MENU, self.OnReadPowderPeaks, id=item.GetId())
     
    758747
    759748    def _Add_CalculateMenuItems(self,parent):
     749        '''Add items to the Calculate menu
     750        '''
    760751        item = parent.Append(wx.ID_ANY,'Setup PDFs','Create PDF tree entries for selected powder patterns')
    761752        self.MakePDF.append(item)
     
    18321823                                     u'Error opening/reading file {}'.format(instfile))
    18331824    def EnableRefineCommand(self):
     1825        '''Check that phases are connected to histograms - if so then Refine is enabled
     1826        '''
    18341827        haveData = False
    1835         # check for phases connected to histograms
    18361828        sub = GetGPXtreeItemId(self,self.root,'Phases')
    18371829        if sub:
     
    18481840            self.dataWindow.DataMenu.Enable(G2G.wxID_DATADELETE,False)
    18491841            for item in self.Refine: item.Enable(False)
    1850 
    18511842       
    18521843    def OnImportPowder(self,event):
     
    24522443        None for the last menu item, which is the "guess" option
    24532444        where all appropriate formats will be tried.
    2454 
     2445        Small angle data is presumed to be as QIE form for either x-rays or neutrons
    24552446        '''
    24562447       
    24572448        def GetSASDIparm(reader):
     2449            ''' Setup instrument parameters for small ang scattering data
     2450            '''
    24582451            parm = reader.instdict
    24592452            Iparm = {'Type':[parm['type'],parm['type'],0],'Lam':[parm['wave'],
     
    24882481            Id = self.GPXtree.AppendItem(parent=self.root,text=HistName)
    24892482            Iparm1,Iparm2 = GetSASDIparm(rd)
    2490 #            if 'T' in Iparm1['Type'][0]:
    2491 #                if not rd.clockWd and rd.GSAS:
    2492 #                    rd.powderdata[0] *= 100.        #put back the CW centideg correction
    2493 #                cw = np.diff(rd.powderdata[0])
    2494 #                rd.powderdata[0] = rd.powderdata[0][:-1]+cw/2.
    2495 #                rd.powderdata[1] = rd.powderdata[1][:-1]/cw
    2496 #                rd.powderdata[2] = rd.powderdata[2][:-1]*cw**2  #1/var=w at this point
    2497 #                if 'Itype' in Iparm2:
    2498 #                    Ibeg = np.searchsorted(rd.powderdata[0],Iparm2['Tminmax'][0])
    2499 #                    Ifin = np.searchsorted(rd.powderdata[0],Iparm2['Tminmax'][1])
    2500 #                    rd.powderdata[0] = rd.powderdata[0][Ibeg:Ifin]
    2501 #                    YI,WYI = G2pwd.calcIncident(Iparm2,rd.powderdata[0])
    2502 #                    rd.powderdata[1] = rd.powderdata[1][Ibeg:Ifin]/YI
    2503 #                    var = 1./rd.powderdata[2][Ibeg:Ifin]
    2504 #                    var += WYI*rd.powderdata[1]**2
    2505 #                    var /= YI**2
    2506 #                    rd.powderdata[2] = 1./var
    2507 #                rd.powderdata[3] = np.zeros_like(rd.powderdata[0])                                       
    2508 #                rd.powderdata[4] = np.zeros_like(rd.powderdata[0])                                       
    2509 #                rd.powderdata[5] = np.zeros_like(rd.powderdata[0])                                       
    25102483            Tmin = min(rd.smallangledata[0])
    25112484            Tmax = max(rd.smallangledata[0])
     
    25632536        None for the last menu item, which is the "guess" option
    25642537        where all appropriate formats will be tried.
    2565 
     2538        Reflectometry data is presumed to be in QIE form for x-rays of neutrons
    25662539        '''
    25672540       
    25682541        def GetREFDIparm(reader):
     2542            ''' Setup reflectometry data instrument parameters
     2543            '''
    25692544            parm = reader.instdict
    25702545            Iparm = {'Type':[parm['type'],parm['type'],0],'Lam':[parm['wave'],
     
    25992574            Id = self.GPXtree.AppendItem(parent=self.root,text=HistName)
    26002575            Iparm1,Iparm2 = GetREFDIparm(rd)
    2601 #            if 'T' in Iparm1['Type'][0]:
    2602 #                if not rd.clockWd and rd.GSAS:
    2603 #                    rd.powderdata[0] *= 100.        #put back the CW centideg correction
    2604 #                cw = np.diff(rd.powderdata[0])
    2605 #                rd.powderdata[0] = rd.powderdata[0][:-1]+cw/2.
    2606 #                rd.powderdata[1] = rd.powderdata[1][:-1]/cw
    2607 #                rd.powderdata[2] = rd.powderdata[2][:-1]*cw**2  #1/var=w at this point
    2608 #                if 'Itype' in Iparm2:
    2609 #                    Ibeg = np.searchsorted(rd.powderdata[0],Iparm2['Tminmax'][0])
    2610 #                    Ifin = np.searchsorted(rd.powderdata[0],Iparm2['Tminmax'][1])
    2611 #                    rd.powderdata[0] = rd.powderdata[0][Ibeg:Ifin]
    2612 #                    YI,WYI = G2pwd.calcIncident(Iparm2,rd.powderdata[0])
    2613 #                    rd.powderdata[1] = rd.powderdata[1][Ibeg:Ifin]/YI
    2614 #                    var = 1./rd.powderdata[2][Ibeg:Ifin]
    2615 #                    var += WYI*rd.powderdata[1]**2
    2616 #                    var /= YI**2
    2617 #                    rd.powderdata[2] = 1./var
    2618 #                rd.powderdata[3] = np.zeros_like(rd.powderdata[0])                                       
    2619 #                rd.powderdata[4] = np.zeros_like(rd.powderdata[0])                                       
    2620 #                rd.powderdata[5] = np.zeros_like(rd.powderdata[0])                                       
    26212576            Tmin = min(rd.reflectometrydata[0])
    26222577            Tmax = max(rd.reflectometrydata[0])
     
    26812636        None for the last menu item, which is the "guess" option
    26822637        where all appropriate formats will be tried.
    2683 
    26842638        '''
    26852639       
     
    27342688   
    27352689    def AddToNotebook(self,text):
     2690        '''Add entry to Notebook tree item
     2691        '''
    27362692        Id =  GetGPXtreeItemId(self,self.root,'Notebook')
    27372693        data = self.GPXtree.GetItemPyData(Id)
     
    31623118#### init_vars ################################################################
    31633119    def init_vars(self):
    3164         # initialize default values for GSAS-II "global" variables (saved in main Frame)
     3120        ''' initialize default values for GSAS-II "global" variables (saved in main Frame)
     3121        '''
    31653122        self.oldFocus = None
    31663123        self.undofile = ''
     
    32883245           
    32893246    def GetTreeItemsList(self,item):
     3247        ''' returns a list of all GSAS-II tree items
     3248        '''
    32903249        return self.GPXtree._getTreeItemsList(item)
    32913250
     
    41394098            dlg.Destroy()
    41404099       
    4141     def GetFileList(self,fileType,skip=None):        #potentially useful?
    4142         'Appears unused. Note routine of same name in GSASIIpwdGUI'
     4100    def GetFileList(self,fileType,skip=None):       
     4101        ''' Get list of file names containing a particular string; can skip one of known GSAS-II id
     4102        param: fileType str: any string within a file name
     4103        param: skip int:default=None, a GSAS-II assigned id of a data item to skip in collecting the names
     4104        returns: list of file names from GSAS-II tree
     4105        returns: str name of file optionally skipped
     4106        Appears unused, but potentially useful.
     4107        Note routine of same name in GSASIIpwdGUI; it does not have the skip option
     4108        '''
    41434109        fileList = []
    41444110        Source = ''
     
    43124278
    43134279    def OnFileReopen(self, event):
     4280        ''' Creates a dialog box showing previously opened GSAS-II projects & offers to open one
     4281        called by File/Reopen recent... menu item
     4282        '''
    43144283        files = GSASIIpath.GetConfigValue('previous_GPX_files')
    43154284        if not files:
     
    43244293#                sellist.append("not found: {}".format(f))
    43254294       
    4326         dlg = G2G.G2SingleChoiceDialog(self,
    4327                                            'Select previous project to open',
    4328                                            'Select project',sellist)
     4295        dlg = G2G.G2SingleChoiceDialog(self,'Select previous project to open',
     4296            'Select project',sellist)
    43294297        dlg.CenterOnParent()
    43304298        if dlg.ShowModal() == wx.ID_OK:
     
    45464514
    45474515    def OnFileSaveas(self, event):
    4548         '''Save the current project in response to the
    4549         File/Save as menu button
     4516        '''Save the current project with a new name in response to the
     4517        File/Save as menu button. The current project then has this new name
    45504518        '''
    45514519        if GSASIIpath.GetConfigValue('Starting_directory'):
     
    48114779       
    48124780    def OnExportPeakList(self,event):
     4781        '''Exports a PWDR peak list as a text file
     4782        '''
    48134783        pth = G2G.GetExportPath(self)
    48144784        dlg = wx.FileDialog(self, 'Choose output peak list file name', pth, '',
     
    48734843       
    48744844    def OnExportHKL(self,event):
     4845        '''Exports a PWDR reflection list as a text file
     4846        '''
    48754847        pth = G2G.GetExportPath(self)
    48764848        dlg = wx.FileDialog(self, 'Choose output reflection list file name', pth, '',
     
    53725344       
    53735345    def OnRefine(self,event):
    5374         '''Perform a refinement or a sequential refinement (depending on controls setting)
     5346        '''Perform a single refinement or a sequential refinement (depending on controls setting)
    53755347        Called from the Calculate/Refine menu.
    53765348        '''
     
    54705442           
    54715443    def OnLeBail(self,event):
    5472         Controls = self.GPXtree.GetItemPyData(GetGPXtreeItemId(self,self.root, 'Controls'))
     5444        '''Do a 1 cycle LeBail refinement with no other variables; usually done upon initialization of a LeBail refinement
     5445        either single or sequentially
     5446        '''
    54735447        self.OnFileSave(event)
    54745448        item = GetGPXtreeItemId(self,self.root,'Covariance')
     
    54805454       
    54815455        dlg = G2G.RefinementProgress(parent=self)
    5482         # dlg = wx.ProgressDialog('Residual','All data Rw =',101.0,
    5483         #     style = wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE|wx.PD_CAN_ABORT|wx.STAY_ON_TOP,parent=self)
    5484         # Size = dlg.GetSize()
    5485         # if 50 < Size[0] < 500: # sanity check on size, since this fails w/Win & wx3.0
    5486         #     dlg.SetSize((int(Size[0]*1.2),Size[1])) # increase size a bit along x
    5487         # dlg.CenterOnParent()
    5488         #dlg.Raise() # dangerous
    54895456        self.SaveTreeSetting() # save the current tree selection
    54905457        self.GPXtree.SaveExposedItems()             # save the exposed/hidden tree items
     
    56875654                self.OnLeBail(event)
    56885655        # select it
    5689         dlgp = G2G.RefinementProgress('Residual for histogram 0','Powder profile Rwp =',
    5690                                           parent=self)
    5691         # dlgp = wx.ProgressDialog('Residual for histogram 0','Powder profile Rwp =',101.0,
    5692         #     style = wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE|wx.PD_CAN_ABORT,
    5693         #     parent=self)           
    5694         # Size = dlgp.GetSize()
    5695         # if 50 < Size[0] < 500: # sanity check on size, since this fails w/Win & wx3.0
    5696         #     dlgp.SetSize((int(Size[0]*1.2),Size[1])) # increase size a bit along x
    5697         # dlgp.CenterOnParent()
    5698         # dlgp.Show()
     5656        dlgp = G2G.RefinementProgress('Residual for histogram 0','Powder profile Rwp =',parent=self)
    56995657        self.PatternId = GetGPXtreeItemId(self,self.root,histNames[0])
    57005658        if self.PatternId and self.GPXtree.GetItemText(self.PatternId).startswith('PWDR '):
     
    57275685                    self.GPXtree.DeleteChildren(self.root)
    57285686                    if len(self.HKL): self.HKL = []
    5729                     # if self.G2plotNB.plotList:
    5730                     #     self.G2plotNB.clear()
    57315687                    G2IO.ProjFileOpen(self,False)
    57325688                    self.GPXtree.RestoreExposedItems()
    57335689                    self.ResetPlots()
    5734                     #self.PatternId = GetGPXtreeItemId(self,self.root,plotHist)
    5735                     #SelectDataTreeItem(self,self.PatternId)
    57365690                    sId = GetGPXtreeItemId(self,self.root,'Sequential results')
    57375691                    SelectDataTreeItem(self,sId)
     
    57425696                dlg.Destroy()
    57435697           
    5744 #            self.SeqTblHideList = []
    57455698        else:
    57465699            self.ErrorDialog('Sequential refinement error',Msg)
    57475700           
    57485701    def OnRunFprime(self,event):
     5702        '''Run Fprime'''
    57495703        import fprime
    57505704        self.fprime = fprime.Fprime(self)
     
    57525706       
    57535707    def OnRunAbsorb(self,event):
     5708        '''Run Absorb'''
    57545709        import Absorb
    57555710        self.absorb = Absorb.Absorb(self)
     
    57575712       
    57585713    def OnRunPlotXNFF(self,evnt):
     5714        '''Run PlotXNFF'''
    57595715        import PlotXNFF
    57605716        self.plotXNFF = PlotXNFF.PlotXNFF(self)
     
    57935749        G2IO.ExportSequentialFullCIF(self,data,Controls)
    57945750
    5795 # Data window side of main GUI ################################################
     5751#### Data window side of main GUI; menu definitions here #########################
    57965752class G2DataWindow(wx.ScrolledWindow):      #wxscroll.ScrolledPanel):
    57975753    '''Create the data item window as well as the menu. Note that
     
    59365892        menu.Append(menu=HelpMenu,title='&Help')
    59375893
     5894#### Menu definitions here
    59385895    def _initMenus(self):
    59395896        '''define all GSAS-II data window menus.
     
    59425899        '''
    59435900       
    5944 #        G2G.Define_wxId('wxID_MCRON', 'wxID_MCRLIST', 'wxID_MCRSAVE', 'wxID_MCRPLAY',)
    59455901##### GSAS-II Menu items
    59465902        # Main menu
     
    60005956                'Show ISODISTORT mode values for all phases')
    60015957        self.ConstraintEdit.Enable(G2G.wxID_SHOWISO,False)
    6002         # for DEBUG only
    6003         #def OnShowISODISTORT(event):
    6004         #    import imp
    6005         #    imp.reload(G2cnstG)  # for testing changes to GSASIIconstrGUI
    6006         #    G2cnstG.ShowIsoDistortCalc(G2frame)
    6007         #G2frame.Bind(wx.EVT_MENU, OnShowISODISTORT, id=G2G.wxID_SHOWISO)
    6008         # end DEBUG
    60095958       
    60105959        self.PostfillDataMenu()
     
    69266875            choices = [i for i in choices if i in usedHistograms]
    69276876            if len(choices) == 0:
    6928                 G2G.G2MessageBox(G2frame,
    6929                                 'No histograms in use found for a sequential fit.',
    6930                                 'No Histograms')
     6877                G2G.G2MessageBox(G2frame,'No histograms in use found for a sequential fit.','No Histograms')
    69316878                return
    69326879            sel = []
    69336880            try:
    69346881                if 'Seq Data' in data:
    6935 #                    for item in data['Seq Data']:
    6936 #                        sel.append(choices.index(item))
    69376882                    sel = [choices.index(item) for item in data['Seq Data']]
    69386883            except ValueError:  #data changed somehow - start fresh
    69396884                sel = []
    69406885            dlg = G2G.G2MultiChoiceDialog(G2frame,
    6941                         'Select datasets to include. Select no datasets to end sequential refinements.',
    6942                         'Sequential refinement selection',choices)
     6886                'Select datasets to include. Select no datasets to end sequential refinements.',
     6887                'Sequential refinement selection',choices)
    69436888            dlg.SetSelections(sel)
    69446889            names = []
     
    72447189       
    72457190    def OnPlot1DHKL(event):
     7191        '''Plots a 1D stick diagram of reflection intensities'''
    72467192        refList = data[1]['RefList']
    72477193        G2plt.Plot1DSngl(G2frame,newPlot=True,hklRef=refList,Super=Super,Title=phaseName)
    72487194
    72497195    def OnPlot3DHKL(event):
     7196        '''Plots in 3D reciprocal space with green dots proportional to F^2, etc. from single histogram'''
    72507197        refList = data[1]['RefList']
    72517198        FoMax = np.max(refList.T[8+Super])
     
    72607207       
    72617208    def OnPlotAll3DHKL(event):
     7209        '''Plots in 3D reciprocal space with green dots proportional to F^2, etc. from all SHKL histograms'''
    72627210        choices = GetGPXtreeDataNames(G2frame,['HKLF',])
    72637211        dlg = G2G.G2MultiChoiceDialog(G2frame, 'Select reflection sets to plot',
     
    72897237        G2plt.Plot3DSngl(G2frame,newPlot=True,Data=controls,hklRef=refList,Title=phaseName)
    72907238       
    7291     def OnToggleExt(event):
    7292         print('TBD')
    7293                  
    72947239    def OnMergeHKL(event):
     7240        '''Merge HKLF data sets to unique set according to Laue symmetry'''
    72957241        Name = G2frame.GPXtree.GetItemText(G2frame.PatternId)
    72967242        Inst = G2frame.GPXtree.GetItemPyData(GetGPXtreeItemId(G2frame,
     
    73927338                   
    73937339    def OnErrorAnalysis(event):
     7340        '''Plots an "Abrams" plot - sorted delta/sig across data set.
     7341        Should be straight line of slope 1 - never is'''
    73947342        G2plt.PlotDeltSig(G2frame,kind)
    73957343       
     
    74327380#    if kind == 'PWDR' and 'Compression' not in data[0]:
    74337381#        data[0]['Compression'] = 1
    7434     #if isinstance(data[1],list) and kind == 'HKLF':
    74357382    if 'list' in str(type(data[1])) and kind == 'HKLF':
    74367383        RefData = {'RefList':[],'FF':[]}
     
    74567403    if G2frame.dataWindow:
    74577404        G2frame.dataWindow.ClearData()
    7458     #G2frame.dataWindow.GetSizer() # don't use this since may be wx.HORIZONTAL or wx.VERTICAL
    74597405    mainSizer = wx.BoxSizer(wx.VERTICAL)
    74607406    mainSizer.Add((5,5),)
     
    75347480        data[0]['Magnification'][1:] = sorted(data[0]['Magnification'][1:],key=lambda x: x[0])
    75357481        if lenmag > 1:
    7536             panel = wx.StaticBox(G2frame.dataWindow, wx.ID_ANY, 'Magnification regions',
    7537                                  style=wx.ALIGN_CENTER)
     7482            panel = wx.StaticBox(G2frame.dataWindow, wx.ID_ANY, 'Magnification regions',style=wx.ALIGN_CENTER)
    75387483            mSizer = wx.StaticBoxSizer(panel,wx.VERTICAL)
    75397484            magSizer = wx.FlexGridSizer(lenmag+1,3,0,0)
     
    77797724                Nvars = len(data['varyList'])
    77807725                Rvals = data['Rvals']
    7781                 text = ('\nResiduals after last refinement:          \n'+
     7726                text = ('\nResiduals after last refinement:                                       \n'+
    77827727                        '\twR = {:.3f}\n\tchi**2 = {:.1f}\n\tGOF = {:.2f}').format(
    77837728                        Rvals['Rwp'],Rvals['chisq'],Rvals['GOF'])
  • TabularUnified trunk/GSASIIpwdGUI.py

    r5210 r5236  
    405405
    406406def GetFileList(G2frame,fileType):
     407    ''' Get list of file names containing a particular string
     408    param: fileType str: any string within a file name
     409    returns: list of file names from GSAS-II tree
     410    Note routine of same name in GSASIIdataGUI; it has a skip option
     411    '''
    407412    fileList = []
    408413    Id, cookie = G2frame.GPXtree.GetFirstChild(G2frame.root)
Note: See TracChangeset for help on using the changeset viewer.