Esempio n. 1
0
 def test_cell_no_points(self):
     point_cloud = create_emtpy_point_cloud()
     targets = create_point_cloud(np.zeros(1), np.zeros(1), np.zeros(1))
     neighborhoods = compute_neighborhoods(point_cloud, targets, Cell(1))
     neighborhood = next(neighborhoods)
     print(neighborhood)
     assert_equal(len(neighborhood[0]), 0)
Esempio n. 2
0
 def test_zero_points_nan_outcome(self):
     """Zero points should return NaN."""
     point_cloud = create_point_cloud(np.zeros(0), np.zeros(0), np.zeros(0))
     targets = create_point_cloud(np.zeros(1), np.zeros(1), np.zeros(1))
     result = BandRatioFeatureExtractor(2,
                                        4).extract(point_cloud, [[]],
                                                   targets, 0, Cell(4))
     self.assertTrue(np.isnan(result[0]))
Esempio n. 3
0
def assert_expected_ratio(expected_ratio=0.4,
                          n_below_limit=10,
                          n_within=40,
                          n_above_limit=50,
                          volume=Cell(4)):
    assert_expected_ratios(np.array([expected_ratio]),
                           np.array([n_below_limit]), np.array([n_within]),
                           np.array([n_above_limit]), volume)
 def test_cell_grid_origin(self):
     _, points = create_points_in_xy_grid(lambda x, y: np.random.rand())
     point_cloud = create_point_cloud(points[:, 0], points[:, 1], points[:,
                                                                         2])
     targets = create_point_cloud(np.array([0]), np.array([0]),
                                  np.array([0]))  # Center of grid
     neighborhoods = list(
         compute_neighborhoods(point_cloud, targets, Cell(1.99)))
     assert_equal(len(neighborhoods[0]), 1)
Esempio n. 5
0
 def test_cell_grid(self):
     _, points = create_points_in_xy_grid(lambda x, y: np.random.rand())
     point_cloud = create_point_cloud(points[:, 0], points[:, 1], points[:,
                                                                         2])
     targets = create_point_cloud(np.array([4.5]), np.array([4.5]),
                                  np.array([4.5]))  # Center of grid
     neighborhoods = compute_neighborhoods(point_cloud, targets, Cell(2))
     neighborhood = next(neighborhoods)
     assert_equal(len(neighborhood[0]), 4)
Esempio n. 6
0
 def test_no_lower_bound_correct_outcome(self):
     """No lower bound should return all points below."""
     n = 10
     point_cloud = create_point_cloud(np.zeros(n), np.zeros(n),
                                      np.hstack([np.zeros(8),
                                                 np.ones(2)]))
     targets = create_point_cloud(np.zeros(1), np.zeros(1), np.zeros(1))
     result = BandRatioFeatureExtractor(None, 0.5).extract(
         point_cloud, [range(n)], targets, 0, Cell(4))
     np.testing.assert_equal(result[0], 0.8)
Esempio n. 7
0
 def test_cell_grid_larger_sample_size(self):
     _, points = create_points_in_xy_grid(lambda x, y: np.random.rand())
     point_cloud = create_point_cloud(points[:, 0], points[:, 1], points[:,
                                                                         2])
     targets = create_point_cloud(np.array([4.5]), np.array([4.5]),
                                  np.array([4.5]))  # Center of grid
     neighborhoods = compute_neighborhoods(
         point_cloud, targets, Cell(5),
         sample_size=10000)  # Result 36 neighbors
     _ = next(neighborhoods)
    def test_cell(self):
        n_included = 123
        n_excluded = 456
        x = np.append(np.zeros(n_included), np.ones(n_excluded))
        environment = create_point_cloud(x, x, x)
        target = create_point_cloud(np.zeros(1), np.zeros(1), np.zeros(1))

        cell = Cell(1)  # area = 1.0
        neighborhoods = compute_neighborhoods(environment, target, cell)

        extractor = PointDensityFeatureExtractor()
        densities = extractor.extract(environment, neighborhoods, target, [0], cell)
        np.testing.assert_allclose(densities, n_included)
Esempio n. 9
0
def assert_expected_ratios(expected_ratios,
                           n_below_limits,
                           n_withins,
                           n_above_limits,
                           volume=Cell(4)):
    n_ratios = len(expected_ratios)
    neighborhoods, point_cloud = generate_test_point_cloud_and_neighborhoods(
        n_below_limits, n_withins, n_above_limits, n_ratios)
    targets = create_point_cloud(np.zeros(n_ratios), np.zeros(n_ratios),
                                 np.zeros(n_ratios))
    extractor = BandRatioFeatureExtractor(LOWER_LIMIT, UPPER_LIMIT)
    result = extractor.extract(point_cloud, neighborhoods, targets, 0, volume)
    np.testing.assert_allclose(result, expected_ratios)
Esempio n. 10
0
    def test_cell(self):
        n_included = 123
        n_excluded = 456
        x = np.append(np.zeros(n_included), np.ones(n_excluded))
        environment = create_point_cloud(x, x, x)
        target = create_point_cloud(np.zeros(1), np.zeros(1), np.zeros(1))

        cell = Cell(1)  # area = 1.0
        neighbors_index = compute_neighborhoods(environment, target, cell)

        extractor = PointDensityFeatureExtractor()
        for index in neighbors_index:
            d = extractor.extract(environment, index, target, [0], cell)
            self.assertEqual(d, n_included)
Esempio n. 11
0
def normalize(point_cloud, cell_size=None):
    z = point_cloud[keys.point]['z']['data']
    point_cloud[keys.point][normalized_height] = {"type": 'float64', "data": np.array(z)}
    if cell_size is None:
        n_points = point_cloud[keys.point][normalized_height]['data'].size
        min_z = _calculate_min_z(range(n_points), point_cloud)
        point_cloud[keys.point][normalized_height]['data'] = z - min_z
    else:
        targets = _create_spanning_grid(point_cloud, cell_size)

        neighborhoods = compute_neighborhoods(point_cloud, targets, Cell(cell_size), sample_size=None)
        for neighborhood in neighborhoods:
            min_z = _calculate_min_z(neighborhood, point_cloud)
            point_cloud[keys.point][normalized_height]['data'][neighborhood] = z[neighborhood] - min_z
    import sys
    module = sys.modules[__name__]
    add_metadata(point_cloud, module, {'cell_size':cell_size})
    return point_cloud
Esempio n. 12
0
    def test_use_optional_data_key(self):
        """Should use data under the given data key (normalized z)."""
        n = 10
        zeros = np.zeros(n)
        point_cloud = create_point_cloud(zeros,
                                         zeros,
                                         zeros,
                                         normalized_z=np.hstack(
                                             [np.zeros(8),
                                              np.ones(2)]))
        targets = create_point_cloud(np.zeros(1), np.zeros(1), np.zeros(1))
        extractor = BandRatioFeatureExtractor(None,
                                              0.5,
                                              data_key=keys.normalized_height)

        result = extractor.extract(point_cloud, [range(n)], targets, 0,
                                   Cell(4))

        np.testing.assert_equal(result[0], 0.8)
Esempio n. 13
0
def normalize(point_cloud, cell_size=None):
    z = point_cloud[keys.point]['z']['data']
    point_cloud[keys.point][normalized_height] = {"type": 'float64', "data": np.array(z)}
    if cell_size is None:
        n_points = point_cloud[keys.point][normalized_height]['data'].size
        _, min_z, _ = range_extractor().extract(point_cloud, range(n_points), None, None, None)
        point_cloud[keys.point][normalized_height]['data'] = z - min_z
    else:
        targets = create_spanning_grid(point_cloud, cell_size)

        neighborhood_sets = compute_neighborhoods(point_cloud, targets, Cell(cell_size), sample_size=None)

        for neighborhood_set in neighborhood_sets:
            for neighborhood in neighborhood_set:
                _, min_z, _ = range_extractor().extract(point_cloud, neighborhood, None, None, None)
                point_cloud[keys.point][normalized_height]['data'][neighborhood] = z[neighborhood] - min_z
    import sys
    module = sys.modules[__name__]
    add_metadata(point_cloud, module, {'cell_size':cell_size})
    return point_cloud
Esempio n. 14
0
target = read_las.read(args.target)

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

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

start = time.time()

#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(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',
 def test_cell_calculateArea():
     assert_almost_equal(Cell(2).calculate_base_area(), 4.0)
 def test_cell_type():
     assert_equal(Cell(2).get_type(), Cell.TYPE)
Esempio n. 17
0
 def test_cell_volume(self):
     assert_expected_ratio(volume=Cell(5))