Beispiel #1
0
 def readfile(self, filename):
     """
     Reads in an ascii columned file
     """
     self.titles = []
     self.bigarray = None
     self.parameters = parameters.parameters(filename=filename)
     self.ncols = 0
     self.nrows = 0
     i = 0
     # Check if this is a hdf file: magic number
     with open(filename, "rb") as f:
         magic = f.read(4)
     #              1 2 3 4 bytes
     if magic == b'\x89HDF':
         print("Reading your columnfile in hdf format")
         colfile_from_hdf(filename, obj=self)
         return
     with open(filename, "r") as f:
         raw = f.readlines()
     header = True
     while header and i < len(raw):
         if len(raw[i].lstrip()) == 0:
             # skip blank lines
             i += 1
             continue
         if raw[i][0] == "#":
             # title line
             if raw[i].find("=") > -1:
                 # key = value line
                 name, value = clean(raw[i][1:].split("="))
                 self.parameters.addpar(parameters.par(name, value))
             else:
                 self.titles = raw[i][1:].split()
             i += 1
         else:
             header = False
     try:
         row0 = [float(v) for v in raw[i].split()]
         lastrow = [float(v) for v in raw[-1].split()]
         if len(row0) == len(lastrow):
             nrows = len(raw) - i
             last = None
         else:
             nrows = len(raw) - i - 1  # skip the last row
             last = -1
         self.bigarray = np.zeros((len(row0), nrows), np.float)
         for i, line in enumerate(raw[i:last]):
             self.bigarray[:, i] = [float(v) for v in line.split()]
     except:
         raise Exception("Problem interpreting your colfile")
     (self.ncols, self.nrows) = self.bigarray.shape
     self.parameters.dumbtypecheck()
     self.set_attributes()
Beispiel #2
0
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

import numpy
import logging
import math
import sys, os
from ImageD11 import transform, unitcell, columnfile
from ImageD11.parameters import par, parameters

PARAMETERS = [
     par("omegasign", 1.0,
          helpstring="Sign of the rotation about z " + \
              "(normally +1 for right handed)",
          vary=False,
          can_vary=False),
     par('z_center', 1024.0,
          helpstring="Beam centre in vertical, pixels",
          vary=True,
          can_vary=True,
          stepsize=1.0),
     par('y_center', 1024.0,
          helpstring="Beam centre in horizontal, pixels",
          vary=True,
          can_vary=True,
          stepsize=1.0),
     par('distance', 50000.0,
          helpstring="sample detector distance, same units as pixel size",
          vary=True,
Beispiel #3
0
    def readfile(self, filename):
        """
        Reads in an ascii columned file
        """
        self.titles = []
        self.bigarray = None
        self.parameters = parameters.parameters(filename=filename)
        self.ncols = 0
        self.nrows = 0
        i = 0

        try:
            raw = open(filename, "r").readlines()
        except:
            raise Exception("Cannot open %s for reading" % (filename))
        header = True
        while header and i < len(raw):
            if len(raw[i].lstrip()) == 0:
                # skip blank lines
                i += 1
                continue
            if raw[i][0] == "#":
                # title line
                if raw[i].find("=") > -1:
                    # key = value line
                    name, value = clean(raw[i][1:].split("="))
                    self.parameters.addpar(parameters.par(name, value))
                else:
                    self.titles = raw[i][1:].split()
                i += 1
            else:
                header = False
        try:
            cc = [numpy.fromstring(v, sep=' ') for v in raw[i:]]
            self.bigarray = numpy.array(cc).transpose()
        except:
            raise Exception("Non numeric data on all lines\n")
        (self.ncols, self.nrows) = self.bigarray.shape

        #         data = []
        #         try:
        #             fileobj = open(filename,"r").readlines()
        #         except:
        #             raise Exception("Cannot open %s for reading"%(filename))
        #         for line in fileobj:
        #             i += 1
        #             if len(line.lstrip())==0:
        #                 # skip blank lines
        #                 continue
        #             if line[0] == "#":
        #                 # title line
        #                 if line.find("=") > -1:
        #                     # key = value line
        #                     name, value = clean(line[1:].split("="))
        #                     self.parameters.addpar(
        #                         parameters.par( name, value ) )
        #                 else:
        #                     self.titles = clean(line[1:].split())
        #                     self.ncols = len(self.titles)
        #                 continue
        #             # Assume a data line
        #             try:
        #                 vals = [ float(v) for v in line.split() ]
        #             except:
        #                 raise Exception("Non numeric data on line\n"+line)
        #             if len(vals) != self.ncols:
        #                 raise Exception("Badly formatted column file\n"\
        #                                     "expecting %d columns, got %d\n"\
        #                                     " line %d in file %s"%
        #                                 (self.ncols, len(vals),
        #                                  i, self.filename))
        #             self.nrows += 1
        #             data.append(vals)
        #         self.bigarray = numpy.transpose(numpy.array(data))
        #         if self.nrows > 0:
        #             assert self.bigarray.shape == (self.ncols, self.nrows)
        self.set_attributes()