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_SumG2: Python pickled image* |
---|
11 | ------------------------------------------ |
---|
12 | |
---|
13 | ''' |
---|
14 | |
---|
15 | import sys |
---|
16 | import os |
---|
17 | import cPickle |
---|
18 | import GSASIIIO as G2IO |
---|
19 | import GSASIIpath |
---|
20 | GSASIIpath.SetVersionNumber("$Revision: $") |
---|
21 | class G2_ReaderClass(G2IO.ImportImage): |
---|
22 | '''Routine to read an image that has been pickled in Python. Images |
---|
23 | in this format are created by the "Sum image data" command. At least for |
---|
24 | now, only one image is permitted per file. |
---|
25 | ''' |
---|
26 | def __init__(self): |
---|
27 | super(self.__class__,self).__init__( # fancy way to self-reference |
---|
28 | extensionlist=('.G2img',), |
---|
29 | strictExtension=True, |
---|
30 | formatName = 'Summed GSAS-II image', |
---|
31 | longFormatName = 'Pickled image from GSAS-II "Sum image data" command' |
---|
32 | ) |
---|
33 | |
---|
34 | def ContentsValidator(self, filepointer): |
---|
35 | '''test by trying to unpickle (should be quick) |
---|
36 | ''' |
---|
37 | try: |
---|
38 | Fp = open(filename,'rb') |
---|
39 | cPickle.load(Fp) |
---|
40 | except: |
---|
41 | return False |
---|
42 | return True |
---|
43 | |
---|
44 | def Reader(self,filename,filepointer, ParentFrame=None, **unused): |
---|
45 | '''Read using cPickle |
---|
46 | ''' |
---|
47 | import scipy.misc |
---|
48 | Fp = open(filename,'rb') |
---|
49 | self.Comments,self.Data,self.Npix,self.Image = cPickle.load(Fp) |
---|
50 | Fp.close() |
---|
51 | self.LoadImage(ParentFrame,filename) |
---|
52 | return True |
---|