def setUp(self): self._surf = FlatSurface() dir = N.array([[1, 1, -1], [-1, 1, -1], [-1, -1, -1], [1, -1, -1] ]).T / math.sqrt(3) position = c_[[0, 0, 1], [1, -1, 1], [1, 1, 1], [-1, 1, 1]] self._bund = RayBundle() self._bund.set_vertices(position) self._bund.set_directions(dir)
def test_intersect_ray2(self): rot = general_axis_rotation([1, 0, 0], N.pi / 4) objects = [FlatSurface(rotation=rot, width=4, height=4)] engine = TracerEngine(objects) params = engine.intersect_ray(self._bund)[0] correct_params = N.r_[[False, True, False]] N.testing.assert_array_almost_equal(params, correct_params)
def setUp(self): self.x = 1 / (math.sqrt(2)) dir = N.c_[[0, -self.x, self.x], [0, 0, -1]] position = N.c_[[0, 2, 1], [0, 2, 1]] self._bund = RayBundle() self._bund.set_vertices(position) self._bund.set_directions(dir) rot1 = general_axis_rotation([1, 0, 0], N.pi / 4) energy = N.array([1, 1]) self._bund.set_energy(energy) objects = [ FlatSurface(rotation=rot1, width=10, height=10), FlatSurface(width=10, height=10) ] self.engine = TracerEngine(objects)
def setUp(self): self._surf = FlatSurface() dir = N.array([[1, 1, -1], [-1, 1, -1], [-1, -1, -1], [1, -1, -1]]).T / math.sqrt(3) position = c_[[0,0,1], [1,-1,1], [1,1,1], [-1,1,1]] self._bund = RayBundle() self._bund.set_vertices(position) self._bund.set_directions(dir)
def setUp(self): dir = N.array([[1, 1, -1], [-1, 1, -1], [-1, -1, -1], [1, -1, -1] ]).T / math.sqrt(3) position = N.c_[[0, 0, 1], [1, -1, 1], [1, 1, 1], [-1, 1, 1]] self._bund = RayBundle() self._bund.set_vertices(position) self._bund.set_directions(dir) energy = N.array([1, 1, 1, 1]) self._bund.set_energy(energy) objects = [FlatSurface()] self.engine = TracerEngine(objects)
class TestTraceProtocol(unittest.TestCase): def setUp(self): self._surf = FlatSurface() dir = N.array([[1, 1, -1], [-1, 1, -1], [-1, -1, -1], [1, -1, -1]]).T / math.sqrt(3) position = c_[[0,0,1], [1,-1,1], [1,1,1], [-1,1,1]] self._bund = RayBundle() self._bund.set_vertices(position) self._bund.set_directions(dir) def test_register_incoming(self): """A simple bundle is registered correctly""" correct_params = r_[[math.sqrt(3)]*3] params = self._surf.register_incoming(self._bund) self.failUnless(params[0] == N.inf) N.testing.assert_array_almost_equal(params[1:], correct_params)
class TestTraceProtocol(unittest.TestCase): def setUp(self): self._surf = FlatSurface() dir = N.array([[1, 1, -1], [-1, 1, -1], [-1, -1, -1], [1, -1, -1] ]).T / math.sqrt(3) position = c_[[0, 0, 1], [1, -1, 1], [1, 1, 1], [-1, 1, 1]] self._bund = RayBundle() self._bund.set_vertices(position) self._bund.set_directions(dir) def test_register_incoming(self): """A simple bundle is registered correctly""" correct_params = r_[[math.sqrt(3)] * 3] params = self._surf.register_incoming(self._bund) self.failUnless(params[0] == N.inf) N.testing.assert_array_almost_equal(params[1:], correct_params)
import numpy as N import pylab as P import ray_bundle from flat_surface import FlatSurface # Create ray bundle dir = N.array([0., 0, -1]) center = N.array([0, 0, 2]).reshape(-1, 1) bund = ray_bundle.solar_disk_bundle(5000, center, dir, 2, N.pi / 1000.) # Intersect the bundle with a flat surface surf = FlatSurface() inters = ~N.isinf(surf.register_incoming(bund)) # Show non-intersecting rays v = bund.get_vertices()[:, ~inters] d = bund.get_directions()[:, ~inters] P.quiver(v[0], v[1], d[0], d[1], scale=0.1) # Show returning rays. outg = surf.get_outgoing(inters) v = outg.get_vertices() d = outg.get_directions() P.quiver(v[0], v[1], d[0], d[1], scale=0.2, color='red') P.show()
def runTest(self): """Doesn't allow negative width or height""" surf = FlatSurface() self.assertRaises(ValueError, surf.set_width, -42) self.assertRaises(ValueError, surf.set_height, -42)
import numpy as N import pylab as P import ray_bundle from flat_surface import FlatSurface # Create ray bundle dir = N.array([0., 0, -1]) center = N.array([0, 0, 2]).reshape(-1, 1) bund = ray_bundle.solar_disk_bundle(5000, center, dir, 2, N.pi/1000.) # Intersect the bundle with a flat surface surf = FlatSurface() inters = ~N.isinf(surf.register_incoming(bund)) # Show non-intersecting rays v = bund.get_vertices()[:, ~inters] d = bund.get_directions()[:, ~inters] P.quiver(v[0], v[1], d[0], d[1], scale=0.1) # Show returning rays. outg = surf.get_outgoing(inters) v = outg.get_vertices() d = outg.get_directions() P.quiver(v[0], v[1], d[0], d[1], scale=0.2, color='red') P.show()