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,283 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
#-*- coding: utf8 -*-
|
|
3
|
+
"""
|
|
4
|
+
FabIO class for dealing with TIFF images.
|
|
5
|
+
In facts wraps TiffIO from Armando (available in PyMca) or falls back to PIL
|
|
6
|
+
|
|
7
|
+
Authors: Jérôme Kieffer (jerome.kieffer@esrf.fr)
|
|
8
|
+
Henning O. Sorensen & Erik Knudsen
|
|
9
|
+
Center for Fundamental Research: Metal Structures in Four Dimensions
|
|
10
|
+
Risoe National Laboratory
|
|
11
|
+
Frederiksborgvej 399
|
|
12
|
+
DK-4000 Roskilde
|
|
13
|
+
email:henning.sorensen@risoe.dk
|
|
14
|
+
License: GPLv3+
|
|
15
|
+
"""
|
|
16
|
+
__authors__ = ["Jérôme Kieffer", "Henning O. Sorensen", "Erik Knudsen"]
|
|
17
|
+
__date__ = "11/07/2011"
|
|
18
|
+
__license__ = "GPLv3+"
|
|
19
|
+
__copyright__ = "ESRF, Grenoble & Risoe National Laboratory"
|
|
20
|
+
|
|
21
|
+
import time, logging, struct
|
|
22
|
+
logger = logging.getLogger("tifimage")
|
|
23
|
+
try:
|
|
24
|
+
import Image
|
|
25
|
+
except ImportError:
|
|
26
|
+
logger.warning("PIL is not installed ... trying to do without")
|
|
27
|
+
Image = None
|
|
28
|
+
import numpy
|
|
29
|
+
from fabioimage import fabioimage
|
|
30
|
+
from TiffIO import TiffIO
|
|
31
|
+
|
|
32
|
+
PIL_TO_NUMPY = { "I;16": numpy.uint16,
|
|
33
|
+
"F": numpy.float32,
|
|
34
|
+
"1": numpy.bool,
|
|
35
|
+
"I": numpy.int32,
|
|
36
|
+
"L": numpy.uint8,
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
LITTLE_ENDIAN = 1234
|
|
40
|
+
BIG_ENDIAN = 3412
|
|
41
|
+
|
|
42
|
+
TYPES = {0:'invalid', 1:'byte', 2:'ascii', 3:'short', 4:'long', 5:'rational', 6:'sbyte', 7:'undefined', 8:'sshort', 9:'slong', 10:'srational', 11:'float', 12:'double'}
|
|
43
|
+
|
|
44
|
+
TYPESIZES = {0:0, 1:1, 2:1, 3:2, 4:4, 5:8, 6:1, 7:1, 8:2, 9:4, 10:8, 11:4, 12:8}
|
|
45
|
+
|
|
46
|
+
baseline_tiff_tags = {
|
|
47
|
+
256:'ImageWidth',
|
|
48
|
+
257:'ImageLength',
|
|
49
|
+
306:'DateTime',
|
|
50
|
+
315:'Artist',
|
|
51
|
+
258:'BitsPerSample',
|
|
52
|
+
265:'CellLength',
|
|
53
|
+
264:'CellWidth',
|
|
54
|
+
259:'Compression',
|
|
55
|
+
|
|
56
|
+
262:'PhotometricInterpretation',
|
|
57
|
+
296:'ResolutionUnit',
|
|
58
|
+
282:'XResolution',
|
|
59
|
+
283:'YResolution',
|
|
60
|
+
|
|
61
|
+
278:'RowsPerStrip',
|
|
62
|
+
273:'StripOffset',
|
|
63
|
+
279:'StripByteCounts',
|
|
64
|
+
|
|
65
|
+
270:'ImageDescription',
|
|
66
|
+
271:'Make',
|
|
67
|
+
272:'Model',
|
|
68
|
+
320:'ColorMap',
|
|
69
|
+
305:'Software',
|
|
70
|
+
339:'SampleFormat',
|
|
71
|
+
33432:'Copyright'
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
class tifimage(fabioimage):
|
|
75
|
+
"""
|
|
76
|
+
Images in TIF format
|
|
77
|
+
Wraps TiffIO
|
|
78
|
+
"""
|
|
79
|
+
_need_a_seek_to_read = True
|
|
80
|
+
|
|
81
|
+
def __init__(self, *args, **kwds):
|
|
82
|
+
""" Tifimage constructor adds an nbits member attribute """
|
|
83
|
+
self.nbits = None
|
|
84
|
+
fabioimage.__init__(self, *args, **kwds)
|
|
85
|
+
self.lib = None
|
|
86
|
+
|
|
87
|
+
def _readheader(self, infile):
|
|
88
|
+
"""
|
|
89
|
+
Try to read Tiff images header...
|
|
90
|
+
"""
|
|
91
|
+
# try:
|
|
92
|
+
# self.header = { "filename" : infile.name }
|
|
93
|
+
# except AttributeError:
|
|
94
|
+
# self.header = {}
|
|
95
|
+
#
|
|
96
|
+
# t = Tiff_header(infile.read())
|
|
97
|
+
# self.header = t.header
|
|
98
|
+
# try:
|
|
99
|
+
# self.dim1 = int(self.header['ImageWidth'])
|
|
100
|
+
# self.dim2 = int(self.header['ImageLength'])
|
|
101
|
+
# except (KeyError):
|
|
102
|
+
# logger.warning("image dimensions could not be determined from header tags, trying to go on anyway")
|
|
103
|
+
# read the first 32 bytes to determine size
|
|
104
|
+
header = numpy.fromstring(infile.read(64), numpy.uint16)
|
|
105
|
+
self.dim1 = int(header[9])
|
|
106
|
+
self.dim2 = int(header[15])
|
|
107
|
+
# nbits is not a fabioimage attribute...
|
|
108
|
+
self.nbits = int(header[21]) # number of bits
|
|
109
|
+
|
|
110
|
+
def read(self, fname, frame=None):
|
|
111
|
+
"""
|
|
112
|
+
Wrapper for TiffIO.
|
|
113
|
+
"""
|
|
114
|
+
infile = self._open(fname, "rb")
|
|
115
|
+
self._readheader(infile)
|
|
116
|
+
infile.seek(0)
|
|
117
|
+
self.lib = None
|
|
118
|
+
try:
|
|
119
|
+
tiffIO = TiffIO(infile)
|
|
120
|
+
if tiffIO.getNumberOfImages() > 0:
|
|
121
|
+
#No support for now of multi-frame tiff images
|
|
122
|
+
self.data = tiffIO.getImage(0)
|
|
123
|
+
self.header = tiffIO.getInfo(0)
|
|
124
|
+
except Exception, error:
|
|
125
|
+
logger.warning("Unable to read %s with TiffIO due to %s, trying PIL" % (fname, error))
|
|
126
|
+
else:
|
|
127
|
+
if self.data.ndim == 2:
|
|
128
|
+
self.dim2, self.dim1 = self.data.shape
|
|
129
|
+
elif self.data.ndim == 3:
|
|
130
|
+
self.dim2, self.dim1, ncol = self.data.shape
|
|
131
|
+
logger.warning("Third dimension is the color")
|
|
132
|
+
else:
|
|
133
|
+
logger.warning("dataset has %s dimensions (%s), check for errors !!!!", self.data.ndim, self.data.shape)
|
|
134
|
+
self.lib = "TiffIO"
|
|
135
|
+
|
|
136
|
+
if (self.lib is None):
|
|
137
|
+
if Image:
|
|
138
|
+
try:
|
|
139
|
+
infile.seek(0)
|
|
140
|
+
self.pilimage = Image.open(infile)
|
|
141
|
+
except Exception:
|
|
142
|
+
logger.error("Error in opening %s with PIL" % fname)
|
|
143
|
+
self.lib = None
|
|
144
|
+
infile.seek(0)
|
|
145
|
+
else:
|
|
146
|
+
self.lib = "PIL"
|
|
147
|
+
self.dim1, self.dim2 = self.pilimage.size
|
|
148
|
+
if self.pilimage.mode in PIL_TO_NUMPY:
|
|
149
|
+
self.data = numpy.fromstring(self.pilimage.tostring(), PIL_TO_NUMPY[self.pilimage.mode])
|
|
150
|
+
else: #probably RGB or RGBA images: rely on PIL to convert it to greyscale float.
|
|
151
|
+
self.data = numpy.fromstring(self.pilimage.convert("F").tostring(), numpy.float32)
|
|
152
|
+
self.data.shape = (self.dim2, self.dim1)
|
|
153
|
+
else:
|
|
154
|
+
logger.error("Error in opening %s: no tiff reader managed to read the file.", fname)
|
|
155
|
+
self.lib = None
|
|
156
|
+
infile.seek(0)
|
|
157
|
+
|
|
158
|
+
self.bpp = len(numpy.zeros(1, dtype=self.data.dtype).tostring())
|
|
159
|
+
self.bytecode = self.data.dtype.name
|
|
160
|
+
self.resetvals()
|
|
161
|
+
return self
|
|
162
|
+
|
|
163
|
+
def write(self, fname):
|
|
164
|
+
"""
|
|
165
|
+
Overrides the fabioimage.write method and provides a simple TIFF image writer.
|
|
166
|
+
@param fname: name of the file to save the image to
|
|
167
|
+
@tag_type fname: string or unicode (file?)...
|
|
168
|
+
"""
|
|
169
|
+
tiffIO = TiffIO(fname, mode="w")
|
|
170
|
+
tiffIO.writeImage(self.data, info=self.header, software="fabio.tifimage", date=time.ctime())
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
#define a couple of helper classes here:
|
|
175
|
+
class Tiff_header(object):
|
|
176
|
+
def __init__(self, string):
|
|
177
|
+
if string[:4] == "II\x2a\x00":
|
|
178
|
+
self.byteorder = LITTLE_ENDIAN
|
|
179
|
+
elif string[:4] == 'MM\x00\x2a':
|
|
180
|
+
self.byteorder = BIG_ENDIAN
|
|
181
|
+
else:
|
|
182
|
+
logger.warning("Warning: This does not appear to be a tiff file")
|
|
183
|
+
#the next two bytes contains the offset of the oth IFD
|
|
184
|
+
offset_first_ifd = struct.unpack_from("h", string[4:])[0]
|
|
185
|
+
self.ifd = [Image_File_Directory()]
|
|
186
|
+
offset_next = self.ifd[0].unpack(string, offset_first_ifd)
|
|
187
|
+
while (offset_next != 0):
|
|
188
|
+
self.ifd.append(Image_File_Directory())
|
|
189
|
+
offset_next = self.ifd[-1].unpack(string, offset_next)
|
|
190
|
+
|
|
191
|
+
self.header = {}
|
|
192
|
+
#read the values of the header items into a dictionary
|
|
193
|
+
for entry in self.ifd[0].entries:
|
|
194
|
+
if entry.tag in baseline_tiff_tags.keys():
|
|
195
|
+
self.header[baseline_tiff_tags[entry.tag]] = entry.val
|
|
196
|
+
else:
|
|
197
|
+
self.header[entry.tag] = entry.val
|
|
198
|
+
|
|
199
|
+
class Image_File_Directory(object):
|
|
200
|
+
def __init__(self, instring=None, offset= -1):
|
|
201
|
+
self.entries = []
|
|
202
|
+
self.offset = offset
|
|
203
|
+
self.count = None
|
|
204
|
+
|
|
205
|
+
def unpack(self, instring, offset= -1):
|
|
206
|
+
if (offset == -1): offset = self.offset
|
|
207
|
+
|
|
208
|
+
strInput = instring[offset:]
|
|
209
|
+
self.count = struct.unpack_from("H", strInput[:2])[0]
|
|
210
|
+
#0th IFD contains count-1 entries (count includes the adress of the next IFD)
|
|
211
|
+
for i in range(self.count - 1):
|
|
212
|
+
e = Image_File_Directory_entry().unpack(strInput[2 + 12 * (i + 1):])
|
|
213
|
+
if (e != None):
|
|
214
|
+
self.entries.append(e)
|
|
215
|
+
#extract data associated with tags
|
|
216
|
+
for e in self.entries:
|
|
217
|
+
if (e.val == None):
|
|
218
|
+
e.extract_data(instring)
|
|
219
|
+
#do we have some more ifds in this file
|
|
220
|
+
offset_next = struct.unpack_from("L", instring[offset + 2 + self.count * 12:])[0]
|
|
221
|
+
return offset_next
|
|
222
|
+
|
|
223
|
+
class Image_File_Directory_entry(object):
|
|
224
|
+
def __init__(self, tag=0, tag_type=0, count=0, offset=0):
|
|
225
|
+
self.tag = tag
|
|
226
|
+
self.tag_type = tag_type
|
|
227
|
+
self.count = count
|
|
228
|
+
self.val_offset = offset
|
|
229
|
+
self.val = None
|
|
230
|
+
|
|
231
|
+
def unpack(self, strInput):
|
|
232
|
+
idfentry = strInput[:12]
|
|
233
|
+
################################################################################
|
|
234
|
+
# # TOFIX: How is it possible that HHL (2+2+4 bytes has a size of )
|
|
235
|
+
################################################################################
|
|
236
|
+
(tag, tag_type, count) = struct.unpack_from("HHL", idfentry)
|
|
237
|
+
self.tag = tag
|
|
238
|
+
self.count = count
|
|
239
|
+
self.tag_type = tag_type
|
|
240
|
+
self.val = None
|
|
241
|
+
if (count <= 0):
|
|
242
|
+
logger.warning("Tag # %s has an invalid count: %s. Tag is ignored" % (tag, count))
|
|
243
|
+
return
|
|
244
|
+
if(count * TYPESIZES[tag_type] <= 4):
|
|
245
|
+
self.val_offset = 8
|
|
246
|
+
self.extract_data(idfentry)
|
|
247
|
+
self.val_offset = None
|
|
248
|
+
else:
|
|
249
|
+
self.val_offset = struct.unpack_from("L", idfentry[8:])[0]
|
|
250
|
+
return self
|
|
251
|
+
|
|
252
|
+
def extract_data(self, full_string):
|
|
253
|
+
tag_type = self.tag_type
|
|
254
|
+
if (TYPES[tag_type] == 'byte'):
|
|
255
|
+
self.val = struct.unpack_from("B", full_string[self.val_offset:])[0]
|
|
256
|
+
elif (TYPES[tag_type] == 'short'):
|
|
257
|
+
self.val = struct.unpack_from("H", full_string[self.val_offset:])[0]
|
|
258
|
+
elif (TYPES[tag_type] == 'long'):
|
|
259
|
+
self.val = struct.unpack_from("L", full_string[self.val_offset:])[0]
|
|
260
|
+
elif (TYPES[tag_type] == 'sbyte'):
|
|
261
|
+
self.val = struct.unpack_from("b", full_string[self.val_offset:])[0]
|
|
262
|
+
elif (TYPES[tag_type] == 'sshort'):
|
|
263
|
+
self.val = struct.unpack_from("h", full_string[self.val_offset:])[0]
|
|
264
|
+
elif (TYPES[tag_type] == 'slong'):
|
|
265
|
+
self.val = struct.unpack_from("l", full_string[self.val_offset:])[0]
|
|
266
|
+
elif (TYPES[tag_type] == 'ascii'):
|
|
267
|
+
self.val = full_string[self.val_offset:self.val_offset + max(self.count, 4)]
|
|
268
|
+
elif (TYPES[tag_type] == 'rational'):
|
|
269
|
+
if self.val_offset != None:
|
|
270
|
+
(num, den) = struct.unpack_from("LL", full_string[self.val_offset:])
|
|
271
|
+
print self.val_offset
|
|
272
|
+
self.val = float(num) / den
|
|
273
|
+
elif (TYPES[tag_type] == 'srational'):
|
|
274
|
+
if self.val_offset != None:
|
|
275
|
+
(num, den) = struct.unpack_from("ll", full_string[self.val_offset:])
|
|
276
|
+
self.val = float(num) / den,
|
|
277
|
+
elif (TYPES[tag_type] == 'float'):
|
|
278
|
+
self.val = struct.unpack_from("f", full_string[self.val_offset:])[0]
|
|
279
|
+
elif (TYPES[tag_type] == 'double'):
|
|
280
|
+
if self.val_offset != None:
|
|
281
|
+
self.val = struct.unpack_from("d", full_string[self.val_offset:])[0]
|
|
282
|
+
else:
|
|
283
|
+
logger.warning("unrecognized type of strInputentry self: %s tag: %s type: %s TYPE: %s" % (self, baseline_tiff_tags[self.tag], self.tag_type, TYPES[tag_type]))
|
|
Binary file
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# coding: utf8
|
|
3
|
+
"""
|
|
4
|
+
Authors: Jérôme Kieffer, ESRF
|
|
5
|
+
email:jerome.kieffer@esrf.fr
|
|
6
|
+
|
|
7
|
+
XSDimge are XML files containing numpy arrays
|
|
8
|
+
"""
|
|
9
|
+
__author__ = "Jérôme Kieffer"
|
|
10
|
+
__contact__ = "jerome.kieffer@esrf.eu"
|
|
11
|
+
__license__ = "GPLv3+"
|
|
12
|
+
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
|
|
13
|
+
|
|
14
|
+
import logging, numpy
|
|
15
|
+
logger = logging.getLogger("xsdimage")
|
|
16
|
+
from fabioimage import fabioimage
|
|
17
|
+
import base64, hashlib
|
|
18
|
+
try:
|
|
19
|
+
from lxml import etree
|
|
20
|
+
except ImportError:
|
|
21
|
+
logger.warning("lxml library is probably not part of your python installation: disabling xsdimage format")
|
|
22
|
+
etree = None
|
|
23
|
+
|
|
24
|
+
class xsdimage(fabioimage):
|
|
25
|
+
"""
|
|
26
|
+
Read the XSDataImage XML File data format
|
|
27
|
+
"""
|
|
28
|
+
def __init__(self, data=None, header=None, fname=None):
|
|
29
|
+
"""
|
|
30
|
+
Constructor of the class XSDataImage.
|
|
31
|
+
|
|
32
|
+
@param _strFilename: the name of the file to open
|
|
33
|
+
@type _strFilename: string
|
|
34
|
+
"""
|
|
35
|
+
fabioimage.__init__(self, data=data, header=header)
|
|
36
|
+
self.dims = []
|
|
37
|
+
self.size = None
|
|
38
|
+
self.coding = None
|
|
39
|
+
self.dtype = None
|
|
40
|
+
self.rawData = None
|
|
41
|
+
self.md5 = None
|
|
42
|
+
if fname is not None:
|
|
43
|
+
self.filename = fname
|
|
44
|
+
self.read(fname)
|
|
45
|
+
|
|
46
|
+
def read(self, fname, frame=None):
|
|
47
|
+
"""
|
|
48
|
+
"""
|
|
49
|
+
self.header = {}
|
|
50
|
+
self.resetvals()
|
|
51
|
+
self.filename = fname
|
|
52
|
+
infile = self._open(fname, "rb")
|
|
53
|
+
self._readheader(infile)
|
|
54
|
+
|
|
55
|
+
try:
|
|
56
|
+
self.dim1, self.dim2 = self.dims[:2]
|
|
57
|
+
except:
|
|
58
|
+
raise IOError("XSD file %s is corrupt, no dimensions in it" % fname)
|
|
59
|
+
try:
|
|
60
|
+
self.bytecode = numpy.dtype(self.dtype).type
|
|
61
|
+
self.bpp = len(numpy.array(0, self.bytecode).tostring())
|
|
62
|
+
except TypeError:
|
|
63
|
+
self.bytecode = numpy.int32
|
|
64
|
+
self.bpp = 32
|
|
65
|
+
logger.warning("Defaulting type to int32")
|
|
66
|
+
|
|
67
|
+
exp_size = 1
|
|
68
|
+
for i in self.dims:
|
|
69
|
+
exp_size *= i
|
|
70
|
+
assert exp_size == self.size
|
|
71
|
+
|
|
72
|
+
decData = None
|
|
73
|
+
if self.coding == "base64":
|
|
74
|
+
decData = base64.b64decode(self.rawData)
|
|
75
|
+
elif self.coding == "base32":
|
|
76
|
+
decData = base64.b32decode(self.rawData)
|
|
77
|
+
elif self.coding == "base16":
|
|
78
|
+
decData = base64.b16decode(self.rawData)
|
|
79
|
+
else:
|
|
80
|
+
logger.warning("Unable to recognize the encoding of the data !!! got %s, expected base64, base32 or base16, I assume it is base64 " % self.coding)
|
|
81
|
+
decData = base64.b64decode(self.rawData)
|
|
82
|
+
if self.md5:
|
|
83
|
+
assert hashlib.md5(decData).hexdigest() == self.md5
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
self.data = numpy.fromstring(decData, dtype=self.bytecode).reshape(tuple(self.dims))
|
|
87
|
+
if not numpy.little_endian: #by default little endian
|
|
88
|
+
self.data.byteswap(inplace=True)
|
|
89
|
+
self.resetvals()
|
|
90
|
+
# # ensure the PIL image is reset
|
|
91
|
+
self.pilimage = None
|
|
92
|
+
return self
|
|
93
|
+
|
|
94
|
+
def _readheader(self, infile):
|
|
95
|
+
"""
|
|
96
|
+
Read all headers in a file and populate self.header
|
|
97
|
+
data is not yet populated
|
|
98
|
+
@type infile: file object open in read mode
|
|
99
|
+
"""
|
|
100
|
+
xml = etree.parse(infile)
|
|
101
|
+
self.dims = []
|
|
102
|
+
for i in xml.xpath("//shape"):
|
|
103
|
+
try:
|
|
104
|
+
self.dims.append(int(i.text))
|
|
105
|
+
except ValueError, error:
|
|
106
|
+
logger.warning("%s Shape: Unable to convert %s to integer in %s" % (error, i.text, i))
|
|
107
|
+
for i in xml.xpath("//size"):
|
|
108
|
+
try:
|
|
109
|
+
self.size = int(i.text)
|
|
110
|
+
except Exception, error:#IGNORE:W0703
|
|
111
|
+
logger.warning("%s Size: Unable to convert %s to integer in %s" % (error, i.text, i))
|
|
112
|
+
self.dtype = None
|
|
113
|
+
for i in xml.xpath("//dtype"):
|
|
114
|
+
self.dtype = i.text
|
|
115
|
+
self.coding = None
|
|
116
|
+
for i in xml.xpath("//coding"):
|
|
117
|
+
j = i.find("value")
|
|
118
|
+
if j is not None:
|
|
119
|
+
self.coding = j.text
|
|
120
|
+
self.rawData = None
|
|
121
|
+
for i in xml.xpath("//data"):
|
|
122
|
+
self.rawData = i.text
|
|
123
|
+
self.md5 = None
|
|
124
|
+
for i in xml.xpath("//md5sum"):
|
|
125
|
+
j = i.find("value")
|
|
126
|
+
if j is not None:
|
|
127
|
+
self.md5 = j.text
|
|
128
|
+
|
|
129
|
+
if etree is None:
|
|
130
|
+
xsdimage = None
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
Binary file
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Metadata-Version: 1.0
|
|
2
|
+
Name: fabio
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Image IO for fable
|
|
5
|
+
Home-page: http://fable.wiki.sourceforge.net/fabio
|
|
6
|
+
Author: Henning Sorensen, Erik Knudsen, Jon Wright, Regis Perdreau, Jérôme Kieffer and Gael Goret
|
|
7
|
+
Author-email: fable-talk@lists.sourceforge.net
|
|
8
|
+
License: UNKNOWN
|
|
9
|
+
Download-URL: http://sourceforge.net/projects/fable/files/fabio/0.0.9
|
|
10
|
+
Description: UNKNOWN
|
|
11
|
+
Platform: UNKNOWN
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
.gitignore
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.TXT
|
|
4
|
+
build-deb.sh
|
|
5
|
+
setup.py
|
|
6
|
+
stdeb.cfg
|
|
7
|
+
debian-orig/changelog
|
|
8
|
+
debian-orig/compat
|
|
9
|
+
debian-orig/control
|
|
10
|
+
debian-orig/copyright
|
|
11
|
+
debian-orig/rules
|
|
12
|
+
debian-orig/watch
|
|
13
|
+
debian-orig/source/format
|
|
14
|
+
fabio-src/GEimage.py
|
|
15
|
+
fabio-src/GEimage_old.py
|
|
16
|
+
fabio-src/HiPiCimage.py
|
|
17
|
+
fabio-src/OXDimage.py
|
|
18
|
+
fabio-src/TiffIO.py
|
|
19
|
+
fabio-src/__init__.py
|
|
20
|
+
fabio-src/adscimage.py
|
|
21
|
+
fabio-src/binaryimage.py
|
|
22
|
+
fabio-src/bruker100image.py
|
|
23
|
+
fabio-src/brukerimage.py
|
|
24
|
+
fabio-src/cbfimage.py
|
|
25
|
+
fabio-src/compression.py
|
|
26
|
+
fabio-src/converters.py
|
|
27
|
+
fabio-src/datIO.py
|
|
28
|
+
fabio-src/dm3image.py
|
|
29
|
+
fabio-src/edfimage.py
|
|
30
|
+
fabio-src/fabioimage.py
|
|
31
|
+
fabio-src/fabioutils.py
|
|
32
|
+
fabio-src/file_series.py
|
|
33
|
+
fabio-src/fit2dmaskimage.py
|
|
34
|
+
fabio-src/fit2dspreadsheetimage.py
|
|
35
|
+
fabio-src/kcdimage.py
|
|
36
|
+
fabio-src/mar345image.py
|
|
37
|
+
fabio-src/marccdimage.py
|
|
38
|
+
fabio-src/openimage.py
|
|
39
|
+
fabio-src/pilatusimage.py
|
|
40
|
+
fabio-src/pnmimage.py
|
|
41
|
+
fabio-src/readbytestream.py
|
|
42
|
+
fabio-src/tifimage.py
|
|
43
|
+
fabio-src/xsdimage.py
|
|
44
|
+
src/byte_offset.c
|
|
45
|
+
src/byte_offset.html
|
|
46
|
+
src/byte_offset.pyx
|
|
47
|
+
src/ccp4_pack.c
|
|
48
|
+
src/ccp4_pack.h
|
|
49
|
+
src/cf_iomodule.c
|
|
50
|
+
src/columnfile.c
|
|
51
|
+
src/columnfile.h
|
|
52
|
+
src/mar345_IO.c
|
|
53
|
+
src/mar345_IO.html
|
|
54
|
+
src/mar345_IO.pyx
|
|
55
|
+
src/pack_c.c
|
|
56
|
+
src/pack_c.h
|
|
57
|
+
src/setup.py
|
|
58
|
+
src/stdint.h
|
|
59
|
+
test/__init__.py
|
|
60
|
+
test/benchheader.py
|
|
61
|
+
test/coral31_benchheaders
|
|
62
|
+
test/coral31_benchmark
|
|
63
|
+
test/eeepc-jonathanw_benchheaders
|
|
64
|
+
test/eeepc-jonathanw_benchmark
|
|
65
|
+
test/esrflinux1-1a_benchheaders
|
|
66
|
+
test/esrflinux1-1a_benchmark
|
|
67
|
+
test/get_test_images.sh
|
|
68
|
+
test/lapwright_benchheaders
|
|
69
|
+
test/lapwright_benchmark
|
|
70
|
+
test/lintaillefer_benchHeaders
|
|
71
|
+
test/profile_compressed.py
|
|
72
|
+
test/testGEimage.py
|
|
73
|
+
test/testOXDimage.py
|
|
74
|
+
test/testXSDimage.py
|
|
75
|
+
test/test_all.bat
|
|
76
|
+
test/test_all.py
|
|
77
|
+
test/test_all.sh
|
|
78
|
+
test/test_all_images.py
|
|
79
|
+
test/test_file_series.py
|
|
80
|
+
test/test_filename_steps.py
|
|
81
|
+
test/test_flat_binary.py
|
|
82
|
+
test/testadscimage.py
|
|
83
|
+
test/testbrukerimage.py
|
|
84
|
+
test/testcbfimage.py
|
|
85
|
+
test/testcompression.py
|
|
86
|
+
test/testedfimage.py
|
|
87
|
+
test/testfabioimage.py
|
|
88
|
+
test/testfilenames.py
|
|
89
|
+
test/testfit2dmaskimage.py
|
|
90
|
+
test/testheadernotsingleton.py
|
|
91
|
+
test/testkcdimage.py
|
|
92
|
+
test/testmar345image.py
|
|
93
|
+
test/testmccdimage.py
|
|
94
|
+
test/testopenheader.py
|
|
95
|
+
test/testopenimage.py
|
|
96
|
+
test/testtifgz.py
|
|
97
|
+
test/testtifimage.py
|
|
98
|
+
test/utilstest.py
|
|
99
|
+
test/win32_benchheaders
|
|
100
|
+
test/win32_benchmark
|
|
101
|
+
test/profile/benchheader.py
|
|
102
|
+
test/profile/coral31_benchheaders
|
|
103
|
+
test/profile/coral31_benchmark
|
|
104
|
+
test/profile/eeepc-jonathanw_benchheaders
|
|
105
|
+
test/profile/eeepc-jonathanw_benchmark
|
|
106
|
+
test/profile/esrflinux1-1a_benchheaders
|
|
107
|
+
test/profile/esrflinux1-1a_benchmark
|
|
108
|
+
test/profile/get_test_images.sh
|
|
109
|
+
test/profile/lapwright_benchheaders
|
|
110
|
+
test/profile/lapwright_benchmark
|
|
111
|
+
test/profile/lintaillefer_benchHeaders
|
|
112
|
+
test/profile/profile_compressed.py
|
|
113
|
+
test/profile/win32_benchheaders
|
|
114
|
+
test/profile/win32_benchmark
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|