Changeset 3913 for trunk/GSASIIplot.py


Ignore:
Timestamp:
Apr 21, 2019 10:05:23 PM (4 years ago)
Author:
toby
Message:

Update Rietveld cycle-by-cycle

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIplot.py

    r3909 r3913  
    17441744##### PlotPatterns
    17451745################################################################################
    1746 def SequentialPlotPattern(G2frame,refdata,histogram):
    1747     '''This is passed into :func:`GSASIIstrMain.SeqRefine` where it is used to
    1748     provide a plot of the current powder histogram just after a refinement. It
    1749     takes the old refinement information (Rfactors, curve locations, etc.) and
    1750     combines it with the refinement results in refdata and passes that to
    1751     :func:`PlotPatterns`
    1752     '''
    1753     if not histogram.startswith('PWDR'): return
    1754     pickId = G2frame.PickId
    1755     G2frame.PickId = G2frame.PatternId = G2gd.GetGPXtreeItemId(G2frame, G2frame.root, histogram)
    1756     treedata = G2frame.GPXtree.GetItemPyData(G2frame.PatternId)
    1757     PlotPatterns(G2frame,newPlot=True,plotType='PWDR',data=[treedata[0],refdata])
    1758     wx.Yield() # force a plot update (needed on Windows?)
    1759     G2frame.PickId = pickId
    1760    
    17611746def ReplotPattern(G2frame,newPlot,plotType,PatternName=None,PickName=None):
    17621747    '''This does the same as PlotPatterns except that it expects the information
     
    17771762
    17781763def PlotPatterns(G2frame,newPlot=False,plotType='PWDR',data=None,
    1779                      extraKeys=[]):
     1764                     extraKeys=[],refineMode=False):
    17801765    '''Powder pattern plotting package - displays single or multiple powder patterns as intensity vs
    17811766    2-theta, q or TOF. Can display multiple patterns as "waterfall plots" or contour plots. Log I
     
    25942579        else:
    25952580            Plot.set_ylim(CurLims['ylims'])
     2581        Page.toolbar.push_current()
    25962582        Plot.figure.canvas.draw()
    25972583        #GSASIIpath.IPyBreak()
    25982584       
    25992585    def onPlotFormat(event):
     2586        '''Change the appearance of the current plot'''
    26002587        changePlotSettings(G2frame,Plot)
     2588       
     2589    def refPlotUpdate(Histograms,cycle=None,restore=False):
     2590        '''called to update an existing plot during a Rietveld fit
     2591        '''
     2592        if restore:
     2593            (G2frame.SinglePlot,G2frame.Contour,G2frame.Weight,
     2594                G2frame.plusPlot,G2frame.SubBack,Page.plotStyle['logPlot']) = savedSettings
     2595            return
     2596
     2597        if plottingItem not in Histograms:
     2598            histoList = [i for i in Histograms.keys() if i.startswith('PWDR ')]
     2599            if len(histoList) == 0:
     2600                print('Skipping plot, no PWDR item found!')
     2601                return
     2602            plotItem = histoList[0]
     2603        else:
     2604            plotItem = plottingItem
     2605        xye = np.array(ma.getdata(Histograms[plotItem]['Data'])) # strips mask
     2606        xye0 = Histograms[plotItem]['Data'][0]
     2607        if Page.plotStyle['qPlot']:
     2608            X = 2.*np.pi/G2lat.Pos2dsp(Parms,xye0)
     2609            Ibeg = np.searchsorted(X,2.*np.pi/G2lat.Pos2dsp(Parms,limits[1][0]))
     2610            Ifin = np.searchsorted(X,2.*np.pi/G2lat.Pos2dsp(Parms,limits[1][1]))
     2611        elif Page.plotStyle['dPlot']:
     2612            X = G2lat.Pos2dsp(Parms,xye0)
     2613            Ibeg = np.searchsorted(X,G2lat.Pos2dsp(Parms,limits[1][1]))
     2614            Ifin = np.searchsorted(X,G2lat.Pos2dsp(Parms,limits[1][0]))
     2615        else:
     2616            X = copy.deepcopy(xye0)
     2617            Ibeg = np.searchsorted(X,limits[1][0])
     2618            Ifin = np.searchsorted(X,limits[1][1])
     2619        if Page.plotStyle['sqrtPlot']:
     2620            olderr = np.seterr(invalid='ignore') #get around sqrt(-ve) error
     2621            Y = np.where(xye[1]>=0.,np.sqrt(xye[1]),-np.sqrt(-xye[1]))
     2622            Z = np.where(xye[3]>=0.,np.sqrt(xye[3]),-np.sqrt(-xye[3]))
     2623            W = np.where(xye[4]>=0.,np.sqrt(xye[4]),-np.sqrt(-xye[4]))
     2624            #D = np.where(xye[5],(Y-Z),0.)-Page.plotStyle['delOffset']
     2625            np.seterr(invalid=olderr['invalid'])
     2626        else:
     2627            Y = copy.copy(xye[1])
     2628            Z = copy.copy(xye[3])
     2629            W = copy.copy(xye[4])
     2630            #D = xye[5]-Page.plotStyle['delOffset']  #powder background
     2631        DZ = (xye[1]-xye[3])*np.sqrt(xye[2])
     2632        DifLine[0].set_xdata(X[Ibeg:Ifin])
     2633        DifLine[0].set_ydata(DZ[Ibeg:Ifin])
     2634        Plot1.set_ylim((min(DZ[Ibeg:Ifin]),max(DZ[Ibeg:Ifin])))
     2635        CalcLine[0].set_xdata(X)
     2636        ObsLine[0].set_xdata(X)
     2637        BackLine[0].set_xdata(X)
     2638        CalcLine[0].set_ydata(Z)
     2639        ObsLine[0].set_ydata(Y)
     2640        BackLine[0].set_ydata(W)
     2641        if cycle:
     2642            Title = '{} cycle #{}'.format(plotItem,cycle)
     2643        else:
     2644            Title = plotItem
     2645        if Page.plotStyle['sqrtPlot']:
     2646            Plot.set_title(r'$\sqrt{I}$ for '+Title)
     2647        else:
     2648            Plot.set_title(Title)
     2649        Page.canvas.draw()
     2650
    26012651    #=====================================================================================
    26022652    # beginning PlotPatterns execution
     
    26352685        G2frame.UseLimits = {'xlims':[False,False],'ylims':[False,False],
    26362686                                       'dylims':[False,False]}
     2687    #=====================================================================================
     2688    # code to setup for plotting Rietveld results. Turns off multiplot,
     2689    # sqrtplot, turn on + and weight plot, but sqrtPlot qPlot and dPlot are not changed.
     2690    # Magnification regions are ignored.
     2691    # the last-plotted histogram (from G2frame.PatternId) is used for this plotting
     2692    #    (except in seq. fitting)
     2693    # Returns a pointer to refPlotUpdate, which is used to update the plot when this
     2694    # returns
     2695    if refineMode:
     2696        plottingItem = G2frame.GPXtree.GetItemText(G2frame.PatternId)
     2697        # save settings to be restored after refinement with repPlotUpdate({},restore=True)
     2698        savedSettings = (G2frame.SinglePlot,G2frame.Contour,G2frame.Weight,
     2699                            G2frame.plusPlot,G2frame.SubBack,Page.plotStyle['logPlot'])
     2700        G2frame.SinglePlot = True
     2701        G2frame.Contour = False
     2702        G2frame.Weight = True
     2703        G2frame.plusPlot = True
     2704        G2frame.SubBack = False
     2705        Page.plotStyle['logPlot'] = False
     2706    #=====================================================================================
    26372707    if not new:
    26382708        G2frame.xylim = limits
     
    29072977        if 'PWDR' in plottype and G2frame.SinglePlot and not (
    29082978                Page.plotStyle['logPlot'] or Page.plotStyle['sqrtPlot'] or G2frame.Contour):
    2909             magLineList = data[0].get('Magnification',[])
     2979            if not refineMode:
     2980                magLineList = data[0].get('Magnification',[])
    29102981            if ('C' in ParmList[0]['Type'][0] and Page.plotStyle['dPlot']) or \
    29112982                ('T' in ParmList[0]['Type'][0] and Page.plotStyle['qPlot']): # reversed regions relative to data order
     
    30543125                    else:
    30553126                        Plot.set_ylim(bottom=np.min(np.trim_zeros(YB))/2.,top=np.max(Y)*2.)
     3127                # Matplotlib artist lists used for refPlotUpdate
     3128                ObsLine = None
     3129                CalcLine = None
     3130                BackLine = None
     3131                DifLine = None
    30563132                if G2frame.Weight:
    30573133                    Plot1.set_yscale("linear")                                                 
     
    30953171                    if G2frame.SubBack:
    30963172                        if 'PWDR' in plottype:
    3097                             Plot.plot(Xum,Y-W,colors[0]+pP,picker=False,clip_on=Clip_on,label='_obs')  #Io-Ib
    3098                             Plot.plot(X,Z-W,colors[1],picker=False,label='_calc')               #Ic-Ib
     3173                            ObsLine = Plot.plot(Xum,Y-W,colors[0]+pP,picker=False,clip_on=Clip_on,label='_obs')  #Io-Ib
     3174                            CalcLine = Plot.plot(X,Z-W,colors[1],picker=False,label='_calc')               #Ic-Ib
    30993175                        else:
    31003176                            Plot.plot(X,YB,colors[0]+pP,picker=3.,clip_on=Clip_on,label='_obs')
     
    31033179                        if 'PWDR' in plottype:
    31043180                            ObsLine = Plot.plot(Xum,Y,colors[0]+pP,picker=3.,clip_on=Clip_on,label='_obs')    #Io
    3105                             Plot.plot(X,Z,colors[1],picker=False,label='_calc')                 #Ic
     3181                            CalcLine = Plot.plot(X,Z,colors[1],picker=False,label='_calc')                 #Ic
    31063182                        else:
    31073183                            Plot.plot(X,YB,colors[0]+pP,picker=3.,clip_on=Clip_on,label='_obs')
    31083184                            Plot.plot(X,ZB,colors[1],picker=False,label='_calc')
    31093185                    if 'PWDR' in plottype and (G2frame.SinglePlot or G2frame.plusPlot):
    3110                         Plot.plot(X,W,colors[2],picker=False,label='_bkg')                 #Ib
     3186                        BackLine = Plot.plot(X,W,colors[2],picker=False,label='_bkg')                 #Ib
    31113187                        if not G2frame.Weight: DifLine = Plot.plot(X,D,colors[3],picker=1.,label='_diff')                 #Io-Ic
    31123188                    Plot.axhline(0.,color='k',label='_zero')
     
    31873263                    Plot.axvline(hkl[-2],color=clr,dashes=(5,5))
    31883264        elif G2frame.GPXtree.GetItemText(PickId) in ['Reflection Lists'] or \
    3189             'PWDR' in G2frame.GPXtree.GetItemText(PickId):
     3265            'PWDR' in G2frame.GPXtree.GetItemText(PickId) or refineMode:
    31903266            Phases = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId,'Reflection Lists'))
    31913267            l = GSASIIpath.GetConfigValue('Tick_length',8.0)
     
    32813357        if DifLine[0]:
    32823358            G2frame.dataWindow.moveDiffCurve.Enable(True)
     3359    if refineMode: return refPlotUpdate
    32833360           
    32843361def PublishRietveldPlot(G2frame,Pattern,Plot,Page):
Note: See TracChangeset for help on using the changeset viewer.