source: trunk/imports/G2pwd_Panalytical.py @ 2835

Last change on this file since 2835 was 2835, checked in by vondreele, 6 years ago

add self.scriptable=False to ImportBaseClass?
set it True in various PWDR readers
when selecting points for image calibration, shift key forces selection at cursor
Status bar text changes to reflect this

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.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        self.comments.append('Date/TimeStart='+header.find(tag+'startTimeStamp').text)
80        self.comments.append('Date/TimeEnd='+header.find(tag+'endTimeStamp').text)
81        self.comments.append('xray tube='+tube.attrib['name'])
82        self.comments.append('Ka1=%s'%(wave.find(tag+'kAlpha1').text))
83        self.comments.append('Ka2=%s'%(wave.find(tag+'kAlpha2').text))
84        self.comments.append('Ka2/Ka1=%s'%(wave.find(tag+'ratioKAlpha2KAlpha1').text))
85        self.comments.append('Kb=%s'%(wave.find(tag+'kBeta').text))
86        self.comments.append('Voltage='+tube.find(tag+'tension').text)
87        self.comments.append('Current='+tube.find(tag+'current').text)
88        limits = dataPoints.find(tag+'positions')
89        startPos = float(limits.find(tag+'startPosition').text)
90        endPos= float(limits.find(tag+'endPosition').text)
91        y = np.fromstring(dataPoints.find(tag+'intensities').text,sep=' ')
92        N = y.shape[0]
93        x = np.linspace(startPos,endPos,N)
94        w = np.where(y>0,1./y,1.)
95        self.powderdata = [
96            np.array(x), # x-axis values
97            np.array(y), # powder pattern intensities
98            np.array(w), # 1/sig(intensity)^2 values (weights)
99            np.zeros(N), # calc. intensities (zero)
100            np.zeros(N), # calc. background (zero)
101            np.zeros(N), # obs-calc profiles
102            ]
103        conditions = scan.find(tag+'nonAmbientPoints')
104        if conditions:
105            kind = conditions.attrib['type']
106            if kind == 'Temperature':
107                Temperature = float(conditions.find(tag+'nonAmbientValues').text.split()[-1])
108                self.Sample['Temperature'] = Temperature
109        return True
Note: See TracBrowser for help on using the repository browser.