source: trunk/exports/G2export_FIT2D.py @ 1997

Last change on this file since 1997 was 1997, checked in by toby, 7 years ago

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

  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3########### SVN repository information ###################
4# $Date: 2015-05-05 09:22:56 -0500 (Tue, 05 May 2015) $
5# $Author: vondreele $
6# $Revision: 1836 $
7# $URL: https://subversion.xray.aps.anl.gov/pyGSAS/trunk/exports/G2export_csv.py $
8# $Id: G2export_csv.py 1836 2015-05-05 14:22:56Z vondreele $
9########### SVN repository information ###################
10'''
11*Module G2export_FIT2D: Fit2D "Chi" export*
12-------------------------------------------
13
14Code to create .chi (Fit2D like) files for GSAS-II powder data export
15
16'''
17import os.path
18import numpy as np
19import GSASIIpath
20GSASIIpath.SetVersionNumber("$Revision: 1836 $")
21import GSASIIIO as G2IO
22import GSASIIpy3 as G2py3
23import GSASIIobj as G2obj
24import GSASIImath as G2mth
25import GSASIIpwd as G2pwd
26
27class ExportPowderCSV(G2IO.ExportBaseclass):
28    '''Used to create a csv file for a powder data set
29
30    :param wx.Frame G2frame: reference to main GSAS-II frame
31    '''
32    def __init__(self,G2frame):
33        super(self.__class__,self).__init__( # fancy way to say <parentclass>.__init__
34            G2frame=G2frame,
35            formatName = 'Fit2D chi file',
36            extension='.chi',
37            longFormatName = 'Export powder data as Fit2D .chi file'
38            )
39        self.exporttype = ['powder']
40        self.multiple = True
41
42    def Writer(self,TreeName,filename=None):
43        self.OpenFile(filename)
44        histblk = self.Histograms[TreeName]
45        self.Write(os.path.split(self.fullpath)[1])
46        self.Write("2-Theta Angle (Degrees)")
47        self.Write("Intensity")
48        self.Write("       "+str(len(histblk['Data'][0])))
49        for X,Y in zip(histblk['Data'][0],histblk['Data'][1]):
50            line = " %5.7e" % X
51            line += "   %5.7e" % Y
52            self.Write(line)
53        self.CloseFile()
54       
55    def Exporter(self,event=None):
56        '''Export a set of powder data as a Fit2D .chi file
57        '''
58        # the export process starts here
59        self.InitExport(event)
60        # load all of the tree into a set of dicts
61        self.loadTree()
62        if self.ExportSelect( # set export parameters
63            AskFile='single' # get a file name/directory to save in
64            ): return
65        filenamelist = []
66        for hist in self.histnam:
67            self.Writer(hist)
68            print('Histogram '+str(hist)+' written to file '+str(self.fullpath))
Note: See TracBrowser for help on using the repository browser.