source: trunk/exports/G2export_image.py @ 2567

Last change on this file since 2567 was 1261, checked in by toby, 8 years ago

reorg exports to implement directory selection

  • 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: 2014-03-24 22:22:41 +0000 (Mon, 24 Mar 2014) $
5# $Author: vondreele $
6# $Revision: 1261 $
7# $URL: trunk/exports/G2export_image.py $
8# $Id: G2export_image.py 1261 2014-03-24 22:22:41Z 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: 1261 $")
21import GSASIIIO as G2IO
22import GSASIImath as G2mth
23
24class ExportImagePNG(G2IO.ExportBaseclass):
25    '''Used to create a PNG file for a GSAS-II image
26
27    :param wx.Frame G2frame: reference to main GSAS-II frame
28    '''
29    def __init__(self,G2frame):
30        super(self.__class__,self).__init__( # fancy way to say <parentclass>.__init__
31            G2frame=G2frame,
32            formatName = 'PNG image file',
33            extension='.png',
34            longFormatName = 'Export image in PNG format'
35            )
36        self.exporttype = ['image']
37        #self.multiple = True
38    def Exporter(self,event=None):
39        '''Export an image
40        '''
41        # the export process starts here
42        self.InitExport(event)
43        # load all of the tree into a set of dicts
44        self.loadTree()
45        if self.ExportSelect(): return # select one image; ask for a file name
46        # process the selected image(s) (at present only one image)
47        for i in sorted(self.histnam): 
48            filename = os.path.join(
49                self.dirname,
50                os.path.splitext(self.filename)[0] + self.extension
51                )
52            imgFile = self.Histograms[i].get('Data',(None,None))
53            Comments,Data,Npix,Image = G2IO.GetImageData(self.G2frame,imgFile)
54            scipy.misc.imsave(filename,Image)
55            print('Image '+str(imgFile)+' written to file '+str(filename))
56           
Note: See TracBrowser for help on using the repository browser.