def test_correctModulesLogged(self): log = load(self.test_file_path)['log'] modules = [entry['module'] for entry in log] # an additional 'load' is added in the log when reading self.assertListEqual(['load', 'filter', 'laserchicken.io.load'], modules)
def locate_shp(self, shp_dir): """ Locate the corresponding ESRI shape file of the point cloud :param shp_dir: directory which contains all candidate shp file for classification """ laserfarm.utils.check_file_exists(self.input_path, should_exist=True) pc = load(self.input_path.as_posix()) shp_path = self.input_folder / shp_dir laserfarm.utils.check_dir_exists(shp_path, should_exist=True) # Get boundary of the point cloud self.point_cloud = pc x = pc[laserchicken.keys.point]['x']['data'] y = pc[laserchicken.keys.point]['y']['data'] point_box = shapely.geometry.box(np.min(x), np.min(y), np.max(x), np.max(y)) for shp in sorted( [f.absolute() for f in shp_path.iterdir() if f.suffix == '.shp']): sf = shapefile.Reader(shp.as_posix()) mbr = shapely.geometry.box(*sf.bbox) if point_box.intersects(mbr): self.input_shp.append(shp) return self
def test_correctPoints(self): data = load(self.test_file_path) points = data[keys.point] point = np.array([ points['x']['data'][0], points['y']['data'][0], points['z']['data'][0], points['return']['data'][0] ]) np.testing.assert_allclose(point, np.array([0.11, 0.12, 0.13, 1]))
def test_load_allAttributes(self): expected_attributes = [ 'x', 'y', 'z', 'intensity', 'raw_classification', 'scan_angle_rank', 'user_data', 'gps_time', 'red', 'green', 'blue' ] for attrs in ('all', ['all']): point_cloud = load(self.test_file_path, attributes=attrs) for attribute in expected_attributes: self.assertIn(attribute, point_cloud[keys.point])
def test_correctTimesLogged(self): log = load(self.test_file_path)['log'] self.assertListEqual( [2018, 1, 18, 16, 1, 0, 3, 18, -1], list(dateutil.parser.parse(log[0]['time']).timetuple())) self.assertListEqual( [2018, 1, 18, 16, 3, 0, 3, 18, -1], list(dateutil.parser.parse(log[1]['time']).timetuple()))
def test_write_processedRealData(self): """ Writing point cloud data and loading it afterwards should result in the same point cloud data. """ pc = load(self.load_file_path) x = pc[keys.point]['x']['data'] pc[keys.point]['test_feature'] = { 'data': np.zeros_like(x), 'type': 'float64' } export(pc, self.test_file_path) file = _get_file_from_path(self.test_file_path) _assert_all_attributes_in_file(pc[keys.point], file)
def test_load_CorrectFirstX(self): """Should run without exception and compare equal.""" point_cloud = load(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 test_load_specificAttribute(self): """Should return only x,y,z""" point_cloud = load(self.test_file_path, attributes=['intensity']) expected_attributes = ['x', 'y', 'z', 'intensity'] _check_expected_attributes(point_cloud, expected_attributes)
def test_existentPly_noError(self): load(self.test_file_path)
def test_load_defaultAttributes(self): point_cloud = load(self.test_file_path) expected_attributes = [attr for attr in DEFAULT_LAS_ATTRIBUTES] _check_expected_attributes(point_cloud, expected_attributes)
def test_load_nonexistentFile(self): """Should raise exception.""" with pytest.raises(OSError): load('nonexistent.las')
def test_correctPointCloud(self): data = load(self.test_file_path) point_cloud = data['pointcloud'] offset = point_cloud['offset']['data'][0] np.testing.assert_allclose(offset, 12.1)
def test_containsPointsElement(self): data = load(self.test_file_path) self.assertIn(keys.point, data)
def test_write_loadRealData(self): """ Writing point cloud data and loading it afterwards should result in the same point cloud data. """ pc = load(self.load_file_path) export(pc, self.test_file_path) file = _get_file_from_path(self.test_file_path) _assert_all_attributes_in_file(pc[keys.point], file)
def test_containsXElement(self): data = load(self.test_file_path) self.assertIn('x', data[keys.point])
def test_wrongFormat_error(self): with raises(ValueError): load(self.las_file_path, format='.PLY')
def test_allLogEntriesContainAllColumns(self): log = load(self.test_file_path)['log'] for entry in log: for key in ['time', 'module', 'parameters', 'version']: self.assertIn(key, entry)
def test_correctPointCloudWithInvalidComments(self): """Invalid comments should not cause error.""" data = load(self.test_file_with_invalid_comments_path) point_cloud = data['pointcloud'] offset = point_cloud['offset']['data'][0] np.testing.assert_allclose(offset, 12.1)
def test_correctPointCloudWithoutComments(self): """Missing comment section should not cause error (regression test).""" data = load(self.test_file_without_comments_path) point_cloud = data['pointcloud'] offset = point_cloud['offset']['data'][0] np.testing.assert_allclose(offset, 12.1)
def test_load_noAttributes(self): """Should return only x,y,z""" point_cloud = load(self.test_file_path, attributes=[]) expected_attributes = ['x', 'y', 'z'] _check_expected_attributes(point_cloud, expected_attributes)
def test_load_containsPoints(self): """Should run without exception and return points.""" point_cloud = load(self.test_file_path) self.assertIn(keys.point, point_cloud)
def test_load_invalidAttributes(self): """Should raise exception.""" with pytest.raises(ValueError): load(self.test_file_path, attributes=None) with pytest.raises(ValueError): load(self.test_file_path, attributes=['ytisnetni'])
def test_load_PointsContainX(self): """Should run without exception and return points.""" point_cloud = load(self.test_file_path) print(point_cloud) self.assertIn('data', point_cloud[keys.point]['x'])
def test_nonexistentFile_error(self): # Catch most specific subclass of FileNotFoundException (3.6) and IOError (2.7). with raises(Exception): load('nonexistentfile.ply')
def test_rightNumberOfPoints(self): data = load(self.test_file_path) self.assertEqual(len(data[keys.point]['x']['data']), 3)