Changeset 4118 for trunk/imports/G2pwd_rigaku.py
- Timestamp:
- Aug 28, 2019 12:32:39 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/imports/G2pwd_rigaku.py
r3136 r4118 10 10 from __future__ import division, print_function 11 11 import os 12 import platform 12 13 import numpy as np 13 14 import GSASIIobj as G2obj 14 15 import GSASIIpath 15 16 GSASIIpath.SetVersionNumber("$Revision: $") 16 class Rigaku_ ReaderClass(G2obj.ImportPowderData):17 class Rigaku_txtReaderClass(G2obj.ImportPowderData): 17 18 '''Routines to import powder data from a Rigaku .txt file with an angle and 18 19 then 1 or 11(!) intensity values on the line. The example file is proceeded … … 135 136 self.idstring = os.path.basename(filename) 136 137 return True 138 class Rigaku_rasReaderClass(G2obj.ImportPowderData): 139 '''Routines to import powder data from a Rigaku .ras file with multiple scans. 140 All scans will be imported as individual PWDR entries 141 ''' 142 def __init__(self): 143 super(self.__class__,self).__init__( # fancy way to self-reference 144 extensionlist=('.ras','.RAS'), 145 strictExtension=True, 146 formatName = 'Rigaku .ras file', 147 longFormatName = 'Rigaku .ras raw multipattern powder data' 148 ) 149 self.scriptable = True 150 self.vals = None 151 self.stepsize = None 152 self.skip = 0 153 154 # Validate the contents -- make sure we only have valid lines and set 155 # values we will need for later read. 156 def ContentsValidator(self, filename): 157 if '2' in platform.python_version_tuple()[0]: 158 fp = open(filename,'Ur') 159 else: 160 fp = open(filename,'r',encoding='latin-1') 161 self.vals = None 162 self.stepsize = None 163 fp.seek(0) 164 if fp.readline()[:-1] != '*RAS_DATA_START': 165 self.errors = 'Bad ras file' 166 fp.close() 167 return False 168 nBanks= 0 169 for i,line in enumerate(fp): 170 if line[:-1] == '*RAS_HEADER_START': 171 nBanks += 1 172 self.dnames.append(os.path.basename(filename)+' sample '+(str(nBanks))) 173 if nBanks: 174 if not len(self.selections): 175 self.selections = range(nBanks) 176 self.numbanks = nBanks 177 fp.close() 178 return True 179 180 def Reader(self,filename, ParentFrame=None, **kwarg): 181 'Read a Rigaku .ras file' 182 if '2' in platform.python_version_tuple()[0]: 183 fp = open(filename,'Ur') 184 else: 185 fp = open(filename,'r',encoding='latin-1') 186 blockNum = self.selections[0] 187 x = [] 188 y = [] 189 w = [] 190 block = 0 191 while True: 192 line = fp.readline()[:-1] 193 if line != '*RAS_INT_START': 194 continue 195 if block == blockNum: 196 line = fp.readline()[:-1] 197 while True: 198 if line == '*RAS_INT_END': 199 break 200 sline = line.split() 201 x.append(float(sline[0])) 202 y.append(float(sline[1])) 203 w.append(1.0/max(1.,float(y[-1]))) 204 line = fp.readline()[:-1] 205 break 206 block += 1 207 N = len(x) 208 self.powderdata = [ 209 np.array(x), # x-axis values 210 np.array(y), # powder pattern intensities 211 np.array(w), # 1/sig(intensity)^2 values (weights) 212 np.zeros(N), # calc. intensities (zero) 213 np.zeros(N), # calc. background (zero) 214 np.zeros(N), # obs-calc profiles 215 ] 216 self.powderentry[0] = self.dnames[blockNum] 217 #self.powderentry[2] = 1 # xye file only has one bank 218 self.idstring = self.dnames[blockNum] 219 self.selections.remove(blockNum) 220 self.repeat = False 221 if len(self.selections): 222 self.repeat = True 223 return True
Note: See TracChangeset
for help on using the changeset viewer.