1 | # -*- coding: utf-8 -*- |
---|
2 | ########### SVN repository information ################### |
---|
3 | # $Date: 2017-10-23 16:39:16 +0000 (Mon, 23 Oct 2017) $ |
---|
4 | # $Author: vondreele $ |
---|
5 | # $Revision: 3136 $ |
---|
6 | # $URL: trunk/imports/G2img_SumG2.py $ |
---|
7 | # $Id: G2img_SumG2.py 3136 2017-10-23 16:39:16Z vondreele $ |
---|
8 | ########### SVN repository information ################### |
---|
9 | ''' |
---|
10 | *Module G2img_SumG2: Python pickled image* |
---|
11 | ------------------------------------------ |
---|
12 | |
---|
13 | ''' |
---|
14 | |
---|
15 | from __future__ import division, print_function |
---|
16 | import platform |
---|
17 | if '2' in platform.python_version_tuple()[0]: |
---|
18 | import cPickle |
---|
19 | else: |
---|
20 | import pickle as cPickle |
---|
21 | import GSASIIobj as G2obj |
---|
22 | import GSASIIpath |
---|
23 | GSASIIpath.SetVersionNumber("$Revision: 3136 $") |
---|
24 | class G2_ReaderClass(G2obj.ImportImage): |
---|
25 | '''Routine to read an image that has been pickled in Python. Images |
---|
26 | in this format are created by the "Sum image data" command. At least for |
---|
27 | now, only one image is permitted per file. |
---|
28 | ''' |
---|
29 | def __init__(self): |
---|
30 | super(self.__class__,self).__init__( # fancy way to self-reference |
---|
31 | extensionlist=('.G2img',), |
---|
32 | strictExtension=True, |
---|
33 | formatName = 'GSAS-II image', |
---|
34 | longFormatName = 'cPickled image from GSAS-II' |
---|
35 | ) |
---|
36 | |
---|
37 | def ContentsValidator(self, filename): |
---|
38 | '''test by trying to unpickle (should be quick) |
---|
39 | ''' |
---|
40 | try: |
---|
41 | fp = open(filename,'rb') |
---|
42 | cPickle.load(fp) |
---|
43 | fp.close() |
---|
44 | except: |
---|
45 | return False |
---|
46 | return True |
---|
47 | |
---|
48 | def Reader(self,filename, ParentFrame=None, **unused): |
---|
49 | '''Read using cPickle |
---|
50 | ''' |
---|
51 | Fp = open(filename,'rb') |
---|
52 | self.Comments,self.Data,self.Npix,self.Image = cPickle.load(Fp) |
---|
53 | Fp.close() |
---|
54 | self.LoadImage(ParentFrame,filename) |
---|
55 | return True |
---|