source: trunk/imports/G2img_CheMin.py @ 2015

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

redo image read to avoid reloads; prevent open of Edit image parms on reread; fix multilevel TIF read error; cleanup self in GSASIIimage

  • Property svn:eol-style set to native
File size: 1.8 KB
Line 
1# -*- coding: utf-8 -*-
2########### SVN repository information ###################
3# $Date: 2014-12-27 11:14:59 -0600 (Sat, 27 Dec 2014) $
4# $Author: $
5# $Revision: $
6# $URL: $
7# $Id: $
8########### SVN repository information ###################
9'''
10*Module G2img_png: png image file*
11---------------------------------------
12
13Routine to read an image in .png (Portable Network Graphics) format.
14For now, the only known use of this is with converted CheMin tif files
15so default parameters are that machine.
16
17'''
18
19import sys
20import os
21import GSASIIIO as G2IO
22import GSASIIpath
23GSASIIpath.SetVersionNumber("$Revision: $")
24class png_ReaderClass(G2IO.ImportImage):
25    def __init__(self):
26        super(self.__class__,self).__init__( # fancy way to self-reference
27            extensionlist=('.png',),
28            strictExtension=True,
29            formatName = 'PNG image',
30            longFormatName = 'PNG image from CheMin'
31            )
32
33    def ContentsValidator(self, filepointer):
34        '''no test at this time
35        '''
36        return True
37       
38    def Reader(self,filename,filepointer, ParentFrame=None, **unused):
39        '''Read using scipy PNG reader
40        '''
41        import scipy.misc
42        self.Image = scipy.misc.imread(filename,flatten=True)
43        self.Npix = self.Image.size
44        if self.Npix == 0:
45            return False
46        if ParentFrame:
47            self.Comments = ['no metadata']
48            pixy = list(self.Image.shape)
49            sizexy = [40,40]
50            self.Data = {'wavelength': 1.78892, 'pixelSize': sizexy, 'distance': 18.0,'size':pixy}
51            self.Data['center'] = [pixy[0]*sizexy[0]/1000,pixy[1]*sizexy[1]/2000]
52            G2IO.EditImageParms(ParentFrame,self.Data,self.Comments,self.Image,filename)
53        self.LoadImage(ParentFrame,filename)
54        return True
55# N.B. This replaces G2IO.GetPNGData
Note: See TracBrowser for help on using the repository browser.