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 | |
---|
14 | Demonstrates how an image is retrieved and written. Uses |
---|
15 | a SciPy routine to write a PNG format file. |
---|
16 | ''' |
---|
17 | import os.path |
---|
18 | import scipy.misc |
---|
19 | import GSASIIpath |
---|
20 | GSASIIpath.SetVersionNumber("$Revision: 2819 $") |
---|
21 | import GSASIIIO as G2IO |
---|
22 | |
---|
23 | class 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 | |
---|