Ignore:
Timestamp:
Oct 10, 2015 11:58:12 AM (8 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_pwdr.py

    r1675 r1997  
    6262        return prmname
    6363
     64    def Writer(self,TreeName,filename=None,prmname=''):
     65        '''Write a single PWDR entry to a FXYE file
     66        '''
     67        histblk = self.Histograms[TreeName]
     68        self.OpenFile(filename) # ***rethink
     69        self.Write(TreeName[5:])
     70        if prmname: self.Write('Instrument parameter file:'+os.path.split(prmname)[1])
     71        x = 100*np.array(histblk['Data'][0])
     72        # convert weights to sigmas; use largest weight as minimum esd
     73        s = np.sqrt(np.maximum(0.,np.array(histblk['Data'][2])))
     74        s[s==0] = np.max(s)
     75        s = 1./s
     76        self.Write('BANK 1 %d %d CONS %.2f %.2f 0 0 FXYE' % (
     77            len(x),len(x),x[0],(x[1]-x[0])
     78            ))
     79#            for X,Y,S in zip(x,histblk['Data'][1],s):
     80#                self.Write("{:15.6g} {:15.6g} {:15.6g}".format(X,Y,S))
     81        for XYS in zip(x,histblk['Data'][1],s):
     82            line = ''
     83            for val in XYS:
     84                line += G2py3.FormatPadValue(val,(15,6))
     85            self.Write(line)
     86        self.CloseFile()
     87       
    6488    def Exporter(self,event=None):
    6589        '''Export one or more sets of powder data as FXYE file(s)
     
    6791        # the export process starts here
    6892        self.InitExport(event)
    69         # load all of the tree into a set of dicts
    70         self.loadTree()
     93        self.loadTree() # load all of the tree into a set of dicts
    7194        if self.ExportSelect( # set export parameters
    7295            AskFile='single' # get a file name/directory to save in
     
    82105                # use the supplied name, but force the extension
    83106                self.filename= os.path.splitext(self.filename)[0] + self.extension
    84                
    85             histblk = self.Histograms[hist]
    86             prmname = self.WriteInstFile(hist,histblk['Instrument Parameters'][0])
    87            
    88             self.OpenFile()
    89             self.Write(hist[5:])
    90             self.Write('Instrument parameter file:'+os.path.split(prmname)[1])
    91             x = 100*np.array(histblk['Data'][0])
    92             # convert weights to sigmas; use largest weight as minimum esd
    93             s = np.sqrt(np.maximum(0.,np.array(histblk['Data'][2])))
    94             s[s==0] = np.max(s)
    95             s = 1./s
    96             self.Write('BANK 1 %d %d CONS %.2f %.2f 0 0 FXYE' % (
    97                 len(x),len(x),x[0],(x[1]-x[0])
    98                 ))
    99 #            for X,Y,S in zip(x,histblk['Data'][1],s):
    100 #                self.Write("{:15.6g} {:15.6g} {:15.6g}".format(X,Y,S))
    101             for XYS in zip(x,histblk['Data'][1],s):
    102                 line = ''
    103                 for val in XYS:
    104                     line += G2py3.FormatPadValue(val,(15,6))
    105                 self.Write(line)
    106             self.CloseFile()
     107
     108            prmname = self.WriteInstFile(TreeName,histblk['Instrument Parameters'][0])
     109            self.Writer(hist,prmname=prmname)
    107110            print('Histogram '+str(hist)+' written to file '+str(self.fullpath))
    108111
     
    122125        self.exporttype = ['powder']
    123126        self.multiple = True
     127       
     128    def Writer(self,TreeName,filename=None):
     129        GSASIIpath.IPyBreak()
     130
     131        self.OpenFile()
     132        histblk = self.Histograms[TreeName]
     133        self.Write('/*')    #The ugly c comment delimiter used in topas!
     134        self.Write('# '+TreeName[5:])  #evidently this by itself fails in topas
     135        self.Write('*/')
     136        x = np.array(histblk['Data'][0])
     137        # convert weights to sigmas; use largest weight as minimum esd
     138        s = np.sqrt(np.maximum(0.,np.array(histblk['Data'][2])))
     139        s[s==0] = np.max(s)
     140        s = 1./s
     141        for XYS in zip(x,histblk['Data'][1],s):
     142            line = ''
     143            for val in XYS:
     144                line += G2py3.FormatPadValue(val,(15,6))
     145            self.Write(line)
     146        self.CloseFile()
    124147
    125148    def Exporter(self,event=None):
     
    144167                self.filename= os.path.splitext(self.filename)[0] + self.extension
    145168
    146             self.OpenFile()
    147             histblk = self.Histograms[hist]
    148             self.Write('/*')    #The ugly c comment delimiter used in topas!
    149             self.Write('# '+hist[5:])  #evidently this by itself fails in topas
    150             self.Write('*/')
    151             x = np.array(histblk['Data'][0])
    152             # convert weights to sigmas; use largest weight as minimum esd
    153             s = np.sqrt(np.maximum(0.,np.array(histblk['Data'][2])))
    154             s[s==0] = np.max(s)
    155             s = 1./s
    156             for XYS in zip(x,histblk['Data'][1],s):
    157                 line = ''
    158                 for val in XYS:
    159                     line += G2py3.FormatPadValue(val,(15,6))
    160                 self.Write(line)
    161             self.CloseFile()
     169            self.Writer(hist)
    162170            print('Histogram '+str(hist)+' written to file '+str(self.fullpath))
Note: See TracChangeset for help on using the changeset viewer.