[1115] | 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: toby $ |
---|
| 6 | # $Revision: 1261 $ |
---|
| 7 | # $URL: trunk/exports/G2export_image.py $ |
---|
| 8 | # $Id: G2export_image.py 1261 2014-03-24 22:22:41Z toby $ |
---|
| 9 | ########### SVN repository information ################### |
---|
| 10 | ''' |
---|
[1123] | 11 | *Module G2export_image: 2D Image data export* |
---|
| 12 | ------------------------------------------------------ |
---|
| 13 | |
---|
| 14 | Demonstrates how an image is retrieved and written. Uses |
---|
| 15 | a SciPy routine to write a PNG format file. |
---|
| 16 | ''' |
---|
[1115] | 17 | import os.path |
---|
| 18 | import scipy.misc |
---|
| 19 | import GSASIIpath |
---|
| 20 | GSASIIpath.SetVersionNumber("$Revision: 1261 $") |
---|
| 21 | import GSASIIIO as G2IO |
---|
| 22 | import GSASIImath as G2mth |
---|
| 23 | |
---|
| 24 | class 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, |
---|
[1191] | 32 | formatName = 'PNG image file', |
---|
[1115] | 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() |
---|
[1261] | 45 | if self.ExportSelect(): return # select one image; ask for a file name |
---|
[1115] | 46 | # process the selected image(s) (at present only one image) |
---|
| 47 | for i in sorted(self.histnam): |
---|
[1261] | 48 | filename = os.path.join( |
---|
| 49 | self.dirname, |
---|
| 50 | os.path.splitext(self.filename)[0] + self.extension |
---|
| 51 | ) |
---|
[1115] | 52 | imgFile = self.Histograms[i].get('Data',(None,None)) |
---|
| 53 | Comments,Data,Npix,Image = G2IO.GetImageData(self.G2frame,imgFile) |
---|
[1261] | 54 | scipy.misc.imsave(filename,Image) |
---|
| 55 | print('Image '+str(imgFile)+' written to file '+str(filename)) |
---|
| 56 | |
---|