numpy.c_

Here are the examples of the python api numpy.c_ taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

151 Examples 7

Example 1

Project: lfd
Source File: move_box.py
View license
def get_move_traj(t_start, t_end, start_fixed):
    hmat_start = np.r_[np.c_[R, t_start], np.c_[0,0,0,1]]
    hmat_end = np.r_[np.c_[R, t_end], np.c_[0,0,0,1]]
    new_hmats = np.asarray(resampling.interp_hmats(np.arange(n_steps), np.r_[0, n_steps-1], [hmat_start, hmat_end]))
    dof_vals = sim.robot.GetManipulator(manip_name).GetArmDOFValues()
    old_traj = np.tile(dof_vals, (n_steps,1))
    
    traj, _, _ = planning.plan_follow_traj(sim.robot, manip_name, ee_link, new_hmats, old_traj, start_fixed=start_fixed, beta_rot=10000.0)
    return traj

Example 2

Project: lfd
Source File: features.py
View license
    def features(self, state, **kwargs):
        self.tgt_cld = state.cloud
        self.tgt_ctx.set_cld(self.tgt_cld)
        self.costs = batch_tps_rpm_bij(self.src_ctx, self.tgt_ctx, component_cost=True)[:, :SimpleMulFeats.N_costs]
        for i in range(self.N):
            self.regind_feats[i,:] = self.indicators[i]*self.costs[i,0]

        return np.c_[self.costs, self.indicators, self.regind_feats]

Example 3

Project: lfd
Source File: features.py
View license
    def features(self, state, timestep=-1, **kwargs):
        if timestep == -1:
            raise ValueError('timestep must be input')
        if timestep < TimestepFeats.N_timesteps:
            self.ts_indicators[:, timestep] = 1
        return np.c_[self.ts_indicators, self.indicators]

Example 4

Project: lfd
Source File: batchtps.py
View license
    def bidir_tps_cost(self, other, bend_coef=1, outlierprior=1e-1, outlierfrac=1e-2, 
                       outliercutoff=1e-2,  T = 5e-3, norm_iters = DEFAULT_NORM_ITERS,
                       sigma = 1, return_components = False):
        self.reset_warp_err()
        mapping_err  = self.mapping_cost(other, outlierprior, outlierfrac, outliercutoff, T, norm_iters)
        bending_cost = self.bending_cost(bend_coef)
        other_bending_cost = other.bending_cost(bend_coef)
        self_gram_mat_cost = self.gram_mat_cost(sigma)
        other_gram_mat_cost = other.gram_mat_cost(sigma)
        if return_components:
            return np.c_[mapping_err, bending_cost, other_bending_cost, self_gram_mat_cost, other_gram_mat_cost]
        return mapping_err + bending_cost + other_bending_cost

Example 5

Project: scikit-learn
Source File: test_rfe.py
View license
def test_rfe_features_importance():
    generator = check_random_state(0)
    iris = load_iris()
    X = np.c_[iris.data, generator.normal(size=(len(iris.data), 6))]
    y = iris.target

    clf = RandomForestClassifier(n_estimators=20,
                                 random_state=generator, max_depth=2)
    rfe = RFE(estimator=clf, n_features_to_select=4, step=0.1)
    rfe.fit(X, y)
    assert_equal(len(rfe.ranking_), X.shape[1])

    clf_svc = SVC(kernel="linear")
    rfe_svc = RFE(estimator=clf_svc, n_features_to_select=4, step=0.1)
    rfe_svc.fit(X, y)

    # Check if the supports are equal
    assert_array_equal(rfe.get_support(), rfe_svc.get_support())

Example 6

Project: scikit-learn
Source File: test_rfe.py
View license
def test_rfe_mockclassifier():
    generator = check_random_state(0)
    iris = load_iris()
    X = np.c_[iris.data, generator.normal(size=(len(iris.data), 6))]
    y = iris.target

    # dense model
    clf = MockClassifier()
    rfe = RFE(estimator=clf, n_features_to_select=4, step=0.1)
    rfe.fit(X, y)
    X_r = rfe.transform(X)
    clf.fit(X_r, y)
    assert_equal(len(rfe.ranking_), X.shape[1])
    assert_equal(X_r.shape, iris.data.shape)

Example 7

Project: scikit-learn
Source File: test_rfe.py
View license
def test_rfecv_mockclassifier():
    generator = check_random_state(0)
    iris = load_iris()
    X = np.c_[iris.data, generator.normal(size=(len(iris.data), 6))]
    y = list(iris.target)   # regression test: list should be supported

    # Test using the score function
    rfecv = RFECV(estimator=MockClassifier(), step=1, cv=5)
    rfecv.fit(X, y)
    # non-regression test for missing worst feature:
    assert_equal(len(rfecv.grid_scores_), X.shape[1])
    assert_equal(len(rfecv.ranking_), X.shape[1])

Example 8

Project: scikit-learn
Source File: test_rfe.py
View license
def test_rfecv_verbose_output():
    # Check verbose=1 is producing an output.
    from sklearn.externals.six.moves import cStringIO as StringIO
    import sys
    sys.stdout = StringIO()

    generator = check_random_state(0)
    iris = load_iris()
    X = np.c_[iris.data, generator.normal(size=(len(iris.data), 6))]
    y = list(iris.target)

    rfecv = RFECV(estimator=SVC(kernel="linear"), step=1, cv=5, verbose=1)
    rfecv.fit(X, y)

    verbose_output = sys.stdout
    verbose_output.seek(0)
    assert_greater(len(verbose_output.readline()), 0)

Example 9

Project: scikit-learn
Source File: test_rfe.py
View license
def test_rfe_cv_n_jobs():
    generator = check_random_state(0)
    iris = load_iris()
    X = np.c_[iris.data, generator.normal(size=(len(iris.data), 6))]
    y = iris.target

    rfecv = RFECV(estimator=SVC(kernel='linear'))
    rfecv.fit(X, y)
    rfecv_ranking = rfecv.ranking_
    rfecv_grid_scores = rfecv.grid_scores_

    rfecv.set_params(n_jobs=2)
    rfecv.fit(X, y)
    assert_array_almost_equal(rfecv.ranking_, rfecv_ranking)
    assert_array_almost_equal(rfecv.grid_scores_, rfecv_grid_scores)

Example 10

View license
def test_multi_task_lasso_and_enet():
    X, y, X_test, y_test = build_dataset()
    Y = np.c_[y, y]
    # Y_test = np.c_[y_test, y_test]
    clf = MultiTaskLasso(alpha=1, tol=1e-8).fit(X, Y)
    assert_true(0 < clf.dual_gap_ < 1e-5)
    assert_array_almost_equal(clf.coef_[0], clf.coef_[1])

    clf = MultiTaskElasticNet(alpha=1, tol=1e-8).fit(X, Y)
    assert_true(0 < clf.dual_gap_ < 1e-5)
    assert_array_almost_equal(clf.coef_[0], clf.coef_[1])

    clf = MultiTaskElasticNet(alpha=1.0, tol=1e-8, max_iter=1)
    assert_warns_message(ConvergenceWarning, 'did not converge', clf.fit, X, Y)

Example 11

View license
def test_multi_task_lasso_readonly_data():
    X, y, X_test, y_test = build_dataset()
    Y = np.c_[y, y]
    with TempMemmap((X, Y)) as (X, Y):
        Y = np.c_[y, y]
        clf = MultiTaskLasso(alpha=1, tol=1e-8).fit(X, Y)
        assert_true(0 < clf.dual_gap_ < 1e-5)
        assert_array_almost_equal(clf.coef_[0], clf.coef_[1])

Example 12

Project: scipy
Source File: test_fitpack.py
View license
    def test_multidim(self):
        # c can have trailing dims
        for n in range(3):
            t, c, k = self.spl
            c2 = np.c_[c, c, c]
            c2 = np.dstack((c2, c2))

            spl2 = splantider((t, c2, k), n)
            spl3 = splder(spl2, n)

            assert_allclose(t, spl3[0])
            assert_allclose(c2, spl3[1])
            assert_equal(k, spl3[2])

Example 13

Project: simpeg
Source File: Optimization.py
View license
    @Utils.count
    def projection(self, x):
        """projection(x)

            Make sure we are feasible.

        """
        return np.median(np.c_[self.lower,x,self.upper],axis=1)

Example 14

Project: simpeg
Source File: Optimization.py
View license
    @Utils.count
    def projection(self, x):
        """projection(x)

            Make sure we are feasible.

        """
        return np.median(np.c_[self.lower,x,self.upper],axis=1)

Example 15

Project: simpeg
Source File: test_cylMeshInnerProducts.py
View license
    def vectors(self, mesh):
        """ Get Vectors sig, sr. jx from sympy"""
        j, Sig = self.fcts()

        f_jr = sympy.lambdify((r, z), j[0], 'numpy')
        f_jz = sympy.lambdify((r, z), j[1], 'numpy')
        f_sigr = sympy.lambdify((r, z), Sig[0], 'numpy')
        f_sigz = sympy.lambdify((r, z), Sig[3], 'numpy')

        jr = f_jr(mesh.gridFx[:, 0], mesh.gridFx[:, 2])
        jz = f_jz(mesh.gridFz[:, 0], mesh.gridFz[:, 2])
        sigr = f_sigr(mesh.gridCC[:, 0], mesh.gridCC[:, 2])
        sigz = f_sigz(mesh.gridCC[:, 0], mesh.gridCC[:, 2])

        return np.c_[sigr, sigr, sigz], np.r_[jr, jz]

Example 16

Project: simpeg
Source File: test_cylMeshInnerProducts.py
View license
    def vectors(self, mesh):
        h, Sig = self.fcts()

        f_h = sympy.lambdify((r, z), h[0], 'numpy')
        f_sig = sympy.lambdify((r, z), Sig[0], 'numpy')

        ht = f_h(mesh.gridEy[:, 0], mesh.gridEy[:, 2])
        sig = f_sig(mesh.gridCC[:, 0], mesh.gridCC[:, 2])

        return np.c_[sig, sig, sig], np.r_[ht]

Example 17

Project: statsmodels
Source File: test_data.py
View license
    def test_drop(self):
        y = self.y
        X = self.X
        combined = np.c_[y, X]
        idx = ~np.isnan(combined).any(axis=1)
        y = y[idx]
        X = X[idx]
        data = sm_data.handle_data(self.y, self.X, 'drop')
        np.testing.assert_array_equal(data.endog, y)
        np.testing.assert_array_equal(data.exog, X)

Example 18

Project: statsmodels
Source File: test_data.py
View license
    def test_drop(self):
        y = self.y
        X = self.X
        combined = np.c_[y, X]
        idx = ~np.isnan(combined).any(axis=1)
        y = y.ix[idx]
        X = X.ix[idx]
        data = sm_data.handle_data(self.y, self.X, 'drop')
        np.testing.assert_array_equal(data.endog, y.values)
        ptesting.assert_series_equal(data.orig_endog, self.y.ix[idx])
        np.testing.assert_array_equal(data.exog, X.values)
        ptesting.assert_frame_equal(data.orig_exog, self.X.ix[idx])

Example 19

Project: tracer
Source File: parabolic_dish_gui.py
View license
    def create_dish_source(self):
        """
        Creates the two basic elements of this simulation: the parabolic dish,
        and the pillbox-sunshape ray bundle. Uses the variables set by 
        TraitsUI.
        """
        dish, f, W, H = standard_minidish(1., self.concent, self.refl, 1., 1.)
        # Add GUI annotations to the dish assembly:
        for surf in dish.get_homogenizer().get_surfaces():
            surf.colour = (1., 0., 0.)
        dish.get_main_reflector().colour = (0., 0., 1.)

        source = solar_disk_bundle(self.disp_num_rays,
            N.c_[[0., 0., f + H + 0.5]], N.r_[0., 0., -1.], 0.5, 0.00465)
        source.set_energy(N.ones(self.disp_num_rays)*1000./self.disp_num_rays)
        
        return dish, source

Example 20

Project: tracer
Source File: test_homogenizer.py
View license
    def test_first_hits(self):
        """Test bundle enters homogenizer correctly"""
        v, d = self.engine.ray_tracer(self.bund, 1, 0.05)
        
        out_dirs = N.c_[[-1, 0, -1], [1, 0, -1], [0, -1, -1], [0, 1, -1]]/N.sqrt(2)
        N.testing.assert_array_almost_equal(d, out_dirs)
        
        out_hits = N.c_[
            [2.5, 0, 8.5], 
            [-2.5, 0, 8.5], 
            [0, 1.5, 9.5], 
            [0, -1.5, 9.5]]
        N.testing.assert_array_almost_equal(v, out_hits)

Example 21

Project: tracer
Source File: test_spherical_lens.py
View license
    def test_paraxial_ray(self):
        """A paraxial ray reaches the focus"""
        rb = RayBundle(N.c_[[0., 0.001, 1.]], N.c_[[0., 0., -1.]], 
            energy=N.r_[1.], ref_index=N.r_[1.])
        screen = rect_one_sided_mirror(5, 5)
        f = self.lens.focal_length()
        screen.set_transform(translate(0, 0, -f))
        
        e = TracerEngine(Assembly([self.lens, screen]))
        vert, _ = e.ray_tracer(rb, 3, 1e-6)
        
        self.failUnlessAlmostEqual(vert[1,2], 0, 4)

Example 22

Project: tracer
Source File: test_spherical_lens.py
View license
    def test_cylinder(self):
        """The bounding cylinder exists for biconvex lens"""
        f = self.lens.focal_length()
        rb = RayBundle(N.c_[[0., 0., 0.08]], N.c_[[1., 0., 0.]],
            energy=N.r_[1.], ref_index=N.r_[1.5])
        
        e = TracerEngine(Assembly([self.lens]))
        verts, dirs = e.ray_tracer(rb, 1, 1e-6)

        N.testing.assert_array_equal(verts, N.tile(N.c_[[0.5, 0., 0.08]], (1,2)))
        N.testing.assert_array_equal(dirs, N.c_[[-1., 0., 0.], [1., 0., 0.]])

Example 23

Project: tracer
Source File: test_spherical_lens.py
View license
    def test_image_size(self):
        """Image size of an object imaged by a biconcave lens matches theory"""
        origin = N.c_[[0., 0.001, 1.]]
        direct = -origin/N.linalg.norm(origin)
        rb = RayBundle(origin, direct, energy=N.r_[1.], ref_index=N.r_[1.])
        
        # Magnification, see [1] p. 26.
        f = self.lens.focal_length()
        m = f/(origin[2] + f)
        
        # Image location, [ibid]:
        loc = origin[2]*m
        screen = rect_one_sided_mirror(5, 5)
        screen.set_transform(translate(0, 0, -loc))
        
        e = TracerEngine(Assembly([self.lens, screen]))
        vert, _ = e.ray_tracer(rb, 3, 1e-6)
        
        self.failUnlessAlmostEqual(vert[1,2], -m*origin[1], 4)

Example 24

Project: tracer
Source File: test_spherical_lens.py
View license
    def test_cylinder(self):
        """The bounding cylinder exists for biconcave lens"""
        f = self.lens.focal_length()
        rb = RayBundle(N.c_[[0., 0., 0.08]], N.c_[[1., 0., 0.]],
            energy=N.r_[1.], ref_index=N.r_[1.5])
        
        e = TracerEngine(Assembly([self.lens]))
        verts, dirs = e.ray_tracer(rb, 1, 1e-6)

        N.testing.assert_array_equal(verts, N.tile(N.c_[[0.5, 0., 0.08]], (1,2)))
        N.testing.assert_array_equal(dirs, N.c_[[-1., 0., 0.], [1., 0., 0.]])

Example 25

Project: tracer
Source File: test_spherical_lens.py
View license
    def test_paraxial_ray(self):
        """A paraxial ray reaches the focus of a planoconvex lens"""
        rb = RayBundle(N.c_[[0., 0.001, 1.]], N.c_[[0., 0., -1.]], 
            energy=N.r_[1.], ref_index=N.r_[1.])
        screen = rect_one_sided_mirror(5, 5)
        f = self.lens.focal_length()
        screen.set_transform(translate(0, 0, -f))
        
        e = TracerEngine(Assembly([self.lens, screen]))
        vert, _ = e.ray_tracer(rb, 3, 1e-6)
        
        self.failUnlessAlmostEqual(vert[1,2], 0, 4)

Example 26

Project: tracer
Source File: test_spherical_lens.py
View license
    def test_cylinder(self):
        """The bounding cylinder exists for planoconvex lens"""
        f = self.lens.focal_length()
        rb = RayBundle(N.c_[[0., 0., 0.001]], N.c_[[1., 0., 0.]],
            energy=N.r_[1.], ref_index=N.r_[1.5])

        e = TracerEngine(Assembly([self.lens]))
        verts, dirs = e.ray_tracer(rb, 1, 1e-6)

        N.testing.assert_array_equal(verts, N.tile(N.c_[[0.5, 0., 0.001]], (1,2)))
        N.testing.assert_array_equal(dirs, N.c_[[-1., 0., 0.], [1., 0., 0.]])

Example 27

Project: tracer
Source File: test_spherical_lens.py
View license
    def test_cylinder_height(self):
        """The bounding cylinder exists for planoconvex lens"""
        f = self.lens.focal_length()
        rb = RayBundle(N.c_[[0., 0., -0.01]], N.c_[[1., 0., 0.]],
            energy=N.r_[1.], ref_index=N.r_[1.5])

        e = TracerEngine(Assembly([self.lens]))
        verts, dirs = e.ray_tracer(rb, 1, 1e-6)

        N.testing.assert_array_equal(verts, N.array([]).reshape(3,0))

Example 28

Project: tracer
Source File: test_cut_sphere.py
View license
    def setUp(self):
        self.num_rays = 10
        dir = N.tile(N.c_[[0, 0, -1]], (1, self.num_rays))
        theta = N.linspace(0, 2*N.pi, self.num_rays, endpoint=False)
        position = N.vstack((N.cos(theta), N.sin(theta), N.ones(self.num_rays)))
        
        self._bund = RayBundle(position, dir)
        
        # The boundary is positioned to create a bottom hemisphere.
        boundary = BoundarySphere(radius=4., location=N.r_[0., 0., -4*N.sqrt(3)/2.])
        self.gm = CutSphereGM(2., boundary)
        self.prm = self.gm.find_intersections(N.eye(4), self._bund)

Example 29

Project: tracer
Source File: test_cylinder.py
View license
    def setUp(self):
        # Two rays inside, two outside; two horizontal, two slanted.
        pos = N.c_[[0., 0., 0.], [0., 0., 0.], [0., 1., 0.], [0., 1., 0.]]
        dir = N.c_[[0., 1., 0.], [0., 1., 1.], [0.,-1., 0.], [0.,-1., 1.]]
        dir /= N.sqrt(N.sum(dir**2, axis=0))
        
        self.bund = RayBundle(pos, dir)
        self.gm = InfiniteCylinder(diameter=1.)

Example 30

Project: tracer
Source File: test_cylinder.py
View license
    def setUp(self):
        # Two rays inside, two outside; two horizontal, two slanted.
        pos = N.c_[[0., 0., 0.], [0., 0., 0.], [0., 1., 0.], [0., 1., 0.],
            [0., 1., 0.], [0., 1., 0.1], [0., 0.2, -0.06], [0., 0., 0.03]]
        dir = N.c_[[0., 1., 0.], [0., 1., 1.], [0.,-1., 0.], [0.,-1., 1.],
            [0., -1., 0.05], [0., -1., -0.05], [0., 1., 0.2], [0., 1., 0.1]]
        dir /= N.sqrt(N.sum(dir**2, axis=0))
        
        self.bund = RayBundle(pos, dir)
        self.gm = FiniteCylinder(diameter=1., height=0.1)

Example 31

View license
    def setUp(self):
        dir = N.c_[[1, 1, -1], [-1, 1, -1], [-1, -1, -1], [1, -1, -1]] / math.sqrt(3)
        position = N.c_[[0,0,1], [1,-1,1], [1,1,1], [-1,1,1]]
        self._bund = RayBundle(position, dir)

        self.gm = FlatGeometryManager()
        self.prm = self.gm.find_intersections(N.eye(4), self._bund)

Example 32

View license
    def setUp(self):
        s2 = math.sqrt(2)
        dir = N.c_[[1, 0, -s2], [-1, 0, -s2], [-1, -s2, 0], [1, -s2, 0]] / math.sqrt(3)
        position = N.c_[[0,1/s2,1/s2], [1,0,s2], [1,s2,0], [-1,s2,0]]
        self._bund = RayBundle(position, dir)

        self.gm = FlatGeometryManager()
        frame = SP.generate_transform(N.r_[1., 0, 0], -N.pi/4., N.zeros((3,1)))
        self.prm = self.gm.find_intersections(frame, self._bund)

Example 33

View license
    def setUp(self):
        dir = N.c_[[1, 1, -1], [-1, 1, -1], [-1, -1, -1], [1, -1, -1]] / math.sqrt(3)
        position = N.c_[[0,0,1], [1,-1,1], [1,1,1], [-1,1,1]]
        self._bund = RayBundle(position, dir)
        
        self.gm = FlatGeometryManager()
        frame = SP.translate(1., 0., 0.)
        self.prm = self.gm.find_intersections(frame, self._bund)

Example 34

View license
    def setUp(self):
        dir = N.c_[[1, 1, 1], [-1, 1, 1], [-1, -1, 1], [1, -1, 1]] / math.sqrt(3)
        position = N.c_[[0,0,-1], [1,-1,-1], [1,1,-1], [-1,1,-1]]
        self._bund = RayBundle(position, dir)

        self.gm = FlatGeometryManager()
        self.prm = self.gm.find_intersections(N.eye(4), self._bund)

Example 35

Project: tracer
Source File: test_hemisphere_gm.py
View license
    def setUp(self):
        self.num_rays = 10
        dir = N.tile(N.c_[[0, 0, -1]], (1, self.num_rays))
        theta = N.linspace(0, 2*N.pi, self.num_rays, endpoint=False)
        position = N.vstack((N.cos(theta), N.sin(theta), N.ones(self.num_rays)))
        self._bund = RayBundle(position, dir)
        
        self.gm = HemisphereGM(radius=2.)
        self.prm = self.gm.find_intersections(N.eye(4), self._bund)

Example 36

Project: tracer
Source File: test_objects.py
View license
    def test_object(self):
        """Tests that the assembly heirarchy works at a basic level"""
        self.engine = TracerEngine(self.assembly)

        inters = self.engine.ray_tracer(self._bund,1,.05)[0]
        correct_inters = N.c_[[0,0,2],[0,0,-2]]

        N.testing.assert_array_almost_equal(inters, correct_inters)

Example 37

Project: tracer
Source File: test_objects.py
View license
    def test_rotation_and_translation(self):
        """Tests an assembly that has been translated and rotated"""
        self._bund = RayBundle()
        self._bund.set_vertices(N.c_[[0,-5,1],[0,5,1]])
        self._bund.set_directions(N.c_[[0,1,0],[0,1,0]])
        self._bund.set_energy(N.r_[[1,1]])
        self._bund.set_ref_index(N.r_[[1,1]])

        trans = generate_transform(N.r_[[1,0,0]], N.pi/2, N.c_[[0,0,1]])
        self.assembly.transform_children(trans)

        self.engine = TracerEngine(self.assembly)

        params =  self.engine.ray_tracer(self._bund,1,.05)[0]
        correct_params = N.c_[[0,-2,1]]

        N.testing.assert_array_almost_equal(params, correct_params)

Example 38

Project: tracer
Source File: test_objects.py
View license
    def test_assembly2(self):
        """Tests the assembly after two iterations"""
        self.engine = TracerEngine(self.assembly)
        params = self.engine.ray_tracer(self._bund,2,.05)[0]
        correct_params = N.c_[[0,-1,1], [0,-1,1],[0,0,1]]
        N.testing.assert_array_almost_equal(params, correct_params)

Example 39

Project: tracer
Source File: test_objects.py
View license
    def test_assembly3(self):      
        """Tests the assembly after three iterations"""  
        self.engine = TracerEngine(self.assembly)
        params = self.engine.ray_tracer(self._bund, 3,.05)[0]
        correct_params = N.c_[[0,-2.069044,-1],[0,0,-1]]

        N.testing.assert_array_almost_equal(params, correct_params)

Example 40

Project: tracer
Source File: test_objects.py
View license
    def setUp(self):
        self.assembly = Assembly()
        surface1 = Surface(Paraboloid(), optics_callables.perfect_mirror)
        self.object = AssembledObject()
        self.object.add_surface(surface1)
        self.assembly.add_object(self.object)
       
        x = 1./(math.sqrt(2))  
        dir = N.c_[[0,0,-1.],[0,x,-x]]
        position = N.c_[[0,0,1.],[0,0,1.]]
        self._bund = RayBundle(position, dir, energy=N.ones(2), ref_index=N.ones(2))

Example 41

Project: tracer
Source File: test_objects.py
View license
    def test_paraboloid1(self):  
        """Tests a paraboloid"""
        
        self.engine = TracerEngine(self.assembly)
        params =  self.engine.ray_tracer(self._bund,1,.05)[0]
        correct_params = N.c_[[0,0,0],[0,0.618033989, 0.381966011]]
        N.testing.assert_array_almost_equal(params, correct_params)

Example 42

Project: tracer
Source File: test_optics.py
View license
    def test_normal_incidence(self):
        """Rays at normal incidence achieve predicted reflectance."""
        dir = N.c_[[0, 0, 1]]
        norm = dir
        R = optics.fresnel(dir, norm, N.r_[1.], N.r_[1.5])
        self.failUnlessAlmostEqual(R, 0.04) # ref [1], page 44

Example 43

Project: tracer
Source File: test_optics.py
View license
    def test_grazing_incidence(self):
        """Grazing rays are not refracted"""
        dir = N.c_[[0, 0, 1]]
        norm = N.c_[[0, 1, 0]]
        R = optics.fresnel(dir, norm, N.r_[1.], N.r_[1.5])
        self.failUnlessAlmostEqual(R, 1.) # ref [1], page 45

Example 44

Project: tracer
Source File: test_optics.py
View license
    def test_no_reflectance(self):
        """With index of refraction = 1, no reflection"""
        dir = N.c_[[0, 1, 1]]/math.sqrt(2)
        norm = N.c_[[0, 1, 0]]
        R = optics.fresnel(dir, norm, N.r_[1.], N.r_[1.])
        self.failUnlessAlmostEqual(R, 0)

Example 45

Project: tracer
Source File: test_optics.py
View license
    def test_single_ref_idx(self):
        """Single refractive index is acceptable for refractions"""
        n1 = 1.
        n2 = 1.5
        dir = N.c_[[0, -1, 1], [0, -1, -1]]/math.sqrt(2)
        norm = N.c_[[0, -1, 0]]
        refr, dirs = optics.refractions(n1, n2, dir, norm)

        self.failUnless(refr.all(), "Some rays did not refract")
        correct_refrs = N.c_[N.sqrt([0, 7./9, 2./9])*N.r_[0,-1,1], -N.sqrt([0, 7./9, 2./9])]
        N.testing.assert_array_almost_equal(dirs, correct_refrs)

Example 46

Project: tracer
Source File: test_opt_callable.py
View license
    def setUp(self):
        """Set up the ray bundle and geometry"""
        dir = N.c_[[1, 1, -1], [-1, 1, -1], [-1, -1, -1], [1, -1, -1]] / N.sqrt(3)
        position = N.c_[[0,0,1], [1,-1,1], [1,1,1], [-1,1,1]]
        en = N.r_[100, 200, 300, 400]
        self._bund = RayBundle(position, dir, energy=en)
        
        self.gm = FlatGeometryManager()
        self.prm = self.gm.find_intersections(N.eye(4), self._bund)

Example 47

Project: tracer
Source File: test_opt_callable.py
View license
    def setUp(self):
        """Set up the ray bundle and geometry"""
        direct = N.c_[[1, 1, -1], [-1, 1, -1], [-1, -1, -1], [1, -1, -1]] / N.sqrt(3)
        position = N.c_[[0,0,1], [1,-1,1], [1,1,1], [-1,1,1]]
        en = N.r_[100, 200, 300, 400]
        self._bund = RayBundle(position, direct, energy=en)
        
        self.gm = FlatGeometryManager()
        self.prm = self.gm.find_intersections(N.eye(4), self._bund)

Example 48

Project: tracer
Source File: test_paraboloid_gm.py
View license
    def setUp(self):
        self.num_rays = 10
        dir = N.tile(N.c_[[0, 0, -1]], (1, self.num_rays))
        theta = N.linspace(0, 2*N.pi, self.num_rays, endpoint=False)
        position = N.vstack((N.cos(theta), N.sin(theta), N.ones(self.num_rays)))
        
        self._bund = RayBundle()
        self._bund.set_vertices(position)
        self._bund.set_directions(dir)

        self.gm = Paraboloid(a=5., b=5.)
        self.prm = self.gm.find_intersections(N.eye(4), self._bund)

Example 49

Project: tracer
Source File: test_paraboloid_gm.py
View license
    def setUp(self):
        dir = N.c_[[0., 0, -1], [0, 1, -1], [0, 11, -2], [0, 1, 0]]
        dir /= N.sqrt(N.sum(dir**2, axis=0))
        position = N.c_[[0., 0, 1], [0, -1, 1], [0, -11, 2], [0, 1, 1]]

        bund = RayBundle()
        bund.set_vertices(position)
        bund.set_directions(dir)
        self.bund = bund
        
        self.correct = N.r_[1., N.sqrt(2), N.sqrt(11**2 + 4)]

Example 50

Project: tracer
Source File: test_tracer_engine.py
View license
    def setUp(self):
        self.x = 1/(math.sqrt(2))
        dir = N.c_[[0,self.x,-self.x],[0,1,0]]
        position = N.c_[[0,0,1],[0,0,1]]
        self._bund = RayBundle(position, dir, energy=N.ones(2))

        rot1 = general_axis_rotation([1,0,0],N.pi/4)
        rot2 = general_axis_rotation([1,0,0],N.pi/(-4))
        surf1 = Surface(FlatGeometryManager(), opt.perfect_mirror, rotation=rot1)
        surf2 = Surface(FlatGeometryManager(), opt.perfect_mirror, rotation=rot2)
        
        self.assembly = Assembly()
        object = AssembledObject()
        object.add_surface(surf1)
        object.add_surface(surf2)
        self.assembly.add_object(object)

        self.engine = TracerEngine(self.assembly)