def test_height_stats(self):
     pc_in = load("testdata/AHN2.las")
     neighborhood = [89664, 23893, 30638, 128795, 62052, 174453, 29129, 17127, 128215, 29667, 116156, 119157, 98591,
                     7018,
                     61494, 65194, 117931, 62971, 10474, 90322]
     kurtosis_z = self.extractor.extract(pc_in, [neighborhood], None, None, None)[0]
     np.testing.assert_allclose(kurtosis_z, 3.968414258629714)
예제 #2
0
 def test_wkt_polygons_contains_original_not_changed(self):
     """Point cloud in should not change by filtering."""
     pc_in = load("testdata/AHN2.las")
     len_x_before = len(pc_in[point]['x']['data'])
     _pc_out = select_polygon(pc_in, self.polygon_around_1_point_ahn2)
     len_x_after = len(pc_in[point]['x']['data'])
     assert_equal(len_x_after, len_x_before)
    def setUp(self):
        """
        Set up the test.

        Load in a bunch of real data from AHN3.
        """
        np.random.seed(1234)

        _TEST_FILE_NAME = 'AHN3.las'
        _TEST_DATA_SOURCE = 'testdata'

        _CYLINDER = InfiniteCylinder(4)
        _PC_260807 = load(os.path.join(_TEST_DATA_SOURCE, _TEST_FILE_NAME))
        _PC_1000 = copy_point_cloud(
            _PC_260807,
            array_mask=(np.random.choice(range(
                len(_PC_260807[keys.point]['x']['data'])),
                                         size=1000,
                                         replace=False)))
        _1000_NEIGHBORHOODS_IN_260807 = list(
            compute_neighbors.compute_neighborhoods(_PC_260807, _PC_1000,
                                                    _CYLINDER))

        self.point_cloud = _PC_260807
        self.neigh = _1000_NEIGHBORHOODS_IN_260807
 def test_height_stats_without_neighbors(self):
     pc_in = load("testdata/AHN2.las")
     neighborhood = []
     max_z, min_z, range_z = RangeFeatureExtractor().extract(
         pc_in, [neighborhood], pc_in, None, None)[:, 0]
     assert np.isnan(range_z)
     assert np.isnan(max_z)
     assert np.isnan(min_z)
예제 #5
0
 def test_shp_polygons_containsEmpty():
     """ Selecting all points within a Polygon. """
     pc_in = load("testdata/AHN2.las")
     pc_out = select_polygon(pc_in, "testdata/ahn2_geometries_shp/ahn2_polygon_empty.shp", read_from_file=True)
     x = pc_out[point]['x']['data']
     y = pc_out[point]['y']['data']
     assert (len(x) == 0)
     assert (len(y) == 0)
 def test_height_stats_without_neighbors(self):
     pc_in = load("testdata/AHN2.las")
     neighborhood = []
     mean_z, std_z, coeff_var_z = self.extractor.extract(
         pc_in, [neighborhood], pc_in, None, None)[:, 0]
     assert np.isnan(mean_z)
     assert np.isnan(std_z)
     assert np.isnan(coeff_var_z)
예제 #7
0
 def test_points_in_polygon_wkt_invalidPolygon():
     """Polygon is not closed so should raise error."""
     pc_in = load("testdata/AHN2.las")
     with pytest.raises(ValueError):
         select_polygon(
             pc_in,
             "POLYGON(( 243590.0 572110.0, 243640.0 572160.0, 243700.0 572110.0, 243640.0 572060.0 ))"
         )
예제 #8
0
 def test_shp_polygons_contains():
     """ Selecting all points within a Polygon. """
     pc_in = load("testdata/AHN2.las")
     pc_out = select_polygon(pc_in, "testdata/ahn2_geometries_shp/ahn2_polygon.shp", read_from_file=True)
     x = pc_out[point]['x']['data']
     y = pc_out[point]['y']['data']
     # Seemingly redundant 'astype' call: since pandas 0.24 Dataframe() doesn't enforce the given dtype as before
     df_out = pd.DataFrame({'x': x, 'y': y}, dtype=np.int32).astype(dtype=np.int32)
     df = pd.read_csv("testdata/ahn2_polygon.out", sep=',', header=0, index_col=0, dtype=np.int32)
     assert (pd.DataFrame.equals(df, df_out))
    def setUp(self):
        """Set up the test."""
        self.point_cloud = load(os.path.join(self._test_data_source, self._test_file_name))

        random.seed(102938482634)
        self.target_point_cloud = self._get_random_targets()

        radius = 0.5
        self.sphere = Sphere(radius)
        self.cyl = InfiniteCylinder(radius)
예제 #10
0
 def test_wkt_polygons_containsEmpty():
     """ Selecting all points within a Polygon. """
     pc_in = load("testdata/AHN2.las")
     pc_out = select_polygon(pc_in,
                             ("POLYGON(( 253590.0 582110.0, "
                              "253640.0 582160.0, 253700.0 582110.0, "
                              "253640.0 582060.0, 253590.0 582110.0 ))"))
     x = pc_out[point]['x']['data']
     y = pc_out[point]['y']['data']
     assert (len(x) == 0)
     assert (len(y) == 0)
예제 #11
0
 def test_wkt_polygons_contains_single_point(self):
     """Selecting a single point with a tiny polygon. Test for https://github.com/eEcoLiDAR/eEcoLiDAR/issues/64. """
     pc_in = load("testdata/AHN2.las")
     pc_out = select_polygon(pc_in, self.polygon_around_1_point_ahn2)
     x = pc_out[point]['x']['data']
     y = pc_out[point]['y']['data']
     expected_x = 243627.841248
     expected_y = 572073.440002
     assert_equal(len(x), 1)
     assert_almost_equal(x[0], expected_x, 4)
     assert_almost_equal(y[0], expected_y, 4)
 def test_height_stats(self):
     pc_in = load("testdata/AHN2.las")
     neighborhood = [
         89664, 23893, 30638, 128795, 62052, 174453, 29129, 17127, 128215,
         29667, 116156, 119157, 98591, 7018, 61494, 65194, 117931, 62971,
         10474, 90322
     ]
     max_z, min_z, range_z = RangeFeatureExtractor().extract(
         pc_in, [neighborhood], None, None, None)[:, 0]
     np.testing.assert_allclose(range_z, 5.5)
     np.testing.assert_allclose(max_z, 5.979999973773956)
     np.testing.assert_allclose(min_z, 0.47999997377395631)
 def test_height_stats(self):
     pc_in = load("testdata/AHN2.las")
     neighborhood = [
         89664, 23893, 30638, 128795, 62052, 174453, 29129, 17127, 128215,
         29667, 116156, 119157, 98591, 7018, 61494, 65194, 117931, 62971,
         10474, 90322
     ]
     mean_z, std_z, coeff_var_z = self.extractor.extract(
         pc_in, [neighborhood], None, None, None)[:, 0]
     np.testing.assert_allclose(mean_z, 1.3779999737739566)
     np.testing.assert_allclose(std_z, 1.3567741153191268)
     np.testing.assert_allclose(coeff_var_z, 0.9845966191155302)
예제 #14
0
    def test_percentile(self):
        """Compute the percentile of a given selection."""
        _test_file_name = 'AHN3.las'
        _test_data_source = 'testdata'

        point_cloud = load(os.path.join(_test_data_source, _test_file_name))
        index = [
            89664, 23893, 30638, 128795, 62052, 174453, 29129, 17127, 128215, 29667, 116156, 119157, 98591, 7018, 61494,
            65194, 117931, 62971, 10474, 90322
        ]
        extractor = PercentileFeatureExtractor()

        extractor.extract(point_cloud, index, None, None, None)
예제 #15
0
    def load(self, **load_opts):
        """
        Read point cloud from disk.

        :param load_opts: Arguments passed to the laserchicken load function
        """
        check_path_exists(self.input_path, should_exist=True)
        input_file_list = _get_input_file_list(self.input_path)
        logger.info('Loading point cloud data ...')
        for file in input_file_list:
            logger.info('... loading {}'.format(file))
            add_to_point_cloud(self.point_cloud, load(file, **load_opts))
        logger.info('... loading 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_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 test_valid(self):
        """Compute the echo ratio for a sphere/cylinder at different target points without crashing."""
        # read the data
        self.point_cloud = load(
            os.path.join(self._test_data_source, self._test_file_name))

        # get the target point clouds
        random.seed(102938482634)
        self.target_point_cloud = self._get_random_targets()
        self.target_point_cloud_index = 0

        # volume descriptions
        radius = 0.5
        self.cyl = InfiniteCylinder(radius)
        neighborhoods = compute_neighborhoods(self.point_cloud,
                                              self.target_point_cloud,
                                              self.cyl)

        # extractor
        extractor = PulsePenetrationFeatureExtractor()
        extractor.extract(self.point_cloud, neighborhoods, None, None, None)
예제 #19
0
 def setUp(self):
     self.pointcloud = load(
         os.path.join(self._test_data_source, self._test_file_name))
예제 #20
0
 def test_points_in_polygon_wkt_Line():
     pc_in = load("testdata/AHN2.las")
     with pytest.raises(ValueError):
         select_polygon(pc_in, "LINESTRING(3 4,10 50,20 25)")
예제 #21
0
 def test_points_in_polygon_wkt_MultiLine():
     pc_in = load("testdata/AHN2.las")
     with pytest.raises(ValueError):
         select_polygon(
             pc_in,
             "MULTILINESTRING((3 4,10 50,20 25),(-5 -8,-10 -8,-15 -4))")
예제 #22
0
def assert_none_path_raises_value_error(function):
    pc_in = load("testdata/AHN2.las")
    with pytest.raises(Exception):
        function(pc_in, None, read_from_file=True)
예제 #23
0
 def test_points_in_polygon_shp_invalidPolygon():
     pc_in = load("testdata/AHN2.las")
     with pytest.raises(ValueError):
         select_polygon(pc_in,
                        "testdata/ahn2_geometries_shp/invalid_polygon.shp",
                        read_from_file=True)
예제 #24
0
 def test_points_in_polygon_shp_MultiLine():
     pc_in = load("testdata/AHN2.las")
     with pytest.raises(ValueError):
         select_polygon(pc_in,
                        "testdata/ahn2_geometries_shp/multiline.shp",
                        read_from_file=True)
 def test_height_stats_without_neighbors(self):
     pc_in = load("testdata/AHN2.las")
     neighborhood = []
     kurtosis_z = self.extractor.extract(pc_in, [neighborhood], pc_in, None, None)[0]
     assert np.isnan(kurtosis_z)
예제 #26
0
 def test_points_in_polygon_wkt_MultiPoint():
     pc_in = load("testdata/AHN2.las")
     with pytest.raises(ValueError):
         select_polygon(pc_in, "MULTIPOINT(3.5 5.6, 4.8 10.5)")
예제 #27
0
def assert_none_wkt_raises_value_error(function):
    pc_in = load("testdata/AHN2.las")
    with pytest.raises(ValueError):
        function(pc_in, None)
예제 #28
0
 def test_points_in_polygon_wkt_Collection():
     pc_in = load("testdata/AHN2.las")
     with pytest.raises(ValueError):
         select_polygon(
             pc_in, "GEOMETRYCOLLECTION(POINT(4 6),LINESTRING(4 6,7 10))")
 def setUp(self):
     self.point_cloud = load(
         os.path.join(self._test_data_source, self._test_file_name))
     random.seed(102938482634)
예제 #30
0
 def test_points_in_polygon_wkt_Collection():
     pc_in = load("testdata/AHN2.las")
     with pytest.raises(ValueError):
         select_polygon(pc_in,
                        "testdata/ahn2_geometries_wkt/collection.wkt",
                        read_from_file=True)