예제 #1
0
    def testVector(self):
        temp = Vector(100., 200., 300.)

        self.assertEqual(len(temp), 3)

        self.assertEqual(temp, (100., 200., 300.))
        self.assertEqual(temp.x, 100.)
        self.assertEqual(temp.y, 200.)
        self.assertEqual(temp.z, 300.)
        self.assertEqual(temp.x, temp[0])
        self.assertEqual(temp.y, temp[1])
        self.assertEqual(temp.z, temp[2])

        self.assertAlmostEqual(temp.length, 374.16573867739413)
        self.assertEqual(temp.normalize().length, 1.)
예제 #2
0
    def testVector(self):
        temp = Vector(100., 200., 300.)

        self.assertEqual(len(temp), 3)

        self.assertEqual(temp, (100., 200., 300.))
        self.assertEqual(temp.x, 100.)
        self.assertEqual(temp.y, 200.)
        self.assertEqual(temp.z, 300.)
        self.assertEqual(temp.x, temp[0])
        self.assertEqual(temp.y, temp[1])
        self.assertEqual(temp.z, temp[2])

        self.assertAlmostEqual(temp.length, 374.16573867739413)
        self.assertEqual(temp.normalize().length, 1.)
    def testVectorMath(self):
        a = Vector(UNIT_X)
        b = Vector(UNIT_Y)
        a = a+b
        self.assertEqual(a.x, 1.)
        self.assertEqual(a.y, 1.)
        self.assertEqual(a.z, 0.)

        a = Vector(UNIT_X)
        b = Vector(UNIT_Y)
        a = a-b
        self.assertEqual(a.x,  1.)
        self.assertEqual(a.y, -1.)
        self.assertEqual(a.z,  0.)

        a = Vector(UNIT_X)
        a = a/2.
        self.assertEqual(a.x,  .5)
        self.assertEqual(a.y,  0.)
        self.assertEqual(a.z,  0.)

        a = Vector(UNIT_X)
        a = a*2.
        self.assertEqual(a.x,  2.)
        self.assertEqual(a.y,  0.)
        self.assertEqual(a.z,  0.)

        a = Vector(UNIT_X)
        a = 2.*a
        self.assertEqual(a.x,  2.)
        self.assertEqual(a.y,  0.)
        self.assertEqual(a.z,  0.)
def getRectangle(bank_num, positions, corners, tolerance_len=0.006):
    # TODO for some reason tolerance is bigger than the default
    try:
        one = positions[corners[0]]
        two = positions[corners[1]]
        three = positions[corners[2]]
        four = positions[corners[3]]
        if bank_num in (90, 91):
            if bank_num == 90:  # .046875 -> 0.148
                y_offset = 0.10113
            elif bank_num == 91:  # -.0390625 -> -0.148
                y_offset = -0.1089375
            one = Vector(one.x, one.y + y_offset, one.z)
            two = Vector(two.x, two.y + y_offset, two.z)
            three = Vector(three.x, three.y + y_offset, three.z)
            four = Vector(four.x, four.y + y_offset, four.z)
        return Rectangle(one, two, three, four, tolerance_len=tolerance_len)
    except RuntimeError as e:
        print('bank', bank_num, corners)
        raise e
예제 #5
0
def addCenterRectangle(instr, det, name, detinfo, index):
    # get the center
    center = ['x', 'y', 'z']
    center = [float(detinfo[item][index])/1000. for item in center]

    # create the two unit vectors
    u = Vector(detinfo["PUx"][index], detinfo["PUy"][index],
               detinfo["PUz"][index])
    v = Vector(detinfo["PVx"][index], detinfo["PVy"][index],
               detinfo["PVz"][index])

    # turn them into rotations
    (phi, chi, omega) = getEuler(u, v, degrees=True)
    rotations = [[phi,   (0., 1., 0.)],
                 [chi,   (0., 0., 1.)],
                 [omega, (0., 1., 0.)]]
    
    print name, center
    print "     ", u.normalize(), v.normalize()
    print "     ", rotations
    makeLocation(instr, det, name, center, rotations)
    def __init__(self, *args):
        if len(args) != 16:
            raise RuntimeError('Expeceted 16 args found {}'.format(len(args)))

        self.det_num = int(args[0])
        self.first_pixel = 256 * 256 * self.det_num

        self.nrows = int(args[1])
        self.ncols = int(args[2])

        # must get values before the rest ar converted to meters
        base_vector = Vector(args[10:13])  # 10, 11, 12
        up_vector = Vector(args[13:16])  # 13, 14, 15

        # convert everything else to floats in meeters
        args = np.array(args, dtype=np.float) / 100.

        self._calc_panel_size(width=args[3], height=args[4])

        # skip args[5] which is the depth and not apparently used
        # skip args[6] with is the length of the center vector
        self.center = Vector(args[7:10])  # 7, 8, 9
        self._calc_panel_pos_and_orient(base_vector, up_vector)
def readEngineeringPositions(filename):
    positions = readFile(filename, hasLabels=False)

    tube = np.fromiter(map(int, positions[0]), dtype=int)
    pixel = np.fromiter(map(int, positions[1]), dtype=int)
    id = tube * 128 + pixel

    x = -1. * np.fromiter(map(float, positions[6]), dtype=float)
    x[x == -0.] = 0.
    y = np.fromiter(map(float, positions[5]), dtype=float)
    z = np.fromiter(map(float, positions[7]), dtype=float)

    positions = {}
    for i, x_i, y_i, z_i in zip(id, x, y, z):
        positions[i] = Vector(x_i, y_i, z_i)

    return positions
def readSurveyPositions(filename):
    # label1, label2, z, x, y
    positions = readFile(filename, hasLabels=False, headerLines=1)

    labels = positions[0]
    # NOTE: label2 column is empty on latest survey, so these indices are shifted back one
    x = np.fromiter(map(float, positions[2]), dtype=float)
    y = np.fromiter(map(float, positions[3]), dtype=float)
    z = np.fromiter(map(float, positions[1]), dtype=float)

    ids = []

    for i in range(0, len(labels), 4):
        det = labels[i]

        # this assumes the label column is in the format "Det#_[1U,2U,1D,2D]"
        [bank, _] = det.split("_")
        bank = int(bank.lstrip("Det"))

        # mapping between survey points to getCorner indices
        # this allows survey measurements to be in any ordering in the file
        # getCorners returns in order: LL, UL, UR, LR
        mapping = {"1U": 3, "2U": 0, "2D": 1, "1D": 2}

        # loop over each measurement for this bank and find the correct
        # detector id it corresponds to
        corners = getCorners(bank)
        for j in range(0, 4):
            [b, pos] = labels[i + j].split("_")
            b = int(b.lstrip("Det"))
            # print("bank {} - {} --> {} ({})".format(b, pos, mapping[pos], corners[mapping[pos]]))
            # verify that this bank is the one we are working on
            assert (b == bank)
            ids.append(corners[mapping[pos]])

    positions = {}
    for i, x_i, y_i, z_i in zip(ids, x, y, z):
        if x_i == 0. and y_i == 0. and z_i == 0:
            continue
        # subtract off distance to source from z values
        positions[i] = Vector(x_i, y_i, z_i - 19.5)
    return positions
예제 #9
0
def addCenterRectangle(instr, det, name, detinfo, index):
    # get the center
    center = ['x', 'y', 'z']
    center = [float(detinfo[item][index]) / 1000. for item in center]

    # create the two unit vectors
    u = Vector(detinfo["PUx"][index], detinfo["PUy"][index],
               detinfo["PUz"][index])
    v = Vector(detinfo["PVx"][index], detinfo["PVy"][index],
               detinfo["PVz"][index])

    # turn them into rotations
    (phi, chi, omega) = getEuler(u, v, degrees=True)
    rotations = [[phi, (0., 1., 0.)], [chi, (0., 0., 1.)],
                 [omega, (0., 1., 0.)]]

    print name, center
    print "     ", u.normalize(), v.normalize()
    print "     ", rotations
    makeLocation(instr, det, name, center, rotations)