Changeset 5351
- Timestamp:
- Oct 19, 2022 10:06:15 AM (5 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/imports/G2pwd_BrukerRAW.py
r4339 r5351 16 16 17 17 from __future__ import division, print_function 18 import os 18 19 import os.path as ospath 19 20 import struct as st 20 21 import numpy as np 21 22 import GSASIIobj as G2obj 23 import GSASIIctrlGUI as G2G 22 24 import GSASIIpath 23 25 GSASIIpath.SetVersionNumber("$Revision$") … … 214 216 215 217 return True 218 219 class brml_ReaderClass(G2obj.ImportPowderData): 220 'Routines to import powder data from a zip Bruker .brml file' 221 def __init__(self): 222 super(self.__class__,self).__init__( # fancy way to self-reference 223 extensionlist=('.brml',), 224 strictExtension=False, 225 formatName = 'Bruker brml', 226 longFormatName = 'Bruker .brml powder data file' 227 ) 228 self.scriptable = True 229 self.data = None 230 231 def ContentsValidator(self, filename): 232 try: 233 import xmltodict as xml 234 except: 235 print('Attempting to conda install xmltodict - please wait') 236 res = GSASIIpath.condaInstall('xmltodict') 237 if res: 238 msg = 'Installation of the xmltodict package failed with error:\n' + str(res) 239 G2G.G2MessageBox(self,msg,'Install xmltodict Error') 240 return False 241 import zipfile as ZF 242 243 with ZF.ZipFile(filename, 'r') as zipObj: 244 zipObj.extract('Experiment0/RawData0.xml') 245 with open('Experiment0/RawData0.xml') as fd: 246 self.data = dict(xml.parse(fd.read())) 247 self.formatName = 'Bruker .brml file' 248 os.remove('Experiment0/RawData0.xml') 249 os.rmdir('Experiment0') 250 self.idstring = ospath.basename(filename) + ' Bank 1' 251 self.powderentry[0] = filename 252 self.comments = [] 253 return True 254 255 def Reader(self,filename, ParentFrame=None, **kwarg): 256 'Read a Bruker brml file' 257 print(filename) 258 nSteps = int(self.data['RawData']['DataRoutes']['DataRoute'][1]['ScanInformation']['MeasurementPoints']) 259 260 x = np.zeros(nSteps, dtype=float) 261 y = np.zeros(nSteps, dtype=float) 262 w = np.zeros(nSteps, dtype=float) 263 264 effTime = float(self.data['RawData']['DataRoutes']['DataRoute'][1]['ScanInformation']['TimePerStepEffective']) 265 266 # Extract 2-theta angle and counts from the XML document 267 i=0 268 while i < nSteps : 269 entry = self.data['RawData']['DataRoutes']['DataRoute'][1]['Datum'][i].split(',') 270 x[i] = float(entry[2]) 271 y[i] = float(entry[4])*float(entry[0])/effTime 272 i = i + 1 273 274 w = np.where(y>0,1/y,0.) 275 self.powderdata = [x,y,w,np.zeros(nSteps),np.zeros(nSteps),np.zeros(nSteps)] 276 277 278 279 return True
Note: See TracChangeset
for help on using the changeset viewer.