Changeset 2441
 Timestamp:
 Aug 21, 2016 2:58:27 PM (6 years ago)
 Location:
 trunk
 Files:

 21 edited
Legend:
 Unmodified
 Added
 Removed

trunk/fsource/unpack_cbf.for
r2437 r2441 19 19 INTEGER*2 ITWOBYTES 20 20 INTEGER*4 IFOURBYTES 21 21 22 22 E1 = CHAR(128) 23 23 E2 = CHAR(0)//CHAR(128) 24 24 E4 = CHAR(0)//CHAR(0)//CHAR(0)//CHAR(128) 25 25 26 I = 126 I = 0 27 27 J = 0 28 BASEPIXEL = 0 28 29 DO WHILE ( I.LT.N ) 29 30 C1 = CMPR(I) … … 43 44 END IF 44 45 END IF 45 c BASEPIXEL = 046 46 IF ( ISIZE .EQ. 1 ) THEN 47 47 IONEBYTE = ICHAR(CMPR(I)) … … 61 61 BASEPIXEL = BASEPIXEL+IFOURBYTES 62 62 END IF 63 c IF ( MOD(J,100000).EQ.0 ) PRINT *,I,J,BASEPIXEL 63 64 IMG(J) = BASEPIXEL 64 65 J = J+1 
trunk/imports/G2img_CBF.py
r2440 r2441 50 50 51 51 import numpy as np 52 import cPickle53 54 def analyse(stream):55 """56 Analyze a stream of char with any length of exception (2,4, or 8 bytes integers)57 58 @return list of NParrays59 """60 listnpa = []61 key16 = "\x80"62 key32 = "\x00\x80"63 key64 = "\x00\x00\x00\x80"64 idx = 065 shift = 166 position = 067 while True:68 lns = len(stream)69 idx = stream.find(key16)70 if idx == 1:71 listnpa.append(np.fromstring(stream, dtype="int8"))72 break73 listnpa.append(np.fromstring(stream[:idx], dtype="int8"))74 position += listnpa[1].size75 76 if stream[idx + 1:idx + 3] == key32:77 if stream[idx + 3:idx + 7] == key64:78 listnpa.append(np.fromstring(stream[idx + 7:idx + 15], dtype="int64"))79 position += 180 # print "loop64 x=%4i y=%4i in idx %4i lns %4i value=%s" % ((position % 2463), (position // 2463), idx, lns, listnpa[1])81 shift = 1582 else: #32 bit int83 listnpa.append(np.fromstring(stream[idx + 3:idx + 7], dtype="int32"))84 position += 185 # print "loop32 x=%4i y=%4i in idx %4i lns %4i value=%s" % ((position % 2463), (position // 2463), idx, lns, listnpa[1])86 shift = 787 else: #int1688 listnpa.append(np.fromstring(stream[idx + 1:idx + 3], dtype="int16"))89 position += 190 # print "loop16 x=%4i y=%4i in idx %4i lns %4i value=%s" % ((position % 2463), (position // 2463), idx, lns, listnpa[1])91 shift = 392 stream = stream[idx + shift:]93 return listnpa94 95 96 52 if GSASIIpath.GetConfigValue('debug'): 97 53 print 'Read cif binary detector data cbf file: ',filename … … 134 90 elif 'NumberofElements' in line: 135 91 Npix = int(fields[1]) 92 nxy = sizexy[0]*sizexy[1] 93 image = np.zeros(nxy,dtype=np.int32) 136 94 cent = [cent[0]*pixSize[0]/1000.,cent[1]*pixSize[1]/1000.] 137 95 compImage = stream[imageBeg:imageBeg+compImageSize] 138 96 # GSASIIpath.IPyBreak() 139 97 time0 = time.time() 140 nxy = sizexy[0]*sizexy[1]141 98 nimg = len(compImage) 142 image = np.zeros(nxy,dtype=np.float32)143 99 image = cbf.unpack_cbf(nimg,compImage,nxy,image) 144 # image = np.hstack(analyse(compImage)).cumsum()145 100 image = np.reshape(image,(sizexy[1],sizexy[0])) 146 #print 'import time:',time.time()time0101 print 'import time:',time.time()time0 147 102 data = {'pixelSize':pixSize,'wavelength':wave,'distance':dist,'center':cent,'size':sizexy} 148 103 Npix = sizexy[0]*sizexy[1]
Note: See TracChangeset
for help on using the changeset viewer.