source: branch/2frame/exports/G2export_image.py @ 2930

Last change on this file since 2930 was 2819, checked in by vondreele, 8 years ago

fix printing of nonascii characters (e.g. "umlaut-o") in file names, etc. in exporters

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Author Revision URL Id
File size: 1.9 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3########### SVN repository information ###################
4# $Date: 2017-05-04 14:14:19 +0000 (Thu, 04 May 2017) $
5# $Author: vondreele $
6# $Revision: 2819 $
7# $URL: branch/2frame/exports/G2export_image.py $
8# $Id: G2export_image.py 2819 2017-05-04 14:14:19Z vondreele $
9########### SVN repository information ###################
10'''
11*Module G2export_image: 2D Image data export*
12------------------------------------------------------
13
14Demonstrates how an image is retrieved and written. Uses
15a SciPy routine to write a PNG format file.
16'''
17import os.path
18import scipy.misc
19import GSASIIpath
20GSASIIpath.SetVersionNumber("$Revision: 2819 $")
21import GSASIIIO as G2IO
22
23class ExportImagePNG(G2IO.ExportBaseclass):
24    '''Used to create a PNG file for a GSAS-II image
25
26    :param wx.Frame G2frame: reference to main GSAS-II frame
27    '''
28    def __init__(self,G2frame):
29        super(self.__class__,self).__init__( # fancy way to say <parentclass>.__init__
30            G2frame=G2frame,
31            formatName = 'PNG image file',
32            extension='.png',
33            longFormatName = 'Export image in PNG format'
34            )
35        self.exporttype = ['image']
36        #self.multiple = True
37    def Exporter(self,event=None):
38        '''Export an image
39        '''
40        # the export process starts here
41        self.InitExport(event)
42        # load all of the tree into a set of dicts
43        self.loadTree()
44        if self.ExportSelect(): return # select one image; ask for a file name
45        # process the selected image(s) (at present only one image)
46        for i in sorted(self.histnam): 
47            filename = os.path.join(
48                self.dirname,
49                os.path.splitext(self.filename)[0] + self.extension
50                )
51            imgFile = self.Histograms[i].get('Data',(None,None))
52            Comments,Data,Npix,Image = G2IO.GetImageData(self.G2frame,imgFile)
53            scipy.misc.imsave(filename,Image)
54            print('Image '+imgFile+' written to file '+filename)
55           
Note: See TracBrowser for help on using the repository browser.