[2001] | 1 | # -*- coding: utf-8 -*- |
---|
| 2 | ########### SVN repository information ################### |
---|
[2133] | 3 | # $Date: 2016-05-27 16:25:21 +0000 (Fri, 27 May 2016) $ |
---|
| 4 | # $Author: vondreele $ |
---|
| 5 | # $Revision: 2297 $ |
---|
| 6 | # $URL: trunk/imports/G2img_SumG2.py $ |
---|
| 7 | # $Id: G2img_SumG2.py 2297 2016-05-27 16:25:21Z vondreele $ |
---|
[2001] | 8 | ########### SVN repository information ################### |
---|
| 9 | ''' |
---|
[2068] | 10 | *Module G2img_SumG2: Python pickled image* |
---|
| 11 | ------------------------------------------ |
---|
[2001] | 12 | |
---|
| 13 | ''' |
---|
| 14 | |
---|
| 15 | import sys |
---|
| 16 | import os |
---|
[2065] | 17 | import cPickle |
---|
[2001] | 18 | import GSASIIIO as G2IO |
---|
| 19 | import GSASIIpath |
---|
[2133] | 20 | GSASIIpath.SetVersionNumber("$Revision: 2297 $") |
---|
[2001] | 21 | class G2_ReaderClass(G2IO.ImportImage): |
---|
[2068] | 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 | ''' |
---|
[2001] | 26 | def __init__(self): |
---|
| 27 | super(self.__class__,self).__init__( # fancy way to self-reference |
---|
| 28 | extensionlist=('.G2img',), |
---|
| 29 | strictExtension=True, |
---|
[2003] | 30 | formatName = 'Summed GSAS-II image', |
---|
[2001] | 31 | longFormatName = 'Pickled image from GSAS-II "Sum image data" command' |
---|
| 32 | ) |
---|
| 33 | |
---|
| 34 | def ContentsValidator(self, filepointer): |
---|
[2068] | 35 | '''test by trying to unpickle (should be quick) |
---|
[2001] | 36 | ''' |
---|
[2068] | 37 | try: |
---|
[2297] | 38 | cPickle.load(filepointer) |
---|
[2068] | 39 | except: |
---|
| 40 | return False |
---|
[2001] | 41 | return True |
---|
| 42 | |
---|
| 43 | def Reader(self,filename,filepointer, ParentFrame=None, **unused): |
---|
[2068] | 44 | '''Read using cPickle |
---|
[2001] | 45 | ''' |
---|
| 46 | import scipy.misc |
---|
| 47 | Fp = open(filename,'rb') |
---|
[2065] | 48 | self.Comments,self.Data,self.Npix,self.Image = cPickle.load(Fp) |
---|
[2001] | 49 | Fp.close() |
---|
[2015] | 50 | self.LoadImage(ParentFrame,filename) |
---|
[2001] | 51 | return True |
---|