Changeset 4857


Ignore:
Timestamp:
Mar 19, 2021 12:56:44 PM (7 months ago)
Author:
vondreele
Message:

Add new button to Covariance page - Show last shift/esd bar plot
Add PlotNamedFloatBarGraph? to G2plot to do it.
Fix a missing default on get in ReportProblems? in G2strMain

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIdataGUI.py

    r4852 r4857  
    73677367    Also Called in GSASIIphsGUI.UpdatePhaseData by OnTransform callback.
    73687368    '''
     7369    def OnShowShift(event):
     7370        if 'Lastshft' not in data:
     7371            return
     7372        if data['Lastshft'] is None:
     7373            return
     7374        shftesd = data['Lastshft']/data['sig']
     7375       
     7376        G2plt.PlotNamedFloatHBarGraph(G2frame,shftesd,data['varyList'],Xlabel='Last shift/esd',
     7377            Ylabel='Variables',Title='Last shift/esd',PlotName='Shift/esd')
     7378   
    73697379    if G2frame.PickIdText == G2frame.GetTreeItemsList(item): # don't redo the current data tree item
    73707380        if GSASIIpath.GetConfigValue('debug'): print('Skipping SelectDataTreeItem as G2frame.PickIdText unchanged')
     
    74477457    if G2frame.dataWindow:
    74487458        G2frame.dataWindow.ClearData()
    7449 #    G2frame.dataWindow.ClearData()
    74507459    # process first-level entries in tree
    74517460    if G2frame.GPXtree.GetItemParent(item) == G2frame.root:
     
    74917500                    text += '\n\tReduced χ**2 = {:.2f}'.format(Rvals['GOF']**2)
    74927501                subSizer.Add(wx.StaticText(G2frame.dataWindow,wx.ID_ANY,text))
     7502                if 'Lastshft' in data and not data['Lastshft'] is None:
     7503                    showShift = wx.Button(G2frame.dataWindow,label='Show shift/esd plot')
     7504                    showShift.Bind(wx.EVT_BUTTON,OnShowShift)
     7505                    subSizer.Add(showShift)
    74937506            mainSizer.Add(subSizer)
    74947507            mainSizer.Add(G2G.HelpButton(G2frame.dataWindow,helpIndex='Covariance'))
    7495             #mainSizer.Add((-1,-1),1,wx.EXPAND)
    74967508            G2frame.dataWindow.GetSizer().Add(mainSizer)
    7497 #            G2frame.dataWindow.GetSizer().Add((-1,-1),1,wx.EXPAND,1)
    74987509            G2plt.PlotCovariance(G2frame,data)
    74997510        elif G2frame.GPXtree.GetItemText(item) == 'Constraints':
  • trunk/GSASIIplot.py

    r4850 r4857  
    57055705##### PlotBarGraph ################################################################################
    57065706def PlotBarGraph(G2frame,Xarray,Xname='',Yname='Number',Title='',PlotName=None,ifBinned=False,maxBins=None):
    5707     'Needs a description'
     5707    ''' does a vertical bar graph
     5708    '''
    57085709   
    57095710    def OnPageChanged(event):
     
    57465747    Page.canvas.draw()
    57475748
     5749##### PlotNamedFloatBarGraph ################################################################################
     5750def PlotNamedFloatHBarGraph(G2frame,Xvals,Ynames,Xlabel='Value',Ylabel='',Title='',PlotName=None):
     5751    ''' does a horizintal bar graph
     5752    '''
     5753   
     5754    def OnPageChanged(event):
     5755        PlotText = G2frame.G2plotNB.nb.GetPageText(G2frame.G2plotNB.nb.GetSelection())
     5756        if PlotText == PlotName:
     5757            PlotNamedFloatHBarGraph(G2frame,Xvals,Ynames,Xlabel,Ylabel,Title,PlotText)
     5758   
     5759    def OnMotion(event):
     5760        if event.ydata is None:
     5761            return
     5762        ypos = int(event.ydata+.5)
     5763        if ypos and ypos < len(Ynames):                                        #avoid out of frame mouse position
     5764            SetCursor(Page)
     5765            try:
     5766                G2frame.G2plotNB.status.SetStatusText('X =%s %s = %9.3g'%(Ynames[ypos],Xlabel,Xvals[ypos]),1)                   
     5767            except TypeError:
     5768                G2frame.G2plotNB.status.SetStatusText('Select %s first'%PlotName,1)
     5769
     5770    if PlotName is None or not len(Ynames):
     5771        return
     5772    new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab(PlotName,'mpl')
     5773    if new:
     5774        G2frame.G2plotNB.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGED,OnPageChanged)
     5775        Page.canvas.mpl_connect('motion_notify_event', OnMotion)
     5776    Yvals = np.arange(len(Ynames))
     5777    colors = ['blue' if x >= 0. else 'red' for x in Xvals]
     5778    Page.Choice = None
     5779    Plot.set_title(Title)
     5780    Plot.set_xlabel(Xlabel,fontsize=14)
     5781    Plot.set_ylabel(Ylabel,fontsize=14)
     5782    Plot.barh(Yvals,Xvals,height=0.8,align='center',color=colors,edgecolor='black',tick_label=Ynames)
     5783    Page.canvas.draw()
     5784   
    57485785##### PlotSASDSizeDist ################################################################################
    57495786def PlotSASDSizeDist(G2frame):
     
    67756812        imgAx = Img.axes
    67766813        ytics = imgAx.get_yticks()
     6814        imgAx.set_yticks(ytics[:-1])
    67776815        ylabs = [Page.varyList[int(i)] for i in ytics[:-1]]
    67786816        imgAx.set_yticklabels(ylabs)
  • trunk/GSASIIstrMain.py

    r4850 r4857  
    8282                    msg += ', {}'.format(varyList[val])
    8383        if m: G2fil.G2Print(m, mode='warn')
    84     SVD0 = result[2].get('SVD0')
     84    SVD0 = result[2].get('SVD0',0)
    8585    if SVD0 == 1:
    8686        msg += 'Warning: Soft (SVD) singularity in the Hessian'
     
    253253            covMatrix = result[1]*Rvals['GOF']**2
    254254            sig = np.sqrt(np.diag(covMatrix))
    255             Lastshft = result[2].get('Xvec',None)
    256             if Lastshft is None:
    257                 Rvals['Max shft/sig'] = None
    258             else:
    259                 Rvals['Max shft/sig'] = np.max(np.nan_to_num(Lastshft/sig))
     255            Lastshft = result[0]-values
     256            Rvals['Max shft/sig'] = np.max(np.nan_to_num(Lastshft/sig))
    260257            if np.any(np.isnan(sig)) or not sig.shape:
    261258                G2fil.G2Print ('*** Least squares aborted - some invalid esds possible ***',mode='error')
    262 #            table = dict(zip(varyList,zip(values,result[0],(result[0]-values)/sig)))
    263 #            for item in table: print item,table[item]               #useful debug - are things shifting?
    264259            # report on refinement issues. Result in Rvals['msg']
    265260            ReportProblems(result,Rvals,varyList)
     
    304299    if chisq0 is not None:
    305300        Rvals['GOF0'] = np.sqrt(chisq0/(Histograms['Nobs']-len(varyList)))
    306     return IfOK,Rvals,result,covMatrix,sig
     301    return IfOK,Rvals,result,covMatrix,sig,Lastshft
    307302
    308303def Refine(GPXfile,dlg=None,makeBack=True,refPlotUpdate=None):
     
    398393    try:
    399394        covData = {}
    400         IfOK,Rvals,result,covMatrix,sig = RefineCore(Controls,Histograms,Phases,restraintDict,
     395        IfOK,Rvals,result,covMatrix,sig,Lastshft = RefineCore(Controls,Histograms,Phases,restraintDict,
    401396            rigidbodyDict,parmDict,varyList,calcControls,pawleyLookup,ifSeq,printFile,dlg,
    402397            refPlotUpdate=refPlotUpdate)
     
    406401            newAtomDict = G2stMth.ApplyXYZshifts(parmDict,varyList)
    407402            covData = {'variables':result[0],'varyList':varyList,'sig':sig,'Rvals':Rvals,
    408                        'varyListStart':varyListStart,
     403                       'varyListStart':varyListStart,'Lastshft':Lastshft,
    409404                       'covMatrix':covMatrix,'title':GPXfile,'newAtomDict':newAtomDict,
    410405                       'newCellDict':newCellDict,'freshCOV':True}
     
    818813               .format(s))
    819814        try:
    820             IfOK,Rvals,result,covMatrix,sig = RefineCore(Controls,Histo,Phases,restraintDict,
     815            IfOK,Rvals,result,covMatrix,sig,Lastshft = RefineCore(Controls,Histo,Phases,restraintDict,
    821816                rigidbodyDict,parmDict,varyList,calcControls,pawleyLookup,ifSeq,printFile,dlg,
    822817                refPlotUpdate=refPlotUpdate)
     
    860855            histRefData = {
    861856                'variables':result[0],'varyList':varyList,'sig':sig,'Rvals':Rvals,
    862                 'varyListStart':varyListStart,
     857                'varyListStart':varyListStart,'Lastshft':Lastshft,
    863858                'covMatrix':covMatrix,'title':histogram,'newAtomDict':newAtomDict,
    864859                'newCellDict':newCellDict,'depParmDict':depParmDict,
Note: See TracChangeset for help on using the changeset viewer.