source: trunk/exports/G2export_FIT2D.py @ 3011

Last change on this file since 3011 was 2819, checked in by vondreele, 5 years ago

fix printing of nonascii characters (e.g. "umlaut-o") in file names, etc. in exporters

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Author Revision URL Id
File size: 4.4 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3########### SVN repository information ###################
4# $Date: 2017-05-04 14:14:19 +0000 (Thu, 04 May 2017) $
5# $Author: odonnell $
6# $Revision: 2819 $
7# $URL: trunk/exports/G2export_FIT2D.py $
8# $Id: G2export_FIT2D.py 2819 2017-05-04 14:14:19Z odonnell $
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: 2819 $")
21import GSASIIIO as G2IO
22import GSASIIpy3 as G2py3
23import GSASIIobj as G2obj
24import GSASIImath as G2mth
25import GSASIIpwd as G2pwd
26
27class ExportPowderCHI(G2IO.ExportBaseclass):
28    '''Used to create a CHI 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(str(TreeName)[5:]) # drop 'PWDR '
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            # multiple files: create a unique name from the histogram
68            fileroot = G2obj.MakeUniqueLabel(self.MakePWDRfilename(hist),filenamelist)
69            # create an instrument parameter file
70            self.filename = os.path.join(self.dirname,fileroot + self.extension)
71            self.Writer(hist)
72            print('Histogram '+hist+' written to file '+self.fullpath)
73
74class ExportPowderQCHI(G2IO.ExportBaseclass):
75    '''Used to create a q-binned CHI file for a powder data set
76
77    :param wx.Frame G2frame: reference to main GSAS-II frame
78    '''
79    def __init__(self,G2frame):
80        super(self.__class__,self).__init__( # fancy way to say <parentclass>.__init__
81            G2frame=G2frame,
82            formatName = 'Fit2D q-bin chi file',
83            extension='.chi',
84            longFormatName = 'Export powder data as q-bin Fit2D .chi file'
85            )
86        self.exporttype = ['powder']
87        self.multiple = True
88
89    def Writer(self,TreeName,filename=None):
90        import GSASIIlattice as G2lat
91        self.OpenFile(filename)
92        histblk = self.Histograms[TreeName]
93        inst = histblk['Instrument Parameters'][0]
94        self.Write(str(TreeName)[5:]) # drop 'PWDR '
95        self.Write("Q")
96        self.Write("Intensity")
97        self.Write("       "+str(len(histblk['Data'][0])))
98        for X,Y in zip(histblk['Data'][0],histblk['Data'][1]):
99            line = " %5.7e" % (2.*np.pi/G2lat.Pos2dsp(inst,X))
100            line += "   %5.7e" % Y
101            self.Write(line)
102        self.CloseFile()
103       
104    def Exporter(self,event=None):
105        '''Export a set of powder data as a q-bin Fit2D .chi file
106        '''
107        # the export process starts here
108        self.InitExport(event)
109        # load all of the tree into a set of dicts
110        self.loadTree()
111        if self.ExportSelect( # set export parameters
112            AskFile='single' # get a file name/directory to save in
113            ): return
114        filenamelist = []
115        for hist in self.histnam:
116            # multiple files: create a unique name from the histogram
117            fileroot = G2obj.MakeUniqueLabel(self.MakePWDRfilename(hist),filenamelist)
118            # create an instrument parameter file
119            self.filename = os.path.join(self.dirname,fileroot + self.extension)
120            self.Writer(hist)
121            print('Histogram '+hist+' written to file '+self.fullpath)
Note: See TracBrowser for help on using the repository browser.