source: trunk/exports/G2export_FIT2D.py

Last change on this file was 3670, checked in by toby, 4 years ago

read in qchi files

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Author Revision URL Id
File size: 4.7 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3########### SVN repository information ###################
4# $Date: 2018-10-11 16:52:33 +0000 (Thu, 11 Oct 2018) $
5# $Author: vondreele $
6# $Revision: 3670 $
7# $URL: trunk/exports/G2export_FIT2D.py $
8# $Id: G2export_FIT2D.py 3670 2018-10-11 16:52:33Z 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'''
17from __future__ import division, print_function
18import os.path
19import numpy as np
20import GSASIIpath
21GSASIIpath.SetVersionNumber("$Revision: 3670 $")
22import GSASIIIO as G2IO
23import GSASIIobj as G2obj
24
25class ExportPowderCHI(G2IO.ExportBaseclass):
26    '''Used to create a CHI file for a powder data set
27
28    :param wx.Frame G2frame: reference to main GSAS-II frame
29    '''
30    def __init__(self,G2frame):
31        super(self.__class__,self).__init__( # fancy way to say <parentclass>.__init__
32            G2frame=G2frame,
33            formatName = 'Fit2D chi file',
34            extension='.chi',
35            longFormatName = 'Export powder data as Fit2D .chi file'
36            )
37        self.exporttype = ['powder']
38        self.multiple = True
39
40    def Writer(self,TreeName,filename=None):
41        self.OpenFile(filename)
42        histblk = self.Histograms[TreeName]
43        self.Write(str(TreeName)[5:]) # drop 'PWDR '
44        self.Write("2-Theta Angle (Degrees)")
45        self.Write("Intensity")
46        self.Write("       "+str(len(histblk['Data'][0])))
47        for X,Y in zip(histblk['Data'][0],histblk['Data'][1]):
48            line = " %5.7e" % X
49            line += "   %5.7e" % Y
50            self.Write(line)
51        self.CloseFile()
52       
53    def Exporter(self,event=None):
54        '''Export a set of powder data as a Fit2D .qchi file
55        '''
56        # the export process starts here
57        self.InitExport(event)
58        # load all of the tree into a set of dicts
59        self.loadTree()
60        if self.ExportSelect( # set export parameters
61            AskFile='single' # get a file name/directory to save in
62            ): return
63        filenamelist = []
64        for hist in self.histnam:
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]
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='.qchi',
84            longFormatName = 'Export powder data as q-bin Fit2D .qchi 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        if 'Lam1' in inst: 
96            print('Do you really want to write a multi-wavelength pattern in Q?')
97            lam = 0.
98        else:
99            lam = inst['Lam'][1]
100        self.Write("Q{:>20.6f}".format(lam))
101        self.Write("Intensity")
102        self.Write("       "+str(len(histblk['Data'][0])))
103        for X,Y in zip(histblk['Data'][0],histblk['Data'][1]):
104            line = " %5.7e" % (2.*np.pi/G2lat.Pos2dsp(inst,X))
105            line += "   %5.7e" % Y
106            self.Write(line)
107        self.CloseFile()
108       
109    def Exporter(self,event=None):
110        '''Export a set of powder data as a q-bin Fit2D .qchi file
111        '''
112        # the export process starts here
113        self.InitExport(event)
114        # load all of the tree into a set of dicts
115        self.loadTree()
116        if self.ExportSelect( # set export parameters
117            AskFile='single' # get a file name/directory to save in
118            ): return
119        filenamelist = []
120        for hist in self.histnam:
121            if len(self.histnam) == 1:
122                name = self.filename
123            else:    # multiple files: create a unique name from the histogram
124                name = self.MakePWDRfilename(hist)
125            fileroot = os.path.splitext(G2obj.MakeUniqueLabel(name,filenamelist))[0]
126            self.filename = os.path.join(self.dirname,fileroot + self.extension)
127            self.Writer(hist)
128            print('Histogram '+hist+' written to file '+self.fullpath)
Note: See TracBrowser for help on using the repository browser.