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 = read_las.read( 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 = next( 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 = read_las.read("testdata/AHN2.las") neighborhood = [] max_z, min_z, range_z = RangeFeatureExtractor().extract(pc_in, neighborhood, pc_in, None, None) assert np.isnan(range_z) assert np.isnan(max_z) assert np.isnan(min_z)
def test_height_stats(self): pc_in = read_las.read("testdata/AHN2.las") neighborhood = [89664, 23893, 30638, 128795, 62052, 174453, 29129, 17127, 128215, 29667, 116156, 119157, 98591, 7018, 61494, 65194, 117931, 62971, 10474, 90322] median_z = self.extractor.extract(pc_in, neighborhood, None, None, None) np.testing.assert_allclose(median_z, 0.69999997377395629)
def test_valid(self): """Compute the echo ratio for a sphere/cylinder at different target points without crashing.""" # read the data self.point_cloud = read_las.read( 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) neighbors = compute_neighborhoods(self.point_cloud, self.target_point_cloud, self.cyl) cylinder_index = [] for x in neighbors: cylinder_index += x # extractor extractor = PulsePenetrationFeatureExtractor() for index in cylinder_index: extractor.extract(self.point_cloud, index, None, None, None)
def test_wkt_polygons_contains_original_not_changed(self): """Point cloud in should not change by filtering.""" pc_in = read_las.read("testdata/AHN2.las") len_x_before = len(pc_in[point]['x']['data']) _pc_out = points_in_polygon_wkt(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 test_shp_polygons_containsEmpty(): """ Selecting all points within a Polygon. """ pc_in = read_las.read("testdata/AHN2.las") pc_out = points_in_polygon_shp_file(pc_in, "testdata/ahn2_geometries_shp/ahn2_polygon_empty.shp") 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 = read_las.read("testdata/AHN2.las") neighborhood = [] mean_z, std_z, coeff_var_z = self.extractor.extract( pc_in, neighborhood, pc_in, None, None) assert np.isnan(mean_z) assert np.isnan(std_z) assert np.isnan(coeff_var_z)
def test_height_stats(self): pc_in = read_las.read("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) 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_wkt_polygons_containsEmpty(): """ Selecting all points within a Polygon. """ pc_in = read_las.read("testdata/AHN2.las") pc_out = points_in_polygon_wkt(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)
def test_shp_polygons_contains(): """ Selecting all points within a Polygon. """ pc_in = read_las.read("testdata/AHN2.las") pc_out = points_in_polygon_shp_file(pc_in, "testdata/ahn2_geometries_shp/ahn2_polygon.shp") 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 = read_las.read(os.path.join( self._test_data_source, self._test_file_name)) random.seed(102938482634) self.targetpc = self._get_random_targets() radius = 0.5 self.sphere = Sphere(radius) self.cyl = InfiniteCylinder(radius)
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 = read_las.read("testdata/AHN2.las") pc_out = points_in_polygon_wkt(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 = read_las.read("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) 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)
def test_load_CorrectFirstX(self): """ Should . """ point_cloud = read(self.test_file_path) point = [ point_cloud['points']['x']['data'][0], point_cloud['points']['y']['data'][0], point_cloud['points']['z']['data'][0] ] np.testing.assert_allclose( np.array(point), np.array( [-1870.480059509277, 338897.281499328557, 192.363999260664]))
def test_percentile(self): """Compute the percentile of a given selection.""" _test_file_name = 'AHN3.las' _test_data_source = 'testdata' point_cloud = read_las.read(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)
def test_load_CorrectFirstX(self): """Should run without exception and compare equal.""" point_cloud = read(self.test_file_path) data = { 'x': 131999.984125, 'y': 549718.375, 'z': -0.34100002, 'gps_time': 78563787.97322202, 'intensity': 41, 'raw_classification': 9, } names = sorted(data) print("Order:", names) point = [point_cloud[keys.point][name]['data'][0] for name in names] np.testing.assert_allclose(np.array(point), np.array([data[name] for name in names]))
def setUp(self): # read the data self.point_cloud = read_las.read( os.path.join(self._test_data_source, self._test_file_name)) # get the target point clouds random.seed(102938482634) self.target_pc_sequential = self._get_random_targets() self.target_pc_vector = utils.copy_point_cloud( self.target_pc_sequential) self.target_pc_index = 0 # volume descriptions radius = 0.5 self.cyl = InfiniteCylinder(radius) self.neighbors = compute_neighborhoods(self.point_cloud, self.target_pc_sequential, self.cyl) self.cylinder_index = [] for x in self.neighbors: self.cylinder_index += x
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 = read_las.read(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) target_idx_base = 0 for x in neighbors: feature_extractor.compute_features( point_cloud, x, target_idx_base, target_point_cloud, ["eigenv_1", "eigenv_2", "eigenv_3"], InfiniteCylinder(5)) target_idx_base += len(x) self.assertEqual( "laserchicken.feature_extractor.eigenvals_feature_extractor", target_point_cloud[keys.provenance][0]["module"])
def test_load_nonexistentFile(self): """ Should raise exception. """ with pytest.raises(OSError): read('nonexistent.las')
def test_load_PointsContainX(self): """ Should run without exception and return points. """ point_cloud = read(self.test_file_path) print(point_cloud) self.assertIn('data', point_cloud['points']['x'])
from laserchicken import read_las from laserchicken.keys import point from laserchicken.spatial_selections import points_in_polygon_wkt from laserchicken import compute_neighbors from laserchicken.feature_extractor.height_statistics_feature_extractor import HeightStatisticsFeatureExtractor import numpy as np # Import pc = read_las.read( "D:/NAEM/Data/ALS_AHN2/SelStudyArea2_sel1_ground_height_sub3.las") pc_out = points_in_polygon_wkt( pc, "POLYGON((196550 446510,196550 446540,196580 446540,196580 446510,196550 446510))" ) #""" # Neighborhood calculation indices_cyl = compute_neighbors.compute_cylinder_neighborhood_indices( pc_out, pc_out, 0.5) indices_sph = compute_neighbors.compute_sphere_neighborhood_indices( pc_out, pc_out, 1) # Statistical descriptor feature calculation output_text = "" for i in range(len(indices_sph)): extractor = HeightStatisticsFeatureExtractor() max_z, min_z, mean_z, median_z, std_z, var_z, range_z, coeff_var_z, skew_z, kurto_z = extractor.extract( pc_out, indices_sph[i], None, None, None)
out_LAS.x = x out_LAS.y = y out_LAS.z = z out_LAS.intensity = false_intensity out_LAS.close() end1 = time.time() difftime1 = end1 - start1 print(("create target point: %f sec") % (difftime1)) # Calculate features start1 = time.time() print("------ Import is started ------") pc = read_las.read(workingdirectory + filename + ".las") target = read_las.read(workingdirectory + filename + "_target.las") radius = 10 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 ------") #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(radius)))
def test_load_containsPoints(self): """ Should run without exception and return points. """ point_cloud = read(self.test_file_path) self.assertIn('points', point_cloud)
def setUp(self): self.point_cloud = read_las.read( os.path.join(self._test_data_source, self._test_file_name)) random.seed(102938482634) kd_tree.initialize_cache()
parser.add_argument('output', help='absolute path of output point cloud') args = parser.parse_args() import sys sys.path.insert(0, args.path_of_laserchicken) from laserchicken import read_las from laserchicken.keys import point from laserchicken.volume_specification import Cell from laserchicken.compute_neighbors import compute_neighborhoods from laserchicken.feature_extractor import compute_features from laserchicken.write_ply import write print("------ Import is started ------") pc = read_las.read(args.input) 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))) #
# global variables parser = argparse.ArgumentParser() parser.add_argument('input', help='absolute path of input point cloud (las file)') args = parser.parse_args() filename = args.input resolution = 2.5 # Calculate features start1 = time.time() print("------ Import is started ------") pc = read_las.read(filename + ".las") target = read_las.read(filename + "_target.las") radius = resolution 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 ------") #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(radius)))
import sys sys.path.insert(0, 'D:/GitHub/eEcoLiDAR/develop-branch/eEcoLiDAR/') ## Import libraries from laserchicken import read_las from laserchicken.spatial_selections import points_in_polygon_wkt from laserchicken.keys import point from laserchicken.compute_neighbors import compute_neighbourhoods, compute_cylinder_neighborhood_indices, compute_sphere_neighborhood_indices from laserchicken.feature_extractor.height_statistics_feature_extractor import HeightStatisticsFeatureExtractor from laserchicken import write_ply ## Read-Write pc = read_las.read("D:/NAEM/Data/ALS_AHN2/SelStudyArea2_v2.las") pc_sub = points_in_polygon_wkt( pc, "POLYGON((196550 446510,196550 446540,196580 446540,196580 446510,196550 446510))" ) #write_ply.write(pc_sub, "D:/NAEM/Data/ALS_AHN2/SelStudyArea2_v3.ply") ## Compute neighborhood #indices_cyl=compute_cylinder_neighborhood_indices(pc_sub, pc_sub,1) indices_sph = compute_sphere_neighborhood_indices(pc_sub, pc_sub, 1) output_text = "" for i in range(len(indices_sph)):
parser.add_argument('output', help='absolute path of output point cloud') parser.add_argument('radius', help='radius of the volume') args = parser.parse_args() import sys sys.path.insert(0, args.path_of_laserchicken) from laserchicken import read_las from laserchicken.keys import point from laserchicken.volume_specification import Sphere from laserchicken.compute_neighbors import compute_neighborhoods print("------ Building kd-tree is started ------") # Import pc = read_las.read(args.input) print(("Number of points: %s ") % (pc[point]['x']['data'].shape[0])) # Neighborhood calculation 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, Sphere(args.radius)) # neighbors = compute_neighborhoods(pc, pc, Sphere(np.float(args.radius))) indices_cyl = [] for x in neighbors: print("Iteration %d" % num_iterations)
from laserchicken import read_las from laserchicken.spatial_selections import points_in_polygon_wkt from laserchicken import write_ply pc = read_las.read("D:/GitHub/eEcoLiDAR/eEcoLiDAR/testdata/AHN2.las") pc_out = points_in_polygon_wkt( pc, "POLYGON(( 243590.0 572110.0, 243640.0 572160.0, 243700.0 572110.0, 243640.0 572060.0, 243590.0 572110.0 ))" ) write_ply.write( pc, "D:/GitHub/komazsofi/myPhD_escience_analysis/test_data/testply_orig1.ply") write_ply.write( pc_out, "D:/GitHub/komazsofi/myPhD_escience_analysis/test_data/withinplygonply1.ply" )
def test_height_stats_without_neighbors(self): pc_in = read_las.read("testdata/AHN2.las") neighborhood = [] skew_z = self.extractor.extract(pc_in, neighborhood, pc_in, None, None) assert np.isnan(skew_z)