1 | # -*- coding: utf-8 -*- |
---|
2 | ########### SVN repository information ################### |
---|
3 | # $Date: 2017-10-23 16:39:16 +0000 (Mon, 23 Oct 2017) $ |
---|
4 | # $Author: toby $ |
---|
5 | # $Revision: 3136 $ |
---|
6 | # $URL: trunk/imports/G2img_CheMin.py $ |
---|
7 | # $Id: G2img_CheMin.py 3136 2017-10-23 16:39:16Z toby $ |
---|
8 | ########### SVN repository information ################### |
---|
9 | ''' |
---|
10 | *Module G2img_png: png image file* |
---|
11 | --------------------------------------- |
---|
12 | |
---|
13 | Routine to read an image in .png (Portable Network Graphics) format. |
---|
14 | For now, the only known use of this is with converted Mars Rover (CheMin) |
---|
15 | tif files, so default parameters are for that. |
---|
16 | |
---|
17 | ''' |
---|
18 | |
---|
19 | from __future__ import division, print_function |
---|
20 | import GSASIIobj as G2obj |
---|
21 | import GSASIIpath |
---|
22 | GSASIIpath.SetVersionNumber("$Revision: 3136 $") |
---|
23 | class png_ReaderClass(G2obj.ImportImage): |
---|
24 | '''Reads standard PNG images; parameters are set to those of the |
---|
25 | Mars Rover (CheMin) diffractometer. |
---|
26 | ''' |
---|
27 | def __init__(self): |
---|
28 | super(self.__class__,self).__init__( # fancy way to self-reference |
---|
29 | extensionlist=('.png',), |
---|
30 | strictExtension=True, |
---|
31 | formatName = 'PNG image', |
---|
32 | longFormatName = 'PNG image from CheMin' |
---|
33 | ) |
---|
34 | |
---|
35 | def ContentsValidator(self, filename): |
---|
36 | '''no test at this time |
---|
37 | ''' |
---|
38 | return True |
---|
39 | |
---|
40 | def Reader(self,filename, ParentFrame=None, **unused): |
---|
41 | '''Reads using standard scipy PNG reader |
---|
42 | ''' |
---|
43 | import scipy.misc |
---|
44 | self.Image = scipy.misc.imread(filename,flatten=True) |
---|
45 | self.Npix = self.Image.size |
---|
46 | if self.Npix == 0: |
---|
47 | return False |
---|
48 | if ParentFrame: |
---|
49 | self.SciPy = True |
---|
50 | self.Comments = ['no metadata'] |
---|
51 | pixy = list(self.Image.shape) |
---|
52 | sizexy = [40.,40.] |
---|
53 | self.Data = {'wavelength': 1.78892, 'pixelSize': sizexy, 'distance': 18.0,'size':pixy} |
---|
54 | self.Data['center'] = [pixy[0]*sizexy[0]/1000.,pixy[1]*sizexy[1]/2000.] |
---|
55 | self.LoadImage(ParentFrame,filename) |
---|
56 | return True |
---|