source: trunk/exports/G2export_FIT2D.py @ 3136

Last change on this file since 3136 was 3136, checked in by vondreele, 4 years ago

make GSAS-II python 3.6 compliant & preserve python 2.7 use;changes:
do from future import division, print_function for all GSAS-II py sources
all menu items revised to be py 2.7/3.6 compliant
all wx.OPEN --> wx.FD_OPEN in file dialogs
all integer divides (typically for image pixel math) made explicit with ; ambiguous ones made floats as appropriate
all print "stuff" --> print (stuff)
all print >> pFile,'stuff' --> pFile.writeCIFtemplate('stuff')
all read file opens made explicit 'r' or 'rb'
all cPickle imports made for py2.7 or 3.6 as cPickle or _pickle; test for '2' platform.version_tuple[0] for py 2.7
define cPickleload to select load(fp) or load(fp,encoding='latin-1') for loading gpx files; provides cross compatibility between py 2.7/3.6 gpx files
make dict.keys() as explicit list(dict.keys()) as needed (NB: possible source of remaining py3.6 bugs)
make zip(a,b) as explicit list(zip(a,b)) as needed (NB: possible source of remaining py3.6 bugs)
select unichr/chr according test for '2' platform.version_tuple[0] for py 2.7 (G2pwdGUI * G2plot) for special characters
select wg.EVT_GRID_CELL_CHANGE (classic) or wg.EVT_GRID_CELL_CHANGED (phoenix) in grid Bind
maxint --> maxsize; used in random number stuff
raise Exception,"stuff" --> raise Exception("stuff")
wx 'classic' sizer.DeleteWindows?() or 'phoenix' sizer.Clear(True)
wx 'classic' SetToolTipString?(text) or 'phoenix' SetToolTip?(wx.ToolTip?(text)); define SetToolTipString?(self,text) to handle the choice in plots
status.SetFields? --> status.SetStatusText?
'classic' AddSimpleTool? or 'phoenix' self.AddTool? for plot toolbar; Bind different as well
define GetItemPydata? as it doesn't exist in wx 'phoenix'
allow python versions 2.7 & 3.6 to run GSAS-II
Bind override commented out - no logging capability (NB: remove all logging code?)
all import ContentsValidator? open filename & test if valid then close; filepointer removed from Reader
binary importers (mostly images) test for 'byte' type & convert as needed to satisfy py 3.6 str/byte rules

  • 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-10-23 16:39:16 +0000 (Mon, 23 Oct 2017) $
5# $Author: vondreele $
6# $Revision: 3136 $
7# $URL: trunk/exports/G2export_FIT2D.py $
8# $Id: G2export_FIT2D.py 3136 2017-10-23 16:39:16Z 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: 3136 $")
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 .chi 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            # multiple files: create a unique name from the histogram
66            fileroot = G2obj.MakeUniqueLabel(self.MakePWDRfilename(hist),filenamelist)
67            # create an instrument parameter file
68            self.filename = os.path.join(self.dirname,fileroot + self.extension)
69            self.Writer(hist)
70            print('Histogram '+hist+' written to file '+self.fullpath)
71
72class ExportPowderQCHI(G2IO.ExportBaseclass):
73    '''Used to create a q-binned CHI file for a powder data set
74
75    :param wx.Frame G2frame: reference to main GSAS-II frame
76    '''
77    def __init__(self,G2frame):
78        super(self.__class__,self).__init__( # fancy way to say <parentclass>.__init__
79            G2frame=G2frame,
80            formatName = 'Fit2D q-bin chi file',
81            extension='.chi',
82            longFormatName = 'Export powder data as q-bin Fit2D .chi file'
83            )
84        self.exporttype = ['powder']
85        self.multiple = True
86
87    def Writer(self,TreeName,filename=None):
88        import GSASIIlattice as G2lat
89        self.OpenFile(filename)
90        histblk = self.Histograms[TreeName]
91        inst = histblk['Instrument Parameters'][0]
92        self.Write(str(TreeName)[5:]) # drop 'PWDR '
93        self.Write("Q")
94        self.Write("Intensity")
95        self.Write("       "+str(len(histblk['Data'][0])))
96        for X,Y in zip(histblk['Data'][0],histblk['Data'][1]):
97            line = " %5.7e" % (2.*np.pi/G2lat.Pos2dsp(inst,X))
98            line += "   %5.7e" % Y
99            self.Write(line)
100        self.CloseFile()
101       
102    def Exporter(self,event=None):
103        '''Export a set of powder data as a q-bin Fit2D .chi file
104        '''
105        # the export process starts here
106        self.InitExport(event)
107        # load all of the tree into a set of dicts
108        self.loadTree()
109        if self.ExportSelect( # set export parameters
110            AskFile='single' # get a file name/directory to save in
111            ): return
112        filenamelist = []
113        for hist in self.histnam:
114            # multiple files: create a unique name from the histogram
115            fileroot = G2obj.MakeUniqueLabel(self.MakePWDRfilename(hist),filenamelist)
116            # create an instrument parameter file
117            self.filename = os.path.join(self.dirname,fileroot + self.extension)
118            self.Writer(hist)
119            print('Histogram '+hist+' written to file '+self.fullpath)
Note: See TracBrowser for help on using the repository browser.