Changeset 3223 for trunk/exports


Ignore:
Timestamp:
Jan 14, 2018 11:28:10 AM (4 years ago)
Author:
toby
Message:

fix histogram export file naming

Location:
trunk/exports
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/exports/G2export_FIT2D.py

    r3180 r3223  
    6363        filenamelist = []
    6464        for hist in self.histnam:
    65             # multiple files: create a unique name from the histogram
    66             fileroot = G2obj.MakeUniqueLabel(self.MakePWDRfilename(hist),filenamelist)
    67             # create an instrument parameter file
     65            if len(self.histnam) == 1:
     66                name = self.filename
     67            else:    # multiple files: create a unique name from the histogram
     68                name = self.MakePWDRfilename(hist)
     69            fileroot = os.path.splitext(G2obj.MakeUniqueLabel(name,filenamelist))[0]
    6870            self.filename = os.path.join(self.dirname,fileroot + self.extension)
    6971            self.Writer(hist)
     
    112114        filenamelist = []
    113115        for hist in self.histnam:
    114             # multiple files: create a unique name from the histogram
    115             fileroot = G2obj.MakeUniqueLabel(self.MakePWDRfilename(hist),filenamelist)
    116             # create an instrument parameter file
     116            if len(self.histnam) == 1:
     117                name = self.filename
     118            else:    # multiple files: create a unique name from the histogram
     119                name = self.MakePWDRfilename(hist)
     120            fileroot = os.path.splitext(G2obj.MakeUniqueLabel(name,filenamelist))[0]
    117121            self.filename = os.path.join(self.dirname,fileroot + self.extension)
    118122            self.Writer(hist)
  • trunk/exports/G2export_csv.py

    r3140 r3223  
    206206        filenamelist = []
    207207        for hist in self.histnam:
    208             # multiple files: create a unique name from the histogram
    209             fileroot = G2obj.MakeUniqueLabel(self.MakePWDRfilename(hist),filenamelist)
    210             # create an instrument parameter file
     208            if len(self.histnam) == 1:
     209                name = self.filename
     210            else:    # multiple files: create a unique name from the histogram
     211                name = self.MakePWDRfilename(hist)
     212            fileroot = os.path.splitext(G2obj.MakeUniqueLabel(name,filenamelist))[0]
     213            # create the file
    211214            self.filename = os.path.join(self.dirname,fileroot + self.extension)
    212215            self.Writer(hist)
     
    230233
    231234    def Exporter(self,event=None):
    232         '''Export a set of powder data as a csv file
     235        '''Export a set of powder data as a single csv file
    233236        '''
    234237        # the export process starts here
     
    237240        self.loadTree()
    238241        if self.ExportSelect( # set export parameters
    239             AskFile='single' # get a file name/directory to save in
     242            AskFile='ask' # only one file is ever written
    240243            ): return
    241         filenamelist = []
    242244        csvData = []
    243245        headList = ["x",]
    244246        digitList = []
    245         fileroot = G2obj.MakeUniqueLabel(self.MakePWDRfilename(self.histnam[0]),filenamelist)
    246         # create a file
    247         self.filename = os.path.join(self.dirname,fileroot + self.extension)
     247        self.filename = os.path.join(self.dirname,os.path.splitext(self.filename)[0]
     248                                     + self.extension)
    248249        for ihst,hist in enumerate(self.histnam):
    249250            histblk = self.Histograms[hist]
     
    254255            digitList += [(13,3),]
    255256            csvData.append(histblk['Data'][1])
    256             print('Histogram '+hist+' written to file '+self.fullpath)
     257            print('Histogram '+hist+' added to file...')
    257258        self.OpenFile()
    258259        WriteList(self,headList)
     
    264265            self.Write(line)
    265266        self.CloseFile()
     267        print('...file '+self.fullpath+' written')
    266268
    267269class ExportPowderReflCSV(G2IO.ExportBaseclass):
  • trunk/exports/G2export_examples.py

    r3136 r3223  
    2121'''
    2222from __future__ import division, print_function
     23import os
    2324import numpy as np
    2425import GSASIIpath
     
    2627import GSASIIIO as G2IO
    2728import GSASIIpy3 as G2py3
    28 #import GSASIIstrIO as G2stIO
     29import GSASIIobj as G2obj
    2930import GSASIImath as G2mth
    3031import GSASIIpwd as G2pwd
    31 #import GSASIIlattice as G2lat
    32 #import GSASIIspc as G2spc
    33 #import GSASIIphsGUI as G2pg
    34 #import GSASIIstrMain as G2stMn
    3532
    3633class ExportPhaseText(G2IO.ExportBaseclass):
     
    129126            )
    130127        self.exporttype = ['powder']
    131         self.multiple = False # only allow one histogram to be selected
     128        self.multiple = True # allow one or more histogram(s) to be selected
    132129
    133130    def Writer(self,TreeName,filename=None):
     
    159156        self.loadTree()
    160157        if self.ExportSelect( # set export parameters
    161             AskFile='default' # base name on the GPX file name
     158            AskFile='single' # selected one or more histograms; get file name (1 hist) or a directory (>1)
    162159            ): return
    163         hist = self.histnam[0] # there should only be one histogram, in any case take the 1st
    164         self.Writer(hist)
    165         print(hist+' written to file '+self.fullpath)
     160        filenamelist = []
     161        for hist in self.histnam:
     162            if len(self.histnam) == 1:
     163                name = self.filename
     164            else:    # multiple files: create a unique name from the histogram
     165                name = self.MakePWDRfilename(hist)
     166            fileroot = os.path.splitext(G2obj.MakeUniqueLabel(name,filenamelist))[0]
     167            self.filename = os.path.join(self.dirname,fileroot + self.extension)
     168            self.Writer(hist)
     169            print(hist+' written to file '+self.fullpath)
    166170       
    167171class ExportPowderReflText(G2IO.ExportBaseclass):
  • trunk/exports/G2export_pwdr.py

    r3136 r3223  
    6060        self.Write(('INS  1PRCF12%15.6e%15.6e%15.6e%15.6e   ')%(Inst['X'][1],Inst['Y'][1],Inst['SH/L'][1]/2.,Inst['SH/L'][1]/2.))
    6161        self.CloseFile()
    62         print('Parameters from '+hist+' written to file '+prmname)
     62        print('Parameters from '+hist+' written to '+prmname)
    6363        return prmname
    6464
     
    9898        filenamelist = []
    9999        for hist in self.histnam:
    100             # multiple files: create a unique name from the histogram
    101             fileroot = G2obj.MakeUniqueLabel(self.MakePWDRfilename(hist),filenamelist)
    102             # create an instrument parameter file
     100            if len(self.histnam) == 1:
     101                name = self.filename
     102            else:    # multiple files: create a unique name from the histogram
     103                name = self.MakePWDRfilename(hist)
     104            fileroot = os.path.splitext(G2obj.MakeUniqueLabel(name,filenamelist))[0]
    103105            self.filename = os.path.join(self.dirname,fileroot + self.extension)
    104106            histblk = self.Histograms[hist]
     107            # create an instrument parameter file
    105108            prmname = self.WriteInstFile(hist,histblk['Instrument Parameters'][0])
    106109            self.Writer(hist,prmname=prmname)
    107             print('Histogram '+hist+' written to file '+self.fullpath)
     110            print('Histogram '+hist+' written to '+self.fullpath)
    108111
    109112class ExportPowderXYE(G2IO.ExportBaseclass):
     
    152155        filenamelist = []
    153156        for hist in self.histnam:
    154             # multiple files: create a unique name from the histogram
    155             fileroot = G2obj.MakeUniqueLabel(self.MakePWDRfilename(hist),filenamelist)
    156             # create an instrument parameter file
     157            if len(self.histnam) == 1:
     158                name = self.filename
     159            else:    # multiple files: create a unique name from the histogram
     160                name = self.MakePWDRfilename(hist)
     161            fileroot = os.path.splitext(G2obj.MakeUniqueLabel(name,filenamelist))[0]
    157162            self.filename = os.path.join(self.dirname,fileroot + self.extension)
    158163            self.Writer(hist)
    159             print('Histogram '+hist+' written to file '+self.fullpath)
     164            print('Histogram '+hist+' written to '+self.fullpath)
Note: See TracChangeset for help on using the changeset viewer.