source: trunk/imports/G2pwd_Panalytical.py @ 3681

Last change on this file since 3681 was 3681, checked in by vondreele, 4 years ago

change Panalytical importer to read multi xrdMeasurement blocks - can each have multiple scans; all recorded as separate PWDR histograms.
Begin implementation of access to Bilbao SUBGROUPS routine
some work on incommensurate magnetic structure stuff
Add new option for PWDR contour plots to show temperature on y-axis

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