fabio 0.1.1__zip
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- Library/Python/2.7/site-packages/fabio/GEimage.py +334 -0
- Library/Python/2.7/site-packages/fabio/GEimage.pyc +0 -0
- Library/Python/2.7/site-packages/fabio/GEimage_old.py +501 -0
- Library/Python/2.7/site-packages/fabio/GEimage_old.pyc +0 -0
- Library/Python/2.7/site-packages/fabio/HiPiCimage.py +106 -0
- Library/Python/2.7/site-packages/fabio/HiPiCimage.pyc +0 -0
- Library/Python/2.7/site-packages/fabio/OXDimage.py +442 -0
- Library/Python/2.7/site-packages/fabio/OXDimage.pyc +0 -0
- Library/Python/2.7/site-packages/fabio/TiffIO.py +1197 -0
- Library/Python/2.7/site-packages/fabio/TiffIO.pyc +0 -0
- Library/Python/2.7/site-packages/fabio/__init__.py +10 -0
- Library/Python/2.7/site-packages/fabio/__init__.pyc +0 -0
- Library/Python/2.7/site-packages/fabio/adscimage.py +137 -0
- Library/Python/2.7/site-packages/fabio/adscimage.pyc +0 -0
- Library/Python/2.7/site-packages/fabio/binaryimage.py +87 -0
- Library/Python/2.7/site-packages/fabio/binaryimage.pyc +0 -0
- Library/Python/2.7/site-packages/fabio/bruker100image.py +96 -0
- Library/Python/2.7/site-packages/fabio/bruker100image.pyc +0 -0
- Library/Python/2.7/site-packages/fabio/brukerimage.py +195 -0
- Library/Python/2.7/site-packages/fabio/brukerimage.pyc +0 -0
- Library/Python/2.7/site-packages/fabio/byte_offset.so +0 -0
- Library/Python/2.7/site-packages/fabio/cbfimage.py +758 -0
- Library/Python/2.7/site-packages/fabio/cbfimage.pyc +0 -0
- Library/Python/2.7/site-packages/fabio/cf_io.so +0 -0
- Library/Python/2.7/site-packages/fabio/compression.py +388 -0
- Library/Python/2.7/site-packages/fabio/compression.pyc +0 -0
- Library/Python/2.7/site-packages/fabio/converters.py +54 -0
- Library/Python/2.7/site-packages/fabio/converters.pyc +0 -0
- Library/Python/2.7/site-packages/fabio/datIO.py +60 -0
- Library/Python/2.7/site-packages/fabio/datIO.pyc +0 -0
- Library/Python/2.7/site-packages/fabio/dm3image.py +219 -0
- Library/Python/2.7/site-packages/fabio/dm3image.pyc +0 -0
- Library/Python/2.7/site-packages/fabio/edfimage.py +924 -0
- Library/Python/2.7/site-packages/fabio/edfimage.pyc +0 -0
- Library/Python/2.7/site-packages/fabio/fabioimage.py +556 -0
- Library/Python/2.7/site-packages/fabio/fabioimage.pyc +0 -0
- Library/Python/2.7/site-packages/fabio/fabioutils.py +491 -0
- Library/Python/2.7/site-packages/fabio/fabioutils.pyc +0 -0
- Library/Python/2.7/site-packages/fabio/file_series.py +313 -0
- Library/Python/2.7/site-packages/fabio/file_series.pyc +0 -0
- Library/Python/2.7/site-packages/fabio/fit2dmaskimage.py +94 -0
- Library/Python/2.7/site-packages/fabio/fit2dmaskimage.pyc +0 -0
- Library/Python/2.7/site-packages/fabio/fit2dspreadsheetimage.py +85 -0
- Library/Python/2.7/site-packages/fabio/fit2dspreadsheetimage.pyc +0 -0
- Library/Python/2.7/site-packages/fabio/kcdimage.py +131 -0
- Library/Python/2.7/site-packages/fabio/kcdimage.pyc +0 -0
- Library/Python/2.7/site-packages/fabio/mar345_IO.so +0 -0
- Library/Python/2.7/site-packages/fabio/mar345image.py +320 -0
- Library/Python/2.7/site-packages/fabio/mar345image.pyc +0 -0
- Library/Python/2.7/site-packages/fabio/marccdimage.py +309 -0
- Library/Python/2.7/site-packages/fabio/marccdimage.pyc +0 -0
- Library/Python/2.7/site-packages/fabio/openimage.py +162 -0
- Library/Python/2.7/site-packages/fabio/openimage.pyc +0 -0
- Library/Python/2.7/site-packages/fabio/pilatusimage.py +81 -0
- Library/Python/2.7/site-packages/fabio/pilatusimage.pyc +0 -0
- Library/Python/2.7/site-packages/fabio/pnmimage.py +165 -0
- Library/Python/2.7/site-packages/fabio/pnmimage.pyc +0 -0
- Library/Python/2.7/site-packages/fabio/readbytestream.py +86 -0
- Library/Python/2.7/site-packages/fabio/readbytestream.pyc +0 -0
- Library/Python/2.7/site-packages/fabio/tifimage.py +283 -0
- Library/Python/2.7/site-packages/fabio/tifimage.pyc +0 -0
- Library/Python/2.7/site-packages/fabio/xsdimage.py +134 -0
- Library/Python/2.7/site-packages/fabio/xsdimage.pyc +0 -0
- Library/Python/2.7/site-packages/fabio-0.1.1-py2.7.egg-info/PKG-INFO +11 -0
- Library/Python/2.7/site-packages/fabio-0.1.1-py2.7.egg-info/SOURCES.txt +114 -0
- Library/Python/2.7/site-packages/fabio-0.1.1-py2.7.egg-info/dependency_links.txt +1 -0
- Library/Python/2.7/site-packages/fabio-0.1.1-py2.7.egg-info/top_level.txt +4 -0
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
Authors: Henning O. Sorensen & Erik Knudsen
|
|
6
|
+
Center for Fundamental Research: Metal Structures in Four Dimensions
|
|
7
|
+
Risoe National Laboratory
|
|
8
|
+
Frederiksborgvej 399
|
|
9
|
+
DK-4000 Roskilde
|
|
10
|
+
email:erik.knudsen@risoe.dk
|
|
11
|
+
|
|
12
|
+
+ Jon Wright, ESRF
|
|
13
|
+
"""
|
|
14
|
+
import logging, sys
|
|
15
|
+
logger = logging.getLogger("fileseries")
|
|
16
|
+
import traceback as pytraceback
|
|
17
|
+
|
|
18
|
+
from fabioutils import filename_object, next_filename
|
|
19
|
+
|
|
20
|
+
from openimage import openimage
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def new_file_series0(first_object, first=None, last=None, step=1):
|
|
24
|
+
"""
|
|
25
|
+
Created from a fabio image
|
|
26
|
+
first and last are file numbers
|
|
27
|
+
"""
|
|
28
|
+
im = first_object
|
|
29
|
+
nimages = 0
|
|
30
|
+
# for counting images
|
|
31
|
+
if None in (first, last):
|
|
32
|
+
step = 0
|
|
33
|
+
total = 1
|
|
34
|
+
else:
|
|
35
|
+
total = last - first
|
|
36
|
+
|
|
37
|
+
yield im
|
|
38
|
+
while nimages < total:
|
|
39
|
+
nimages += step
|
|
40
|
+
try:
|
|
41
|
+
newim = im.next()
|
|
42
|
+
im = newim
|
|
43
|
+
except Exception, error:
|
|
44
|
+
pytraceback.print_exc()
|
|
45
|
+
|
|
46
|
+
# Skip bad images
|
|
47
|
+
logger.warning("Got a problem here: %s", error)
|
|
48
|
+
try:
|
|
49
|
+
im.filename = next_filename(im.filename)
|
|
50
|
+
except Exception, error:
|
|
51
|
+
# KE: This will not work and will throw an exception
|
|
52
|
+
# fabio.next_filename doesn't understand %nnnn on the end
|
|
53
|
+
logger.warning("Got another problem here: %s", error)
|
|
54
|
+
im.filename = next_filename(im.sequencefilename)
|
|
55
|
+
yield None
|
|
56
|
+
yield im
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def new_file_series(first_object, nimages=0, step=1, traceback=False):
|
|
61
|
+
"""
|
|
62
|
+
A generator function that creates a file series starting from a a fabioimage.
|
|
63
|
+
Iterates through all images in a file (if more than 1), then proceeds to
|
|
64
|
+
the next file as determined by fabio.next_filename.
|
|
65
|
+
|
|
66
|
+
first_object: the starting fabioimage, which will be the first one yielded
|
|
67
|
+
in the sequence
|
|
68
|
+
nimages: the maximum number of images to consider
|
|
69
|
+
step: step size, will yield the first and every step'th image until nimages
|
|
70
|
+
is reached. (e.g. nimages = 5, step = 2 will yield 3 images (0, 2, 4)
|
|
71
|
+
traceback: if True causes it to print a traceback in the event of an
|
|
72
|
+
exception (missing image, etc.). Otherwise the calling routine can handle
|
|
73
|
+
the exception as it chooses
|
|
74
|
+
yields: the next fabioimage in the series.
|
|
75
|
+
In the event there is an exception, it yields the sys.exec_info for the
|
|
76
|
+
exception instead. sys.exec_info is a tuple:
|
|
77
|
+
( exceptionType, exceptionValue, exceptionTraceback )
|
|
78
|
+
from which all the exception information can be obtained.
|
|
79
|
+
Suggested usage:
|
|
80
|
+
for obj in new_file_series( ... ):
|
|
81
|
+
if not isinstance( obj, fabio.fabioimage.fabioimage ):
|
|
82
|
+
# deal with errors like missing images, non readable files, etc
|
|
83
|
+
# e.g.
|
|
84
|
+
traceback.print_exception(obj[0], obj[1], obj[2])
|
|
85
|
+
"""
|
|
86
|
+
im = first_object
|
|
87
|
+
nprocessed = 0
|
|
88
|
+
abort = False
|
|
89
|
+
if nimages > 0:
|
|
90
|
+
yield im
|
|
91
|
+
nprocessed += 1
|
|
92
|
+
while nprocessed < nimages:
|
|
93
|
+
try:
|
|
94
|
+
newim = im.next()
|
|
95
|
+
im = newim
|
|
96
|
+
retVal = im
|
|
97
|
+
except Exception, ex:
|
|
98
|
+
retVal = sys.exc_info()
|
|
99
|
+
if(traceback):
|
|
100
|
+
pytraceback.print_exc()
|
|
101
|
+
# Skip bad images
|
|
102
|
+
logger.warning("Got a problem here: next() failed %s", ex)
|
|
103
|
+
# Skip bad images
|
|
104
|
+
try:
|
|
105
|
+
im.filename = next_filename(im.filename)
|
|
106
|
+
except Exception, ex:
|
|
107
|
+
logger.warning("Got another problem here: next_filename(im.filename) %s", ex)
|
|
108
|
+
if nprocessed % step == 0:
|
|
109
|
+
yield retVal
|
|
110
|
+
# Avoid cyclic references with exc_info ?
|
|
111
|
+
retVal = None
|
|
112
|
+
if abort: break
|
|
113
|
+
nprocessed += 1
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
class file_series(list):
|
|
118
|
+
"""
|
|
119
|
+
represents a series of files to iterate
|
|
120
|
+
has an idea of a current position to do next and prev
|
|
121
|
+
|
|
122
|
+
You also get from the list python superclass:
|
|
123
|
+
append
|
|
124
|
+
count
|
|
125
|
+
extend
|
|
126
|
+
insert
|
|
127
|
+
pop
|
|
128
|
+
remove
|
|
129
|
+
reverse
|
|
130
|
+
sort
|
|
131
|
+
"""
|
|
132
|
+
def __init__(self, list_of_strings):
|
|
133
|
+
"""
|
|
134
|
+
arg should be a list of strings which are filenames
|
|
135
|
+
"""
|
|
136
|
+
super(file_series, self).__init__(list_of_strings)
|
|
137
|
+
# track current position in list
|
|
138
|
+
self._current = 0
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
# methods which return a filename
|
|
142
|
+
|
|
143
|
+
def first(self):
|
|
144
|
+
""" first image in series """
|
|
145
|
+
return self[0]
|
|
146
|
+
|
|
147
|
+
def last(self):
|
|
148
|
+
""" last in series """
|
|
149
|
+
return self[-1]
|
|
150
|
+
|
|
151
|
+
def previous(self):
|
|
152
|
+
""" prev in a sequence"""
|
|
153
|
+
self._current -= 1
|
|
154
|
+
return self[self._current]
|
|
155
|
+
|
|
156
|
+
def current(self):
|
|
157
|
+
""" current position in a sequence """
|
|
158
|
+
return self[self._current]
|
|
159
|
+
|
|
160
|
+
def next(self):
|
|
161
|
+
""" next in a sequence """
|
|
162
|
+
self._current += 1
|
|
163
|
+
return self[self._current]
|
|
164
|
+
|
|
165
|
+
def jump(self, num):
|
|
166
|
+
""" goto a position in sequence """
|
|
167
|
+
assert num < len(self) and num > 0, "num out of range"
|
|
168
|
+
self._current = num
|
|
169
|
+
return self[self._current]
|
|
170
|
+
|
|
171
|
+
def len(self):
|
|
172
|
+
""" number of files"""
|
|
173
|
+
return len(self)
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
# Methods which return a fabioimage
|
|
177
|
+
|
|
178
|
+
def first_image(self):
|
|
179
|
+
""" first image in a sequence """
|
|
180
|
+
return openimage(self.first())
|
|
181
|
+
|
|
182
|
+
def last_image(self):
|
|
183
|
+
""" last image in a sequence """
|
|
184
|
+
return openimage(self.last())
|
|
185
|
+
|
|
186
|
+
def next_image(self):
|
|
187
|
+
""" Return the next image """
|
|
188
|
+
return openimage(self.next())
|
|
189
|
+
|
|
190
|
+
def previous_image(self):
|
|
191
|
+
""" Return the previous image """
|
|
192
|
+
return openimage(self.previous())
|
|
193
|
+
|
|
194
|
+
def jump_image(self, num):
|
|
195
|
+
""" jump to and read image """
|
|
196
|
+
return openimage(self.jump(num))
|
|
197
|
+
|
|
198
|
+
def current_image(self):
|
|
199
|
+
""" current image in sequence """
|
|
200
|
+
return openimage(self.current())
|
|
201
|
+
|
|
202
|
+
# methods which return a file_object
|
|
203
|
+
|
|
204
|
+
def first_object(self):
|
|
205
|
+
""" first image in a sequence """
|
|
206
|
+
return filename_object(self.first())
|
|
207
|
+
|
|
208
|
+
def last_object(self):
|
|
209
|
+
""" last image in a sequence """
|
|
210
|
+
return filename_object(self.last())
|
|
211
|
+
|
|
212
|
+
def next_object(self):
|
|
213
|
+
""" Return the next image """
|
|
214
|
+
return filename_object(self.next())
|
|
215
|
+
|
|
216
|
+
def previous_object(self):
|
|
217
|
+
""" Return the previous image """
|
|
218
|
+
return filename_object(self.previous())
|
|
219
|
+
|
|
220
|
+
def jump_object(self, num):
|
|
221
|
+
""" jump to and read image """
|
|
222
|
+
return filename_object(self.jump(num))
|
|
223
|
+
|
|
224
|
+
def current_object(self):
|
|
225
|
+
""" current image in sequence """
|
|
226
|
+
return filename_object(self.current())
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
class numbered_file_series(file_series):
|
|
232
|
+
"""
|
|
233
|
+
mydata0001.edf = "mydata" + 0001 + ".edf"
|
|
234
|
+
mydata0002.edf = "mydata" + 0002 + ".edf"
|
|
235
|
+
mydata0003.edf = "mydata" + 0003 + ".edf"
|
|
236
|
+
"""
|
|
237
|
+
def __init__(self, stem, first, last, extension,
|
|
238
|
+
digits=4, padding='Y', step=1):
|
|
239
|
+
"""
|
|
240
|
+
stem - first part of the name
|
|
241
|
+
step - in case of every nth file
|
|
242
|
+
padding - possibility for specifying that numbers are not padded
|
|
243
|
+
with zeroes up to digits
|
|
244
|
+
"""
|
|
245
|
+
if padding == 'Y':
|
|
246
|
+
fmt = "%s%0" + str(digits) + "d%s"
|
|
247
|
+
else:
|
|
248
|
+
fmt = "%s%i%s"
|
|
249
|
+
|
|
250
|
+
super(numbered_file_series, self).__init__(
|
|
251
|
+
[ fmt % (stem, i, extension) for i in range(first,
|
|
252
|
+
last + 1,
|
|
253
|
+
step) ])
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
class filename_series:
|
|
257
|
+
""" Much like the others, but created from a string filename """
|
|
258
|
+
def __init__(self, filename):
|
|
259
|
+
""" create from a filename (String)"""
|
|
260
|
+
self.obj = filename_object(filename)
|
|
261
|
+
|
|
262
|
+
def next(self):
|
|
263
|
+
""" increment number """
|
|
264
|
+
self.obj.num += 1
|
|
265
|
+
return self.obj.tostring()
|
|
266
|
+
|
|
267
|
+
def previous(self):
|
|
268
|
+
""" decrement number """
|
|
269
|
+
self.obj.num -= 1
|
|
270
|
+
return self.obj.tostring()
|
|
271
|
+
|
|
272
|
+
def current(self):
|
|
273
|
+
""" return current filename string"""
|
|
274
|
+
return self.obj.tostring()
|
|
275
|
+
|
|
276
|
+
def jump(self, num):
|
|
277
|
+
""" jump to a specific number """
|
|
278
|
+
self.obj.num = num
|
|
279
|
+
return self.obj.tostring()
|
|
280
|
+
|
|
281
|
+
# image methods
|
|
282
|
+
def next_image(self):
|
|
283
|
+
""" returns the next image as a fabioimage """
|
|
284
|
+
return openimage(self.next())
|
|
285
|
+
def prev_image(self):
|
|
286
|
+
""" returns the previos image as a fabioimage """
|
|
287
|
+
return openimage(self.previous())
|
|
288
|
+
def current_image(self):
|
|
289
|
+
""" returns the current image as a fabioimage"""
|
|
290
|
+
return openimage(self.current())
|
|
291
|
+
def jump_image(self, num):
|
|
292
|
+
""" returns the image number as a fabioimage"""
|
|
293
|
+
return openimage(self.jump(num))
|
|
294
|
+
# object methods
|
|
295
|
+
def next_object(self):
|
|
296
|
+
""" returns the next filename as a fabio.filename_object"""
|
|
297
|
+
self.obj.num += 1
|
|
298
|
+
return self.obj
|
|
299
|
+
def previous_object(self):
|
|
300
|
+
""" returns the previous filename as a fabio.filename_object"""
|
|
301
|
+
self.obj.num -= 1
|
|
302
|
+
return self.obj
|
|
303
|
+
def current_object(self):
|
|
304
|
+
""" returns the current filename as a fabio.filename_object"""
|
|
305
|
+
return self.obj
|
|
306
|
+
def jump_object(self, num):
|
|
307
|
+
""" returns the filename num as a fabio.filename_object"""
|
|
308
|
+
self.obj.num = num
|
|
309
|
+
return self.obj
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
|
|
Binary file
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
## Automatically adapted for numpy.oldnumeric Oct 05, 2007 by alter_code1.py
|
|
2
|
+
|
|
3
|
+
#!/usr/bin/env python
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
Author: Andy Hammersley, ESRF
|
|
7
|
+
Translation into python/fabio: Jon Wright, ESRF
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import numpy
|
|
11
|
+
|
|
12
|
+
from fabioimage import fabioimage
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class fit2dmaskimage(fabioimage):
|
|
16
|
+
""" Read and try to write Andy Hammersley's mask format """
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _readheader(self, infile):
|
|
20
|
+
"""
|
|
21
|
+
Read in a header from an already open file
|
|
22
|
+
"""
|
|
23
|
+
# 1024 bytes gives 256x32 bit integers
|
|
24
|
+
header = infile.read(1024)
|
|
25
|
+
for i, j in [ ("M", 0),
|
|
26
|
+
("A", 4),
|
|
27
|
+
("S", 8),
|
|
28
|
+
("K", 12) ]:
|
|
29
|
+
if header[j] != i:
|
|
30
|
+
raise Exception("Not a fit2d mask file")
|
|
31
|
+
fit2dhdr = numpy.fromstring(header, numpy.int32)
|
|
32
|
+
self.dim1 = fit2dhdr[4] # 1 less than Andy's fortran
|
|
33
|
+
self.dim2 = fit2dhdr[5]
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def read(self, fname, frame=None):
|
|
37
|
+
"""
|
|
38
|
+
Read in header into self.header and
|
|
39
|
+
the data into self.data
|
|
40
|
+
"""
|
|
41
|
+
fin = self._open(fname)
|
|
42
|
+
self._readheader(fin)
|
|
43
|
+
# Compute image size
|
|
44
|
+
self.bytecode = numpy.uint8
|
|
45
|
+
self.bpp = len(numpy.array(0, self.bytecode).tostring())
|
|
46
|
+
|
|
47
|
+
# integer division
|
|
48
|
+
num_ints = (self.dim1 + 31) // 32
|
|
49
|
+
total = self.dim2 * num_ints * 4
|
|
50
|
+
data = fin.read(total)
|
|
51
|
+
assert len(data) == total
|
|
52
|
+
fin.close()
|
|
53
|
+
|
|
54
|
+
# Now to unpack it
|
|
55
|
+
data = numpy.fromstring(data, numpy.uint8)
|
|
56
|
+
data = numpy.reshape(data, (self.dim2, num_ints * 4))
|
|
57
|
+
|
|
58
|
+
result = numpy.zeros((self.dim2, num_ints * 4 * 8), numpy.uint8)
|
|
59
|
+
|
|
60
|
+
# Unpack using bitwise comparisons to 2**n
|
|
61
|
+
bits = numpy.ones((1), numpy.uint8)
|
|
62
|
+
for i in range(8):
|
|
63
|
+
temp = numpy.bitwise_and(bits, data)
|
|
64
|
+
result[:, i::8] = temp.astype(numpy.uint8)
|
|
65
|
+
bits = bits * 2
|
|
66
|
+
# Extra rows needed for packing odd dimensions
|
|
67
|
+
spares = num_ints * 4 * 8 - self.dim1
|
|
68
|
+
if spares == 0:
|
|
69
|
+
self.data = numpy.where(result == 0, 0, 1)
|
|
70
|
+
else:
|
|
71
|
+
self.data = numpy.where(result[:, :-spares] == 0, 0, 1)
|
|
72
|
+
# Transpose appears to be needed to match edf reader (scary??)
|
|
73
|
+
# self.data = numpy.transpose(self.data)
|
|
74
|
+
self.data = numpy.reshape(self.data.astype(numpy.uint16),
|
|
75
|
+
(self.dim2, self.dim1))
|
|
76
|
+
self.pilimage = None
|
|
77
|
+
return self
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def write(self, fname):
|
|
82
|
+
"""
|
|
83
|
+
Try to write a file
|
|
84
|
+
check we can write zipped also
|
|
85
|
+
mimics that fabian was writing uint16 (we sometimes want floats)
|
|
86
|
+
"""
|
|
87
|
+
raise Exception("Not implemented yet")
|
|
88
|
+
|
|
89
|
+
@staticmethod
|
|
90
|
+
def checkData(data=None):
|
|
91
|
+
if data is None:
|
|
92
|
+
return None
|
|
93
|
+
else:
|
|
94
|
+
return data.astype(int)
|
|
Binary file
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
Read the fit2d ascii image output
|
|
5
|
+
+ Jon Wright, ESRF
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import numpy
|
|
9
|
+
|
|
10
|
+
from fabioimage import fabioimage
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class fit2dspreadsheetimage(fabioimage):
|
|
16
|
+
"""
|
|
17
|
+
Read a fit2d ascii format
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
def _readheader(self, infile):
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
TODO : test for minimal attributes?
|
|
24
|
+
"""
|
|
25
|
+
line = infile.readline()
|
|
26
|
+
try:
|
|
27
|
+
items = line.split()
|
|
28
|
+
xdim = int(items[0])
|
|
29
|
+
ydim = int(items[1])
|
|
30
|
+
except:
|
|
31
|
+
raise
|
|
32
|
+
self.header['title'] = line
|
|
33
|
+
self.header['Dim_1'] = xdim
|
|
34
|
+
self.header['Dim_2'] = ydim
|
|
35
|
+
|
|
36
|
+
def read(self, fname, frame=None):
|
|
37
|
+
"""
|
|
38
|
+
Read in header into self.header and
|
|
39
|
+
the data into self.data
|
|
40
|
+
"""
|
|
41
|
+
self.header = {}
|
|
42
|
+
self.resetvals()
|
|
43
|
+
infile = self._open(fname)
|
|
44
|
+
self._readheader(infile)
|
|
45
|
+
# Compute image size
|
|
46
|
+
try:
|
|
47
|
+
self.dim1 = int(self.header['Dim_1'])
|
|
48
|
+
self.dim2 = int(self.header['Dim_2'])
|
|
49
|
+
except:
|
|
50
|
+
raise Exception("file", str(fname) + \
|
|
51
|
+
"is corrupt, cannot read it")
|
|
52
|
+
bytecode = numpy.float32
|
|
53
|
+
|
|
54
|
+
self.bpp = len(numpy.array(0, bytecode).tostring())
|
|
55
|
+
|
|
56
|
+
#now read the data into the array
|
|
57
|
+
try:
|
|
58
|
+
vals = []
|
|
59
|
+
for line in infile.readlines():
|
|
60
|
+
try:
|
|
61
|
+
vals.append([float(x) for x in line.split()])
|
|
62
|
+
except:
|
|
63
|
+
pass
|
|
64
|
+
self.data = numpy.array(vals).astype(bytecode)
|
|
65
|
+
assert self.data.shape == (self.dim2, self.dim1)
|
|
66
|
+
|
|
67
|
+
except:
|
|
68
|
+
raise IOError, "Error reading ascii"
|
|
69
|
+
|
|
70
|
+
self.resetvals()
|
|
71
|
+
# ensure the PIL image is reset
|
|
72
|
+
self.pilimage = None
|
|
73
|
+
return self
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
if __name__ == "__main__":
|
|
77
|
+
import sys, time
|
|
78
|
+
start = time.time()
|
|
79
|
+
img = fit2dspreadsheetimage()
|
|
80
|
+
img.read(sys.argv[1])
|
|
81
|
+
print time.time() - start
|
|
82
|
+
print img.dim1, img.dim2, img.data.shape
|
|
83
|
+
from matplotlib.pylab import imshow, show
|
|
84
|
+
imshow(img.data.T)
|
|
85
|
+
show()
|
|
Binary file
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
"""
|
|
3
|
+
Authors: Jerome Kieffer, ESRF
|
|
4
|
+
email:jerome.kieffer@esrf.fr
|
|
5
|
+
|
|
6
|
+
kcd images are 2D images written by the old KappaCCD diffractometer built by Nonius in the 1990's
|
|
7
|
+
Based on the edfimage.py parser.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import numpy, logging
|
|
11
|
+
import os, string
|
|
12
|
+
from fabioimage import fabioimage
|
|
13
|
+
logger = logging.getLogger("kcdimage")
|
|
14
|
+
|
|
15
|
+
DATA_TYPES = {"u16" : numpy.uint16 }
|
|
16
|
+
|
|
17
|
+
MINIMUM_KEYS = [
|
|
18
|
+
'ByteOrder',
|
|
19
|
+
'Data type',
|
|
20
|
+
'X dimension',
|
|
21
|
+
'Y dimension',
|
|
22
|
+
'Number of readouts']
|
|
23
|
+
|
|
24
|
+
DEFAULT_VALUES = { "Data type": "u16" }
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class kcdimage(fabioimage):
|
|
30
|
+
"""
|
|
31
|
+
Read the Nonius kcd data format """
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _readheader(self, infile):
|
|
35
|
+
"""
|
|
36
|
+
Read in a header in some KCD format from an already open file
|
|
37
|
+
@
|
|
38
|
+
"""
|
|
39
|
+
oneLine = infile.readline()
|
|
40
|
+
alphanum = string.digits + string.letters + ". "
|
|
41
|
+
asciiHeader = True
|
|
42
|
+
for oneChar in oneLine.strip():
|
|
43
|
+
if not oneChar in alphanum:
|
|
44
|
+
asciiHeader = False
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
if asciiHeader is False:
|
|
48
|
+
# This does not look like an edf file
|
|
49
|
+
logger.warning("First line of %s does not seam to be ascii text!" % infile.name)
|
|
50
|
+
endOfHeaders = False
|
|
51
|
+
while not endOfHeaders:
|
|
52
|
+
oneLine = infile.readline()
|
|
53
|
+
if len(oneLine) > 100:
|
|
54
|
+
endOfHeaders = True
|
|
55
|
+
break
|
|
56
|
+
if oneLine.strip() == "Binned mode":
|
|
57
|
+
oneLine = "Mode = Binned"
|
|
58
|
+
try:
|
|
59
|
+
key, val = oneLine.split('=' , 1)
|
|
60
|
+
except:
|
|
61
|
+
endOfHeaders = True
|
|
62
|
+
break
|
|
63
|
+
key = key.strip()
|
|
64
|
+
self.header_keys.append(key)
|
|
65
|
+
self.header[key] = val.strip()
|
|
66
|
+
missing = []
|
|
67
|
+
for item in MINIMUM_KEYS:
|
|
68
|
+
if item not in self.header_keys:
|
|
69
|
+
missing.append(item)
|
|
70
|
+
if len(missing) > 0:
|
|
71
|
+
logger.debug("KCD file misses the keys " + " ".join(missing))
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def read(self, fname, frame=None):
|
|
75
|
+
"""
|
|
76
|
+
Read in header into self.header and
|
|
77
|
+
the data into self.data
|
|
78
|
+
"""
|
|
79
|
+
self.header = {}
|
|
80
|
+
self.resetvals()
|
|
81
|
+
infile = self._open(fname, "rb")
|
|
82
|
+
self._readheader(infile)
|
|
83
|
+
# Compute image size
|
|
84
|
+
try:
|
|
85
|
+
self.dim1 = int(self.header['X dimension'])
|
|
86
|
+
self.dim2 = int(self.header['Y dimension'])
|
|
87
|
+
except:
|
|
88
|
+
raise Exception("KCD file %s is corrupt, cannot read it" % fname)
|
|
89
|
+
try:
|
|
90
|
+
bytecode = DATA_TYPES[self.header['Data type']]
|
|
91
|
+
self.bpp = len(numpy.array(0, bytecode).tostring())
|
|
92
|
+
except KeyError:
|
|
93
|
+
bytecode = numpy.uint16
|
|
94
|
+
self.bpp = 2
|
|
95
|
+
logger.warning("Defaulting type to uint16")
|
|
96
|
+
try:
|
|
97
|
+
nbReadOut = int(self.header['Number of readouts'])
|
|
98
|
+
except KeyError:
|
|
99
|
+
logger.warning("Defaulting number of ReadOut to 1")
|
|
100
|
+
nbReadOut = 1
|
|
101
|
+
fileSize = os.stat(fname)[6]
|
|
102
|
+
expected_size = self.dim1 * self.dim2 * self.bpp * nbReadOut
|
|
103
|
+
infile.seek(fileSize - expected_size)
|
|
104
|
+
block = infile.read()
|
|
105
|
+
assert len(block) == expected_size
|
|
106
|
+
infile.close()
|
|
107
|
+
|
|
108
|
+
#now read the data into the array
|
|
109
|
+
self.data = numpy.zeros((self.dim2, self.dim1))
|
|
110
|
+
try:
|
|
111
|
+
for i in range(nbReadOut):
|
|
112
|
+
self.data += numpy.reshape(numpy.fromstring(
|
|
113
|
+
block[i * expected_size / nbReadOut:(i + 1) * expected_size / nbReadOut], bytecode),
|
|
114
|
+
[self.dim2, self.dim1])
|
|
115
|
+
except:
|
|
116
|
+
print len(block), bytecode, self.bpp, self.dim2, self.dim1
|
|
117
|
+
raise IOError, \
|
|
118
|
+
'Size spec in kcd-header does not match size of image data field'
|
|
119
|
+
self.bytecode = self.data.dtype.type
|
|
120
|
+
self.resetvals()
|
|
121
|
+
# ensure the PIL image is reset
|
|
122
|
+
self.pilimage = None
|
|
123
|
+
return self
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
@staticmethod
|
|
127
|
+
def checkData(data=None):
|
|
128
|
+
if data is None:
|
|
129
|
+
return None
|
|
130
|
+
else:
|
|
131
|
+
return data.astype(int)
|
|
Binary file
|
|
Binary file
|