def test_zAllZeros_consistentOutput(feature):
    n = 10
    pc = _create_point_cloud(z=0, n=n)
    compute_features(pc, [[] for _ in range(n)],
                     pc, [feature],
                     volume=_CYLINDER)
    _assert_consistent_attribute_length(pc)
def test_manyTargets_consistentOutput(feature):
    target_point_cloud = copy_point_cloud(_PC_260807)
    compute_features(copy_point_cloud(_PC_10),
                     _260807_NEIGHBORHOODS_IN_10,
                     target_point_cloud, [feature],
                     volume=_CYLINDER)
    _assert_consistent_attribute_length(target_point_cloud)
def test_completeTile_consistentOutput(feature):
    target_point_cloud = copy_point_cloud(_PC_1000)
    compute_features(copy_point_cloud(_PC_260807),
                     _1000_NEIGHBORHOODS_IN_260807,
                     target_point_cloud, [feature],
                     volume=_CYLINDER)
    _assert_consistent_attribute_length(target_point_cloud)
def _assert_consistent_output_with_n_neighbors(feature, n_neighbors):
    n_points = 10
    pc = _create_point_cloud(n=n_points)
    compute_features(pc, [range(n_neighbors) for _ in range(n_points)],
                     pc, [feature],
                     volume=_CYLINDER)
    _assert_consistent_attribute_length(pc)
Beispiel #5
0
    def extract_features(self,
                         volume_type,
                         volume_size,
                         feature_names,
                         sample_size=None):
        """
        Extract point-cloud features and assign them to the specified target
        point cloud.

        :param volume_type: Type of volume used to construct neighborhoods
        :param volume_size: Size of the volume-related parameter (in m)
        :param feature_names: List of the feature names to be computed
        :param sample_size: Sample neighborhoods with a random subset of points
        """
        logger.info('Building volume of type {}'.format(volume_type))
        volume = build_volume(volume_type, volume_size)
        logger.info('Constructing neighborhoods')
        neighborhoods = compute_neighborhoods(self.point_cloud,
                                              self.targets,
                                              volume,
                                              sample_size=sample_size)
        logger.info('Starting feature extraction ...')
        compute_features(self.point_cloud, neighborhoods, self.targets,
                         feature_names, volume)
        logger.info('... feature extraction completed.')
        return self
    def test_tutorial_once(self):
        """This test should be identical to running all cells in the tutorial notebook once, in order."""
        from laserchicken import load
        point_cloud = load('testdata/AHN3.las')

        point_cloud

        from laserchicken.normalize import normalize
        normalize(point_cloud)

        point_cloud

        from laserchicken.filter import select_polygon
        polygon = "POLYGON(( 131963.984125 549718.375000," + \
                  " 132000.000125 549718.375000," + \
                  " 132000.000125 549797.063000," + \
                  " 131963.984125 549797.063000," + \
                  " 131963.984125 549718.375000))"
        point_cloud = select_polygon(point_cloud, polygon)

        from laserchicken.filter import select_above, select_below
        points_below_1_meter = select_below(point_cloud, 'normalized_height', 1)
        points_above_1_meter = select_above(point_cloud, 'normalized_height', 1)

        from laserchicken import compute_neighborhoods
        from laserchicken import build_volume
        targets = point_cloud
        volume = build_volume("sphere", radius=5)
        neighborhoods = compute_neighborhoods(point_cloud, targets, volume)

        from laserchicken import compute_features
        compute_features(point_cloud, neighborhoods, targets, ['std_z', 'mean_z', 'slope'], volume)

        from laserchicken import register_new_feature_extractor
        from laserchicken.feature_extractor.band_ratio_feature_extractor import BandRatioFeatureExtractor
        register_new_feature_extractor(BandRatioFeatureExtractor(None, 1, data_key='normalized_height'))
        register_new_feature_extractor(BandRatioFeatureExtractor(1, 2, data_key='normalized_height'))
        register_new_feature_extractor(BandRatioFeatureExtractor(2, None, data_key='normalized_height'))
        register_new_feature_extractor(BandRatioFeatureExtractor(None, 0, data_key='z'))

        from laserchicken.feature_extractor.feature_extraction import list_feature_names
        sorted(list_feature_names())

        cylinder = build_volume("infinite cylinder", radius=5)
        neighborhoods = compute_neighborhoods(point_cloud, targets, cylinder)
        compute_features(point_cloud, neighborhoods, targets, ['band_ratio_1<normalized_height<2'], cylinder)

        from laserchicken import export
        export(point_cloud, 'my_output.ply')
def test_inputNotChanged(feature):
    original_environment = _PC_260807
    environment = copy_point_cloud(original_environment)
    original_targets = _PC_10
    targets = copy_point_cloud(original_targets)
    original_neighborhoods = _10_NEIGHBORHOODS_IN_260807
    neighborhoods = [[e for e in l] for l in original_neighborhoods]

    compute_features(environment,
                     neighborhoods,
                     targets, [feature],
                     volume=_CYLINDER)

    _assert_attributes_not_changed(original_environment, environment)
    _assert_attributes_not_changed(original_targets, targets)
    assert json.dumps(original_neighborhoods) == json.dumps(neighborhoods)
 def _find_neighbors_for_random_targets_and_compute_entropy(self):
     num_all_pc_points = len(self.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(self.point_cloud,
                                                 rand_indices)
     radius = 25
     neighborhoods = list(
         compute_cylinder_neighborhood(self.point_cloud, target_point_cloud,
                                       radius))
     compute_features(self.point_cloud,
                      neighborhoods,
                      target_point_cloud, ["entropy_z"],
                      InfiniteCylinder(5),
                      layer_thickness=0.1)
     return target_point_cloud