Esempio n. 1
0
    def setUp(self):
        """Set up the test."""
        # get the points
        self._set_sphere_data()

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

        # get the sphere
        self.sphere = Sphere(np.mean(self.radius))

        # get the theoretical value +1 for central point
        npts = self.points_per_sphere + 1
        self.voldens = npts / self.sphere.calculate_volume()
Esempio n. 2
0
class TestDensityFeatureExtractorSphere(unittest.TestCase):
    """Test density extractor on artificial spherical data."""

    point_cloud = None

    def test_sphere(self):
        """Compute the density for a sphere given as index of the source pc."""
        neighbors_index = list(compute_neighborhoods(self.point_cloud, self.targetpc, self.sphere))

        extractor = PointDensityFeatureExtractor()
        for index in neighbors_index:
            d = extractor.extract(self.point_cloud, index,
                                  None, None, self.sphere)
            self.assertEqual(d, self.voldens)

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

    def _set_sphere_data(self):
        """Generate a pc of points regularly positionned on a two spheres of radius 1 and 2."""
        nteta, nphi = 11, 11
        self.teta = np.linspace(0.1, 2 * np.pi, nteta)
        self.phi = np.linspace(0.1, np.pi, nphi)
        self.radius = [1., 2.]
        self.points_per_sphere = nteta * nphi
        self.xyz = []
        self.xyz.append([0., 0., 0.])
        for r in self.radius:
            for t in self.teta:
                for p in self.phi:
                    x = r * np.cos(t) * np.sin(p)
                    y = r * np.sin(t) * np.sin(p)
                    z = r * np.cos(p)
                    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."""
        # get the points
        self._set_sphere_data()

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

        # get the sphere
        self.sphere = Sphere(np.mean(self.radius))

        # get the theoretical value +1 for central point
        npts = self.points_per_sphere + 1
        self.voldens = npts / self.sphere.calculate_volume()

    def tearDown(self):
        pass
 def test_compute_neighbors_sphereVolume(self):
     """Compute neighbors should detect sphere volume and find neighbors accordingly"""
     target_point_cloud = self._get_random_targets()
     sphere = Sphere(0.5)
     neighborhoods = compute_neighborhoods(self.point_cloud,
                                           target_point_cloud, sphere)
     self._assert_all_points_within_sphere(neighborhoods,
                                           target_point_cloud,
                                           sphere.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_with_neighborhood_generator():
     """Should run for all extractors without error meaning that neighborhood generator is only iterated once.
     Using actual feature extractors here because test feature extractors don't use neighborhoods. """
     n = 200
     feature_names = ['vectorized1', 'test1_a', 'median_z', 'mean_z']
     x = np.ones(n)
     y = np.ones(n)
     z = np.ones(n)
     target = test_tools.create_point_cloud(x, y, z)
     neighborhoods = ([] for _ in range(len(target["vertex"]["x"]["data"])))
     feature_extraction.compute_features({}, neighborhoods, target,
                                         feature_names, Sphere(5))
    def test_invalid(self):
        """ Must raise TypeError as we do not provide correct indexes."""

        extractor = EchoRatioFeatureExtractor()
        # target point cloud must not be None
        with pytest.raises(ValueError):
            extractor.extract(self.point_cloud, self.neighborhoods, None,
                              self.indexpc, self.cylinder)

        # target index must not be None
        with pytest.raises(ValueError):
            extractor.extract(self.point_cloud, self.neighborhoods,
                              self.target_point_cloud, None, self.cylinder)

        # volume must be a cylinder
        with pytest.raises(ValueError):
            sphere = Sphere(self.radius)
            extractor.extract(self.point_cloud, self.neighborhoods,
                              self.target_point_cloud, self.indexpc, sphere)
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)
    indices_cyl += x
    num_iterations += 1
end = time.time()
difftime = end - start
print(("build kd-tree: %f sec") % (difftime))
print("Computed neighborhoods list length is: %d" % len(indices_cyl))

output = open(args.output, 'wb')
pickle.dump(indices_cyl, output)
output.close()
 def test_sphere_correctType():
     assert_equal(Sphere(1).get_type(), Sphere.TYPE)
 def test_sphere_calculateVolume():
     assert_almost_equal(Sphere(2).calculate_volume(), 33.510321638)
Esempio n. 10
0
print("------ Feature calculation is started ------")

# Import
pc = read_las.read(args.input)

f = open(args.kdtree, 'rb')
kdtree = pickle.load(f)
f.close()

start1 = time.time()

compute_features(pc, kdtree, 0, pc, [
    'max_z', 'min_z', 'mean_z', 'median_z', 'std_z', 'var_z', 'range',
    'coeff_var_z', 'skew_z', 'kurto_z', 'sigma_z', 'perc_20', 'perc_40',
    'perc_60', 'perc_80', 'pulse_penetration_ratio', 'density_absolute_mean'
], Sphere(np.float(args.radius)))
"""											   
feadataframe=pd.DataFrame({'_x':pc[point]['x']['data'],'_y':pc[point]['y']['data'],'_z':pc[point]['z']['data'],
                           'max_z':pc[point]['max_z']['data'],'min_z':pc[point]['min_z']['data'], 'mean_z':pc[point]['mean_z']['data'],
                           'median_z':pc[point]['median_z']['data'],'std_z':pc[point]['std_z']['data'], 'var_z':pc[point]['var_z']['data'],
                           'range':pc[point]['range']['data'],'coeff_var_z':pc[point]['coeff_var_z']['data'], 'skew_z':pc[point]['skew_z']['data'],'kurto_z':pc[point]['kurto_z']['data'],
						   'pulse_penetration_ratio':pc[point]['pulse_penetration_ratio']['data'],'density_absolute_mean':pc[point]['density_absolute_mean']['data'],
                           'sigma_z':pc[point]['sigma_z']['data'], 'perc_20':pc[point]['perc_20']['data'],
                           'perc_40':pc[point]['perc_40']['data'],'perc_60':pc[point]['perc_60']['data'], 'perc_80':pc[point]['perc_80']['data']})

feadataframe.to_csv(args.output,sep=";",index=False)
"""

end1 = time.time()
difftime1 = end1 - start1
print(("feature calc: %f sec") % (difftime1))
Esempio n. 11
0
 def test_sphere_volume_raise(self):
     with pytest.raises(ValueError):
         assert_expected_ratio(volume=Sphere(5))
def _compute_features(target, feature_names):
    neighborhoods = [[] for _ in range(len(target["vertex"]["x"]["data"]))]
    feature_extraction.compute_features({}, neighborhoods, target,
                                        feature_names, Sphere(5))
    return target
def _compute_features(target, feature_names, overwrite=False):
    neighborhoods = [[] for i in range(len(target["vertex"]["x"]["data"]))]
    feature_extractor.compute_features({}, neighborhoods, 0, target,
                                       feature_names, Sphere(5), overwrite)
    return target
import numpy as np
import pandas as pd
import time

# Import
pc = read_las.read(args.input)

# 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(2.5))
#
neighbors = compute_neighborhoods(pc, pc, Sphere(2.5))
iteration = 0
target_idx_base = 0
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(indices_cyl)))

    start1 = time.time()
    compute_features(pc, indices_cyl, target_idx_base, pc, [
        'max_z', 'min_z', 'mean_z', 'median_z', 'std_z', 'var_z', 'range',
        'coeff_var_z', 'skew_z', 'kurto_z', 'eigenv_1', 'eigenv_2', 'eigenv_3',
        'z_entropy', 'sigma_z', 'perc_20', 'perc_40', 'perc_60', 'perc_80'
    ], Sphere(2.5))