1 | # -*- coding: utf-8 -*- |
---|
2 | ########### SVN repository information ################### |
---|
3 | # $Date: 2012-02-13 11:33:35 -0600 (Mon, 13 Feb 2012) $ |
---|
4 | # $Author: vondreele & toby $ |
---|
5 | # $Revision: 482 $ |
---|
6 | # $URL: https://subversion.xor.aps.anl.gov/pyGSAS/trunk/G2importphase_GPX.py $ |
---|
7 | # $Id: G2importphase_GPX.py 482 2012-02-13 17:33:35Z vondreele $ |
---|
8 | ########### SVN repository information ################### |
---|
9 | # Routines to import Phase information from GSAS-II .gpx files |
---|
10 | import cPickle |
---|
11 | import GSASIIIO as G2IO |
---|
12 | import GSASIIstrIO as G2stIO |
---|
13 | |
---|
14 | class PhaseReaderClass(G2IO.ImportPhase): |
---|
15 | def __init__(self): |
---|
16 | super(self.__class__,self).__init__( # fancy way to say ImportPhase.__init__ |
---|
17 | extensionlist=('.gpx',), |
---|
18 | strictExtension=True, |
---|
19 | formatName = 'GSAS-II gpx', |
---|
20 | longFormatName = 'GSAS-II project (.gpx file) import' |
---|
21 | ) |
---|
22 | def ContentsValidator(self, filepointer): |
---|
23 | # if the 1st section can't be read as a cPickle file, it can't be! |
---|
24 | try: |
---|
25 | cPickle.load(filepointer) |
---|
26 | except: |
---|
27 | return False |
---|
28 | return True |
---|
29 | def Reader(self,filename,filepointer, ParentFrame=None, **unused): |
---|
30 | try: |
---|
31 | phasenames = G2stIO.GetPhaseNames(filename) |
---|
32 | except: |
---|
33 | return False |
---|
34 | if not phasenames: |
---|
35 | return False # no blocks with coordinates |
---|
36 | elif len(phasenames) == 1: # no choices |
---|
37 | selblk = 0 |
---|
38 | else: # choose from options |
---|
39 | selblk = self.PhaseSelector( |
---|
40 | phasenames, |
---|
41 | ParentFrame=ParentFrame, |
---|
42 | title= 'Select a phase from the list below', |
---|
43 | ) |
---|
44 | if selblk is None: return False # User pressed cancel |
---|
45 | try: |
---|
46 | self.Phase = G2stIO.GetAllPhaseData(filename,phasenames[selblk]) |
---|
47 | self.Phase['Histograms'] = {} #remove any histograms |
---|
48 | self.Phase['Pawley ref'] = [] # & any Pawley refl. |
---|
49 | return True |
---|
50 | except Exception as detail: |
---|
51 | import sys |
---|
52 | print self.formatName+' error:',detail # for testing |
---|
53 | print sys.exc_info()[0] # for testing |
---|
54 | import traceback |
---|
55 | print traceback.format_exc() |
---|