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,442 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
#coding: utf8
|
|
3
|
+
|
|
4
|
+
from __future__ import with_statement
|
|
5
|
+
__doc__ = """
|
|
6
|
+
Reads Oxford Diffraction Sapphire 3 images
|
|
7
|
+
|
|
8
|
+
Authors: 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:erik.knudsen@risoe.dk
|
|
14
|
+
|
|
15
|
+
+ Jon Wright, ESRF
|
|
16
|
+
+ Gaël Goret, ESRF
|
|
17
|
+
+ Jérôme Kieffer, ESRF
|
|
18
|
+
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
import time, logging, struct
|
|
22
|
+
logger = logging.getLogger("OXDimage")
|
|
23
|
+
import numpy
|
|
24
|
+
from fabioimage import fabioimage
|
|
25
|
+
from compression import decTY1, compTY1
|
|
26
|
+
|
|
27
|
+
try:
|
|
28
|
+
from numpy import rad2deg, deg2rad
|
|
29
|
+
except ImportError: #naive implementation for very old numpy (v1.0.1 on MacOSX from Risoe)
|
|
30
|
+
rad2deg = lambda x: 180.0 * x / numpy.pi
|
|
31
|
+
deg2rad = lambda x: x * numpy.pi / 180.
|
|
32
|
+
|
|
33
|
+
DETECTOR_TYPES = {0: 'Sapphire/KM4CCD (1x1: 0.06mm, 2x2: 0.12mm)',
|
|
34
|
+
1: 'Sapphire2-Kodak (1x1: 0.06mm, 2x2: 0.12mm)',
|
|
35
|
+
2: 'Sapphire3-Kodak (1x1: 0.03mm, 2x2: 0.06mm, 4x4: 0.12mm)',
|
|
36
|
+
3: 'Onyx-Kodak (1x1: 0.06mm, 2x2: 0.12mm, 4x4: 0.24mm)',
|
|
37
|
+
4: 'Unknown Oxford diffraction detector'}
|
|
38
|
+
|
|
39
|
+
DEFAULT_HEADERS = {'Header Version': 'OD SAPPHIRE 3.0',
|
|
40
|
+
'Compression': "TY1",
|
|
41
|
+
'Header Size In Bytes': 5120,
|
|
42
|
+
"ASCII Section size in Byte": 256,
|
|
43
|
+
"General Section size in Byte": 512,
|
|
44
|
+
"Special Section size in Byte": 768,
|
|
45
|
+
"KM4 Section size in Byte": 1024,
|
|
46
|
+
"Statistic Section in Byte": 512,
|
|
47
|
+
"History Section in Byte": 2048,
|
|
48
|
+
'NSUPPLEMENT':0
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
class OXDimage(fabioimage):
|
|
52
|
+
"""
|
|
53
|
+
Oxford Diffraction Sapphire 3 images reader/writer class
|
|
54
|
+
"""
|
|
55
|
+
def _readheader(self, infile):
|
|
56
|
+
|
|
57
|
+
infile.seek(0)
|
|
58
|
+
|
|
59
|
+
# Ascii header part 256 byes long
|
|
60
|
+
self.header['Header Version'] = infile.readline()[:-2]
|
|
61
|
+
block = infile.readline()
|
|
62
|
+
self.header['Compression'] = block[12:15]
|
|
63
|
+
block = infile.readline()
|
|
64
|
+
self.header['NX'] = int(block[3:7])
|
|
65
|
+
self.header['NY'] = int(block[11:15])
|
|
66
|
+
self.header['OI'] = int(block[19:26])
|
|
67
|
+
self.header['OL'] = int(block[30:37])
|
|
68
|
+
block = infile.readline()
|
|
69
|
+
self.header['Header Size In Bytes'] = int(block[8:15])
|
|
70
|
+
self.header['General Section size in Byte'] = int(block[19:26])
|
|
71
|
+
self.header['Special Section size in Byte'] = int(block[30:37])
|
|
72
|
+
self.header['KM4 Section size in Byte'] = int(block[41:48])
|
|
73
|
+
self.header['Statistic Section in Byte'] = int(block[52:59])
|
|
74
|
+
self.header['History Section in Byte'] = int(block[63:])
|
|
75
|
+
block = infile.readline()
|
|
76
|
+
self.header['NSUPPLEMENT'] = int(block[12:19])
|
|
77
|
+
block = infile.readline()
|
|
78
|
+
self.header['Time'] = block[5:29]
|
|
79
|
+
self.header["ASCII Section size in Byte"] = self.header['Header Size In Bytes']\
|
|
80
|
+
- self.header['General Section size in Byte']\
|
|
81
|
+
- self.header['Special Section size in Byte'] \
|
|
82
|
+
- self.header['KM4 Section size in Byte']\
|
|
83
|
+
- self.header['Statistic Section in Byte']\
|
|
84
|
+
- self.header['History Section in Byte']\
|
|
85
|
+
# Skip to general section (NG) 512 byes long <<<<<<"
|
|
86
|
+
infile.seek(self.header["ASCII Section size in Byte"])
|
|
87
|
+
block = infile.read(self.header['General Section size in Byte'])
|
|
88
|
+
self.header['Binning in x'] = numpy.fromstring(block[0:2], numpy.uint16)[0]
|
|
89
|
+
self.header['Binning in y'] = numpy.fromstring(block[2:4], numpy.uint16)[0]
|
|
90
|
+
self.header['Detector size x'] = numpy.fromstring(block[22:24], numpy.uint16)[0]
|
|
91
|
+
self.header['Detector size y'] = numpy.fromstring(block[24:26], numpy.uint16)[0]
|
|
92
|
+
self.header['Pixels in x'] = numpy.fromstring(block[26:28], numpy.uint16)[0]
|
|
93
|
+
self.header['Pixels in y'] = numpy.fromstring(block[28:30], numpy.uint16)[0]
|
|
94
|
+
self.header['No of pixels'] = numpy.fromstring(block[36:40], numpy.uint32)[0]
|
|
95
|
+
|
|
96
|
+
# Speciel section (NS) 768 bytes long
|
|
97
|
+
block = infile.read(self.header['Special Section size in Byte'])
|
|
98
|
+
self.header['Gain'] = numpy.fromstring(block[56:64], numpy.float)[0]
|
|
99
|
+
self.header['Overflows flag'] = numpy.fromstring(block[464:466], numpy.int16)[0]
|
|
100
|
+
self.header['Overflow after remeasure flag'] = numpy.fromstring(block[466:468], numpy.int16)[0]
|
|
101
|
+
self.header['Overflow threshold'] = numpy.fromstring(block[472:476], numpy.int32)[0]
|
|
102
|
+
self.header['Exposure time in sec'] = numpy.fromstring(block[480:488], numpy.float)[0]
|
|
103
|
+
self.header['Overflow time in sec'] = numpy.fromstring(block[488:496], numpy.float)[0]
|
|
104
|
+
self.header['Monitor counts of raw image 1'] = numpy.fromstring(block[528:532], numpy.int32)[0]
|
|
105
|
+
self.header['Monitor counts of raw image 2'] = numpy.fromstring(block[532:536], numpy.int32)[0]
|
|
106
|
+
self.header['Monitor counts of overflow raw image 1'] = numpy.fromstring(block[536:540], numpy.int32)[0]
|
|
107
|
+
self.header['Monitor counts of overflow raw image 2'] = numpy.fromstring(block[540:544], numpy.int32)[0]
|
|
108
|
+
self.header['Unwarping'] = numpy.fromstring(block[544:548], numpy.int32)[0]
|
|
109
|
+
self.header['Detector type'] = DETECTOR_TYPES[numpy.fromstring(block[548:552], numpy.int32)[0]]
|
|
110
|
+
self.header['Real pixel size x (mm)'] = numpy.fromstring(block[568:576], numpy.float)[0]
|
|
111
|
+
self.header['Real pixel size y (mm)'] = numpy.fromstring(block[576:584], numpy.float)[0]
|
|
112
|
+
|
|
113
|
+
# KM4 goniometer section (NK) 1024 bytes long
|
|
114
|
+
block = infile.read(self.header['KM4 Section size in Byte'])
|
|
115
|
+
# Spatial correction file
|
|
116
|
+
self.header['Spatial correction file'] = block[26:272].strip("\x00")
|
|
117
|
+
self.header['Spatial correction file date'] = block[0:26].strip("\x00")
|
|
118
|
+
# Angles are in steps due to stepper motors - conversion factor RAD
|
|
119
|
+
# angle[0] = omega, angle[1] = theta, angle[2] = kappa, angle[3] = phi,
|
|
120
|
+
start_angles_step = numpy.fromstring(block[284:304], numpy.int32)
|
|
121
|
+
end_angles_step = numpy.fromstring(block[324:344], numpy.int32)
|
|
122
|
+
step2rad = numpy.fromstring(block[368:408], numpy.float)
|
|
123
|
+
step_angles_deg = rad2deg(step2rad)
|
|
124
|
+
# calc angles
|
|
125
|
+
start_angles_deg = start_angles_step * step_angles_deg
|
|
126
|
+
end_angles_deg = end_angles_step * step_angles_deg
|
|
127
|
+
self.header['Omega start in deg'] = start_angles_deg[0]
|
|
128
|
+
self.header['Theta start in deg'] = start_angles_deg[1]
|
|
129
|
+
self.header['Kappa start in deg'] = start_angles_deg[2]
|
|
130
|
+
self.header['Phi start in deg'] = start_angles_deg[3]
|
|
131
|
+
self.header['Omega end in deg'] = end_angles_deg[0]
|
|
132
|
+
self.header['Theta end in deg'] = end_angles_deg[1]
|
|
133
|
+
self.header['Kappa end in deg'] = end_angles_deg[2]
|
|
134
|
+
self.header['Phi end in deg'] = end_angles_deg[3]
|
|
135
|
+
self.header['Omega step in deg'] = step_angles_deg[0]
|
|
136
|
+
self.header['Theta step in deg'] = step_angles_deg[1]
|
|
137
|
+
self.header['Kappa step in deg'] = step_angles_deg[2]
|
|
138
|
+
self.header['Phi step in deg'] = step_angles_deg[3]
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
zero_correction_soft_step = numpy.fromstring(block[512:532], numpy.int32)
|
|
142
|
+
zero_correction_soft_deg = zero_correction_soft_step * step_angles_deg
|
|
143
|
+
self.header['Omega zero corr. in deg'] = zero_correction_soft_deg[0]
|
|
144
|
+
self.header['Theta zero corr. in deg'] = zero_correction_soft_deg[1]
|
|
145
|
+
self.header['Kappa zero corr. in deg'] = zero_correction_soft_deg[2]
|
|
146
|
+
self.header['Phi zero corr. in deg'] = zero_correction_soft_deg[3]
|
|
147
|
+
# Beam rotation about e2,e3
|
|
148
|
+
self.header['Beam rot in deg (e2)'] = numpy.fromstring(block[552:560], numpy.float)[0]
|
|
149
|
+
self.header['Beam rot in deg (e3)'] = numpy.fromstring(block[560:568], numpy.float)[0]
|
|
150
|
+
# Wavelenghts alpha1, alpha2, beta
|
|
151
|
+
self.header['Wavelength alpha1'] = numpy.fromstring(block[568:576], numpy.float)[0]
|
|
152
|
+
self.header['Wavelength alpha2'] = numpy.fromstring(block[576:584], numpy.float)[0]
|
|
153
|
+
self.header['Wavelength alpha'] = numpy.fromstring(block[584:592], numpy.float)[0]
|
|
154
|
+
self.header['Wavelength beta'] = numpy.fromstring(block[592:600], numpy.float)[0]
|
|
155
|
+
|
|
156
|
+
# Detector tilts around e1,e2,e3 in deg
|
|
157
|
+
self.header['Detector tilt e1 in deg'] = numpy.fromstring(block[640:648], numpy.float)[0]
|
|
158
|
+
self.header['Detector tilt e2 in deg'] = numpy.fromstring(block[648:656], numpy.float)[0]
|
|
159
|
+
self.header['Detector tilt e3 in deg'] = numpy.fromstring(block[656:664], numpy.float)[0]
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
# Beam center
|
|
163
|
+
self.header['Beam center x'] = numpy.fromstring(block[664:672], numpy.float)[0]
|
|
164
|
+
self.header['Beam center y'] = numpy.fromstring(block[672:680], numpy.float)[0]
|
|
165
|
+
# Angle (alpha) between kappa rotation axis and e3 (ideally 50 deg)
|
|
166
|
+
self.header['Alpha angle in deg'] = numpy.fromstring(block[672:680], numpy.float)[0]
|
|
167
|
+
# Angle (beta) between phi rotation axis and e3 (ideally 0 deg)
|
|
168
|
+
self.header['Beta angle in deg'] = numpy.fromstring(block[672:680], numpy.float)[0]
|
|
169
|
+
|
|
170
|
+
# Detector distance
|
|
171
|
+
self.header['Distance in mm'] = numpy.fromstring(block[712:720], numpy.float)[0]
|
|
172
|
+
# Statistics section (NS) 512 bytes long
|
|
173
|
+
block = infile.read(self.header['Statistic Section in Byte'])
|
|
174
|
+
self.header['Stat: Min '] = numpy.fromstring(block[0:4], numpy.int32)[0]
|
|
175
|
+
self.header['Stat: Max '] = numpy.fromstring(block[4:8], numpy.int32)[0]
|
|
176
|
+
self.header['Stat: Average '] = numpy.fromstring(block[24:32], numpy.float)[0]
|
|
177
|
+
self.header['Stat: Stddev '] = numpy.sqrt(numpy.fromstring(block[32:40], numpy.float)[0])
|
|
178
|
+
self.header['Stat: Skewness '] = numpy.fromstring(block[40:48], numpy.float)[0]
|
|
179
|
+
|
|
180
|
+
# History section (NH) 2048 bytes long
|
|
181
|
+
block = infile.read(self.header['History Section in Byte'])
|
|
182
|
+
self.header['Flood field image'] = block[99:126].strip("\x00")
|
|
183
|
+
|
|
184
|
+
def read(self, fname, frame=None):
|
|
185
|
+
"""
|
|
186
|
+
Read in header into self.header and
|
|
187
|
+
the data into self.data
|
|
188
|
+
"""
|
|
189
|
+
self.header = {}
|
|
190
|
+
self.resetvals()
|
|
191
|
+
infile = self._open(fname)
|
|
192
|
+
self._readheader(infile)
|
|
193
|
+
|
|
194
|
+
infile.seek(self.header['Header Size In Bytes'])
|
|
195
|
+
|
|
196
|
+
# Compute image size
|
|
197
|
+
try:
|
|
198
|
+
self.dim1 = int(self.header['NX'])
|
|
199
|
+
self.dim2 = int(self.header['NY'])
|
|
200
|
+
except:
|
|
201
|
+
raise Exception("Oxford file", str(fname) + \
|
|
202
|
+
"is corrupt, cannot read it")
|
|
203
|
+
#
|
|
204
|
+
if self.header['Compression'] == 'TY1':
|
|
205
|
+
#Compressed with the KM4CCD compression
|
|
206
|
+
raw8 = infile.read(self.dim1 * self.dim2)
|
|
207
|
+
raw16 = None
|
|
208
|
+
raw32 = None
|
|
209
|
+
if self.header['OI'] > 0:
|
|
210
|
+
raw16 = infile.read(self.header['OI'] * 2)
|
|
211
|
+
if self.header['OL'] > 0:
|
|
212
|
+
raw32 = infile.read(self.header['OL'] * 4)
|
|
213
|
+
#DEBUG stuff ...
|
|
214
|
+
self.raw8 = raw8
|
|
215
|
+
self.raw16 = raw16
|
|
216
|
+
self.raw32 = raw32
|
|
217
|
+
#END DEBUG
|
|
218
|
+
block = decTY1(raw8, raw16, raw32)
|
|
219
|
+
bytecode = block.dtype
|
|
220
|
+
|
|
221
|
+
else:
|
|
222
|
+
bytecode = numpy.int32
|
|
223
|
+
self.bpp = len(numpy.array(0, bytecode).tostring())
|
|
224
|
+
ReadBytes = self.dim1 * self.dim2 * self.bpp
|
|
225
|
+
block = numpy.fromstring(infile.read(ReadBytes), bytecode)
|
|
226
|
+
|
|
227
|
+
logger.debug('OVER_SHORT2: %s', block.dtype)
|
|
228
|
+
logger.debug("%s" % (block < 0).sum())
|
|
229
|
+
infile.close()
|
|
230
|
+
logger.debug("BYTECODE: %s", bytecode)
|
|
231
|
+
self.data = block.reshape((self.dim2, self.dim1))
|
|
232
|
+
self.bytecode = self.data.dtype.type
|
|
233
|
+
self.pilimage = None
|
|
234
|
+
return self
|
|
235
|
+
|
|
236
|
+
def _writeheader(self):
|
|
237
|
+
"""
|
|
238
|
+
@return a string containing the header for Oxford images
|
|
239
|
+
"""
|
|
240
|
+
linesep = "\r\n"
|
|
241
|
+
for key in DEFAULT_HEADERS:
|
|
242
|
+
if key not in self.header_keys:
|
|
243
|
+
self.header_keys.append(key)
|
|
244
|
+
self.header[key] = DEFAULT_HEADERS[key]
|
|
245
|
+
|
|
246
|
+
if "NX" not in self.header.keys() or "NY" not in self.header.keys():
|
|
247
|
+
self.header['NX'] = self.dim1
|
|
248
|
+
self.header['NY'] = self.dim2
|
|
249
|
+
ascii_headers = [self.header['Header Version'],
|
|
250
|
+
"COMPRESSION=%s (%5.1f)" % (self.header["Compression"], self.getCompressionRatio()),
|
|
251
|
+
"NX=%4i NY=%4i OI=%7i OL=%7i " % (self.header["NX"], self.header["NY"], self.header["OI"], self.header["OL"]),
|
|
252
|
+
"NHEADER=%7i NG=%7i NS=%7i NK=%7i NS=%7i NH=%7i" % (self.header['Header Size In Bytes'],
|
|
253
|
+
self.header['General Section size in Byte'],
|
|
254
|
+
self.header['Special Section size in Byte'],
|
|
255
|
+
self.header['KM4 Section size in Byte'],
|
|
256
|
+
self.header['Statistic Section in Byte'],
|
|
257
|
+
self.header['History Section in Byte']),
|
|
258
|
+
"NSUPPLEMENT=%7i" % (self.header["NSUPPLEMENT"])]
|
|
259
|
+
if "Time" in self.header:
|
|
260
|
+
ascii_headers.append("TIME=%s" % self.header["Time"])
|
|
261
|
+
else:
|
|
262
|
+
|
|
263
|
+
ascii_headers.append("TIME=%s" % time.ctime())
|
|
264
|
+
|
|
265
|
+
header = (linesep.join(ascii_headers)).ljust(256)
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
NG = Section(self.header['General Section size in Byte'], self.header)
|
|
269
|
+
NG.setData('Binning in x', 0, numpy.uint16)
|
|
270
|
+
NG.setData('Binning in y', 2, numpy.uint16)
|
|
271
|
+
NG.setData('Detector size x', 22, numpy.uint16)
|
|
272
|
+
NG.setData('Detector size y', 24, numpy.uint16)
|
|
273
|
+
NG.setData('Pixels in x', 26, numpy.uint16)
|
|
274
|
+
NG.setData('Pixels in y', 28, numpy.uint16)
|
|
275
|
+
NG.setData('No of pixels', 36, numpy.uint32)
|
|
276
|
+
header += NG.__repr__()
|
|
277
|
+
|
|
278
|
+
NS = Section(self.header['Special Section size in Byte'], self.header)
|
|
279
|
+
NS.setData('Gain', 56, numpy.float)
|
|
280
|
+
NS.setData('Overflows flag', 464, numpy.int16)
|
|
281
|
+
NS.setData('Overflow after remeasure flag', 466, numpy.int16)
|
|
282
|
+
NS.setData('Overflow threshold', 472, numpy.int32)
|
|
283
|
+
NS.setData('Exposure time in sec', 480, numpy.float)
|
|
284
|
+
NS.setData('Overflow time in sec', 488, numpy.float)
|
|
285
|
+
NS.setData('Monitor counts of raw image 1', 528, numpy.int32)
|
|
286
|
+
NS.setData('Monitor counts of raw image 2', 532, numpy.int32)
|
|
287
|
+
NS.setData('Monitor counts of overflow raw image 1', 536, numpy.int32)
|
|
288
|
+
NS.setData('Monitor counts of overflow raw image 2', 540, numpy.int32)
|
|
289
|
+
NS.setData('Unwarping', 544, numpy.int32)
|
|
290
|
+
if 'Detector type' in self.header:
|
|
291
|
+
for key, value in DETECTOR_TYPES.items():
|
|
292
|
+
if value == self.header['Detector type']:
|
|
293
|
+
NS.setData(None, 548, numpy.int32, default=key)
|
|
294
|
+
NS.setData('Real pixel size x (mm)', 568, numpy.float)
|
|
295
|
+
NS.setData('Real pixel size y (mm)', 576, numpy.float)
|
|
296
|
+
header += NS.__repr__()
|
|
297
|
+
|
|
298
|
+
KM = Section(self.header['KM4 Section size in Byte'], self.header)
|
|
299
|
+
KM.setData('Spatial correction file date', 0, "|S26")
|
|
300
|
+
KM.setData('Spatial correction file', 26, "|S246")
|
|
301
|
+
# Angles are in steps due to stepper motors - conversion factor RAD
|
|
302
|
+
# angle[0] = omega, angle[1] = theta, angle[2] = kappa, angle[3] = phi,
|
|
303
|
+
if self.header.get('Omega step in deg', None):
|
|
304
|
+
KM.setData(None, 368, numpy.float64, deg2rad(self.header["Omega step in deg"]))
|
|
305
|
+
if self.header.get('Omega start in deg', None):
|
|
306
|
+
KM.setData(None, 284, numpy.int32, self.header["Omega start in deg"] / self.header["Omega step in deg"])
|
|
307
|
+
if self.header.get('Omega end in deg', None):
|
|
308
|
+
KM.setData(None, 324, numpy.int32, self.header["Omega end in deg"] / self.header["Omega step in deg"])
|
|
309
|
+
if self.header.get('Omega zero corr. in deg', None):
|
|
310
|
+
KM.setData(None, 512, numpy.int32, self.header['Omega zero corr. in deg'] / self.header["Omega step in deg"])
|
|
311
|
+
|
|
312
|
+
if self.header.get('Theta step in deg', None):
|
|
313
|
+
KM.setData(None, 368 + 8, numpy.float64, deg2rad(self.header["Theta step in deg"]))
|
|
314
|
+
if self.header.get('Theta start in deg', None):
|
|
315
|
+
KM.setData(None, 284 + 4, numpy.int32, self.header["Theta start in deg"] / self.header["Theta step in deg"])
|
|
316
|
+
if self.header.get('Theta end in deg', None):
|
|
317
|
+
KM.setData(None, 324 + 4, numpy.int32, self.header["Theta end in deg"] / self.header["Theta step in deg"])
|
|
318
|
+
if self.header.get('Theta zero corr. in deg', None):
|
|
319
|
+
KM.setData(None, 512 + 4, numpy.int32, self.header['Theta zero corr. in deg'] / self.header["Theta step in deg"])
|
|
320
|
+
|
|
321
|
+
if self.header.get('Kappa step in deg', None):
|
|
322
|
+
KM.setData(None, 368 + 16, numpy.float64, deg2rad(self.header["Kappa step in deg"]))
|
|
323
|
+
if self.header.get('Kappa start in deg', None):
|
|
324
|
+
KM.setData(None, 284 + 8, numpy.int32, self.header["Kappa start in deg"] / self.header["Kappa step in deg"])
|
|
325
|
+
if self.header.get('Kappa end in deg', None):
|
|
326
|
+
KM.setData(None, 324 + 8, numpy.int32, self.header["Kappa end in deg"] / self.header["Kappa step in deg"])
|
|
327
|
+
if self.header.get('Kappa zero corr. in deg', None):
|
|
328
|
+
KM.setData(None, 512 + 8, numpy.int32, self.header['Kappa zero corr. in deg'] / self.header["Kappa step in deg"])
|
|
329
|
+
|
|
330
|
+
if self.header.get('Phi step in deg', None):
|
|
331
|
+
KM.setData(None, 368 + 24, numpy.float64, deg2rad(self.header["Phi step in deg"]))
|
|
332
|
+
if self.header.get('Phi start in deg', None):
|
|
333
|
+
KM.setData(None, 284 + 12, numpy.int32, self.header["Phi start in deg"] / self.header["Phi step in deg"])
|
|
334
|
+
if self.header.get('Phi end in deg', None):
|
|
335
|
+
KM.setData(None, 324 + 12, numpy.int32, self.header["Phi end in deg"] / self.header["Phi step in deg"])
|
|
336
|
+
if self.header.get('Phi zero corr. in deg', None):
|
|
337
|
+
KM.setData(None, 512 + 12, numpy.int32, self.header['Phi zero corr. in deg'] / self.header["Phi step in deg"])
|
|
338
|
+
|
|
339
|
+
# Beam rotation about e2,e3
|
|
340
|
+
KM.setData('Beam rot in deg (e2)', 552, numpy.float64)
|
|
341
|
+
KM.setData('Beam rot in deg (e3)', 560, numpy.float64)
|
|
342
|
+
# Wavelenghts alpha1, alpha2, beta
|
|
343
|
+
KM.setData('Wavelength alpha1', 568, numpy.float64)
|
|
344
|
+
KM.setData('Wavelength alpha2', 576, numpy.float64)
|
|
345
|
+
KM.setData('Wavelength alpha', 584, numpy.float64)
|
|
346
|
+
KM.setData('Wavelength beta', 592, numpy.float64)
|
|
347
|
+
|
|
348
|
+
# Detector tilts around e1,e2,e3 in deg
|
|
349
|
+
KM.setData('Detector tilt e1 in deg', 640, numpy.float64)
|
|
350
|
+
KM.setData('Detector tilt e2 in deg', 648, numpy.float64)
|
|
351
|
+
KM.setData('Detector tilt e3 in deg', 656, numpy.float64)
|
|
352
|
+
|
|
353
|
+
# Beam center
|
|
354
|
+
KM.setData('Beam center x', 664, numpy.float64)
|
|
355
|
+
KM.setData('Beam center y', 672, numpy.float64)
|
|
356
|
+
# Angle (alpha) between kappa rotation axis and e3 (ideally 50 deg)
|
|
357
|
+
KM.setData('Alpha angle in deg', 672, numpy.float64)
|
|
358
|
+
# Angle (beta) between phi rotation axis and e3 (ideally 0 deg)
|
|
359
|
+
KM.setData('Beta angle in deg', 672, numpy.float64)
|
|
360
|
+
|
|
361
|
+
# Detector distance
|
|
362
|
+
KM.setData('Distance in mm', 712, numpy.float64)
|
|
363
|
+
header += KM.__repr__()
|
|
364
|
+
|
|
365
|
+
SS = Section(self.header['Statistic Section in Byte'], self.header)
|
|
366
|
+
SS.setData('Stat: Min ', 0, numpy.int32)
|
|
367
|
+
SS.setData('Stat: Max ', 4, numpy.int32)
|
|
368
|
+
SS.setData('Stat: Average ', 24, numpy.float64)
|
|
369
|
+
if self.header.get('Stat: Stddev ', None):
|
|
370
|
+
SS.setData(None, 32, numpy.float64, self.header['Stat: Stddev '] ** 2)
|
|
371
|
+
SS.setData('Stat: Skewness ', 40, numpy.float64)
|
|
372
|
+
header += SS.__repr__()
|
|
373
|
+
|
|
374
|
+
HS = Section(self.header['History Section in Byte'], self.header)
|
|
375
|
+
HS.setData('Flood field image', 99, "|S27")
|
|
376
|
+
header += HS.__repr__()
|
|
377
|
+
|
|
378
|
+
return header
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
def write(self, fname):
|
|
382
|
+
"""Write Oxford diffraction images: this is still beta
|
|
383
|
+
@param fname: output filename
|
|
384
|
+
"""
|
|
385
|
+
datablock8, datablock16, datablock32 = compTY1(self.data)
|
|
386
|
+
self.header["OI"] = len(datablock16) / 2
|
|
387
|
+
self.header["OL"] = len(datablock32) / 4
|
|
388
|
+
with self._open(fname, mode="wb") as outfile:
|
|
389
|
+
outfile.write(self._writeheader())
|
|
390
|
+
outfile.write(datablock8)
|
|
391
|
+
outfile.write(datablock16)
|
|
392
|
+
outfile.write(datablock32)
|
|
393
|
+
|
|
394
|
+
def getCompressionRatio(self):
|
|
395
|
+
"calculate the compression factor obtained vs raw data"
|
|
396
|
+
return 100.0 * (self.data.size + 2 * self.header["OI"] + 4 * self.header["OL"]) / (self.data.size * 4)
|
|
397
|
+
|
|
398
|
+
@staticmethod
|
|
399
|
+
def checkData(data=None):
|
|
400
|
+
if data is None:
|
|
401
|
+
return None
|
|
402
|
+
else:
|
|
403
|
+
return data.astype(int)
|
|
404
|
+
|
|
405
|
+
class Section(object):
|
|
406
|
+
"""
|
|
407
|
+
Small helper class for writing binary headers
|
|
408
|
+
"""
|
|
409
|
+
def __init__(self, size, dictHeader):
|
|
410
|
+
"""
|
|
411
|
+
@param size: size of the header section in bytes
|
|
412
|
+
@param dictHeader: headers of the image
|
|
413
|
+
"""
|
|
414
|
+
self.size = size
|
|
415
|
+
self.header = dictHeader
|
|
416
|
+
self.lstChr = ["\x00"] * size
|
|
417
|
+
self._dictSize = {}
|
|
418
|
+
def __repr__(self):
|
|
419
|
+
return "".join(self.lstChr)
|
|
420
|
+
|
|
421
|
+
def getSize(self, dtype):
|
|
422
|
+
if not dtype in self._dictSize:
|
|
423
|
+
self._dictSize[dtype] = len(numpy.zeros(1, dtype=dtype).tostring())
|
|
424
|
+
return self._dictSize[dtype]
|
|
425
|
+
|
|
426
|
+
def setData(self, key, offset, dtype, default=None):
|
|
427
|
+
"""
|
|
428
|
+
@param offset: int, starting position in the section
|
|
429
|
+
@param key: name of the header key
|
|
430
|
+
@param dtype: type of the data to insert (defines the size!)
|
|
431
|
+
"""
|
|
432
|
+
if key in self.header:
|
|
433
|
+
value = self.header[key]
|
|
434
|
+
elif key in DEFAULT_HEADERS:
|
|
435
|
+
value = DEFAULT_HEADERS[key]
|
|
436
|
+
else:
|
|
437
|
+
value = default
|
|
438
|
+
if value is None:
|
|
439
|
+
value = "\x00" * self.getSize(dtype)
|
|
440
|
+
else:
|
|
441
|
+
value = numpy.array(value).astype(dtype).tostring()
|
|
442
|
+
self.lstChr[offset:offset + self.getSize(dtype)] = value
|
|
Binary file
|