Changeset 2422 for trunk/GSASIIIO.py


Ignore:
Timestamp:
Aug 13, 2016 4:15:35 PM (5 years ago)
Author:
vondreele
Message:

allow saving of plotted XY data from PlotXY as csv file

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIIO.py

    r2401 r2422  
    949949                [np.array(X),np.array(Y),np.array(W),np.zeros(N),np.zeros(N),np.zeros(N)]])
    950950    return Id       #last powder pattern generated
     951   
     952def XYsave(G2frame,XY,labelX='X',labelY='Y',names=None):
     953    'Save XY table data'
     954    pth = G2G.GetExportPath(G2frame)
     955    dlg = wx.FileDialog(
     956        G2frame, 'Enter csv filename for XY table', pth, '',
     957        'XY table file (*.csv)|*.csv',wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT)
     958    try:
     959        if dlg.ShowModal() == wx.ID_OK:
     960            filename = dlg.GetPath()
     961            filename = os.path.splitext(filename)[0]+'.csv'
     962            File = open(filename,'w')
     963        else:
     964            filename = None
     965    finally:
     966        dlg.Destroy()
     967    if not filename:
     968        return
     969    for i in range(len(XY)):
     970        if names != None:
     971            header = '%s,%s(%s)\n'%(labelX,labelY,names[i])
     972        else:
     973            header = '%s,%s(%d)\n'%(labelX,labelY,i)
     974        File.write(header)
     975        for x,y in XY[i].T:
     976            File.write('%.3f,%.3f\n'%(x,y))   
     977    File.close()
     978    print ' XY data saved to: ',filename
    951979           
    952980def PDFSave(G2frame,exports):
    953     'Save a PDF G(r) and S(Q) in column formats'
     981    'Save a PDF G(r) and F(Q), S(Q) in column formats'
    954982    for export in exports:
    955983        PickId = G2gd.GetPatternTreeItemId(G2frame, G2frame.root, export)
    956984        SQname = 'S(Q)'+export[4:]
     985        FQname = 'F(Q)'+export[4:]
    957986        GRname = 'G(R)'+export[4:]
    958987        sqfilename = ospath.join(G2frame.dirname,export.replace(' ','_')[5:]+'.sq')
     988        fqfilename = ospath.join(G2frame.dirname,export.replace(' ','_')[5:]+'.fq')
    959989        grfilename = ospath.join(G2frame.dirname,export.replace(' ','_')[5:]+'.gr')
    960990        sqId = G2gd.GetPatternTreeItemId(G2frame, PickId, SQname)
     991        fqId = G2gd.GetPatternTreeItemId(G2frame, PickId, FQname)
    961992        grId = G2gd.GetPatternTreeItemId(G2frame, PickId, GRname)
    962993        sqdata = np.array(G2frame.PatternTree.GetItemPyData(sqId)[1][:2]).T
     994        fqdata = np.array(G2frame.PatternTree.GetItemPyData(fqId)[1][:2]).T
    963995        grdata = np.array(G2frame.PatternTree.GetItemPyData(grId)[1][:2]).T
    964996        sqfile = open(sqfilename,'w')
     997        fqfile = open(sqfilename,'w')
    965998        grfile = open(grfilename,'w')
    966999        sqfile.write('#T S(Q) %s\n'%(export))
     1000        fqfile.write('#T F(Q) %s\n'%(export))
    9671001        grfile.write('#T G(R) %s\n'%(export))
    9681002        sqfile.write('#L Q     S(Q)\n')
     1003        sqfile.write('#L Q     F(Q)\n')
    9691004        grfile.write('#L R     G(R)\n')
    9701005        for q,sq in sqdata:
    9711006            sqfile.write("%15.6g %15.6g\n" % (q,sq))
    9721007        sqfile.close()
     1008        print ' S(Q) saved to: ',sqfilename
     1009        for q,fq in fqdata:
     1010            fqfile.write("%15.6g %15.6g\n" % (q,fq))
     1011        fqfile.close()
     1012        print ' F(Q) saved to: ',fqfilename
    9731013        for r,gr in grdata:
    9741014            grfile.write("%15.6g %15.6g\n" % (r,gr))
    9751015        grfile.close()
     1016        print ' G)R) saved to: ',grfilename
    9761017   
    9771018def PeakListSave(G2frame,file,peaks):
Note: See TracChangeset for help on using the changeset viewer.