Ignore:
Timestamp:
Oct 10, 2015 11:58:12 AM (6 years ago)
Author:
toby
Message:

Add API for direct image read (G2IO.ExportPowderList?) and powder exports w/o GUI (G2IO.ExportPowderList?); redo export to add new method (Writer)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/exports/G2export_csv.py

    r1836 r1997  
    126126        self.multiple = True
    127127
     128    def Writer(self,TreeName,filename=None):
     129        self.OpenFile(filename)
     130        histblk = self.Histograms[TreeName]
     131        WriteList(self,("x","y_obs","weight","y_calc","y_bkg"))
     132        digitList = 2*((13,3),) + ((13,5),) + 2*((13,3),)
     133        for vallist in zip(histblk['Data'][0],
     134                       histblk['Data'][1],
     135                       histblk['Data'][2],
     136                       histblk['Data'][3],
     137                       histblk['Data'][4],
     138                       #histblk['Data'][5],
     139                       ):
     140            line = ""
     141            for val,digits in zip(vallist,digitList):
     142                if line: line += ','
     143                line += G2py3.FormatValue(val,digits)
     144            self.Write(line)
     145        self.CloseFile()
     146       
    128147    def Exporter(self,event=None):
    129148        '''Export a set of powder data as a csv file
     
    138157        filenamelist = []
    139158        for hist in self.histnam:
    140             if len(self.histnam) > 1:
    141                 # multiple files: create a unique name from the histogram
    142                 fileroot = G2obj.MakeUniqueLabel(self.MakePWDRfilename(hist),filenamelist)
    143                 # create an instrument parameter file
    144                 self.filename = os.path.join(self.dirname,fileroot + self.extension)
    145             self.OpenFile()
    146             histblk = self.Histograms[hist]
    147             WriteList(self,("x","y_obs","weight","y_calc","y_bkg"))
    148             digitList = 2*((13,3),) + ((13,5),) + 2*((13,3),)
    149             for vallist in zip(histblk['Data'][0],
    150                            histblk['Data'][1],
    151                            histblk['Data'][2],
    152                            histblk['Data'][3],
    153                            histblk['Data'][4],
    154                            #histblk['Data'][5],
    155                            ):
    156                 line = ""
    157                 for val,digits in zip(vallist,digitList):
    158                     if line: line += ','
    159                     line += G2py3.FormatValue(val,digits)
    160                 self.Write(line)
    161             self.CloseFile()
     159            #if len(self.histnam) > 1:
     160            #    # multiple files: create a unique name from the histogram
     161            #    fileroot = G2obj.MakeUniqueLabel(self.MakePWDRfilename(hist),filenamelist)
     162            #    # create an instrument parameter file
     163            #    self.filename = os.path.join(self.dirname,fileroot + self.extension)
     164            self.Writer(hist)
    162165            print('Histogram '+str(hist)+' written to file '+str(self.fullpath))
    163166
Note: See TracChangeset for help on using the changeset viewer.