source: trunk/imports/G2phase_GPX.py @ 4671

Last change on this file since 4671 was 4671, checked in by vondreele, 12 months ago

add refinable multiplier for a fixed background; multiplier is now normally > 0
usable for peak fitting and Rietved refinement
add the fixed background entry to all background defaults
fix bug in GetDetectorXY fo when cursor outside image - returns [0,0] not None; changes elsewhere to use this
GetTthAzmDsp? now returns explicit list not assumed tuple
put the abs in the nl.qr test for singularities in HessianLSQ
Add 'BF mult' to name list in G2obj
put a try - except TypeError? around setting plot style stuff in PlotPatterns?
Remove the setting of Pattern[0]BackFile? - this was redundant for PWDR
remove picker/pickradius from linescan plot - failed
remove the alternate fixed background definition ('_fixedVary', etc.)
clear the PhaseReaderClass?Drawing? dictionary upon import of phase from a gpx file

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