This file is indexed.

/usr/share/pyshared/fabio/bruker100image.py is in python-fabio 0.1.4-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from __future__ import with_statement, print_function
import numpy
import math
import logging
logger = logging.getLogger("bruker100image")
try:
    from PIL import Image
except ImportError:
    logger.warning("PIL is not installed ... trying to do without")
    Image = None

from .brukerimage import brukerimage
from .readbytestream import readbytestream

class bruker100image(brukerimage):


    def toPIL16(self, filename=None):
        if not Image:
            raise RuntimeError("PIL is not installed !!! ")

        if filename:
            self.read(filename)
        PILimage = Image.frombuffer("F",
                                        (self.dim1, self.dim2),
                                        self.data,
                                        "raw",
                                        "F;16", 0, -1)
        return PILimage

    def read(self, fname, frame=None):
        f = open(fname, "rb")
        try:
            self._readheader(f)
        except:
            raise

        rows = int(self.header['NROWS'])
        cols = int(self.header['NCOLS'])
        npixelb = int(self.header['NPIXELB'][0])
        # you had to read the Bruker docs to know this!

        # We are now at the start of the image - assuming 
        #   readbrukerheader worked
        # size = rows * cols * npixelb
        self.data = readbytestream(f, f.tell(), rows, cols, npixelb,
                                    datatype="int", signed='n', swap='n')

        noverfl = self.header['NOVERFL'].split() # now process the overflows
        #read the set of "underflow pixels" - these will be completely 
        # disregarded for now
        data = self.data
        k = 0

        while k < 2:#for the time being things - are done in 16 bits
            datatype = {'1' : numpy.uint8,
                        '2' : numpy.uint16,
                        '4' : numpy.uint32 }[("%d" % 2 ** k)]
            ar = numpy.array(numpy.fromstring(f.read(int(noverfl[k]) * (2 ** k)),
                                        datatype), numpy.uint16)
            #insert the the overflow pixels in the image array:
            #this is probably a memory intensive way of doing this - 
            # might be done in a more clever way
            lim = 2 ** (8 * k) - 1
            #generate an array comprising of the indices into data.ravel() 
            # where its value equals lim.
            M = numpy.compress(numpy.equal(data.ravel(), lim), numpy.arange(rows * cols))
            #now put values from ar into those indices
            numpy.put(data.ravel(), M, ar)
            padding = 16 * int(math.ceil(int(noverfl[k]) * (2 ** k) / 16.)) - \
                         int(noverfl[k]) * (2 ** k)
            f.seek(padding, 1)
            print ("%s bytes read + %d bytes padding" % (noverfl[k],padding))
            k = k + 1

        f.close()

        (self.dim1, self.dim2) = (rows, cols)
        print( self.dim1, self.dim2)
        self.resetvals()
        return self

if __name__ == '__main__':
    import sys, time
    I = bruker100image()
    b = time.clock()
    while (sys.argv[1:]):
        I.read(sys.argv[1])
        r = I.toPIL16()
        I.rebin(2, 2)
        print(sys.argv[1] + (": max=%d, min=%d, mean=%.2e, stddev=%.2e") % (
            I.getmax(), I.getmin(), I.getmean(), I.getstddev()))
        print('integrated intensity (%d %d %d %d) =%.3f' % (
            10, 20, 20, 40, I.integrate_area((10, 20, 20, 40))))
        sys.argv[1:] = sys.argv[2:]
    e = time.clock()
    print (e - b)