fabio.pilatusimage

Package fabio :: Module pilatusimage |
[hide private]
[frames] | no frames]

# Source Code for Module fabio.pilatusimage

     1  #!/usr/bin/env python
     2  #coding: utf8
     3  """
     4
     5  Authors:
     6  ........
     7  * Henning O. Sorensen & Erik Knudsen:
     8    Center for Fundamental Research: Metal Structures in Four Dimensions;
     9    Risoe National Laboratory;
    10    Frederiksborgvej 399;
    11    DK-4000 Roskilde;
    12    email:erik.knudsen@risoe.dk
    13  * Jon Wright:
    14    European Synchrotron Radiation Facility;
    15    Grenoble (France)
    16
    17  """
    18
    19
    20  # Base this on the tifimage (as Pilatus is tiff with a
    21  # tiff header
    22
    23  from fabio.tifimage import tifimage
    24
    25
    26 -class pilatusimage(tifimage):
    27      """ Read in Pilatus format, also
    28          pilatus images, including header info """
    29
    30
    31 -    def _readheader(self, infile):
    32          """
    33          Parser based approach
    34          Gets all entries
    35          """
    36
    37          self.header = {}
    38
    39  #        infile = open(infile)
    40          hstr = infile.read(4096)
    41          # well not very pretty - but seems to find start of
    42          # header information
    43          if (hstr.find('# ') == -1):
    44              return self.header
    45
    46          hstr = hstr[hstr.index('# '):]
    47          hstr = hstr[:hstr.index('\x00')]
    48          hstr = hstr.split('#')
    49          go_on = True
    50          while go_on:
    51              try:
    52                  hstr.remove('')
    53              except Exception:
    54                  go_on = False
    55
    56          for line in hstr:
    57              line = line[1:line.index('\r\n')]
    58              if line.find(':') > -1:
    59                  dump = line.split(':')
    60                  self.header[dump[0]] = dump[1]
    61              elif line.find('=') > -1:
    62                  dump = line.split('=')
    63                  self.header[dump[0]] = dump[1]
    64              elif line.find(' ') > -1:
    65                  i = line.find(' ')
    66                  self.header[line[:i]] = line[i:]
    67              elif line.find(',') > -1:
    68                  dump = line.split(',')
    69                  self.header[dump[0]] = dump[1]
    70
    71          return self.header
    72
    73
    74
    75 -    def _read(self, fname):
    76          """
    77          inherited from tifimage
    78          ... a Pilatus image *is a* tif image
    79          just with a header
    80          """
    81          return tifimage.read(self, fname)
    82