Changeset 3825 for trunk/exports/G2export_csv.py
- Timestamp:
- Feb 15, 2019 10:43:35 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/exports/G2export_csv.py
r3738 r3825 354 354 print(hist+' reflections written to file '+self.fullpath) 355 355 356 class ExportSASDCSV(G2IO.ExportBaseclass): 357 '''Used to create a csv file for a small angle data set 358 359 :param wx.Frame G2frame: reference to main GSAS-II frame 360 ''' 361 def __init__(self,G2frame): 362 super(self.__class__,self).__init__( # fancy way to say <parentclass>.__init__ 363 G2frame=G2frame, 364 formatName = 'CSV file', 365 extension='.csv', 366 longFormatName = 'Export small angle data as comma-separated (csv) file' 367 ) 368 self.exporttype = ['sasd'] 369 #self.multiple = False # only allow one histogram to be selected 370 self.multiple = True 371 372 def Writer(self,TreeName,filename=None): 373 self.OpenFile(filename) 374 histblk = self.Histograms[TreeName] 375 if len(self.Histograms[TreeName]['Models']['Size']['Distribution']): 376 self.Write('"Size Distribution"') 377 Distr = np.array(self.Histograms[TreeName]['Models']['Size']['Distribution']) 378 WriteList(self,("bin_pos","bin_width","bin_value")) 379 digitList = 2*((13,3),)+((13,4,'g'),) 380 for bindata in Distr.T: 381 line = "" 382 for val,digits in zip(bindata,digitList): 383 if line: line += ',' 384 line += G2py3.FormatValue(val,digits) 385 self.Write(line) 386 self.Write('"Small angle data"') 387 Parms = self.Histograms[TreeName]['Instrument Parameters'][0] 388 for parm in Parms: 389 if parm in ['Type','Source',]: 390 line = '"Instparm: %s","%s"'%(parm,Parms[parm][0]) 391 elif parm in ['Lam',]: 392 line = '"Instparm: %s",%10.6f'%(parm,Parms[parm][1]) 393 else: 394 line = '"Instparm: %s",%10.2f'%(parm,Parms[parm][1]) 395 self.Write(line) 396 WriteList(self,("q","y_obs","y_sig","y_calc","y_bkg")) 397 digitList = 5*((13,5,'g'),) 398 for vallist in zip(histblk['Data'][0], 399 histblk['Data'][1], 400 1./np.sqrt(histblk['Data'][2]), 401 histblk['Data'][3], 402 histblk['Data'][4], 403 ): 404 line = "" 405 for val,digits in zip(vallist,digitList): 406 if line: line += ',' 407 line += G2py3.FormatValue(val,digits) 408 self.Write(line) 409 self.CloseFile() 410 411 def Exporter(self,event=None): 412 '''Export a set of small angle data as a csv file 413 ''' 414 # the export process starts here 415 self.InitExport(event) 416 # load all of the tree into a set of dicts 417 self.loadTree() 418 if self.ExportSelect( # set export parameters 419 AskFile='single' # get a file name/directory to save in 420 ): return 421 filenamelist = [] 422 for hist in self.histnam: 423 if len(self.histnam) == 1: 424 name = self.filename 425 else: # multiple files: create a unique name from the histogram 426 name = self.MakePWDRfilename(hist) 427 fileroot = os.path.splitext(G2obj.MakeUniqueLabel(name,filenamelist))[0] 428 # create the file 429 self.filename = os.path.join(self.dirname,fileroot + self.extension) 430 self.Writer(hist) 431 print('Histogram '+hist+' written to file '+self.fullpath) 432 356 433 class ExportSingleCSV(G2IO.ExportBaseclass): 357 434 '''Used to create a csv file with single crystal reflection data
Note: See TracChangeset
for help on using the changeset viewer.