Пример #1
0
def test():
    obj1abspos, obj1absori = (0,0,0), array(((1,0,0),
                                             (0,1,0),
                                             (0,0,1)))
    obj2abspos, obj2absori = (0,0,1), array(((0,1,0),
                                             (-1,0,0),
                                             (0,0,1)))
    test_template(obj1abspos, obj1absori,
                  obj2abspos, obj2absori)

    obj1abspos, obj1absori = (0,0,1), array(((0,1,0),
                                             (-1,0,0),
                                             (0,0,1)))
    obj2abspos, obj2absori = (0,0,0), array(((1,0,0),
                                             (0,1,0),
                                             (0,0,1)))
    test_template(obj1abspos, obj1absori,
                  obj2abspos, obj2absori)

    from mcni.neutron_coordinates_transformers.mcstasRotations import toMatrix
    obj1abspos, obj1absori = (0,0,1), toMatrix(0, 90, 90)
    obj2abspos, obj2absori = (0,0,0), toMatrix(90,0,90)
    test_template(obj1abspos, obj1absori,
                  obj2abspos, obj2absori)
    return
Пример #2
0
    def test1(self):
        'mcni: relative coordinates for geometer'

        from mcni.Geometer2 import Geometer, AbsoluteCoord as abs, RelativeCoord as rel
        geometer = Geometer()

        geometer.register('comp0', abs((0, 0, 0)), abs((0, 0, 0)))
        geometer.register('comp1', abs((0, 0, 0)), abs((0, 90, 0)))
        geometer.register('comp2', rel((0, 0, 1), 'comp1'), abs((0, 0, 0)))
        geometer.register('comp3', rel((0, 0, 0), 'comp2'),
                          rel((3, 4, 5), 'comp2'))
        geometer.register('comp4', abs((0, 0, 0)), rel((0, 0, 90), 'comp0'))
        geometer.register('comp5', abs((0, 0, 0)), rel((0, 90, 0), 'comp4'))
        geometer.register('comp6', rel((1, 2, 3), 'comp5'), abs((0, 0, 0)))

        comp2pos = geometer.position('comp2')
        nt.assert_array_almost_equal(comp2pos, (1, 0, 0))

        comp2ori = geometer.orientation('comp2')
        nt.assert_array_almost_equal(comp2ori, (0, 0, 0))

        comp3pos = geometer.position('comp3')
        nt.assert_array_almost_equal(comp3pos, (1, 0, 0))

        comp3ori = geometer.orientation('comp3')
        nt.assert_array_almost_equal(comp3ori, toMatrix((3, 4, 5)))

        comp5ori = geometer.orientation('comp5')
        nt.assert_array_almost_equal(comp5ori, toMatrix((-90, 0, 90)))

        comp6pos = geometer.position('comp6')
        nt.assert_array_almost_equal(comp6pos, (-2, 3, -1))

        return
Пример #3
0
    def test1(self):
        "mcni: relative coordinates for geometer"

        from mcni.Geometer2 import Geometer, AbsoluteCoord as abs, RelativeCoord as rel

        geometer = Geometer()

        geometer.register("comp0", abs((0, 0, 0)), abs((0, 0, 0)))
        geometer.register("comp1", abs((0, 0, 0)), abs((0, 90, 0)))
        geometer.register("comp2", rel((0, 0, 1), "comp1"), abs((0, 0, 0)))
        geometer.register("comp3", rel((0, 0, 0), "comp2"), rel((3, 4, 5), "comp2"))
        geometer.register("comp4", abs((0, 0, 0)), rel((0, 0, 90), "comp0"))
        geometer.register("comp5", abs((0, 0, 0)), rel((0, 90, 0), "comp4"))
        geometer.register("comp6", rel((1, 2, 3), "comp5"), abs((0, 0, 0)))

        comp2pos = geometer.position("comp2")
        nt.assert_array_almost_equal(comp2pos, (1, 0, 0))

        comp2ori = geometer.orientation("comp2")
        nt.assert_array_almost_equal(comp2ori, (0, 0, 0))

        comp3pos = geometer.position("comp3")
        nt.assert_array_almost_equal(comp3pos, (1, 0, 0))

        comp3ori = geometer.orientation("comp3")
        nt.assert_array_almost_equal(comp3ori, toMatrix((3, 4, 5)))

        comp5ori = geometer.orientation("comp5")
        nt.assert_array_almost_equal(comp5ori, toMatrix((-90, 0, 90)))

        comp6pos = geometer.position("comp6")
        nt.assert_array_almost_equal(comp6pos, (-2, 3, -1))

        return
    def main(self):
        import numpy.testing as nt
        from mcni.neutron_coordinates_transformers.mcstasRotations import toMatrix

        geometer = self.inventory.geometer

        comp2pos = geometer.position('comp2')
        nt.assert_array_almost_equal(comp2pos, (1,0,0))

        comp2ori = geometer.orientation('comp2')
        nt.assert_array_almost_equal(comp2ori, (0,0,0))

        comp3pos = geometer.position('comp3')
        nt.assert_array_almost_equal(comp3pos, (1,0,0))

        comp3ori = geometer.orientation('comp3')
        nt.assert_array_almost_equal(comp3ori, toMatrix((3,4,5)))

        comp5ori = geometer.orientation('comp5')
        nt.assert_array_almost_equal(comp5ori, toMatrix((-90,0,90)))

        comp6pos = geometer.position('comp6')
        nt.assert_array_almost_equal(comp6pos, (-2,3,-1))

        return
Пример #5
0
 def pixel_orientation_func(theta, phi):
     from mcni.neutron_coordinates_transformers.mcstasRotations import toMatrix
     if np.rad2deg(np.abs(theta)) > 34:
         m = np.dot(toMatrix(0, np.rad2deg(phi), 0), toMatrix(0, 0, 90.))
     else:
         m = np.dot(toMatrix(np.rad2deg(theta) - 90., 0, 0),
                    toMatrix(0, np.rad2deg(phi), 0))
     return m
Пример #6
0
def test2_template(absr1, relr2, expected_absr2):
    from mcni.neutron_coordinates_transformers.mcstasRotations import toMatrix, toAngles
    obj1abspos, obj1absori = (0,0,0), toMatrix(*absr1)
    obj2relpos, obj2relori = (0,0,0), toMatrix(*relr2)
    obj2abspos, obj2absori = transformCoordinateSystem(
        obj1abspos, obj1absori, obj2relpos, obj2relori)
    r = toAngles(array(obj2absori))
    import numpy.testing as nt
    nt.assert_array_almost_equal( r, expected_absr2 )
    return    
Пример #7
0
            def main(self):
                geometer = self.inventory.geometer

                comp2pos = geometer.position('comp2')
                nt.assert_array_almost_equal(comp2pos, (1, 0, 0))

                comp2ori = geometer.orientation('comp2')
                nt.assert_array_almost_equal(comp2ori, (0, 0, 0))

                comp3pos = geometer.position('comp3')
                nt.assert_array_almost_equal(comp3pos, (1, 0, 0))

                comp3ori = geometer.orientation('comp3')
                nt.assert_array_almost_equal(comp3ori, toMatrix((3, 4, 5)))

                comp5ori = geometer.orientation('comp5')
                nt.assert_array_almost_equal(comp5ori, toMatrix((-90, 0, 90)))

                comp6pos = geometer.position('comp6')
                nt.assert_array_almost_equal(comp6pos, (-2, 3, -1))

                return
Пример #8
0
 def main(self):
     geometer = self.inventory.geometer
     
     comp2pos = geometer.position('comp2')
     nt.assert_array_almost_equal(comp2pos, (1,0,0))
     
     comp2ori = geometer.orientation('comp2')
     nt.assert_array_almost_equal(comp2ori, (0,0,0))
     
     comp3pos = geometer.position('comp3')
     nt.assert_array_almost_equal(comp3pos, (1,0,0))
     
     comp3ori = geometer.orientation('comp3')
     nt.assert_array_almost_equal(comp3ori, toMatrix((3,4,5)))
     
     comp5ori = geometer.orientation('comp5')
     nt.assert_array_almost_equal(comp5ori, toMatrix((-90,0,90)))
     
     comp6pos = geometer.position('comp6')
     nt.assert_array_almost_equal(comp6pos, (-2,3,-1))
     
     return
Пример #9
0
def tomatrix(orientation):
    ''' convert orientation to matrix representation

    if the input is a 3-tuple, it is assumed to be rotation angles
    in degrees (3 consecutive rotations along x,y,z axis)

    if the input can be reshaped to 3X3 matrix, just reshape it and return
    '''
    orientation = np.array(orientation)
    if orientation.size == 3:
        return mcstasRotations.toMatrix(*orientation)
    elif orientation.size == 9:
        orientation.shape = 3, 3
        return orientation
    raise ValueError, str(orientation)
Пример #10
0
def tomatrix(orientation):
    ''' convert orientation to matrix representation

    if the input is a 3-tuple, it is assumed to be rotation angles
    in degrees (3 consecutive rotations along x,y,z axis)

    if the input can be reshaped to 3X3 matrix, just reshape it and return
    '''
    orientation = np.array(orientation)
    if orientation.size==3:
        return mcstasRotations.toMatrix(*orientation)
    elif orientation.size==9:
        orientation.shape =3,3
        return orientation
    raise ValueError, str(orientation)
Пример #11
0
 def angles2matrix(self, angles):
     x, y, z = angles
     return mr.toMatrix(x, y, z, unit='deg').T
Пример #12
0
def transformCoordinateSystem(obj1abspos, obj1absori, obj2relpos, obj2relori):
    obj1absori = toMatrix(obj1absori)
    obj2relori = toMatrix(obj2relori)
    pos = obj1abspos + dot(obj1absori.T, obj2relpos)
    ori = mat(obj2relori) * mat(obj1absori)
    return pos, ori
Пример #13
0
 def angles2matrix(self, angles):
     x,y,z = angles
     return mr.toMatrix(x,y,z, unit='deg').T