source: trunk/imports/G2pwd_Panalytical.py @ 2817

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

major revision - move all importers to GSASIIobj & make them independent of wx so they can be used in a scripting environment.
Still to move are PhaseSelector?, and 3 BlockSelector? dialogs

File size: 4.5 KB
Line 
1# -*- coding: utf-8 -*-
2########### SVN repository information ###################
3# $Date: $
4# $Author: von dreele $
5# $Revision: $
6# $URL: $
7# $Id: $
8########### SVN repository information ###################
9
10import os.path as ospath
11import xml.etree.ElementTree as ET
12import numpy as np
13import GSASIIobj as G2obj
14import GSASIIpath
15GSASIIpath.SetVersionNumber("$Revision: $")
16class Panalytical_ReaderClass(G2obj.ImportPowderData):
17    '''Routines to import powder data from a Pananalytical.xrdm (xml) file.
18   
19    '''
20    def __init__(self):
21        super(self.__class__,self).__init__( # fancy way to self-reference
22            extensionlist=('.xrdml','.xml'),
23            strictExtension=True,
24            formatName = 'Panalytical xrdml (xml)',
25            longFormatName = 'Panalytical powder data as *.xrdml'
26            )
27        self.vals = None
28        self.stepsize = None
29        self.skip = 0
30        self.root = None
31
32    # Validate the contents -- make sure we only have valid lines and set
33    # values we will need for later read.
34    def ContentsValidator(self, filepointer):
35        self.vals = None
36        self.stepsize = None
37        filepointer.seek(0)
38        try:
39            self.root = ET.parse(filepointer).getroot()
40            tag = self.root.tag
41            tag = tag.split('}')[0]+'}'
42            self.root.find(tag+'comment')
43           
44        except:
45            self.errors = 'Bad xml file'
46            return False
47        return True
48           
49    def Reader(self,filename,filepointer, ParentFrame=None, **kwarg):
50        'Read a Panalytical .xrdml (.xml) file; already in self.root'
51        blockNum = kwarg.get('blocknum',0)
52        self.idstring = ospath.basename(filename) + ' Scan '+str(blockNum)
53        x = []
54        y = []
55        w = []
56        tag = self.root.tag
57        tag = tag.split('}')[0]+'}'
58        sample = self.root.find(tag+'sample')
59        self.idstring = ospath.basename(filename) + ' Scan '+str(blockNum)
60        dataSets = self.root.findall(tag+'xrdMeasurement')
61        if blockNum-1 == len(dataSets):
62            self.repeat = False
63            return False
64        data = dataSets[blockNum-1]
65        if len(dataSets) > 1:
66            self.repeat = True
67        wave = data.find(tag+'usedWavelength')
68        incident = data.find(tag+'incidentBeamPath')
69        radius = float(incident.find(tag+'radius').text)
70        tube = incident.find(tag+'xRayTube')
71        scan = data.find(tag+'scan')
72        header = scan.find(tag+'header')
73        dataPoints = scan.find(tag+'dataPoints')
74        self.comments.append('Gonio. radius=%.2f'%(radius))
75        self.Sample['Gonio. radius'] = radius
76        if sample.find(tag+'id').text:
77            self.comments.append('Sample name='+sample.find(tag+'id').text)
78        self.comments.append('Date/TimeStart='+header.find(tag+'startTimeStamp').text)
79        self.comments.append('Date/TimeEnd='+header.find(tag+'endTimeStamp').text)
80        self.comments.append('xray tube='+tube.attrib['name'])
81        self.comments.append('Ka1=%s'%(wave.find(tag+'kAlpha1').text))
82        self.comments.append('Ka2=%s'%(wave.find(tag+'kAlpha2').text))
83        self.comments.append('Ka2/Ka1=%s'%(wave.find(tag+'ratioKAlpha2KAlpha1').text))
84        self.comments.append('Kb=%s'%(wave.find(tag+'kBeta').text))
85        self.comments.append('Voltage='+tube.find(tag+'tension').text)
86        self.comments.append('Current='+tube.find(tag+'current').text)
87        limits = dataPoints.find(tag+'positions')
88        startPos = float(limits.find(tag+'startPosition').text)
89        endPos= float(limits.find(tag+'endPosition').text)
90        y = np.fromstring(dataPoints.find(tag+'intensities').text,sep=' ')
91        N = y.shape[0]
92        x = np.linspace(startPos,endPos,N)
93        w = np.where(y>0,1./y,1.)
94        self.powderdata = [
95            np.array(x), # x-axis values
96            np.array(y), # powder pattern intensities
97            np.array(w), # 1/sig(intensity)^2 values (weights)
98            np.zeros(N), # calc. intensities (zero)
99            np.zeros(N), # calc. background (zero)
100            np.zeros(N), # obs-calc profiles
101            ]
102        conditions = scan.find(tag+'nonAmbientPoints')
103        if conditions:
104            kind = conditions.attrib['type']
105            if kind == 'Temperature':
106                Temperature = float(conditions.find(tag+'nonAmbientValues').text.split()[-1])
107                self.Sample['Temperature'] = Temperature
108        return True
Note: See TracBrowser for help on using the repository browser.