source: trunk/imports/G2pwd_Panalytical.py @ 3052

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

fix Panalytical import to read summed data

File size: 4.6 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.scriptable = True
28        self.vals = None
29        self.stepsize = None
30        self.skip = 0
31        self.root = None
32
33    # Validate the contents -- make sure we only have valid lines and set
34    # values we will need for later read.
35    def ContentsValidator(self, filepointer):
36        self.vals = None
37        self.stepsize = None
38        filepointer.seek(0)
39        try:
40            self.root = ET.parse(filepointer).getroot()
41            tag = self.root.tag
42            tag = tag.split('}')[0]+'}'
43            self.root.find(tag+'comment')
44           
45        except:
46            self.errors = 'Bad xml file'
47            return False
48        return True
49           
50    def Reader(self,filename,filepointer, ParentFrame=None, **kwarg):
51        'Read a Panalytical .xrdml (.xml) file; already in self.root'
52        blockNum = kwarg.get('blocknum',0)
53        self.idstring = ospath.basename(filename) + ' Scan '+str(blockNum)
54        x = []
55        y = []
56        w = []
57        tag = self.root.tag
58        tag = tag.split('}')[0]+'}'
59        sample = self.root.find(tag+'sample')
60        self.idstring = ospath.basename(filename) + ' Scan '+str(blockNum)
61        dataSets = self.root.findall(tag+'xrdMeasurement')
62        if blockNum-1 == len(dataSets):
63            self.repeat = False
64            return False
65        data = dataSets[blockNum-1]
66        if len(dataSets) > 1:
67            self.repeat = True
68        wave = data.find(tag+'usedWavelength')
69        incident = data.find(tag+'incidentBeamPath')
70        radius = float(incident.find(tag+'radius').text)
71        tube = incident.find(tag+'xRayTube')
72        scan = data.find(tag+'scan')
73        header = scan.find(tag+'header')
74        dataPoints = scan.find(tag+'dataPoints')
75        self.comments.append('Gonio. radius=%.2f'%(radius))
76        self.Sample['Gonio. radius'] = radius
77        if sample.find(tag+'id').text:
78            self.comments.append('Sample name='+sample.find(tag+'id').text)
79        try:
80            self.comments.append('Date/TimeStart='+header.find(tag+'startTimeStamp').text)
81            self.comments.append('Date/TimeEnd='+header.find(tag+'endTimeStamp').text)
82            self.comments.append('xray tube='+tube.attrib['name'])
83        except AttributeError:
84            pass
85        self.comments.append('Ka1=%s'%(wave.find(tag+'kAlpha1').text))
86        self.comments.append('Ka2=%s'%(wave.find(tag+'kAlpha2').text))
87        self.comments.append('Ka2/Ka1=%s'%(wave.find(tag+'ratioKAlpha2KAlpha1').text))
88        self.comments.append('Kb=%s'%(wave.find(tag+'kBeta').text))
89        self.comments.append('Voltage='+tube.find(tag+'tension').text)
90        self.comments.append('Current='+tube.find(tag+'current').text)
91        limits = dataPoints.find(tag+'positions')
92        startPos = float(limits.find(tag+'startPosition').text)
93        endPos= float(limits.find(tag+'endPosition').text)
94        y = np.fromstring(dataPoints.find(tag+'intensities').text,sep=' ')
95        N = y.shape[0]
96        x = np.linspace(startPos,endPos,N)
97        w = np.where(y>0,1./y,1.)
98        self.powderdata = [
99            np.array(x), # x-axis values
100            np.array(y), # powder pattern intensities
101            np.array(w), # 1/sig(intensity)^2 values (weights)
102            np.zeros(N), # calc. intensities (zero)
103            np.zeros(N), # calc. background (zero)
104            np.zeros(N), # obs-calc profiles
105            ]
106        conditions = scan.find(tag+'nonAmbientPoints')
107        if conditions:
108            kind = conditions.attrib['type']
109            if kind == 'Temperature':
110                Temperature = float(conditions.find(tag+'nonAmbientValues').text.split()[-1])
111                self.Sample['Temperature'] = Temperature
112        return True
Note: See TracBrowser for help on using the repository browser.