Exemple #1
0
    def read(self, filename):
        hklfile = file(filename, "r")
        ## TODO  OPT: Use lineiter = iter(hklfile) instead of iter(lines).
        ## Then it's not necessary to create an array of lines.
        lines = hklfile.readlines()
        lineiter = iter(lines)
        line = lineiter.next()
        while not line.startswith('XCells'):
            line = lineiter.next()
        xcells = string.atoi(string.split(line)[1])
        line = lineiter.next()
        ycells = string.atoi(string.split(line)[1])
        line = lineiter.next()
        xstep = string.atof(string.split(line)[1])
        line = lineiter.next()
        ystep = string.atof(string.split(line)[1])
        line = lineiter.next()

        od = orientmapdata.OrientMap(
            primitives.iPoint(xcells, ycells),
            primitives.Point(xcells * xstep, ycells * ystep))

        while not string.split(line)[0] == 'Phase':
            line = lineiter.next()
        prog = progress.getProgress(os.path.basename(filename),
                                    progress.DEFINITE)
        try:
            count = 0
            npts = xcells * ycells
            for line in lineiter:
                vals = string.split(line)
                phase = vals[0]
                x = string.atof(vals[1])
                y = string.atof(vals[2])
                angles = map(string.atof, vals[5:8])
                mad = string.atof(vals[8])  # mean angular deviation
                ij = primitives.iPoint(int(round(x / xstep)),
                                       ycells - 1 - int(round(y / ystep)))
                try:
                    self.phaselists[phase].append(ij)
                except KeyError:
                    self.phaselists[phase] = [ij]
                self.set_angle(
                    od, ij,
                    corientation.COrientBunge(*map(math.radians, angles)))
                prog.setFraction(float(count) / npts)
                prog.setMessage("%d/%d orientations" % (count, npts))
                count += 1
                if pbar.stopped():
                    return None
        finally:
            prog.finish()
        return od
Exemple #2
0
def _bunge_to_base(bunge_reg, vlist=None):
    args = vlist or bunge_reg.getParamValues()  # (phi1, theta, phi2)
    return corient_to_base(corientation.COrientBunge(*map(math.radians, args)))
Exemple #3
0
 def __init__(self, position, angletuple, phasename):
     self.position = position
     self.angle = corientation.COrientBunge(*angletuple)
     self.phasename = phasename
Exemple #4
0
 def __init__(self, phi1, theta, phi2):
     self.phi1 = phi1
     self.theta = theta
     self.phi2 = phi2
     self.corient = corientation.COrientBunge(
         *map(math.radians, (phi1, theta, phi2)))
Exemple #5
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