Beispiel #1
0
def _get_default_extractors():
    return [PointDensityFeatureExtractor(),
            EchoRatioFeatureExtractor(),
            EigenValueVectorizeFeatureExtractor(),
            EntropyFeatureExtractor(),
            EntropyFeatureExtractor(data_key=keys.normalized_height),
            PulsePenetrationFeatureExtractor(),
            SigmaZFeatureExtractor(),
            MedianFeatureExtractor(),
            MedianFeatureExtractor(data_key=keys.normalized_height),
            VarianceFeatureExtractor(),
            VarianceFeatureExtractor(data_key=keys.normalized_height),
            MeanStdCoeffFeatureExtractor(),
            MeanStdCoeffFeatureExtractor(data_key=keys.normalized_height),
            MeanStdCoeffFeatureExtractor(data_key=keys.intensity),
            SkewFeatureExtractor(),
            SkewFeatureExtractor(data_key=keys.normalized_height),
            KurtosisFeatureExtractor(),
            KurtosisFeatureExtractor(data_key=keys.normalized_height),
            RangeFeatureExtractor(),
            RangeFeatureExtractor(data_key=keys.normalized_height),
            RangeFeatureExtractor(data_key=keys.intensity),
            DensityAbsoluteMeanFeatureExtractor(),
            DensityAbsoluteMeanFeatureExtractor(data_key=keys.normalized_height),
            BandRatioFeatureExtractor(None, 1, data_key=keys.normalized_height),
            BandRatioFeatureExtractor(1, 2, data_key=keys.normalized_height),
            BandRatioFeatureExtractor(2, 3, data_key=keys.normalized_height),
            BandRatioFeatureExtractor(3, None, data_key=keys.normalized_height)] \
           + [PercentileFeatureExtractor(percentile=p) for p in range(1, 101)] \
           + [PercentileFeatureExtractor(percentile=p, data_key=keys.normalized_height) for p in range(1, 101)]
Beispiel #2
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)
    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')
Beispiel #4
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]))
Beispiel #5
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)
Beispiel #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)
Beispiel #7
0
 def test_provides_with_data_key(self):
     self.assertEqual(['band_ratio_1<normalized_height<3'],
                      BandRatioFeatureExtractor(
                          1, 3, data_key=keys.normalized_height).provides())
Beispiel #8
0
 def test_provides_with_zero_upper_limit(self):
     self.assertEqual(['band_ratio_z<0'],
                      BandRatioFeatureExtractor(None, 0).provides())
Beispiel #9
0
 def test_provides_with_zero_lower_limit(self):
     self.assertEqual(['band_ratio_0<z'],
                      BandRatioFeatureExtractor(0, None).provides())
Beispiel #10
0
 def test_provides_simple(self):
     self.assertEqual(['band_ratio_6<z<20'],
                      BandRatioFeatureExtractor(6, 20).provides())