Exemplo n.º 1
0
    def test_entropy_in_cylinders(self):
        """Test computing of eigenvalues in cylinder."""
        num_all_pc_points = len(self.point_cloud[keys.point]["x"]["data"])
        rand_indices = [
            random.randint(0, num_all_pc_points) for p in range(20)
        ]
        target_point_cloud = utils.copy_point_cloud(self.point_cloud,
                                                    rand_indices)
        n_targets = len(target_point_cloud[keys.point]["x"]["data"])
        radius = 25
        neighbors = compute_neighbors.compute_cylinder_neighborhood(
            self.point_cloud, target_point_cloud, radius)

        target_idx_base = 0
        for x in neighbors:
            feature_extractor.compute_features(self.point_cloud,
                                               x,
                                               target_idx_base,
                                               target_point_cloud,
                                               ["entropy_z"],
                                               InfiniteCylinder(5),
                                               layer_thickness=0.1)
            target_idx_base += len(x)

        for i in range(n_targets):
            H = utils.get_attribute_value(target_point_cloud, i, "entropy_z")
            self.assertTrue(H >= 0)
        self.assertEqual(
            "laserchicken.feature_extractor.entropy_feature_extractor",
            target_point_cloud[keys.provenance][0]["module"])
        self.assertEqual([0.1],
                         target_point_cloud[keys.provenance][0]["parameters"])
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)], 0, targets, ['sigma_z'],
                     InfiniteCylinder(10))
    np.testing.assert_almost_equal(targets[keys.point]['sigma_z']['data'][0],
                                   expected)
Exemplo n.º 3
0
    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)

        feature_extractor.compute_features(
            pc, [[0]], 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))
Exemplo n.º 4
0
    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 = read_las.read(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)

        target_idx_base = 0
        for x in neighbors:
            feature_extractor.compute_features(
                point_cloud, x, target_idx_base, target_point_cloud,
                ["eigenv_1", "eigenv_2", "eigenv_3"], InfiniteCylinder(5))
            target_idx_base += len(x)

        self.assertEqual(
            "laserchicken.feature_extractor.eigenvals_feature_extractor",
            target_point_cloud[keys.provenance][0]["module"])
Exemplo n.º 5
0
#
neighbors = compute_neighborhoods(pc, target, Cell(np.float(args.radius)))
iteration = 0
target_idx_base = 0
for x in neighbors:
    end = time.time()
    difftime = end - start
    print(("build kd-tree: %f sec") % (difftime))
    print("Computed neighborhoods list length at iteration %d is: %d" %
          (iteration, len(x)))

    start1 = time.time()
    print("------ Feature calculation is started ------")
    compute_features(pc, x, target_idx_base, target, [
        'max_z', 'min_z', 'mean_z', 'median_z', 'std_z', 'var_z',
        'coeff_var_z', 'skew_z', 'kurto_z', 'sigma_z', 'perc_20', 'perc_40',
        'perc_60', 'perc_80', 'perc_90', 'pulse_penetration_ratio',
        'point_density', 'eigenv_1', 'eigenv_2', 'eigenv_3'
    ], Cell(np.float(args.radius)))
    target_idx_base += len(x)
    end1 = time.time()
    difftime1 = end1 - start1
    print(("feature calc: %f sec") % (difftime1))
    iteration += 1

write(target, args.output)

#
# example usage: computefea_wtargets_cylinder.py D:/GitHub/eEcoLiDAR/develop-branch/eEcoLiDAR/ D:/GitHub/eEcoLiDAR/myPhD_escience_analysis/test_data/testdata.las D:/GitHub/eEcoLiDAR/myPhD_escience_analysis/test_data/testdata.las 2.5 D:/GitHub/eEcoLiDAR/myPhD_escience_analysis/test_data/testdata.ply
#python D:/GitHub/eEcoLiDAR/myPhD_escience_analysis/test_laserchicken/release1/computefea_wtargets_cell.py D:/GitHub/eEcoLiDAR/develop-branch/eEcoLiDAR/ D:/Koma/Paper1_ReedStructure/Data/ALS/02gz2/testmetrics/tile_00003_norm2.las D:/Koma/Paper1_ReedStructure/Data/ALS/02gz2/testmetrics/tile_00003_norm_target.las 2.5 D:/Koma/Paper1_ReedStructure/Data/ALS/02gz2/testmetrics/testdata.ply
#
Exemplo n.º 6
0
print("------ Computing neighborhood is started ------")

#compute_neighborhoods is now a generator. To get the result of a generator the user
#needs to call next(compute_neighborhoods). The following shows how to get the results.
#
#indices_cyl=compute_neighborhoods(pc, target, Cell(np.float(args.radius)))
#
neighbors = compute_neighborhoods(pc, target, Cell(np.float(radius)))
iteration = 0
target_idx_base = 0
for x in neighbors:
    print("Computed neighborhoods list length at iteration %d is: %d" %
          (iteration, len(x)))

    print("------ Feature calculation is started ------")
    compute_features(pc, x, target_idx_base, target, [
        'min_z', 'max_z', 'mean_z', 'median_z', 'perc_10', 'perc_30',
        'perc_50', 'perc_70', 'perc_90', 'point_density', 'eigenv_1',
        'eigenv_2', 'eigenv_3', 'z_entropy', 'std_z', 'var_z', 'skew_z',
        'kurto_z', 'pulse_penetration_ratio', 'density_absolute_mean'
    ], Cell(np.float(radius)))
    target_idx_base += len(x)

    iteration += 1

write(target, filename + str(resolution) + "m_cell.ply")

end1 = time.time()
difftime1 = end1 - start1
print(("feature calc: %f sec") % (difftime1))
Exemplo n.º 7
0
print(("Number of points in target: %s ") %
      (target[point]['x']['data'].shape[0]))

print("------ Computing neighborhood is started ------")

#compute_neighborhoods is now a generator. To get the result of a generator the user
#needs to call next(compute_neighborhoods). The following shows how to get the results.
#
#indices_cyl=compute_neighborhoods(pc, target, Cell(np.float(args.radius)))
#
neighbors = compute_neighborhoods(pc, target, Cell(np.float(radius)))
iteration = 0
target_idx_base = 0
for x in neighbors:
    print("Computed neighborhoods list length at iteration %d is: %d" %
          (iteration, len(x)))

    print("------ Feature calculation is started ------")
    compute_features(pc, x, target_idx_base, target, [
        'max_z', 'mean_z', 'median_z', 'perc_10', 'perc_30', 'perc_50',
        'perc_70', 'perc_90'
    ], Cell(np.float(radius)))
    target_idx_base += len(x)

    iteration += 1

write(target, filename + str(resolution) + "m_cell.ply")

end1 = time.time()
difftime1 = end1 - start1
print(("feature calc: %f sec") % (difftime1))
Exemplo n.º 8
0
iteration = 0
target_idx_base = 0

fullstarttime = time.time()

for x in neighbors:
    end = time.time()
    difftime = end - start
    print(("build kd-tree: %f sec") % (difftime))
    print("Computed neighborhoods list length at iteration %d is: %d" %
          (iteration, len(x)))

    start1 = time.time()
    print("------ Feature calculation is started ------")
    compute_features(pc, x, target_idx_base, target,
                     ['eigenv_1', 'eigenv_2', 'eigenv_3'],
                     InfiniteCylinder(np.float(args.radius)))
    target_idx_base += len(x)
    end1 = time.time()
    difftime1 = end1 - start1
    print(("feature calc: %f sec") % (difftime1))
    iteration += 1

fullendtime = time.time()
fulldifftime = fullendtime - fullstarttime

print(fulldifftime)

write(target, args.output)

#
print(("Number of points in target: %s ") %
      (target[point]['x']['data'].shape[0]))

print("------ Computing neighborhood is started ------")

#compute_neighborhoods is now a generator. To get the result of a generator the user
#needs to call next(compute_neighborhoods). The following shows how to get the results.
#
#indices_cyl=compute_neighborhoods(pc, target, Cell(np.float(args.radius)))
#
neighbors = compute_neighborhoods(pc, target, Cell(np.float(radius)))
iteration = 0
target_idx_base = 0
for x in neighbors:
    print("Computed neighborhoods list length at iteration %d is: %d" %
          (iteration, len(x)))

    print("------ Feature calculation is started ------")
    compute_features(pc, x, target_idx_base, target, [
        'max_z', 'min_z', 'mean_z', 'median_z', 'std_z', 'var_z',
        'coeff_var_z', 'skew_z', 'kurto_z'
    ], Cell(np.float(radius)))
    target_idx_base += len(x)

    iteration += 1

write(target, workingdirectory + filename + "_cell_10m.ply")

end1 = time.time()
difftime1 = end1 - start1
print(("feature calc: %f sec") % (difftime1))
Exemplo n.º 10
0
from laserchicken.write_ply import write

print("------ Feature calculation is started ------")

# Import
pc = read_las.read(args.input)

f = open(args.kdtree, 'rb')
kdtree = pickle.load(f)
f.close()

start1 = time.time()

compute_features(pc, kdtree, 0, pc, [
    'max_z', 'min_z', 'mean_z', 'median_z', 'std_z', 'var_z', 'range',
    'coeff_var_z', 'skew_z', 'kurto_z', 'sigma_z', 'perc_20', 'perc_40',
    'perc_60', 'perc_80', 'pulse_penetration_ratio', 'density_absolute_mean'
], Sphere(np.float(args.radius)))
"""											   
feadataframe=pd.DataFrame({'_x':pc[point]['x']['data'],'_y':pc[point]['y']['data'],'_z':pc[point]['z']['data'],
                           'max_z':pc[point]['max_z']['data'],'min_z':pc[point]['min_z']['data'], 'mean_z':pc[point]['mean_z']['data'],
                           'median_z':pc[point]['median_z']['data'],'std_z':pc[point]['std_z']['data'], 'var_z':pc[point]['var_z']['data'],
                           'range':pc[point]['range']['data'],'coeff_var_z':pc[point]['coeff_var_z']['data'], 'skew_z':pc[point]['skew_z']['data'],'kurto_z':pc[point]['kurto_z']['data'],
						   'pulse_penetration_ratio':pc[point]['pulse_penetration_ratio']['data'],'density_absolute_mean':pc[point]['density_absolute_mean']['data'],
                           'sigma_z':pc[point]['sigma_z']['data'], 'perc_20':pc[point]['perc_20']['data'],
                           'perc_40':pc[point]['perc_40']['data'],'perc_60':pc[point]['perc_60']['data'], 'perc_80':pc[point]['perc_80']['data']})

feadataframe.to_csv(args.output,sep=";",index=False)
"""

end1 = time.time()
#needs to call next(compute_neighborhoods). The following shows how to get the results.
#
#indices_cyl=compute_neighborhoods(pc, target, InfiniteCylinder(np.float(args.radius)))
#
neighbors = compute_neighborhoods(pc, target,
                                  InfiniteCylinder(np.float(args.radius)))
iteration = 0
target_idx_base
for x in neighbors:
    end = time.time()
    difftime = end - start
    print(("build kd-tree: %f sec") % (difftime))
    print("Computed neighborhoods list length at iteration %d is: %d" %
          (iteration, len(indices_cyl)))

    # Calculate features
    start1 = time.time()
    compute_features(pc, indices_cyl, target_idx_base, target, [
        'max_z', 'min_z', 'mean_z', 'median_z', 'std_z', 'var_z', 'range',
        'coeff_var_z', 'skew_z', 'kurto_z', 'sigma_z', 'perc_20', 'perc_40',
        'perc_60', 'perc_80', 'echo_ratio', 'pulse_penetration_ratio',
        'density_absolute_mean'
    ], InfiniteCylinder(np.float(args.radius)))
    end1 = time.time()
    difftime1 = end1 - start1
    print(("feature calc: %f sec") % (difftime1))
    target_idx_base += len(x)
    iteration += 1

write(target, args.output)
#needs to call next(compute_neighborhoods). The following shows how to get the results.
#
#indices_cyl=compute_neighborhoods(pc, target, InfiniteCylinder(np.float(args.radius)))
#

neighbors = compute_neighborhoods(pc, target,
                                  InfiniteCylinder(np.float(args.radius)))
iteration = 0
target_idx_base = 0
for x in neighbors:
    end = time.time()
    difftime = end - start
    print(("build kd-tree: %f sec") % (difftime))
    print("Computed neighborhoods list length at iteration %d is: %d" %
          (iteration, len(x)))

    start1 = time.time()
    print("------ Feature calculation is started ------")
    compute_features(pc, x, target_idx_base, target, [
        'max_z', 'echo_ratio', 'eigenv_1', 'eigenv_2', 'eigenv_3',
        'normal_vector_1', 'normal_vector_2', 'normal_vector_3', 'slope',
        'pulse_penetration_ratio', 'sigma_z'
    ], InfiniteCylinder(np.float(args.radius)))
    target_idx_base += len(x)
    end1 = time.time()
    difftime1 = end1 - start1
    print(("feature calc: %f sec") % (difftime1))
    iteration += 1

write(target, args.output)
def _compute_features(target, feature_names, overwrite=False):
    neighborhoods = [[] for i in range(len(target["vertex"]["x"]["data"]))]
    feature_extractor.compute_features({}, neighborhoods, 0, target,
                                       feature_names, Sphere(5), overwrite)
    return target
#indices_cyl=compute_neighborhoods(pc, target, Sphere(2.5))
#
neighbors = compute_neighborhoods(pc, pc, Sphere(2.5))
iteration = 0
target_idx_base = 0
for x in neighbors:
    end = time.time()
    difftime = end - start
    print(("build kd-tree: %f sec") % (difftime))
    print("Computed neighborhoods list length at iteration %d is: %d" %
          (iteration, len(indices_cyl)))

    start1 = time.time()
    compute_features(pc, indices_cyl, target_idx_base, pc, [
        'max_z', 'min_z', 'mean_z', 'median_z', 'std_z', 'var_z', 'range',
        'coeff_var_z', 'skew_z', 'kurto_z', 'eigenv_1', 'eigenv_2', 'eigenv_3',
        'z_entropy', 'sigma_z', 'perc_20', 'perc_40', 'perc_60', 'perc_80'
    ], Sphere(2.5))
    feadataframe = pd.DataFrame({
        '_x': pc[point]['x']['data'],
        '_y': pc[point]['y']['data'],
        '_z': pc[point]['z']['data'],
        'max_z': pc[point]['max_z']['data'],
        'min_z': pc[point]['min_z']['data'],
        'mean_z': pc[point]['mean_z']['data'],
        'median_z': pc[point]['median_z']['data'],
        'std_z': pc[point]['std_z']['data'],
        'var_z': pc[point]['var_z']['data'],
        'range': pc[point]['range']['data'],
        'coeff_var_z': pc[point]['coeff_var_z']['data'],
        'skew_z': pc[point]['skew_z']['data'],