Changeset 5610


Ignore:
Timestamp:
Jun 8, 2023 9:23:45 PM (2 years ago)
Author:
toby
Message:

add .csv option for single pattern plots

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/GSASIIplot.py

    r5572 r5610  
    202202plotOpt['fmtChoices']  = {}
    203203plotOpt['lineWid'] = '1'
    204 
     204plotOpt['saveCSV'] = False
     205plotOpt['CSVfile'] = None
     206 
    205207def Write2csv(fil,dataItems,header=False):
    206208    '''Write a line to a CSV file
     
    23212323                    KeyItem[1]()
    23222324                    break
     2325        elif event.key == 'v' and 'PWDR' in plottype and G2frame.SinglePlot:
     2326            plotOpt['CSVfile'] = G2G.askSaveFile(G2frame,'','.csv',
     2327                                        'Comma separated variable file')
     2328            if plotOpt['CSVfile']: plotOpt['saveCSV'] = True
    23232329        else:
    23242330            #print('no binding for key',event.key)
     
    32993305            else:
    33003306                Page.Choice = Page.Choice+ ['p: toggle partials (if available)',]
     3307            if G2frame.SinglePlot:
     3308                Page.Choice += ['v: CSV output of plot']
    33013309        elif plottype in ['SASD','REFD']:
    33023310            Page.Choice = [' key press',
     
    36313639            # limit lines
    36323640            Lines.append(Plot.axvline(lims[0][0],color='g',dashes=(5,5),picker=True,pickradius=3.))   
    3633             Lines.append(Plot.axvline(lims[0][1],color='r',dashes=(5,5),picker=True,pickradius=3.)) 
     3641            Lines.append(Plot.axvline(lims[0][1],color='r',dashes=(5,5),picker=True,pickradius=3.))
    36343642            # excluded region lines
    36353643            for i,item in enumerate(lims[1:]):
     
    38303838                                picker=True,pickradius=1.,label=incCptn('diff'))                 #Io-Ic
    38313839                    Plot.axhline(0.,color='k',label='_zero')
     3840                    # write a .csv file; not fully tested, but probably works where allowed
     3841                    if 'PWDR' in plottype and G2frame.SinglePlot and plotOpt['saveCSV']:
     3842                        plotOpt['saveCSV'] = False
     3843                        fp = open(plotOpt['CSVfile'],'w')
     3844                        Write2csv(fp,['"limits"',lims[0][0],lims[0][1]])
     3845                        l = []
     3846                        PeakId = G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId, 'Peak List')
     3847                        peaks = G2frame.GPXtree.GetItemPyData(PeakId)
     3848                        for i,item in enumerate(peaks['peaks']):
     3849                            if type(item) is dict: continue
     3850                            pos = item[0]
     3851                            if Page.plotStyle['qPlot']:
     3852                                l.append(2.*np.pi/G2lat.Pos2dsp(Parms,pos))
     3853                            elif Page.plotStyle['dPlot']:
     3854                                l.append(G2lat.Pos2dsp(Parms,pos))
     3855                            else:
     3856                                l.append(pos)
     3857                        if l: Write2csv(fp,['"peaks"']+l)
     3858                        peaks['LaueFringe'] = peaks.get('LaueFringe',{})
     3859                        l = []
     3860                        for pos in peaks['LaueFringe'].get('satellites',[]):
     3861                            if Page.plotStyle['qPlot']:
     3862                                l.append(2.*np.pi/G2lat.Pos2dsp(Parms,pos))
     3863                            elif Page.plotStyle['dPlot']:
     3864                                l.append(G2lat.Pos2dsp(Parms,pos))
     3865                            else:
     3866                                l.append(pos)
     3867                        if l: Write2csv(fp,['"satellites"']+l)
     3868
     3869                        Write2csv(fp,['masked X','X','obs','calc','bkg','diff'],header=True)
     3870                        for i in range(len(X)):
     3871                            Write2csv(fp,[X[i],X.data[i],Y[i],Z[i],W[i],D[i]],header=False)
     3872                        fp.close()
     3873                        print('file',plotOpt['CSVfile'],'written')
     3874                       
    38323875                Page.SetToolTipString('')
    38333876                if PickId:
Note: See TracChangeset for help on using the changeset viewer.