source: trunk/exports/G2export_FIT2D.py @ 2152

Last change on this file since 2152 was 2152, checked in by vondreele, 7 years ago

all PWDR exporters will make file name from histogram name
allow read of multibank data
alert user to duplicate histograms (by name)
rename data will not change Bank or Azm part of histogram name
fix L&R plotting commands for TOF data

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Author Revision URL Id
File size: 2.4 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3########### SVN repository information ###################
4# $Date: 2016-02-18 19:01:27 +0000 (Thu, 18 Feb 2016) $
5# $Author: vondreele $
6# $Revision: 2152 $
7# $URL: trunk/exports/G2export_FIT2D.py $
8# $Id: G2export_FIT2D.py 2152 2016-02-18 19:01:27Z 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: 2152 $")
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 '+str(hist)+' written to file '+str(self.fullpath))
Note: See TracBrowser for help on using the repository browser.