def test_extend_pointcloud1(self): LOG.info("Testing pointcloud extension - bad") pc1 = pointcloud.Pointcloud( np.ones((2, 2)), np.ones(2), some_attr=np.ones(2)) pc2 = pointcloud.Pointcloud(np.ones((2, 2)), np.ones(2)) with self.assertRaises(ValueError): pc1.extend(pc2)
def test_extend_pointcloud3(self): LOG.info("Testing pointcloud extension - least common") pc1 = pointcloud.Pointcloud(np.ones((2, 2)), np.ones( 2), some_attr=np.ones(2), some_other=np.ones(2)) pc2 = pointcloud.Pointcloud( np.ones((2, 2)), np.ones(2), some_attr=np.ones(2) * 3) pc1.extend(pc2, least_common=True) self.assertSetEqual(pc1.attributes, {"some_attr"})
def test_extend_pointcloud2(self): LOG.info("Testing pointcloud extension - ok") pc1 = pointcloud.Pointcloud( np.ones((2, 2)), np.ones(2), some_attr=np.ones(2)) pc2 = pointcloud.Pointcloud( np.ones((2, 2)), np.ones(2), some_attr=np.ones(2) * 3) pc1.extend(pc2) self.assertEqual(pc1.size, 4) self.assertIn("some_attr", pc1.attributes)
def test_pointcloud_empty_like(self): LOG.info("Testing pointcloud empty_like factory function") pc = pointcloud.Pointcloud( np.ones((2, 2)), np.ones(2), some_attr=np.ones(2)) empty = pointcloud.empty_like(pc) self.assertSetEqual(pc.attributes, empty.attributes) self.assertEqual(empty.size, 0)
def test_pointcloud_min_filter(self): LOG.info("Test pointcloud min filter") pc = pointcloud.Pointcloud( ((0, 0), (1, 0), (2, 0), (3, 0)), (1, 2, 3, 4)) pc.sort_spatially(2) z = pc.min_filter(1.5) self.assertTrue((z == (1, 1, 2, 3)).all())
def test_pointcloud_conversion(self): LOG.info("Testing pointcloud conversion") pc = pointcloud.Pointcloud(np.ones((5, 2)), np.ones(5), c=np.ones(5, dtype=np.uint8)) lpc1 = pc.astype(pointcloud.LidarPointcloud) lpc2 = lpc1.cut_to_class(1) self.assertEqual(lpc1.size, lpc2.size)
def test_cut_pointcloud(self): LOG.info("Testing cut poincloud") pc = pointcloud.Pointcloud(np.ones((5, 2)), np.ones(5), some_attr=np.ones(5), some_other=np.ones(5)) M = np.array([1, 0, 1, 1, 0]).astype(np.bool) pc = pc.cut(M) self.assertEqual(pc.size, M.sum()) self.assertSetEqual(pc.attributes, {"some_attr", "some_other"})
def test_spike_filter(self): LOG.info("Test pointcloud spike filter") pc = pointcloud.Pointcloud.from_array(np.ones((2, 2)), [-0.5, 1, 0, 1.5, 0, -1]) pc.extend(pointcloud.Pointcloud([[0.5, 0.5]], (-5.0,))) pc.sort_spatially(2) vlim = (0.4) ** 2 M = pc.spike_filter(2, vlim) self.assertTrue(M.sum() == 1) self.assertEqual(pc.z[np.where(M)[0][0]], -5.0)
def test_sort_pointcloud(self): LOG.info("Test pointcloud sorting") r = np.linspace(0, np.pi * 2, 100) xy = np.column_stack((r * np.cos(r), r * np.sin(r))) * 5 c = np.arange(xy.shape[0]) pc = pointcloud.Pointcloud(xy, np.ones(xy.shape[0]), c=c) pc.sort_spatially(1, keep_sorting=True) self.assertTrue((c != pc.c).any()) pc.sort_back() self.assertTrue((pc.c == c).all())
def test_pointcloud_attributes(self): LOG.info("Test pointcloud attributes") pc = pointcloud.Pointcloud( np.ones((10, 2)), np.ones(10), a=np.arange(10)) with self.assertRaises(pointcloud.InvalidArrayError): pc.xy = 10 with self.assertRaises(pointcloud.InvalidArrayError): pc.a = "abc" # Should be ok pc.a = range(10, 0, -1) self.assertEqual(pc.a[0], 10)
def test_pointcloud_constructor_bad(self): LOG.info("Testing pointcloud constructor -bad") with self.assertRaises(AssertionError): pc = pointcloud.Pointcloud(np.ones((2, 2)), np.ones( 2), some_attr=np.ones(4, dtype=np.uint8))
def test_pointcloud_constructor1(self): LOG.info("Testing pointcloud constructor") pc = pointcloud.Pointcloud(np.ones((2, 2)), np.ones( 2), some_attr=np.ones(2, dtype=np.uint8)) self.assertIn("some_attr", pc.attributes) self.assertTrue(pc.some_attr.dtype == np.uint8)