fabio.datIO

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

# Source Code for Module fabio.datIO

     1  #!/usr/bin/env python
     2  #coding: utf8
     3  """
     4  Authors: Henning O. Sorensen & Erik Knudsen
     5           Center for Fundamental Research: Metal Structures in Four Dimensions
     6           Risoe National Laboratory
     7           Frederiksborgvej 399
     8           DK-4000 Roskilde
     9           email:erik.knudsen@risoe.dk
    10
    11           and Jon Wright, ESRF
    12  """
    13
    14 -class fabiodata(object):
    15      """
    16      A common class for dataIO in fable
    17      Contains a 2d numpy array for keeping data, and two lists (clabels and rlabels)
    18      containing labels for columns and rows respectively
    19      """
    20
    21 -    def __init__(self, data=None, clabels=None, rlabels=None, fname=None):
    22          """
    23          set up initial values
    24          """
    25          if type(data) == type("string"):
    26              raise Exception("fabioimage.__init__ bad argument - " + \
    27                                  "data should be numpy array")
    28          self.data = data
    29          if (self.data):
    30              self.dims = self.data.shape
    31          self.clabels = clabels
    32          self.rlabels = rlabels
    33          if (fname):
    34              self.read(fname)
    35
    36 -    def read(self, fname=None, frame=None):
    37          """
    38          To be overridden by format specific subclasses
    39          """
    40          raise Exception("Class has not implemented read method yet")
    41
    42  #import stuff from Jon's columnfile things
    43
    44
    45 -class columnfile(fabiodata):
    46      "Concrete fabiodata class"
    47 -    def read(self, fname, frame=None):
    48          import cf_io
    49          try:
    50              infile = open(fname, 'rb')
    51          except:
    52              raise Exception("columnfile: file" + str(fname) + "not found.")
    53          try:
    54              (self.data, self.clabels) = cf_io.read(infile)
    55          except:
    56              raise Exception("columnfile: read error, file " + str(fname) + " possibly corrupt")
    57          self.dims = self.data.shape
    58          infile.close()
    59