Changeset 649 for trunk/GSASIIIO.py
- Timestamp:
- Jun 16, 2012 3:47:37 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIIO.py
r643 r649 43 43 file += ext 44 44 return file 45 46 ## to be removed 47 #def SelectPowderData(G2frame, filename): 48 # """Selects banks of data from a filename of any GSAS powder data format 49 # Input - filename: any GSAS powder data formatted file (currently STD, FXYE, FXY & ESD) 50 # Returns - a list of banks to be read; each entry in list is a tuple containing: 51 # filename: same as input filename 52 # Pos: position for start of data; record just after BANK record 53 # Bank: the BANK record 54 # """ 55 # File = open(filename,'Ur') 56 # Title = ''' 57 #First line of this file: 58 #'''+File.readline() 59 # dlg = wx.MessageDialog(G2frame, Title, 'Is this the file you want?', 60 # wx.YES_NO | wx.ICON_QUESTION) 61 # try: 62 # result = dlg.ShowModal() 63 # finally: 64 # dlg.Destroy() 65 # if result == wx.ID_NO: return (0,0) 66 # Temperature = 300 67 # 68 # if '.xye' in filename: #Topas style xye file (e.g. 2-th, I, sig) - no iparm file/no BANK record 69 # dlg = wx.MessageDialog(G2frame,'''Is this laboratory Cu Ka1/Ka2 data? 70 #(No = 0.6A wavelength synchrotron data) 71 #Change wavelength in Instrument Parameters if needed''','Data type?', 72 # wx.YES_NO | wx.ICON_QUESTION) 73 # try: 74 # result = dlg.ShowModal() 75 # finally: 76 # dlg.Destroy() 77 # print result 78 # if result == wx.ID_YES: 79 # Iparm = {} #Assume CuKa lab data 80 # Iparm['INS HTYPE '] = 'PXC ' 81 # Iparm['INS 1 ICONS'] = ' 1.540500 1.544300 0.0 0 0.7 0 0.5 ' 82 # Iparm['INS 1PRCF1 '] = ' 3 8 0.01 ' 83 # Iparm['INS 1PRCF11'] = ' 2.000000E+00 -2.000000E+00 5.000000E+00 0.000000E+00 ' 84 # Iparm['INS 1PRCF12'] = ' 0.000000E+00 0.000000E+00 0.100000E-01 0.100000E-01 ' 85 # else: 86 # Iparm = {} #Assume 0.6A synchrotron data 87 # Iparm['INS HTYPE '] = 'PXC ' 88 # Iparm['INS 1 ICONS'] = ' 0.600000 0.000000 0.0 0 0.99 0 0.5 ' 89 # Iparm['INS 1PRCF1 '] = ' 3 8 0.01 ' 90 # Iparm['INS 1PRCF11'] = ' 1.000000E+00 -1.000000E+00 0.300000E+00 0.000000E+00 ' 91 # Iparm['INS 1PRCF12'] = ' 0.000000E+00 0.000000E+00 0.100000E-02 0.100000E-02 ' 92 # 93 # 94 # else: #GSAS style fxye or fxy file (e.g. 100*2-th, I, sig) 95 # G2frame.IparmName = GetInstrumentFile(G2frame,filename) 96 # if G2frame.IparmName: 97 # Iparm = GetInstrumentData(G2frame.IparmName) 98 # else: 99 # Iparm = {} #Assume CuKa lab data if no iparm file 100 # Iparm['INS HTYPE '] = 'PXC ' 101 # Iparm['INS 1 ICONS'] = ' 1.540500 1.544300 0.0 0 0.7 0 0.5 ' 102 # Iparm['INS 1PRCF1 '] = ' 3 8 0.01 ' 103 # Iparm['INS 1PRCF11'] = ' 2.000000E+00 -2.000000E+00 5.000000E+00 0.000000E+00 ' 104 # Iparm['INS 1PRCF12'] = ' 0.000000E+00 0.000000E+00 0.100000E-01 0.100000E-01 ' 105 # S = 1 106 # Banks = [] 107 # Pos = [] 108 # FoundData = [] 109 # Comments = [] 110 # wx.BeginBusyCursor() 111 # try: 112 # while S: 113 # S = File.readline() 114 # if S[:1] != '#': 115 # if S[:4] == 'BANK': 116 # Banks.append(S) 117 # Pos.append(File.tell()) 118 # elif '.xye' in filename: #No BANK in a xye file 119 # Banks.append('BANK 1 XYE') 120 # Pos.append(File.tell()) 121 # break 122 # else: 123 # Comments.append(S[:-1]) 124 # if 'Temp' in S.split('=')[0]: 125 # Temperature = float(S.split('=')[1]) 126 # File.close() 127 # finally: 128 # wx.EndBusyCursor() 129 # if Comments: 130 # print 'Comments on file:' 131 # for Comment in Comments: print Comment 132 # if Banks: 133 # result = [0] 134 # if len(Banks) >= 2: 135 # dlg = wx.MultiChoiceDialog(G2frame, 'Which scans do you want?', 'Select scans', Banks, wx.CHOICEDLG_STYLE) 136 # try: 137 # if dlg.ShowModal() == wx.ID_OK: 138 # result = dlg.GetSelections() 139 # else: 140 # result = [] 141 # finally: 142 # dlg.Destroy() 143 # for i in result: 144 # FoundData.append((filename,Pos[i],Banks[i])) 145 # else: 146 # dlg = wx.MessageDialog(G2frame, 'ERROR - this is not a GSAS powder data file', 'No BANK records', wx.OK | wx.ICON_ERROR) 147 # try: 148 # result = dlg.ShowModal() 149 # finally: 150 # dlg.Destroy() 151 # return FoundData,Iparm,Comments,Temperature 152 # 153 ## to be removed 154 #def GetInstrumentFile(G2frame,filename): 155 # import os.path as op 156 # dlg = wx.FileDialog(G2frame,'Choose an instrument file','.', '', 'GSAS iparm file (*.prm)|*.prm|All files(*.*)|*.*', 157 # wx.OPEN|wx.CHANGE_DIR) 158 # Tname = filename[:filename.index('.')]+'.prm' 159 # if op.exists(Tname): 160 # G2frame.IparmName = Tname 161 # if G2frame.IparmName: dlg.SetFilename(G2frame.IparmName) 162 # filename = '' 163 # try: 164 # if dlg.ShowModal() == wx.ID_OK: 165 # filename = dlg.GetPath() 166 # finally: 167 # dlg.Destroy() 168 # return filename 169 # 170 ## to be removed 171 #def GetInstrumentData(IparmName): 172 # file = open(IparmName, 'Ur') 173 # S = 1 174 # Iparm = {} 175 # while S: 176 # S = file.readline() 177 # Iparm[S[:12]] = S[12:-1] 178 # return Iparm 179 45 180 46 def GetPowderPeaks(fileName): 181 47 sind = lambda x: math.sin(x*math.pi/180.) … … 217 83 return Comments,Peaks 218 84 219 #def GetPawleyPeaks(filename): #dead code??220 # rt2ln2x2 = 2.35482221 # File = open(filename,'Ur')222 # PawleyPeaks = []223 # S = File.readline() #skip header224 # S = File.readline()225 # item = S.split()226 # while S:227 # h,k,l = int(item[0]),int(item[1]),int(item[2])228 # mult = int(item[3])229 # tth = float(item[5])230 # sig = float(item[6])/rt2ln2x2231 # Iobs = float(item[7])*mult232 # PawleyPeaks.append([h,k,l,mult,tth,False,Iobs,0.0])233 # S = File.readline()234 # item = S.split()235 # if item[3] == '-100.0000': #find trailer236 # break237 # File.close()238 # return PawleyPeaks239 240 # this will be removed eventually241 #def GetHKLData(filename):242 # print 'Reading: '+filename243 # File = open(filename,'Ur')244 # HKLref = []245 # HKLmin = [1000,1000,1000]246 # HKLmax = [0,0,0]247 # FoMax = 0248 # ifFc = False249 # S = File.readline()250 # while '#' in S[0]: #get past comments if any251 # S = File.readline()252 # if '_' in S: #cif style .hkl file253 # while 'loop_' not in S: #skip preliminaries if any - can't have 'loop_' in them!254 # S = File.readline()255 # S = File.readline() #get past 'loop_' line256 # pos = 0257 # hpos = kpos = lpos = Fosqpos = Fcsqpos = sigpos = -1258 # while S:259 # if '_' in S:260 # if 'index_h' in S:261 # hpos = pos262 # elif 'index_k' in S:263 # kpos = pos264 # elif 'index_l' in S:265 # lpos = pos266 # elif 'F_squared_meas' in S:267 # Fosqpos = pos268 # elif 'F_squared_calc' in S:269 # Fcsqpos = pos270 # elif 'F_squared_sigma' in S:271 # sigpos = pos272 # pos += 1273 # else:274 # data = S.split()275 # if data: #avoid blank lines276 # HKL = np.array([int(data[hpos]),int(data[kpos]),int(data[lpos])])277 # h,k,l = HKL278 # Fosq = float(data[Fosqpos])279 # if sigpos != -1:280 # sigFosq = float(data[sigpos])281 # else:282 # sigFosq = 1.283 # if Fcsqpos != -1:284 # Fcsq = float(data[Fcsqpos])285 # if Fcsq:286 # ifFc = True287 # else:288 # Fcsq = 0.289 #290 # HKLmin = [min(h,HKLmin[0]),min(k,HKLmin[1]),min(l,HKLmin[2])]291 # HKLmax = [max(h,HKLmax[0]),max(k,HKLmax[1]),max(l,HKLmax[2])]292 # FoMax = max(FoMax,Fosq)293 # HKLref.append([HKL,Fosq,sigFosq,Fcsq,0,0,0]) #room for Fcp, Fcpp & phase294 # S = File.readline()295 # else: #dumb h,k,l,Fo,sigFo .hkl file296 # while S:297 # h,k,l,Fo,sigFo = S.split()298 # HKL = np.array([int(h),int(k),int(l)])299 # h,k,l = HKL300 # Fo = float(Fo)301 # sigFo = float(sigFo)302 # HKLmin = [min(h,HKLmin[0]),min(k,HKLmin[1]),min(l,HKLmin[2])]303 # HKLmax = [max(h,HKLmax[0]),max(k,HKLmax[1]),max(l,HKLmax[2])]304 # FoMax = max(FoMax,Fo)305 # HKLref.append([HKL,Fo**2,2.*Fo*sigFo,0,0,0,0]) #room for Fc, Fcp, Fcpp & phase306 # S = File.readline()307 # File.close()308 # return HKLref,HKLmin,HKLmax,FoMax,ifFc309 310 ## to be removed311 #def GetPowderData(filename,Pos,Bank,DataType):312 # '''Reads one BANK of data from GSAS raw powder data file313 # input:314 # filename: GSAS raw powder file dataname315 # Pos: start of data in file just after BANK record316 # Bank: the BANK record317 # DataType: powder data type, e.g. "PXC" for Powder X-ray CW data318 # returns: list [x,y,e,yc,yb]319 # x: np.array of x-axis values320 # y: np.array of powder pattern intensities321 # w: np.array of w=sig(intensity)^2 values322 # yc: np.array of calc. intensities (zero)323 # yb: np.array of calc. background (zero)324 # yd: np.array of obs-calc profiles325 # '''326 # print 'Reading: '+filename327 # print 'Bank: '+Bank[:-1]328 # if 'FXYE' in Bank:329 # return GetFXYEdata(filename,Pos,Bank,DataType)330 # elif ' XYE' in Bank:331 # return GetXYEdata(filename,Pos,Bank,DataType)332 # elif 'FXY' in Bank:333 # return GetFXYdata(filename,Pos,Bank,DataType)334 # elif 'ESD' in Bank:335 # return GetESDdata(filename,Pos,Bank,DataType)336 # elif 'STD' in Bank:337 # return GetSTDdata(filename,Pos,Bank,DataType)338 # else:339 # return GetSTDdata(filename,Pos,Bank,DataType)340 # return []341 #342 ## to be removed343 #def GetFXYEdata(filename,Pos,Bank,DataType):344 # File = open(filename,'Ur')345 # File.seek(Pos)346 # x = []347 # y = []348 # w = []349 # S = File.readline()350 # while S and S[:4] != 'BANK':351 # vals = S.split()352 # if DataType[2] == 'C':353 # x.append(float(vals[0])/100.) #CW: from centidegrees to degrees354 # elif DataType[2] == 'T':355 # x.append(float(vals[0])/1000.0) #TOF: from musec to millisec356 # f = float(vals[1])357 # if f <= 0.0:358 # y.append(0.0)359 # w.append(1.0)360 # else:361 # y.append(float(vals[1]))362 # w.append(1.0/float(vals[2])**2)363 # S = File.readline()364 # File.close()365 # N = len(x)366 # return [np.array(x),np.array(y),np.array(w),np.zeros(N),np.zeros(N),np.zeros(N)]367 #368 ## to be removed369 #def GetXYEdata(filename,Pos,Bank,DataType):370 # File = open(filename,'Ur')371 # File.seek(Pos)372 # x = []373 # y = []374 # w = []375 # S = File.readline()376 # while S:377 # vals = S.split()378 # try:379 # x.append(float(vals[0]))380 # f = float(vals[1])381 # if f <= 0.0:382 # y.append(0.0)383 # w.append(1.0)384 # else:385 # y.append(float(vals[1]))386 # w.append(1.0/float(vals[2])**2)387 # S = File.readline()388 # except ValueError:389 # break390 # File.close()391 # N = len(x)392 # return [np.array(x),np.array(y),np.array(w),np.zeros(N),np.zeros(N),np.zeros(N)]393 #394 #395 ## to be removed396 #def GetFXYdata(filename,Pos,Bank,DataType):397 # File = open(filename,'Ur')398 # File.seek(Pos)399 # x = []400 # y = []401 # w = []402 # S = File.readline()403 # while S and S[:4] != 'BANK':404 # vals = S.split()405 # if DataType[2] == 'C':406 # x.append(float(vals[0])/100.) #CW: from centidegrees to degrees407 # elif DataType[2] == 'T':408 # x.append(float(vals[0])/1000.0) #TOF: from musec to millisec409 # f = float(vals[1])410 # if f > 0.0:411 # y.append(f)412 # w.append(1.0/f)413 # else:414 # y.append(0.0)415 # w.append(1.0)416 # S = File.readline()417 # File.close()418 # N = len(x)419 # return [np.array(x),np.array(y),np.array(w),np.zeros(N),np.zeros(N),np.zeros(N)]420 #421 ## to be removed422 #def GetESDdata(filename,Pos,Bank,DataType):423 # File = open(filename,'Ur')424 # cons = Bank.split()425 # if DataType[2] == 'C':426 # start = float(cons[5])/100.0 #CW: from centidegrees to degrees427 # step = float(cons[6])/100.0428 # elif DataType[2] == 'T':429 # start = float(cons[5])/1000.0 #TOF: from musec to millisec430 # step = float(cons[6])/1000.0431 # File.seek(Pos)432 # x = []433 # y = []434 # w = []435 # S = File.readline()436 # j = 0437 # while S and S[:4] != 'BANK':438 # for i in range(0,80,16):439 # xi = start+step*j440 # yi = sfloat(S[i:i+8])441 # ei = sfloat(S[i+8:i+16])442 # x.append(xi)443 # if yi > 0.0:444 # y.append(yi)445 # w.append(1.0/ei**2)446 # else:447 # y.append(0.0)448 # w.append(1.0)449 # j += 1450 # S = File.readline()451 # File.close()452 # N = len(x)453 # return [np.array(x),np.array(y),np.array(w),np.zeros(N),np.zeros(N),np.zeros(N)]454 #455 ## to be removed456 #def GetSTDdata(filename,Pos,Bank,DataType):457 # File = open(filename,'Ur')458 # cons = Bank.split()459 # Nch = int(cons[2])460 # if DataType[2] == 'C':461 # start = float(cons[5])/100.0 #CW: from centidegrees to degrees462 # step = float(cons[6])/100.0463 # elif DataType[2] == 'T':464 # start = float(cons[5])/1000.0 #TOF: from musec to millisec - not likely!465 # step = float(cons[6])/1000.0466 # File.seek(Pos)467 # x = []468 # y = []469 # w = []470 # S = File.readline()471 # j = 0472 # while S and S[:4] != 'BANK':473 # for i in range(0,80,8):474 # xi = start+step*j475 # ni = max(sint(S[i:i+2]),1)476 # yi = max(sfloat(S[i+2:i+8]),0.0)477 # if yi:478 # vi = yi/ni479 # else:480 # yi = 0.0481 # vi = 1.0482 # j += 1483 # if j < Nch:484 # x.append(xi)485 # y.append(yi)486 # w.append(1.0/vi)487 # S = File.readline()488 # File.close()489 # N = len(x)490 # return [np.array(x),np.array(y),np.array(w),np.zeros(N),np.zeros(N),np.zeros(N)]491 492 85 def CheckImageFile(G2frame,imagefile): 493 86 if not ospath.exists(imagefile): … … 792 385 print 'Read APS scanCCD tiff file: ',filename 793 386 image = np.array(ar.array('H',File.read(2*Npix)),dtype=np.int32) 387 elif IFD[273][2][0] == 4096: 388 tifType = 'Canadian' 389 pixy = (347,347) 390 File.seek(4096) 391 if not imageOnly: 392 print 'Read Canadian tiff file: ',filename 393 image = np.array(ar.array('H',File.read(2*Npix)),dtype=np.int32) 794 394 # elif sizexy == [960,960]: 795 395 # tiftype = 'PE-BE'
Note: See TracChangeset
for help on using the changeset viewer.