def assert_std_for_z_function_in_xy_grid(z_checkered, expected):
    """Assert that the standard deviation of z values in a grid of unit x and y"""
    n_points, points = create_points_in_xy_grid(z_checkered)
    point_cloud = create_point_cloud(points[:, 0], points[:, 1], points[:, 2])
    targets = create_point_cloud([0], [0], [0])
    compute_features(point_cloud, [range(n_points)], targets, ['sigma_z'],
                     InfiniteCylinder(10))
    np.testing.assert_almost_equal(targets[keys.point]['sigma_z']['data'][0],
                                   expected)
    def test_eigenvalues_of_too_few_points_results_in_0():
        """If there are too few points to calculate the eigen values don't output NaN or inf."""
        a = np.array([5])
        pc = create_point_cloud(a, a, a)

        compute_features(pc, [[0]], pc, ["eigenv_1", "eigenv_2", "eigenv_3"],
                         InfiniteCylinder(5))

        eigen_val_123 = np.array(
            [pc[keys.point]['eigenv_{}'.format(i)]['data'] for i in [1, 2, 3]])
        assert not np.any(np.isnan(eigen_val_123))
        assert not np.any(np.isinf(eigen_val_123))
 def test_with_neighborhood_generator():
     """Should run for all extractors without error meaning that neighborhood generator is only iterated once.
     Using actual feature extractors here because test feature extractors don't use neighborhoods. """
     n = 200
     feature_names = ['vectorized1', 'test1_a', 'median_z', 'mean_z']
     x = np.ones(n)
     y = np.ones(n)
     z = np.ones(n)
     target = test_tools.create_point_cloud(x, y, z)
     neighborhoods = ([] for _ in range(len(target["vertex"]["x"]["data"])))
     feature_extraction.compute_features({}, neighborhoods, target,
                                         feature_names, Sphere(5))
    def test_eigenvalues_in_cylinders(self):
        """Test provenance added (This should actually be part the general feature extractor test suite)."""
        random.seed(102938482634)
        point_cloud = load(os.path.join('testdata', 'AHN3.las'))
        num_all_pc_points = len(point_cloud[keys.point]["x"]["data"])
        rand_indices = [
            random.randint(0, num_all_pc_points) for _ in range(20)
        ]
        target_point_cloud = utils.copy_point_cloud(point_cloud, rand_indices)
        radius = 2.5
        neighbors = compute_neighbors.compute_cylinder_neighborhood(
            point_cloud, target_point_cloud, radius)

        compute_features(point_cloud, neighbors, target_point_cloud,
                         ["eigenv_1", "eigenv_2", "eigenv_3"],
                         InfiniteCylinder(5))

        self.assertEqual(
            "laserchicken.feature_extractor.eigenvals_feature_extractor",
            target_point_cloud[keys.provenance][-1]["module"])
def _compute_features(target, feature_names):
    neighborhoods = [[] for _ in range(len(target["vertex"]["x"]["data"]))]
    feature_extraction.compute_features({}, neighborhoods, target,
                                        feature_names, Sphere(5))
    return target