source: trunk/exports/G2export_ASCIImap.py @ 1118

Last change on this file since 1118 was 1118, checked in by toby, 9 years ago

fix map export bug

  • 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: 2013-10-21 20:25:03 +0000 (Mon, 21 Oct 2013) $
5# $Author: toby $
6# $Revision: 1118 $
7# $URL: trunk/exports/G2export_ASCIImap.py $
8# $Id: G2export_ASCIImap.py 1118 2013-10-21 20:25:03Z toby $
9########### SVN repository information ###################
10'''Code to demonstrate how export routines are created: Export a Fourier or
11Charge-flip map.
12'''
13import os.path
14import GSASIIpath
15GSASIIpath.SetVersionNumber("$Revision: 1118 $")
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            nx,ny,nz = rho.shape
62            self.Write(" {:3d} {:3d} {:3d}".format(nx,ny,nz))
63            for i in range(nx):
64                for j in range(ny):
65                    for k in range(nz):
66                        self.Write(str(rho[i,j,k]))
67            print('map from Phase '+str(phasenam)+' written to file '+str(self.filename))
68            self.CloseFile()
69            return
Note: See TracBrowser for help on using the repository browser.