Changeset 4004 for trunk/GSASIIplot.py


Ignore:
Timestamp:
May 30, 2019 1:40:09 PM (4 years ago)
Author:
toby
Message:

add file for Inst Parms plot

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIplot.py

    r4003 r4004  
    256256plotOpt['fmtChoices']  = {}
    257257plotOpt['lineWid'] = '1'
     258
     259def Write2csv(fil,dataItems,header=False):
     260    '''Write a line to a CSV file
     261
     262    :param object fil: file object
     263    :param list dataItems: items to write as row in file
     264    :param bool header: True if all items should be written with quotes (default is False)
     265    '''
     266    line = ''
     267    for item in dataItems:
     268        if line: line += ','
     269        item = str(item)
     270        if header or ' ' in item:
     271            line += '"'+item+'"'
     272        else:
     273            line += item
     274    fil.write(line+'\n')
    258275
    259276def MPLsubplots(figure, nrows=1, ncols=1, sharex=False, sharey=False,
     
    34693486        figure.canvas.draw()
    34703487       
    3471     def Write2csv(fil,dataItems,header=False):
    3472         '''Write a line to a CSV file
    3473 
    3474         :param object fil: file object
    3475         :param list dataItems: items to write as row in file
    3476         :param bool header: True if all items should be written with quotes (default is False)
    3477         '''
    3478         line = ''
    3479         for item in dataItems:
    3480             if line: line += ','
    3481             item = str(item)
    3482             if header or ' ' in item:
    3483                 line += '"'+item+'"'
    3484             else:
    3485                 line += item
    3486         fil.write(line+'\n')
    3487 
    34883488    # blocks of code used in grace .agr files
    34893489    linedef = '''@{0} legend "{1}"
     
    53075307        if event.key == 'g':
    53085308            mpl.rcParams['axes.grid'] = not mpl.rcParams['axes.grid']
     5309        elif event.key == 's':
     5310            # write the function values (not peaks) onto a file
     5311            dlg = wx.FileDialog(G2frame, 'Choose CSV file to write',
     5312                    wildcard='column-separated file (*.csv)|.csv',
     5313                    style=wx.FD_CHANGE_DIR|wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT)
     5314            try:
     5315                if dlg.ShowModal() == wx.ID_OK:
     5316                    filename = dlg.GetPath()
     5317                else:
     5318                    return
     5319            finally:
     5320                dlg.Destroy()
     5321            fp = open(filename,'w')
     5322            fp.write("# Peak widths. Def. are default values from InstParms file, fit are from refined Instrument Parameters\n")
     5323            if 'C' in Parms['Type'][0]:
     5324                Write2csv(fp,['Q',
     5325                                'Gauss-def','Lorenz-def,total-def',
     5326                                'Gauss-fit','Lorenz-fit,total-fit']
     5327                                  ,header=True)
     5328                for vals in zip(Q,Y,Z,W,Yf,Zf,Wf): Write2csv(fp,vals)
     5329            else:
     5330                Write2csv(fp,['Q',
     5331                                'Gauss-def','Lorenz-def',
     5332                                'Gauss-fit','Lorenz-fit',]
     5333                                  ,header=True)
     5334                for vals in zip(Q,S,G,Sf,Gf): Write2csv(fp,vals)
     5335            fp.close()
    53095336        wx.CallAfter(PlotPeakWidths,G2frame,PatternName)
    53105337
     
    53375364    xylim = []
    53385365    new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab('Peak Widths','mpl')
    5339     Page.Choice = (' key press','g: toggle grid',)
     5366    Page.Choice = (' key press','g: toggle grid','s: save as .csv file')
    53405367    Page.keyPress = OnKeyPress   
    53415368    if not new:
     
    53875414        Plot.plot(Q,Wf,color='b',dashes=(5,5),label='G+L fit')
    53885415       
    5389         X = []
    5390         Y = []
    5391         Z = []
    5392         W = []
     5416        Xp = []
     5417        Yp = []
     5418        Zp = []
     5419        Wp = []
    53935420        for peak in peaks:
    5394             X.append(4.0*math.pi*sind(peak[0]/2.0)/lam)
     5421            Xp.append(4.0*math.pi*sind(peak[0]/2.0)/lam)
    53955422            try:
    53965423                s = math.sqrt(peak[4])*math.pi/18000.
     
    53995426            g = peak[6]*math.pi/18000.
    54005427            G = G2pwd.getgamFW(g,s)         #/2.
    5401             Y.append(sq8ln2*s/tand(peak[0]/2.))
    5402             Z.append(g/tand(peak[0]/2.))
    5403             W.append(G/tand(peak[0]/2.))
     5428            Yp.append(sq8ln2*s/tand(peak[0]/2.))
     5429            Zp.append(g/tand(peak[0]/2.))
     5430            Wp.append(G/tand(peak[0]/2.))
    54045431        if len(peaks):
    5405             Plot.plot(X,Y,'+',color='r',label='G peak')
    5406             Plot.plot(X,Z,'+',color='g',label='L peak')
    5407             Plot.plot(X,W,'+',color='b',label='G+L peak')
     5432            Plot.plot(Xp,Yp,'+',color='r',label='G peak')
     5433            Plot.plot(Xp,Zp,'+',color='g',label='L peak')
     5434            Plot.plot(Xp,Wp,'+',color='b',label='G+L peak')
    54085435        legend = Plot.legend(loc='best')
    54095436        SetupLegendPick(legend,new)
     
    54405467        Plot.plot(Q,Gf,color='m',dashes=(5,5),label='Lorentzian fit')
    54415468       
    5442         T = []
    5443         A = []
    5444         B = []
    5445         S = []
    5446         G = []
    5447         W = []
    5448         Q = []
     5469        Tp = []
     5470        Ap = []
     5471        Bp = []
     5472        Sp = []
     5473        Gp = []
     5474        Wp = []
     5475        Qp = []
    54495476        for peak in peaks:
    5450             T.append(peak[0])
    5451             A.append(peak[4])
    5452             B.append(peak[6])
    5453             Q.append(2.*np.pi*difC/peak[0])
    5454             S.append(1.17741*np.sqrt(peak[8])/peak[0])
    5455             G.append(peak[10]/peak[0])
     5477            Tp.append(peak[0])
     5478            Ap.append(peak[4])
     5479            Bp.append(peak[6])
     5480            Qp.append(2.*np.pi*difC/peak[0])
     5481            Sp.append(1.17741*np.sqrt(peak[8])/peak[0])
     5482            Gp.append(peak[10]/peak[0])
    54565483           
    5457        
    5458         Plot.plot(Q,A,'+',color='r',label='Alpha peak')
    5459         Plot.plot(Q,B,'+',color='g',label='Beta peak')
    5460         Plot.plot(Q,S,'+',color='b',label='Gaussian peak')
    5461         Plot.plot(Q,G,'+',color='m',label='Lorentzian peak')
     5484        if Qp:
     5485            Plot.plot(Qp,Ap,'+',color='r',label='Alpha peak')
     5486            Plot.plot(Qp,Bp,'+',color='g',label='Beta peak')
     5487            Plot.plot(Qp,Sp,'+',color='b',label='Gaussian peak')
     5488            Plot.plot(Qp,Gp,'+',color='m',label='Lorentzian peak')
    54625489        Plot.legend(loc='best')
    54635490    if xylim and not G2frame.G2plotNB.allowZoomReset:
Note: See TracChangeset for help on using the changeset viewer.