1 | #!/usr/bin/env python |
---|
2 | # -*- coding: utf-8 -*- |
---|
3 | ########### SVN repository information ################### |
---|
4 | # $Date: 2017-10-23 16:39:16 +0000 (Mon, 23 Oct 2017) $ |
---|
5 | # $Author: toby $ |
---|
6 | # $Revision: 3136 $ |
---|
7 | # $URL: trunk/exports/G2export_image.py $ |
---|
8 | # $Id: G2export_image.py 3136 2017-10-23 16:39:16Z toby $ |
---|
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 | from __future__ import division, print_function |
---|
18 | import os.path |
---|
19 | import scipy.misc |
---|
20 | import GSASIIpath |
---|
21 | GSASIIpath.SetVersionNumber("$Revision: 3136 $") |
---|
22 | import GSASIIIO as G2IO |
---|
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, |
---|
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 '+imgFile+' written to file '+filename) |
---|
56 | |
---|