1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 import numpy as np
16 import struct, logging
17 import fabio, fabio.fabioimage
18
19 GE_HEADER_INFO = [
20
21 ('ImageFormat', 10, None),
22 ('VersionOfStandardHeader', 2, '=H'),
23 ('StandardHeaderSizeInBytes', 4, '=L'),
24 ('VersionOfUserHeader', 2, '=H'),
25 ('UserHeaderSizeInBytes', 4, '=L'),
26 ('NumberOfFrames', 2, '=H'),
27 ('NumberOfRowsInFrame', 2, '=H'),
28 ('NumberOfColsInFrame', 2, '=H'),
29 ('ImageDepthInBits', 2, '=H'),
30 ('AcquisitionDate', 20, None),
31 ('AcquisitionTime', 20, None),
32 ('DUTID', 20, None),
33 ('Operator', 50, None),
34 ('DetectorSignature', 20, None),
35 ('TestSystemName', 20, None),
36 ('TestStationRevision', 20, None),
37 ('CoreBundleRevision', 20, None),
38 ('AcquisitionName', 40, None),
39 ('AcquisitionParameterRevision', 20, None),
40 ('OriginalNumberOfRows', 2, '=H'),
41 ('OriginalNumberOfColumns', 2, '=H'),
42 ('RowNumberUpperLeftPointArchiveROI', 2, '=H'),
43 ('ColNumberUpperLeftPointArchiveROI', 2, '=H'),
44 ('Swapped', 2, '=H'),
45 ('Reordered', 2, '=H'),
46 ('HorizontalFlipped', 2, '=H'),
47 ('VerticalFlipped', 2, '=H'),
48 ('WindowValueDesired', 2, '=H'),
49 ('LevelValueDesired', 2, '=H'),
50 ('AcquisitionMode', 2, '=H'),
51 ('AcquisitionType', 2, '=H'),
52 ('UserAcquisitionCoffFileName1', 100, None),
53 ('UserAcquisitionCoffFileName2', 100, None),
54 ('FramesBeforeExpose', 2, '=H'),
55 ('FramesDuringExpose', 2, '=H'),
56 ('FramesAfterExpose', 2, '=H'),
57 ('IntervalBetweenFrames', 2, '=H'),
58 ('ExposeTimeDelayInMicrosecs', 8, '=d'),
59 ('TimeBetweenFramesInMicrosecs', 8, '=d'),
60 ('FramesToSkipExpose', 2, '=H'),
61 ('ExposureMode', 2, '=H'),
62 ('PrepPresetTimeInMicrosecs', 8, '=d'),
63 ('ExposePresetTimeInMicrosecs', 8, '=d'),
64 ('AcquisitionFrameRateInFps', 4, '=f'),
65 ('FOVSelect', 2, '=H'),
66 ('ExpertMode', 2, '=H'),
67 ('SetVCommon1', 8, '=d'),
68 ('SetVCommon2', 8, '=d'),
69 ('SetAREF', 8, '=d'),
70 ('SetAREFTrim', 4, '=L'),
71 ('SetSpareVoltageSource', 8, '=d'),
72 ('SetCompensationVoltageSource', 8, '=d'),
73 ('SetRowOffVoltage', 8, '=d'),
74 ('SetRowOnVoltage', 8, '=d'),
75 ('StoreCompensationVoltage', 4, '=L'),
76 ('RampSelection', 2, '=H'),
77 ('TimingMode', 2, '=H'),
78 ('Bandwidth', 2, '=H'),
79 ('ARCIntegrator', 2, '=H'),
80 ('ARCPostIntegrator', 2, '=H'),
81 ('NumberOfRows', 4, '=L'),
82 ('RowEnable', 2, '=H'),
83 ('EnableStretch', 2, '=H'),
84 ('CompEnable', 2, '=H'),
85 ('CompStretch', 2, '=H'),
86 ('LeftEvenTristate', 2, '=H'),
87 ('RightOddTristate', 2, '=H'),
88 ('TestModeSelect', 4, '=L'),
89 ('AnalogTestSource', 4, '=L'),
90 ('VCommonSelect', 4, '=L'),
91 ('DRCColumnSum', 4, '=L'),
92 ('TestPatternFrameDelta', 4, '=L'),
93 ('TestPatternRowDelta', 4, '=L'),
94 ('TestPatternColumnDelta', 4, '=L'),
95 ('DetectorHorizontalFlip', 2, '=H'),
96 ('DetectorVerticalFlip', 2, '=H'),
97 ('DFNAutoScrubOnOff', 2, '=H'),
98 ('FiberChannelTimeOutInMicrosecs', 4, '=L'),
99 ('DFNAutoScrubDelayInMicrosecs', 4, '=L'),
100 ('StoreAECROI', 2, '=H'),
101 ('TestPatternSaturationValue', 2, '=H'),
102 ('TestPatternSeed', 4, '=L'),
103 ('ExposureTimeInMillisecs', 4, '=f'),
104 ('FrameRateInFps', 4, '=f'),
105 ('kVp', 4, '=f'),
106 ('mA', 4, '=f'),
107 ('mAs', 4, '=f'),
108 ('FocalSpotInMM', 4, '=f'),
109 ('GeneratorType', 20, None),
110 ('StrobeIntensityInFtL', 4, '=f'),
111 ('NDFilterSelection', 2, '=H'),
112 ('RefRegTemp1', 8, '=d'),
113 ('RefRegTemp2', 8, '=d'),
114 ('RefRegTemp3', 8, '=d'),
115 ('Humidity1', 4, '=f'),
116 ('Humidity2', 4, '=f'),
117 ('DetectorControlTemp', 8, '=d'),
118 ('DoseValueInmR', 8, '=d'),
119 ('TargetLevelROIRow0', 2, '=H'),
120 ('TargetLevelROICol0', 2, '=H'),
121 ('TargetLevelROIRow1', 2, '=H'),
122 ('TargetLevelROICol1', 2, '=H'),
123 ('FrameNumberForTargetLevelROI', 2, '=H'),
124 ('PercentRangeForTargetLevel', 2, '=H'),
125 ('TargetValue', 2, '=H'),
126 ('ComputedMedianValue', 2, '=H'),
127 ('LoadZero', 2, '=H'),
128 ('MaxLUTOut', 2, '=H'),
129 ('MinLUTOut', 2, '=H'),
130 ('MaxLinear', 2, '=H'),
131 ('Reserved', 2, '=H'),
132 ('ElectronsPerCount', 2, '=H'),
133 ('ModeGain', 2, '=H'),
134 ('TemperatureInDegC', 8, '=d'),
135 ('LineRepaired', 2, '=H'),
136 ('LineRepairFileName', 100, None),
137 ('CurrentLongitudinalInMM', 4, '=f'),
138 ('CurrentTransverseInMM', 4, '=f'),
139 ('CurrentCircularInMM', 4, '=f'),
140 ('CurrentFilterSelection', 4, '=L'),
141 ('DisableScrubAck', 2, '=H'),
142 ('ScanModeSelect', 2, '=H'),
143 ('DetectorAppSwVersion', 20, None),
144 ('DetectorNIOSVersion', 20, None),
145 ('DetectorPeripheralSetVersion', 20, None),
146 ('DetectorPhysicalAddress', 20, None),
147 ('PowerDown', 2, '=H'),
148 ('InitialVoltageLevel_VCOMMON', 8, '=d'),
149 ('FinalVoltageLevel_VCOMMON', 8, '=d'),
150 ('DmrCollimatorSpotSize', 10, None),
151 ('DmrTrack', 5, None),
152 ('DmrFilter', 5, None),
153 ('FilterCarousel', 2, '=H'),
154 ('Phantom', 20, None),
155 ('SetEnableHighTime', 2, '=H'),
156 ('SetEnableLowTime', 2, '=H'),
157 ('SetCompHighTime', 2, '=H'),
158 ('SetCompLowTime', 2, '=H'),
159 ('SetSyncLowTime', 2, '=H'),
160 ('SetConvertLowTime', 2, '=H'),
161 ('SetSyncHighTime', 2, '=H'),
162 ('SetEOLTime', 2, '=H'),
163 ('SetRampOffsetTime', 2, '=H'),
164 ('FOVStartingValue', 2, '=H'),
165 ('ColumnBinning', 2, '=H'),
166 ('RowBinning', 2, '=H'),
167 ('BorderColumns64', 2, '=H'),
168 ('BorderRows64', 2, '=H'),
169 ('FETOffRows64', 2, '=H'),
170 ('FOVStartColumn128', 2, '=H'),
171 ('FOVStartRow128', 2, '=H'),
172 ('NumberOfColumns128', 2, '=H'),
173 ('NumberOfRows128', 2, '=H'),
174 ('VFPAquisition', 2000, None),
175 ('Comment', 200, None)
176 ]
177
178
179 -class GEimage(fabio.fabioimage.fabioimage):
180
181 _need_a_seek_to_read = True
182
184 """ Read a GE image header """
185
186 infile.seek(0)
187
188 self.header = {}
189 for name, nbytes, format in GE_HEADER_INFO:
190 if format is None:
191 self.header[ name ] = infile.read( nbytes )
192 else:
193 self.header[ name ] = struct.unpack( format,
194 infile.read( nbytes ))[0]
195
196 - def read( self, fname, frame = 0):
197 """
198 Read in header into self.header and
199 the data into self.data
200 """
201 self.header = {}
202 self.resetvals()
203 infile = self._open(fname, "rb")
204 self.sequencefilename = fname
205 self._readheader(infile)
206 self.nframes = self.header['NumberOfFrames']
207 self._readframe( infile, frame )
208 infile.close()
209 return self
210
212 """ The thing to be printed for the user to represent a frame inside
213 a file """
214 self.filename = "%s$%04d"%( self.sequencefilename,
215 self.currentframe )
216
218 """
219 # Load only one image from the sequence
220 # Note: the first image in the sequence 0
221 # raises an exception if you give an invalid image
222 # otherwise fills in self.data
223 """
224 if(img_num > self.nframes or img_num < 0):
225 raise Exception("Bad image number")
226 imgstart = self.header['StandardHeaderSizeInBytes'] + \
227 self.header['UserHeaderSizeInBytes'] + \
228 img_num*self.header['NumberOfRowsInFrame'] * \
229 self.header['NumberOfColsInFrame'] * \
230 self.header['ImageDepthInBits'] / 8
231
232 filepointer.seek( imgstart, 0 )
233
234 self.bpp = self.header['ImageDepthInBits'] / 8
235 imglength = self.header['NumberOfRowsInFrame'] * \
236 self.header['NumberOfColsInFrame'] * self.bpp
237 if self.bpp != 2:
238 logging.warning("Using uint16 for GE but seems to be wrong")
239
240
241 self.data = np.fromstring( filepointer.read( imglength ), np.uint16)
242 self.data.shape = ( self.header['NumberOfRowsInFrame'],
243 self.header['NumberOfColsInFrame'] )
244 self.dim2 , self.dim1 = self.data.shape
245 self.currentframe = int( img_num )
246 self._makeframename( )
247
248
249 - def write(self, fname, force_type= np.uint16):
250 """ Not yet implemented"""
251 raise Exception("Write is not implemented")
252
254 """
255 Returns a frame as a new fabioimage object
256 """
257 if num < 0 or num > self.nframes:
258 raise Exception("Requested frame number is out of range")
259
260 newheader = {}
261 for k in self.header.keys():
262 newheader[k] = self.header[k]
263 frame = GEimage( header = newheader )
264 frame.nframes = self.nframes
265 frame.sequencefilename = self.sequencefilename
266 infile = frame._open(self.sequencefilename, "rb")
267 frame._readframe( infile, num )
268 infile.close()
269 return frame
270
272 """
273 Get the next image in a series as a fabio image
274 """
275 if self.currentframe < (self.nframes - 1) and self.nframes > 1:
276 return self.getframe( self.currentframe + 1 )
277 else:
278 newobj = GEimage()
279 newobj.read( fabio.next_filename(
280 self.sequencefilename ) )
281 return newobj
282
284 """
285 Get the previous image in a series as a fabio image
286 """
287 if self.currentframe > 0:
288 return self.getframe( self.currentframe - 1 )
289 else:
290 newobj = GEimage()
291 newobj.read( fabio.previous_filename(
292 self.sequencefilename ) )
293 return newobj
294
295
297 import sys, time
298
299 if len(sys.argv)<2:
300 print "USAGE: GE_script.py <GEaSi_raw_image_file>"
301 sys.exit()
302
303 image_file = sys.argv[1]
304
305 print "init read_GEaSi_data class and load header.."
306 sequence1 = GEimage()
307 sequence1.read( image_file )
308
309 print "TimeBetweenFramesInMicrosecs = ",
310 print sequence1.header['TimeBetweenFramesInMicrosecs']
311 print "AcquisitionTime = ",
312 print sequence1.header['AcquisitionTime']
313
314
315 print "Mean = ", sequence1.data.ravel().mean()
316
317 while 1:
318 start = time.time()
319 try:
320 sequence1 = sequence1.next()
321 print sequence1.currentframe, sequence1.data.ravel().mean(), \
322 time.time()-start
323 except:
324 raise
325 break
326
327
328
329
330 if __name__ == '__main__':
331 demo()
332