예제 #1
0
    def setUp(self):
        """Set up the test."""
        # generate the points
        self._set_cylinder_data()

        # get the central point as targetpc
        self.targetpc = self._get_central_point()

        # get the cylinder
        self.cyl = InfiniteCylinder(np.mean(self.radius))

        # get the theoretical value +1 for central point
        npts = self.points_per_cylinder + 1
        self.areadens = npts / self.cyl.calculate_base_area()
예제 #2
0
    def test_entropy_in_cylinders(self):
        """Test computing of eigenvalues in cylinder."""
        num_all_pc_points = len(self.point_cloud[keys.point]["x"]["data"])
        rand_indices = [
            random.randint(0, num_all_pc_points) for p in range(20)
        ]
        target_point_cloud = utils.copy_point_cloud(self.point_cloud,
                                                    rand_indices)
        n_targets = len(target_point_cloud[keys.point]["x"]["data"])
        radius = 25
        neighbors = compute_neighbors.compute_cylinder_neighborhood(
            self.point_cloud, target_point_cloud, radius)

        target_idx_base = 0
        for x in neighbors:
            feature_extractor.compute_features(self.point_cloud,
                                               x,
                                               target_idx_base,
                                               target_point_cloud,
                                               ["entropy_z"],
                                               InfiniteCylinder(5),
                                               layer_thickness=0.1)
            target_idx_base += len(x)

        for i in range(n_targets):
            H = utils.get_attribute_value(target_point_cloud, i, "entropy_z")
            self.assertTrue(H >= 0)
        self.assertEqual(
            "laserchicken.feature_extractor.entropy_feature_extractor",
            target_point_cloud[keys.provenance][0]["module"])
        self.assertEqual([0.1],
                         target_point_cloud[keys.provenance][0]["parameters"])
    def setUp(self):
        """
        Set up the test.

        Create a sphere and a cylinder of points and a central point
        The cylinder has no points on the equator of the sphere
        """

        # create the points
        self.radius = 0.5
        self.xyz = [[0., 0., 0.]]
        self._set_sphere_data()
        self._set_cylinder_data()

        # create the pc
        self.point_cloud, self.npts = self._get_pc(np.array(self.xyz))
        self.target_point_cloud = self._get_central_point(0)
        self.indexpc = 0

        # create the volume/neighborhood
        self.cylinder = InfiniteCylinder(self.radius + 1E-3)
        self.neighborhoods = list(
            compute_neighborhoods(self.point_cloud, self.target_point_cloud,
                                  self.cylinder))

        # theoretical value of the echo ratio
        self.theoretical_value = (self.npt_sphere + 1) / (self.npt_sphere +
                                                          self.npt_cyl + 1)
예제 #4
0
    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 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
class TestDensityFeatureExtractorCylinder(unittest.TestCase):
    """Test density extractor on artificial cylindric data."""

    point_cloud = None

    def test_cylinder(self):
        """Compute the density for a cylinder given as index of source pc."""
        neighborhoods = compute_neighborhoods(self.point_cloud, self.targetpc, self.cyl)

        extractor = PointDensityFeatureExtractor()
        densities = extractor.extract(self.point_cloud, neighborhoods, None, None, self.cyl)
        np.testing.assert_allclose(densities, self.real_density)

    def _get_central_point(self):
        """Get the central point."""
        return utils.copy_point_cloud(self.point_cloud, [0])

    def _set_cylinder_data(self):

        # generate a pc of points regularly
        # positionned on two concentric cylinders
        # plus a central point
        nteta, nheight = 11, 11
        teta = np.linspace(0.01, 2 * np.pi, nteta)
        height = np.linspace(-1, 1, nheight)
        self.radius = [1., 2.]

        self.points_per_cylinder = nteta * nheight
        self.xyz = []
        self.xyz.append([0., 0., 0.])
        for r in self.radius:
            for z in height:
                for t in teta:
                    x = r * np.cos(t)
                    y = r * np.sin(t)
                    self.xyz.append([x, y, z])

        self.xyz = np.array(self.xyz)
        self.point_cloud = {keys.point: {'x': {'type': 'double', 'data': self.xyz[:, 0]},
                                         'y': {'type': 'double', 'data': self.xyz[:, 1]},
                                         'z': {'type': 'double', 'data': self.xyz[:, 2]}}}

    def setUp(self):
        """Set up the test."""
        # generate the points
        self._set_cylinder_data()

        # get the central point as target pc
        self.targetpc = self._get_central_point()

        # get the cylinder
        self.cyl = InfiniteCylinder(np.mean(self.radius))

        # get the theoretical value +1 for central point
        n_points = self.points_per_cylinder + 1
        self.real_density = n_points / self.cyl.calculate_base_area()

    def tearDowm(self):
        pass
def assert_std_for_z_function_in_xy_grid(z_checkered, expected):
    """Assert that the standard deviation of z values in a grid of unit x and y"""
    n_points, points = create_points_in_xy_grid(z_checkered)
    point_cloud = create_point_cloud(points[:, 0], points[:, 1], points[:, 2])
    targets = create_point_cloud([0], [0], [0])
    compute_features(point_cloud, [range(n_points)], 0, targets, ['sigma_z'],
                     InfiniteCylinder(10))
    np.testing.assert_almost_equal(targets[keys.point]['sigma_z']['data'][0],
                                   expected)
 def test_compute_neighbors_cylinderVolume(self):
     """Compute neighbors should detect cylinder volume and find neighbors accordingly"""
     target_point_cloud = self._get_random_targets()
     cylinder = InfiniteCylinder(0.5)
     neighborhoods = compute_neighborhoods(self.point_cloud,
                                           target_point_cloud, cylinder)
     self._assert_all_points_within_cylinder(neighborhoods,
                                             target_point_cloud,
                                             cylinder.radius)
    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)
    def test_eigenvalues_of_too_few_points_results_in_0():
        """If there are too few points to calculate the eigen values don't output NaN or inf."""
        a = np.array([5])
        pc = create_point_cloud(a, a, a)

        compute_features(pc, [[0]], pc, ["eigenv_1", "eigenv_2", "eigenv_3"],
                         InfiniteCylinder(5))

        eigen_val_123 = np.array(
            [pc[keys.point]['eigenv_{}'.format(i)]['data'] for i in [1, 2, 3]])
        assert not np.any(np.isnan(eigen_val_123))
        assert not np.any(np.isinf(eigen_val_123))
 def _find_neighbors_for_random_targets_and_compute_entropy(self):
     num_all_pc_points = len(self.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(self.point_cloud,
                                                 rand_indices)
     radius = 25
     neighborhoods = list(
         compute_cylinder_neighborhood(self.point_cloud, target_point_cloud,
                                       radius))
     compute_features(self.point_cloud,
                      neighborhoods,
                      target_point_cloud, ["entropy_z"],
                      InfiniteCylinder(5),
                      layer_thickness=0.1)
     return target_point_cloud
 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 = 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 setUp(self):
        """
        Create a grid of 4 targets and an environment point cloud and neighbors and the echo ratios of those targets.
        """
        self.radius = 0.5
        targets = np.array([[10., 0., 5.], [10., 10., 5.], [0., 0., 5.],
                            [0., 10., 5.]])  # Grid w. steps 10 & height 5
        self.echo_ratios = np.array([0., 0.9, 0.5, 0.8])
        environment_parts = [
            self._create_environment_part(t, ratio, self.radius)
            for t, ratio in zip(targets, self.echo_ratios)
        ]
        environment = np.vstack(environment_parts)

        self.target_pc = create_point_cloud(targets[:, 0], targets[:, 1],
                                            targets[:, 2])
        self.environment_pc = create_point_cloud(environment[:, 0],
                                                 environment[:, 1],
                                                 environment[:, 2])

        self.cylinder = InfiniteCylinder(self.radius)
        self.neighbors = list(
            compute_neighborhoods(self.environment_pc, self.target_pc,
                                  self.cylinder))
예제 #15
0
from laserchicken import read_ply
from laserchicken.feature_extractor import *
from laserchicken.feature_extractor.pulse_penetration_feature_extractor import GROUND_TAGS
from laserchicken.keys import point, normalized_height
from laserchicken.utils import copy_point_cloud
from laserchicken.volume_specification import InfiniteCylinder, Cell
from . import compute_features
from .feature_map import create_default_feature_map, _create_name_extractor_pairs

np.random.seed(1234)

_TEST_FILE_NAME = 'AHN3.ply'
_TEST_NEIGHBORHOODS_FILE_NAME = 'AHN3_1000_random_neighbors.json'
_TEST_DATA_SOURCE = 'testdata'

_CYLINDER = InfiniteCylinder(4)
_PC_260807 = read_ply.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)))
_PC_10 = copy_point_cloud(_PC_260807,
                          array_mask=(np.random.choice(range(
                              len(_PC_260807[keys.point]['x']['data'])),
                                                       size=10,
                                                       replace=False)))
_1000_NEIGHBORHOODS_IN_260807 = next(
    compute_neighbors.compute_neighborhoods(_PC_260807,
                                            _PC_1000,
                                            _CYLINDER,
 def test_infiniteCylinder_type():
     assert_equal(InfiniteCylinder(2).get_type(), InfiniteCylinder.TYPE)
 def test_infiniteCylinder_calculateArea():
     assert_almost_equal(
         InfiniteCylinder(2).calculate_base_area(), 12.56637061436)
예제 #18
0
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, InfiniteCylinder(np.float(args.radius)))
#
neighbors = compute_neighborhoods(pc, target,
                                  InfiniteCylinder(np.float(args.radius)))
iteration = 0
target_idx_base = 0

fullstarttime = time.time()

for x in neighbors:
    end = time.time()
    difftime = end - start
    print(("build kd-tree: %f sec") % (difftime))
    print("Computed neighborhoods list length at iteration %d is: %d" %
          (iteration, len(x)))

    start1 = time.time()
    print("------ Feature calculation is started ------")
    compute_features(pc, x, target_idx_base, target,
예제 #19
0
 def test_cell_volume(self):
     assert_expected_ratio(volume=InfiniteCylinder(5))