1 | # -*- coding: utf-8 -*- |
---|
2 | ########### SVN repository information ################### |
---|
3 | # $Date: 2023-05-11 23:08:12 +0000 (Thu, 11 May 2023) $ |
---|
4 | # $Author: toby $ |
---|
5 | # $Revision: 5577 $ |
---|
6 | # $URL: trunk/imports/G2img_SumG2.py $ |
---|
7 | # $Id: G2img_SumG2.py 5577 2023-05-11 23:08:12Z toby $ |
---|
8 | ########### SVN repository information ################### |
---|
9 | ''' |
---|
10 | ''' |
---|
11 | |
---|
12 | from __future__ import division, print_function |
---|
13 | import platform |
---|
14 | if '2' in platform.python_version_tuple()[0]: |
---|
15 | import cPickle |
---|
16 | else: |
---|
17 | import pickle as cPickle |
---|
18 | import GSASIIobj as G2obj |
---|
19 | import GSASIIpath |
---|
20 | GSASIIpath.SetVersionNumber("$Revision: 5577 $") |
---|
21 | class G2_ReaderClass(G2obj.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 = 'GSAS-II image', |
---|
31 | longFormatName = 'cPickled image from GSAS-II' |
---|
32 | ) |
---|
33 | |
---|
34 | def ContentsValidator(self, filename): |
---|
35 | '''test by trying to unpickle (should be quick) |
---|
36 | ''' |
---|
37 | try: |
---|
38 | fp = open(filename,'rb') |
---|
39 | cPickle.load(fp) |
---|
40 | fp.close() |
---|
41 | except: |
---|
42 | return False |
---|
43 | return True |
---|
44 | |
---|
45 | def Reader(self,filename, ParentFrame=None, **unused): |
---|
46 | '''Read using cPickle |
---|
47 | ''' |
---|
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 |
---|