From 6aff5fd858412a01e4bb0321d58fd6c57285e0cd Mon Sep 17 00:00:00 2001 From: Romulo Goncalves Date: Thu, 25 Jan 2018 17:19:46 +0100 Subject: [PATCH 1/3] Height stats --- laserchicken/height_stats.py | 31 +++++++++++++++++++++++++++++++ laserchicken/test_height_stats.py | 24 ++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 laserchicken/height_stats.py create mode 100644 laserchicken/test_height_stats.py diff --git a/laserchicken/height_stats.py b/laserchicken/height_stats.py new file mode 100644 index 0000000..292fa95 --- /dev/null +++ b/laserchicken/height_stats.py @@ -0,0 +1,31 @@ +import numpy as np +import scipy.stats.stats as stat + +from laserchicken import utils +from laserchicken.feature_extractor.abc import AbstractFeatureExtractor +from laserchicken.keys import point + + + +class heightStatistics(AbstractFeatureExtractor): + @classmethod + def requires(cls): + return [] + + @classmethod + def provides(cls): + return ['max_z', 'min_z', 'mean_z', 'median_z', 'std_z', 'var_z', 'range', 'coeff_var_z', 'skew_z', 'kurto_z'] + + def extract(self,sourcepc,neighborhood,targetpc,targetindex): + z = sourcepc[point]['z']['data'] + max_z = np.max(z) + min_z = np.min(z) + mean_z = np.mean(z) + median_z = np.median(z) + std_z = np.std(z) + var_z = np.var(z) + range = max_z - min_z + coeff_var_z = np.std(z)/np.mean(z) + skew_z = stat.skew(z) + kurto_z = stat.kurtosis(z) + return (max_z, min_z, mean_z, median_z, std_z, var_z, range, coeff_var_z, skew_z, kurto_z) \ No newline at end of file diff --git a/laserchicken/test_height_stats.py b/laserchicken/test_height_stats.py new file mode 100644 index 0000000..b08865d --- /dev/null +++ b/laserchicken/test_height_stats.py @@ -0,0 +1,24 @@ +import random +import unittest + +from laserchicken.height_stats import heightStatistics +from laserchicken import read_las, keys + +class TestHeightStats(unittest.TestCase): + + @staticmethod + def test_height_stats(): + pc_in = read_las.read("testdata/AHN2.las") + num_all_pc_points = len(pc_in[keys.point]["x"]["data"]) + rand_indices = [random.randint(0, num_all_pc_points) for p in range(20)] + (max_z, min_z, mean_z, median_z, std_z, var_z, range, coeff_var_z, skew_z, kurto_z) = heightStatistics.extract(pc_in, rand_indices, None, None) + assert (max_z == 0) + assert (min_z == 0) + assert (mean_z == 0) + assert (median_z == 0) + assert (std_z == 0) + assert (var_z == 0) + assert (range == 0) + assert (coeff_var_z == 0) + assert (skew_z == 0) + assert (kurto_z == 0) \ No newline at end of file From 0c0886b2031fb93c90d24bf244836cf0eca112e0 Mon Sep 17 00:00:00 2001 From: Romulo Goncalves Date: Thu, 25 Jan 2018 17:40:05 +0100 Subject: [PATCH 2/3] Results. --- laserchicken/height_stats.py | 2 +- laserchicken/test_height_stats.py | 40 +++++++++++++++++++------------ 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/laserchicken/height_stats.py b/laserchicken/height_stats.py index 292fa95..4227294 100644 --- a/laserchicken/height_stats.py +++ b/laserchicken/height_stats.py @@ -17,7 +17,7 @@ def provides(cls): return ['max_z', 'min_z', 'mean_z', 'median_z', 'std_z', 'var_z', 'range', 'coeff_var_z', 'skew_z', 'kurto_z'] def extract(self,sourcepc,neighborhood,targetpc,targetindex): - z = sourcepc[point]['z']['data'] + z = sourcepc[point]['z']['data'][neighborhood] max_z = np.max(z) min_z = np.min(z) mean_z = np.mean(z) diff --git a/laserchicken/test_height_stats.py b/laserchicken/test_height_stats.py index b08865d..fb41ccf 100644 --- a/laserchicken/test_height_stats.py +++ b/laserchicken/test_height_stats.py @@ -1,3 +1,4 @@ +import os import random import unittest @@ -5,20 +6,29 @@ from laserchicken import read_las, keys class TestHeightStats(unittest.TestCase): + _test_file_name = 'AHN3.las' + _test_data_source = 'testdata' + pointcloud = None - @staticmethod - def test_height_stats(): + def test_height_stats(self): pc_in = read_las.read("testdata/AHN2.las") - num_all_pc_points = len(pc_in[keys.point]["x"]["data"]) - rand_indices = [random.randint(0, num_all_pc_points) for p in range(20)] - (max_z, min_z, mean_z, median_z, std_z, var_z, range, coeff_var_z, skew_z, kurto_z) = heightStatistics.extract(pc_in, rand_indices, None, None) - assert (max_z == 0) - assert (min_z == 0) - assert (mean_z == 0) - assert (median_z == 0) - assert (std_z == 0) - assert (var_z == 0) - assert (range == 0) - assert (coeff_var_z == 0) - assert (skew_z == 0) - assert (kurto_z == 0) \ No newline at end of file + indices = [89664, 23893, 30638, 128795, 62052, 174453, 29129, 17127, 128215, 29667, 116156, 119157, 98591, 7018, 61494, 65194, 117931, 62971, 10474, 90322] + (max_z, min_z, mean_z, median_z, std_z, var_z, range, coeff_var_z, skew_z, kurto_z) = heightStatistics.extract(self, pc_in, indices, None, None) + print(max_z, min_z, mean_z, median_z, std_z, var_z, range, coeff_var_z, skew_z, kurto_z) + assert (max_z == 5.979999973773956) + assert (min_z == 0.47999997377395631) + assert (mean_z == 1.3779999737739566) + assert (median_z == 0.69999997377395629) + assert (std_z == 1.3567741153191268) + assert (var_z == 1.8408359999999995) + assert (range == 5.5) + assert (coeff_var_z == 0.9845966191155302) + assert (skew_z == 2.083098281031817) + assert (kurto_z == 3.968414258629714) + + def setUp(self): + self.pointcloud = read_las.read(os.path.join(self._test_data_source, self._test_file_name)) + random.seed(20) + + def tearDown(self): + pass \ No newline at end of file From 47e08976b7456134e48bd5dd3875f182c37d287a Mon Sep 17 00:00:00 2001 From: cwmeijer Date: Thu, 1 Feb 2018 17:06:52 +0100 Subject: [PATCH 3/3] fix object oriented error and formatting --- laserchicken/height_stats.py | 12 +++++------- laserchicken/test_height_stats.py | 22 ++++++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/laserchicken/height_stats.py b/laserchicken/height_stats.py index 4227294..c28cafa 100644 --- a/laserchicken/height_stats.py +++ b/laserchicken/height_stats.py @@ -1,13 +1,11 @@ import numpy as np import scipy.stats.stats as stat -from laserchicken import utils from laserchicken.feature_extractor.abc import AbstractFeatureExtractor from laserchicken.keys import point - -class heightStatistics(AbstractFeatureExtractor): +class HeightStatistics(AbstractFeatureExtractor): @classmethod def requires(cls): return [] @@ -16,7 +14,7 @@ def requires(cls): def provides(cls): return ['max_z', 'min_z', 'mean_z', 'median_z', 'std_z', 'var_z', 'range', 'coeff_var_z', 'skew_z', 'kurto_z'] - def extract(self,sourcepc,neighborhood,targetpc,targetindex): + def extract(self, sourcepc, neighborhood, targetpc, targetindex): z = sourcepc[point]['z']['data'][neighborhood] max_z = np.max(z) min_z = np.min(z) @@ -24,8 +22,8 @@ def extract(self,sourcepc,neighborhood,targetpc,targetindex): median_z = np.median(z) std_z = np.std(z) var_z = np.var(z) - range = max_z - min_z - coeff_var_z = np.std(z)/np.mean(z) + range_z = max_z - min_z + coeff_var_z = np.std(z) / np.mean(z) skew_z = stat.skew(z) kurto_z = stat.kurtosis(z) - return (max_z, min_z, mean_z, median_z, std_z, var_z, range, coeff_var_z, skew_z, kurto_z) \ No newline at end of file + return max_z, min_z, mean_z, median_z, std_z, var_z, range_z, coeff_var_z, skew_z, kurto_z diff --git a/laserchicken/test_height_stats.py b/laserchicken/test_height_stats.py index fb41ccf..72db367 100644 --- a/laserchicken/test_height_stats.py +++ b/laserchicken/test_height_stats.py @@ -2,33 +2,35 @@ import random import unittest -from laserchicken.height_stats import heightStatistics +from laserchicken.height_stats import HeightStatistics from laserchicken import read_las, keys + class TestHeightStats(unittest.TestCase): - _test_file_name = 'AHN3.las' - _test_data_source = 'testdata' - pointcloud = None def test_height_stats(self): + print(os.getcwd()) + print(os.path.exists("testdata/AHN2.las")) pc_in = read_las.read("testdata/AHN2.las") - indices = [89664, 23893, 30638, 128795, 62052, 174453, 29129, 17127, 128215, 29667, 116156, 119157, 98591, 7018, 61494, 65194, 117931, 62971, 10474, 90322] - (max_z, min_z, mean_z, median_z, std_z, var_z, range, coeff_var_z, skew_z, kurto_z) = heightStatistics.extract(self, pc_in, indices, None, None) - print(max_z, min_z, mean_z, median_z, std_z, var_z, range, coeff_var_z, skew_z, kurto_z) + indices = [89664, 23893, 30638, 128795, 62052, 174453, 29129, 17127, 128215, 29667, 116156, 119157, 98591, 7018, + 61494, 65194, 117931, 62971, 10474, 90322] + extractor = HeightStatistics() + (max_z, min_z, mean_z, median_z, std_z, var_z, range_z, coeff_var_z, skew_z, kurto_z) = extractor.extract( + pc_in, indices, None, None) + print(max_z, min_z, mean_z, median_z, std_z, var_z, range_z, coeff_var_z, skew_z, kurto_z) assert (max_z == 5.979999973773956) assert (min_z == 0.47999997377395631) assert (mean_z == 1.3779999737739566) assert (median_z == 0.69999997377395629) assert (std_z == 1.3567741153191268) assert (var_z == 1.8408359999999995) - assert (range == 5.5) + assert (range_z == 5.5) assert (coeff_var_z == 0.9845966191155302) assert (skew_z == 2.083098281031817) assert (kurto_z == 3.968414258629714) def setUp(self): - self.pointcloud = read_las.read(os.path.join(self._test_data_source, self._test_file_name)) random.seed(20) def tearDown(self): - pass \ No newline at end of file + pass