Example #1
0
class ParaxToRealCase(unittest.TestCase):
    def setUp(self):
        self.mat = mat = ModelMaterial(n=1.5)
        d = np.random.randn(3) * 1e-1 + (0, 0, 1.)
        a = np.random.randn(3) * 1e-8
        a[1:] = 0
        self.s = Spheroid(curvature=.1,
                          distance=.2,
                          material=mat,
                          direction=d,
                          angles=a)
        de = self.s.excidence(1 / self.s.material.n)
        self.sa = Spheroid(direction=de)

    def test_real_similar_to_parax(self, n=100, e=1e-3):
        y0p = np.random.randn(n, 2) * e
        u0p = np.random.randn(n, 2) * e
        y0r = np.hstack((y0p, np.ones((n, 1)) * -self.s.distance))
        u0r = np.hstack((sinarctan(u0p), np.zeros((n, 1))))
        u0r[:, 2] = np.sqrt(1 - np.square(u0p).sum(1))
        yup, np_ = self.s.propagate_paraxial(np.hstack((y0p, u0p)).T, 1., 1.)
        yp, up = np.hsplit(yup.T, 2)
        # y0r, u0r = self.s.to_normal(y0r, u0r)
        yr, ur, nr, tr = self.s.propagate(y0r, u0r, 1., 1.)
        # yr, ur = self.s.from_normal(yr, ur)
        yr, ur = self.sa.to_axis(yr, ur)
        nptest.assert_allclose(nr, np_, rtol=e**2, atol=3e-8)
        nptest.assert_allclose(yr[:, :2], yp, rtol=e**2, atol=3e-8)
        nptest.assert_allclose(tanarcsin(ur), up / np_, rtol=e**2, atol=3e-8)
Example #2
0
class ParaxToRealCase(unittest.TestCase):
    def setUp(self):
        self.mat = mat = ModelMaterial(n=1.5)
        d = np.random.randn(3)*1e-1 + (0, 0, 1.)
        a = np.random.randn(3)*1e-8
        a[1:] = 0
        self.s = Spheroid(curvature=.1, distance=.2, material=mat,
                          direction=d, angles=a)
        de = self.s.excidence(1/self.s.material.n)
        self.sa = Spheroid(direction=de)

    def test_real_similar_to_parax(self, n=100, e=1e-3):
        y0p = np.random.randn(n, 2)*e
        u0p = np.random.randn(n, 2)*e
        y0r = np.hstack((y0p, np.ones((n, 1))*-self.s.distance))
        u0r = np.hstack((sinarctan(u0p), np.zeros((n, 1))))
        u0r[:, 2] = np.sqrt(1 - np.square(u0p).sum(1))
        yup, np_ = self.s.propagate_paraxial(np.hstack((y0p, u0p)).T, 1., 1.)
        yp, up = np.hsplit(yup.T, 2)
        # y0r, u0r = self.s.to_normal(y0r, u0r)
        yr, ur, nr, tr = self.s.propagate(y0r, u0r, 1., 1.)
        # yr, ur = self.s.from_normal(yr, ur)
        yr, ur = self.sa.to_axis(yr, ur)
        nptest.assert_allclose(nr, np_, rtol=e**2, atol=3e-8)
        nptest.assert_allclose(yr[:, :2], yp, rtol=e**2, atol=3e-8)
        nptest.assert_allclose(tanarcsin(ur), up/np_, rtol=e**2, atol=3e-8)
Example #3
0
 def setUp(self):
     self.mat = mat = ModelMaterial(n=1.5)
     d = np.random.randn(3)*1e-1 + (0, 0, 1.)
     a = np.random.randn(3)*1e-8
     a[1:] = 0
     self.s = Spheroid(curvature=.1, distance=.2, material=mat,
                       direction=d, angles=a)
     de = self.s.excidence(1/self.s.material.n)
     self.sa = Spheroid(direction=de)
Example #4
0
 def setUp(self):
     self.mat = mat = ModelMaterial(n=1.5)
     d = np.random.randn(3)*1e-1 + (0, 0, 1.)
     a = np.random.randn(3)*1e-8
     a[1:] = 0
     self.s = Spheroid(curvature=.1, distance=.2, material=mat,
                       direction=d, angles=a)
     de = self.s.excidence(1/self.s.material.n)
     self.sa = Spheroid(direction=de)
Example #5
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])
Example #6
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])
Example #7
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)))
Example #8
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)))
Example #9
0
 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)
Example #10
0
 def setUp(self):
     self.s = Spheroid(distance=2., direction=(1, 3, 4.),
                       angles=(.3, .2, .1))
Example #11
0
 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)
Example #12
0
 def setUp(self):
     self.s = Spheroid(distance=2.,
                       direction=(1, 3, 4.),
                       angles=(.3, .2, .1))