source: trunk/exports/G2export_ASCIImap.py @ 1117

Last change on this file since 1117 was 1117, checked in by toby, 12 years ago

update some menu labels; Add new multi-item selector; Add map export; misc export cleanups

  • Property svn:eol-style set to native
File size: 2.9 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3########### SVN repository information ###################
4# $Date: 2013-10-12 22:47:06 -0500 (Sat, 12 Oct 2013) $
5# $Author: toby $
6# $Revision: 1102 $
7# $URL: https://subversion.xor.aps.anl.gov/pyGSAS/trunk/exports/G2export_examples.py $
8# $Id: G2export_examples.py 1102 2013-10-13 03:47:06Z toby $
9########### SVN repository information ###################
10'''Code to demonstrate how export routines are created: Export a Fourier or
11Charge-flip map. Note: I am not sure this is working properly, yet.
12'''
13import os.path
14import GSASIIpath
15GSASIIpath.SetVersionNumber("$Revision: 1102 $")
16import GSASIIIO as G2IO
17#import GSASIIgrid as G2gd
18#import GSASIIstrIO as G2stIO
19#import GSASIImath as G2mth
20#import GSASIIlattice as G2lat
21#import GSASIIspc as G2spc
22#import GSASIIphsGUI as G2pg
23#import GSASIIstrMain as G2stMn
24
25class ExportMapASCII(G2IO.ExportBaseclass):
26    '''Used to create a text file for a phase
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 = 'FOX/DrawXTL file',
34            extension='.grd',
35            longFormatName = 'Export map as text (.grd) file'
36            )
37        self.exporttype = ['map']
38        self.multiple = False 
39
40    def Exporter(self,event=None):
41        '''Export a map as a text file
42        '''
43        # the export process starts here
44        self.InitExport(event)
45        # load all of the tree into a set of dicts
46        self.loadTree()
47        if self.ExportSelect( # set export parameters
48            AskFile=True     # prompt the user for a file name
49            ): return 
50        for phasenam in self.phasenam:
51            phasedict = self.Phases[phasenam] # pointer to current phase info           
52            rho = phasedict['General']['Map'].get('rho',[])
53            if not len(rho):
54                return
55            self.OpenFile(self.filename)
56            self.Write("Map of Phase "+str(phasenam)+" from "+str(self.G2frame.GSASprojectfile))
57            # get cell parameters & print them
58            cellList,cellSig = self.GetCell(phasenam)
59            fmt = 3*" {:9.5f}" + 3*" {:9.3f}"
60            self.Write(fmt.format(*cellList[:6]))
61            #print(fmt.format(*cellList[:6]))
62            nx,ny,nz = rho.shape
63            #print(3*" {:3d}".format(nx,ny,nz))
64            self.Write(3*" {:3d}".format(nx,ny,nz))
65#            reverse order of map
66#            for i in range(nx-1,-1,-1):
67#                for j in range(ny-1,-1,-1):
68#                    for k in range(nz-1,-1,-1):
69            for i in range(nx):
70                for j in range(ny):
71                    for k in range(nz):
72                        self.Write(str(rho[i,j,k]))
73            print('map from Phase '+str(phasenam)+' written to file '+str(self.filename))
74            self.CloseFile()
75            return
Note: See TracBrowser for help on using the repository browser.