Changeset 1630 for trunk/exports


Ignore:
Timestamp:
Jan 13, 2015 4:01:13 PM (7 years ago)
Author:
vondreele
Message:

add export routine for tables of x,y0,y1,y2,... for multiple powder data sets - apparently useful for plotting in Excel, etc.
implement SS structure factor calcs for position modulation - Fourier only
working on printing wave results

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/exports/G2export_csv.py

    r1261 r1630  
    161161            print('Histogram '+str(hist)+' written to file '+str(self.fullpath))
    162162
     163class ExportMultiPowderCSV(G2IO.ExportBaseclass):
     164    '''Used to create a csv file for a stack of powder data sets suitable for display
     165    purposes only; no y-calc or weights are exported only x & y-obs
     166    :param wx.Frame G2frame: reference to main GSAS-II frame
     167    '''
     168    def __init__(self,G2frame):
     169        super(self.__class__,self).__init__( # fancy way to say <parentclass>.__init__
     170            G2frame=G2frame,
     171            formatName = 'stacked CSV file',
     172            extension='.csv',
     173            longFormatName = 'Export powder data sets as a (csv) file - x,y-o1,y-o2,... only'
     174            )
     175        self.exporttype = ['powder']
     176        #self.multiple = False # only allow one histogram to be selected
     177        self.multiple = True
     178
     179    def Exporter(self,event=None):
     180        '''Export a set of powder data as a csv file
     181        '''
     182        # the export process starts here
     183        self.InitExport(event)
     184        # load all of the tree into a set of dicts
     185        self.loadTree()
     186        if self.ExportSelect( # set export parameters
     187            AskFile='single' # get a file name/directory to save in
     188            ): return
     189        filenamelist = []
     190        csvData = []
     191        headList = ["x",]
     192        digitList = []
     193        fileroot = G2obj.MakeUniqueLabel(self.MakePWDRfilename(self.histnam[0]),filenamelist)
     194        # create an instrument parameter file
     195        self.filename = os.path.join(self.dirname,fileroot + self.extension)
     196        for ihst,hist in enumerate(self.histnam):
     197            histblk = self.Histograms[hist]
     198            headList.append('y_obs_'+str(ihst))
     199            if not ihst:
     200                digitList = [(13,3),]
     201                csvData.append(histblk['Data'][0])
     202            digitList += [(13,3),]
     203            csvData.append(histblk['Data'][1])
     204            print('Histogram '+str(hist)+' written to file '+str(self.fullpath))
     205        self.OpenFile()
     206        WriteList(self,headList)
     207        for vallist in np.array(csvData).T:
     208            line = ""
     209            for val,digits in zip(vallist,digitList):
     210                if line: line += ','
     211                line += G2py3.FormatValue(val,digits)
     212            self.Write(line)
     213        self.CloseFile()
     214
    163215class ExportPowderReflCSV(G2IO.ExportBaseclass):
    164216    '''Used to create a csv file of reflections from a powder data set
Note: See TracChangeset for help on using the changeset viewer.