Changeset 4003 for trunk/GSASIIplot.py


Ignore:
Timestamp:
May 29, 2019 6:22:27 PM (4 years ago)
Author:
toby
Message:

fix subtle bug in plotCovar where cursor showed only initial vals; add general parameter retrieval routines

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIplot.py

    r3999 r4003  
    60586058           
    60596059def PlotCovariance(G2frame,Data):
    6060     'needs a doc string'
    6061     if not Data:
    6062         print ('No covariance matrix available')
    6063         return
    6064     varyList = Data['varyList']
    6065     values = Data['variables']
    6066     covMatrix = Data['covMatrix']
    6067     sig = np.sqrt(np.diag(covMatrix))
    6068     xvar = np.outer(sig,np.ones_like(sig))
    6069     covArray = np.divide(np.divide(covMatrix,xvar),xvar.T)
    6070     title = G2obj.StripUnicode(' for\n'+Data['title'],'') # matplotlib 1.x does not like unicode
    6071     newAtomDict = Data.get('newAtomDict',{})
    6072     G2frame.G2plotNB.status.DestroyChildren() #get rid of special stuff on status bar
    6073 
     6060    '''Plots the covariance matrix. Also shows values for parameters
     6061    and their standard uncertainties (esd's) or the correlation between
     6062    variables.
     6063    '''
    60746064    def OnPlotKeyPress(event):
    60756065        if event.key == 's':
     
    60906080            covFile.write('*' + 126*' ' + '*\n')
    60916081            covFile.write(128*'*' + '\n\n\n\n')
    6092             llen = len(varyList)
     6082            llen = len(Page.varyList)
    60936083            for start in range(0, llen, 8):  # split matrix into batches of 7 columns
    60946084                if llen >= start + 8:
     
    60986088                covFile.write(12*' ' + '\t')
    60996089                for idx in range(start, stop):
    6100                     covFile.write('{:^12}\t'.format(varyList[idx]))
     6090                    covFile.write('{:^12}\t'.format(Page.varyList[idx]))
    61016091                covFile.write('\n\n')
    61026092                for line in range(llen):
    6103                     covFile.write('{:>12}\t'.format(varyList[line]))
     6093                    covFile.write('{:>12}\t'.format(Page.varyList[line]))
    61046094                    for idx in range(start, stop):
    6105                         covFile.write('{: 12.6f}\t'.format(covArray[line][idx]))
     6095                        covFile.write('{: 12.6f}\t'.format(Page.covArray[line][idx]))
    61066096                    covFile.write('\n')
    61076097                covFile.write('\n\n\n')
    61086098            covFile.close()
    6109         PlotCovariance(G2frame,Data)
     6099        wx.CallAfter(PlotCovariance,G2frame,Data)
    61106100
    61116101    def OnMotion(event):
    61126102        if event.button:
    61136103            ytics = imgAx.get_yticks()
    6114             ytics = np.where(ytics<len(varyList),ytics,-1)
    6115             ylabs = [np.where(0<=i ,varyList[int(i)],' ') for i in ytics]
     6104            ytics = np.where(ytics<len(Page.varyList),ytics,-1)
     6105            ylabs = [np.where(0<=i ,Page.varyList[int(i)],' ') for i in ytics]
    61166106            imgAx.set_yticklabels(ylabs)           
    61176107        if event.xdata and event.ydata:                 #avoid out of frame errors
    61186108            xpos = int(event.xdata+.5)
    61196109            ypos = int(event.ydata+.5)
    6120             if -1 < xpos < len(varyList) and -1 < ypos < len(varyList):
     6110            if -1 < xpos < len(Page.varyList) and -1 < ypos < len(Page.varyList):
    61216111                if xpos == ypos:
    6122                     value = values[xpos]
    6123                     name = varyList[xpos]
    6124                     if varyList[xpos] in newAtomDict:
    6125                         name,value = newAtomDict[name]                       
    6126                     msg = '%s value = %.4g, esd = %.4g'%(name,value,sig[xpos])
     6112                    value = Page.values[xpos]
     6113                    name = Page.varyList[xpos]
     6114                    if Page.varyList[xpos] in Page.newAtomDict:
     6115                        name,value = Page.newAtomDict[name]                       
     6116                    msg = '%s value = %.4g, esd = %.4g'%(name,value,Page.sig[xpos])
    61276117                else:
    6128                     msg = '%s - %s: %5.3f'%(varyList[xpos],varyList[ypos],covArray[xpos][ypos])
     6118                    msg = '%s - %s: %5.3f'%(Page.varyList[xpos],Page.varyList[ypos],Page.covArray[xpos][ypos])
    61296119                Page.SetToolTipString(msg)
    61306120                G2frame.G2plotNB.status.SetStatusText(msg,1)
    61316121               
     6122    #==== PlotCovariance(G2frame,Data) starts here =========================
     6123    if not Data:
     6124        print ('No covariance matrix available')
     6125        return
    61326126    new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab('Covariance','mpl')
    61336127    if not new:
     
    61376131        Page.canvas.mpl_connect('motion_notify_event', OnMotion)
    61386132        Page.canvas.mpl_connect('key_press_event', OnPlotKeyPress)
     6133    Page.varyList = Data['varyList']
     6134    Page.values = Data['variables']
     6135    covMatrix = Data['covMatrix']
     6136    Page.sig = np.sqrt(np.diag(covMatrix))
     6137    xvar = np.outer(Page.sig,np.ones_like(Page.sig))
     6138    Page.covArray = np.divide(np.divide(covMatrix,xvar),xvar.T)
     6139    title = G2obj.StripUnicode(' for\n'+Data['title'],'') # matplotlib 1.x does not like unicode
     6140    Page.newAtomDict = Data.get('newAtomDict',{})
     6141    G2frame.G2plotNB.status.DestroyChildren() #get rid of special stuff on status bar
    61396142    Page.Choice = ['s: to change colors','p: to save covariance as text file']
    61406143    Page.keyPress = OnPlotKeyPress
     
    61436146    G2frame.G2plotNB.status.SetStatusWidths([150,-1])   #need to reset field widths here   
    61446147    acolor = mpl.cm.get_cmap(G2frame.VcovColor)
    6145     Img = Plot.imshow(covArray,aspect='equal',cmap=acolor,interpolation='nearest',origin='lower',
     6148    Img = Plot.imshow(Page.covArray,aspect='equal',cmap=acolor,interpolation='nearest',origin='lower',
    61466149        vmin=-1.,vmax=1.)
    61476150    imgAx = Img.axes
    61486151    ytics = imgAx.get_yticks()
    6149     ylabs = [varyList[int(i)] for i in ytics[:-1]]
     6152    ylabs = [Page.varyList[int(i)] for i in ytics[:-1]]
    61506153    imgAx.set_yticklabels(ylabs)
    61516154    Page.figure.colorbar(Img)
Note: See TracChangeset for help on using the changeset viewer.