source: trunk/imports/G2phase_GPX.py @ 1812

Last change on this file since 1812 was 1812, checked in by vondreele, 7 years ago

make new ranId for phases imported from gpx files
eliminate all raise Exceptions from Refine & seqRefine - now gives a ErrorMessage? popup upon e.g. user abort.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Author Revision URL Id
File size: 2.9 KB
Line 
1# -*- coding: utf-8 -*-
2########### SVN repository information ###################
3# $Date: 2015-04-27 18:22:06 +0000 (Mon, 27 Apr 2015) $
4# $Author: vondreele $
5# $Revision: 1812 $
6# $URL: trunk/imports/G2phase_GPX.py $
7# $Id: G2phase_GPX.py 1812 2015-04-27 18:22:06Z vondreele $
8########### SVN repository information ###################
9'''
10*Module G2phase_GPX: Import phase from GSAS-II project*
11--------------------------------------------------------
12
13Copies a phase from another GSAS-II project file into the
14current project.
15
16'''
17import sys
18import cPickle
19import random as ran
20import GSASIIIO as G2IO
21import GSASIIstrIO as G2stIO
22import GSASIIpath
23GSASIIpath.SetVersionNumber("$Revision: 1812 $")
24
25class PhaseReaderClass(G2IO.ImportPhase):
26    'Opens a .GPX file and pulls out a selected phase'
27    def __init__(self):
28        super(self.__class__,self).__init__( # fancy way to say ImportPhase.__init__
29            extensionlist=('.gpx',),
30            strictExtension=True,
31            formatName = 'GSAS-II gpx',
32            longFormatName = 'GSAS-II project (.gpx file) import'
33            )
34       
35    def ContentsValidator(self, filepointer):
36        "Test if the 1st section can be read as a cPickle block, if not it can't be .GPX!"
37        try: 
38            cPickle.load(filepointer)
39        except:
40            self.errors = 'This is not a valid .GPX file. Not recognized by cPickle'
41            return False
42        return True
43
44    def Reader(self,filename,filepointer, ParentFrame=None, **unused):
45        '''Read a phase from a .GPX file. Does not (yet?) support selecting and reading
46        more than one phase at a time.'''
47        try:
48            phasenames = G2stIO.GetPhaseNames(filename)
49        except:
50            self.errors = 'Reading of phase names failed'
51            return False
52        if not phasenames:
53            self.errors = 'No phases found in '+str(filename)
54            return False            # no blocks with coordinates
55        elif len(phasenames) == 1: # one block, no choices
56            selblk = 0
57        else:                       # choose from options               
58            selblk = self.PhaseSelector(
59                phasenames,
60                ParentFrame=ParentFrame,
61                title= 'Select a phase from the list below',
62                )
63            if selblk is None:
64                self.errors = 'No phase selected'
65                return False # User pressed cancel
66        try:
67            self.Phase = G2stIO.GetAllPhaseData(filename,phasenames[selblk])
68            self.Phase['Histograms'] = {}       #remove any histograms
69            self.Phase['Pawley ref'] = []       # & any Pawley refl.
70            self.Phase['ranId'] = ran.randint(0,sys.maxint)
71            return True
72        except Exception as detail:
73            self.errors = 'Error reading selected phase'
74            self.errors += '\n  '+str(detail)
75            print self.formatName+' error:',detail # for testing
76            print sys.exc_info()[0] # for testing
77            import traceback
78            print traceback.format_exc()
Note: See TracBrowser for help on using the repository browser.