source: branch/2frame/imports/G2phase_GPX.py @ 2978

Last change on this file since 2978 was 2978, checked in by vondreele, 5 years ago

fix plot clipping problem
fix a OnFileClose? problem
fix a import phase from gpx file problem

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Author Revision URL Id
File size: 2.7 KB
Line 
1# -*- coding: utf-8 -*-
2########### SVN repository information ###################
3# $Date: 2017-08-09 17:04:24 +0000 (Wed, 09 Aug 2017) $
4# $Author: vondreele $
5# $Revision: 2978 $
6# $URL: branch/2frame/imports/G2phase_GPX.py $
7# $Id: G2phase_GPX.py 2978 2017-08-09 17:04:24Z 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 GSASIIobj as G2obj
21import GSASIIIO as G2IO
22import GSASIIstrIO as G2stIO
23import GSASIIpath
24GSASIIpath.SetVersionNumber("$Revision: 2978 $")
25
26class PhaseReaderClass(G2obj.ImportPhase):
27    'Opens a .GPX file and pulls out a selected phase'
28    def __init__(self):
29        super(self.__class__,self).__init__( # fancy way to say ImportPhase.__init__
30            extensionlist=('.gpx',),
31            strictExtension=True,
32            formatName = 'GSAS-II gpx',
33            longFormatName = 'GSAS-II project (.gpx file) import'
34            )
35       
36    def ContentsValidator(self, filepointer):
37        "Test if the 1st section can be read as a cPickle block, if not it can't be .GPX!"
38        try: 
39            cPickle.load(filepointer)
40        except:
41            self.errors = 'This is not a valid .GPX file. Not recognized by cPickle'
42            return False
43        return True
44
45    def Reader(self,filename,filepointer, ParentFrame=None, **unused):
46        '''Read a phase from a .GPX file. Does not (yet?) support selecting and reading
47        more than one phase at a time.'''
48        try:
49            phasenames = G2stIO.GetPhaseNames(filename)
50        except:
51            self.errors = 'Reading of phase names failed'
52            return False
53        if not phasenames:
54            self.errors = 'No phases found in '+str(filename)
55            return False            # no blocks with coordinates
56        elif len(phasenames) == 1: # one block, no choices
57            selblk = 0
58        else:                       # choose from options               
59            selblk = G2IO.PhaseSelector(phasenames,ParentFrame=ParentFrame,
60                title= 'Select a phase from the list below',)
61            if selblk is None:
62                self.errors = 'No phase selected'
63                return False # User pressed cancel
64        self.Phase = G2stIO.GetAllPhaseData(filename,phasenames[selblk])
65        self.Phase['Histograms'] = {}       #remove any histograms
66        self.Phase['Pawley ref'] = []       # & any Pawley refl.
67        self.Phase['RBModels'] = {}
68        del self.Phase['MCSA']
69        if 'Map Peaks' in self.Phase:
70            del self.Phase['Map Peaks']
71        del self.Phase['General']['Map']
72        self.Phase['ranId'] = ran.randint(0,sys.maxint)
73        return True
Note: See TracBrowser for help on using the repository browser.