Esempio n. 1
0
class TransformCase(unittest.TestCase):
    def setUp(self):
        self.s = Spheroid(distance=2., direction=(1, 3, 4.),
                          angles=(.3, .2, .1))

    def test_offset(self):
        nptest.assert_allclose(self.s.offset,
                               self.s.distance*self.s.direction)

    def test_from_to_axis(self, n=10):
        x = np.random.randn(n, 3)
        x1 = self.s.to_axis(x)
        x2 = self.s.from_axis(x1)
        nptest.assert_allclose(x, x2)

    def test_from_to_normal(self, n=10):
        x = np.random.randn(n, 3)
        x1 = self.s.to_normal(x)
        x2 = self.s.from_normal(x1)
        nptest.assert_allclose(x, x2)

    def test_rot(self):
        self.s.angles = 0, 0, 0
        x = np.array([0., 0, 3])
        x1 = self.s.from_normal(x)
        nptest.assert_allclose(x1, self.s.direction*3)
        self.s.direction = 0, 0, 1.
        self.s.angles = .1, 0, 0
        x1 = self.s.from_normal(x)
        nptest.assert_allclose(x1, (0, 3*np.sin(.1), 3*np.cos(.1)))
Esempio n. 2
0
class TransformCase(unittest.TestCase):
    def setUp(self):
        self.s = Spheroid(distance=2.,
                          direction=(1, 3, 4.),
                          angles=(.3, .2, .1))

    def test_offset(self):
        nptest.assert_allclose(self.s.offset,
                               self.s.distance * self.s.direction)

    def test_from_to_axis(self, n=10):
        x = np.random.randn(n, 3)
        x1 = self.s.to_axis(x)
        x2 = self.s.from_axis(x1)
        nptest.assert_allclose(x, x2)

    def test_from_to_normal(self, n=10):
        x = np.random.randn(n, 3)
        x1 = self.s.to_normal(x)
        x2 = self.s.from_normal(x1)
        nptest.assert_allclose(x, x2)

    def test_rot(self):
        self.s.angles = 0, 0, 0
        x = np.array([0., 0, 3])
        x1 = self.s.from_normal(x)
        nptest.assert_allclose(x1, self.s.direction * 3)
        self.s.direction = 0, 0, 1.
        self.s.angles = .1, 0, 0
        x1 = self.s.from_normal(x)
        nptest.assert_allclose(x1, (0, 3 * np.sin(.1), 3 * np.cos(.1)))
Esempio n. 3
0
class ParaxialCase(unittest.TestCase):
    def setUp(self):
        self.mat = mat = ModelMaterial(n=1.5)
        self.s0 = Spheroid(curvature=0., distance=0., material=mat)
        self.s = Spheroid(curvature=.1, distance=0, material=mat)
        self.sm0 = Spheroid(curvature=0, distance=0, material=mirror)
        self.sm = Spheroid(curvature=.1, distance=0, material=mirror)

    def test_offset(self):
        nptest.assert_allclose(self.s.direction, (0, 0, 1))
        nptest.assert_allclose(self.s.distance, 0)
        nptest.assert_allclose(self.s.offset, 0)

    def test_rotation(self):
        nptest.assert_allclose(self.s.angles, (0, 0, 0.))
        nptest.assert_allclose(self.s.from_axis([0, 0, 1]), (0, 0, 1))
        nptest.assert_allclose(self.s.from_normal([0, 0, 1]), (0, 0, 1))

    def test_snell_paraxial(self):
        y0, u0 = (1, 2), (.2, .1)
        yu, n = self.s0.propagate_paraxial(np.hstack((y0, u0)), 1., 1.)
        y, u = np.hsplit(yu, 2)
        mu = 1/self.s0.material.n
        nptest.assert_allclose(y, y0)
        nptest.assert_allclose(u, u0)

    def test_snell_paraxial_mirror(self):
        y0, u0 = (1, 2), (.2, .1)
        yu, n = self.sm0.propagate_paraxial(np.hstack((y0, u0)), 1., 1.)
        y, u = np.hsplit(yu, 2)
        nptest.assert_allclose(y, y0)
        nptest.assert_allclose(u, u0)

    def test_align(self):
        d = 0, -.1, 1
        d /= np.linalg.norm(d)
        mu = 1/self.s0.material.n
        self.s0.align(d, mu)
        e = self.s0.from_normal(self.s0.excidence(mu))
        nptest.assert_allclose(e, d)
        y0, u0 = (1, 2), (.2, .0)
        yu, n = self.s0.propagate_paraxial(np.hstack((y0, u0)), 1., 1.)
        y, u = np.hsplit(yu, 2)
        nptest.assert_allclose(y[0], y0[0])
        nptest.assert_allclose(u[0], u0[0])
        nptest.assert_allclose(u[1], d[0])
Esempio n. 4
0
class ParaxialCase(unittest.TestCase):
    def setUp(self):
        self.mat = mat = ModelMaterial(n=1.5)
        self.s0 = Spheroid(curvature=0., distance=0., material=mat)
        self.s = Spheroid(curvature=.1, distance=0, material=mat)
        self.sm0 = Spheroid(curvature=0, distance=0, material=mirror)
        self.sm = Spheroid(curvature=.1, distance=0, material=mirror)

    def test_offset(self):
        nptest.assert_allclose(self.s.direction, (0, 0, 1))
        nptest.assert_allclose(self.s.distance, 0)
        nptest.assert_allclose(self.s.offset, 0)

    def test_rotation(self):
        nptest.assert_allclose(self.s.angles, (0, 0, 0.))
        nptest.assert_allclose(self.s.from_axis([0, 0, 1]), (0, 0, 1))
        nptest.assert_allclose(self.s.from_normal([0, 0, 1]), (0, 0, 1))

    def test_snell_paraxial(self):
        y0, u0 = (1, 2), (.2, .1)
        yu, n = self.s0.propagate_paraxial(np.hstack((y0, u0)), 1., 1.)
        y, u = np.hsplit(yu, 2)
        mu = 1 / self.s0.material.n
        nptest.assert_allclose(y, y0)
        nptest.assert_allclose(u, u0)

    def test_snell_paraxial_mirror(self):
        y0, u0 = (1, 2), (.2, .1)
        yu, n = self.sm0.propagate_paraxial(np.hstack((y0, u0)), 1., 1.)
        y, u = np.hsplit(yu, 2)
        nptest.assert_allclose(y, y0)
        nptest.assert_allclose(u, u0)

    def test_align(self):
        d = 0, -.1, 1
        d /= np.linalg.norm(d)
        mu = 1 / self.s0.material.n
        self.s0.align(d, mu)
        e = self.s0.from_normal(self.s0.excidence(mu))
        nptest.assert_allclose(e, d)
        y0, u0 = (1, 2), (.2, .0)
        yu, n = self.s0.propagate_paraxial(np.hstack((y0, u0)), 1., 1.)
        y, u = np.hsplit(yu, 2)
        nptest.assert_allclose(y[0], y0[0])
        nptest.assert_allclose(u[0], u0[0])
        nptest.assert_allclose(u[1], d[0])