Beispiel #1
0
 def readData(self, tslfile, prog):
     count = 1
     lines = tslfile.readlines()
     nlines = len(lines)
     data = utils.ReservableList(nlines)
     hexgrid = False
     for line in lines:
         if line[0] == '#':  # line is in the header
             if line.startswith('# GRID: HexGrid'):
                 hexgrid = True
         else:  # line is not a header line
             substrings = line.split()
             if len(substrings) < 5:
                 raise ooferror.ErrUserError(
                     "Not enough columns in line %d of %s" %
                     (count, tslfile.name))
             if len(substrings) >= 8:
                 phase = substrings[7]
             else:
                 phase = 'phase0'
             values = map(float, substrings[:5])
             position = primitives.Point(values[3], values[4])
             angles = values[:3]
             angles[0] = angles[0] - math.radians(self.angle_offset)
             data.append(DataPoint(position, angles, 'phase' + phase))
         count += 1
         prog.setMessage("read %d/%d lines" % (count, nlines))
         prog.setFraction(float(count) / nlines)
     debug.fmsg("read %d lines, %d data points" % (count, len(data)))
     return data, hexgrid
Beispiel #2
0
    def readData(self, datafile, prog):
        count = 1
        lines = datafile.readlines()
        nlines = len(lines)
        data = utils.ReservableList(nlines)
        # The number of angle components to read is the number of
        # parameters in the Registration for the selected Orientation
        # subclass.
        for reg in orientationmatrix.Orientation.registry:
            if reg.subclass == self.angle_type:
                nAngleComps = len(reg.params)
                break

        xycol0 = self.xy_column - 1  # UI uses fortran indexing
        xycol1 = xycol0 + 2  # TODO: Are there 3D EBSD files?
        acol0 = self.angle_column - 1  # UI uses fortran indexing
        acol1 = acol0 + nAngleComps

        # Look for the last non-blank non-comment line in the file,
        # and examine it to find out what data lines look like.  This
        # information will be used to skip the header lines at the top
        # of the file.

        for i in xrange(len(lines) - 1, -1, -1):
            line = lines[i].strip()
            if line and line[0] != self.comment_character:
                words = self.separator.split(line)
                nwords = len(words)
                lastline = i
                break

        # Loop over the lines in reverse, and stop at the first one
        # that can't be handled.  That will be the last header line.
        for i in xrange(lastline, -1, -1):
            line = lines[i]
            if line[0] != self.comment_character:  # Skip comments
                cols = self.separator.split(line)
                if len(cols) != nwords:
                    break
                try:
                    angletuple = map(float, cols[acol0:acol1])
                    position = primitives.Point(
                        *map(float, cols[xycol0:xycol1]))
                except ValueError:  # Ran into the header.  Quit reading.
                    break
                grps = [
                    template.replace('%s', cols[gcol - 1])
                    for (template, gcol) in self.groups
                ]
                data.append(DataPoint(position, angletuple, grps))

            count += 1  # count actual lines, comments and all
            prog.setMessage("read %d/%d lines" % (count, nlines))
            prog.setFraction(float(count) / nlines)
        npts = len(data)
        reporter.report("Read %d lines, found %d data points" %
                        (len(lines), npts))
        return data
Beispiel #3
0
    def readfile(self, filename, prog, z=0):
        tslfile = file(filename, "r")
        prog.setMessage("Reading " + filename)
        count = 1                       # line counter
        lines = tslfile.readlines()
        nlines = len(lines)
        data = utils.ReservableList(nlines)
        angletype = None
        for line in lines:
            if line[0] == '#':
                if line.startswith("Column 1-3", 2):
                    if "radians" in line:
                        angletype = "radians"
                    else:
                        angletype = "degrees"
                    debug.fmsg("Angles are in %s." % angletype)
            else:                       # line[0] != '#'
                substrings = line.split()
                if len(substrings) < 5:
                    raise ooferror.ErrUserError(
                        "Too few numbers in line %d of %s" % (count, filename))
                values = map(float, substrings[:5])
                if angletype == "radians":
                    angles = values[:3]
                elif angletype == "degrees":
                    angles = map(math.radians, values[:3])
                else:
                    raise ooferror.ErrDataFileError(
                        "Angle type not specified in TSL data file")
                orientation = corientation.COrientBunge(*angles)
                if config.dimension() == 2:
                    point = primitives.Point(values[3], values[4])
                elif config.dimension() == 3:
                    point = primitives.Point(values[3], values[4], z)
                data.append(DataPoint(point, # position
                    angles,
                    ' '.join(substrings[10:])))    # phase name
            count += 1      # count actual file lines, comments and all
            prog.setMessage("read %d/%d lines" % (count, nlines))
            prog.setFraction(float(count)/nlines)
        npts = len(data)
        debug.fmsg("read %d lines, %d data points" % (count, npts))

        # We don't yet know if the points are on a rectangular or a
        # hexagonal lattice, so split the data up into rows.
        # getrows() is a generator, but we need an actual list so that
        # we can index into it.
        rows = list(getrows(data))

        if len(rows) < 2:
            raise ooferror.ErrUserError(
                "Orientation map data has too few rows.")
        if rows[0][0].position[0] != rows[1][0].position[0]:
            # Must be a hexagonal lattice.  Throw out every other row.
            reporter.warn("Converting hexagonal lattice to rectangular by discarding alternate rows.")
            rows = rows[::2]            # discard odd numbered rows

        return rows, npts
Beispiel #4
0
 def readData(self, tslfile, prog):
     count = 1  # line counter
     lines = tslfile.readlines()
     nlines = len(lines)
     data = utils.ReservableList(nlines)
     angletype = None
     for line in lines:
         if line[0] == '#':
             if line.startswith("Column 1-3", 2):
                 if "radians" in line:
                     angletype = "radians"
                 else:
                     angletype = "degrees"
         else:  # line[0] != '#'
             substrings = line.split()
             if len(substrings) < 5:
                 raise ooferror.ErrUserError(
                     "Too few numbers in line %d of %s" %
                     (count, tslfile.name))
             values = map(float, substrings[:5])
             if angletype == "radians":
                 angles = values[:3]
                 angles[0] = angles[0] - math.radians(self.angle_offset)
             elif angletype == "degrees":
                 angles[0] = angles[0] - self.angle_offset
                 angles = map(math.radians, values[:3])
             else:
                 raise ooferror.ErrDataFileError(
                     "Angle type not specified in TSL data file")
             data.append(
                 DataPoint(
                     primitives.Point(values[3], values[4]),  # position
                     angles,
                     ' '.join(substrings[10:])))  # phase name
         count += 1  # count actual file lines, comments and all
         prog.setMessage("read %d/%d lines" % (count, nlines))
         prog.setFraction(float(count) / nlines)
     npts = len(data)
     debug.fmsg("read %d lines, %d data points" % (count, npts))
     return data, None  # None ==> hexgrid not detected yet