Beispiel #1
0
    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)
Beispiel #2
0
    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
Beispiel #3
0
 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]))
Beispiel #4
0
 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])
Beispiel #5
0
    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)
Beispiel #7
0
 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]))
Beispiel #8
0
 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)
Beispiel #9
0
 def test_existentPly_noError(self):
     load(self.test_file_path)
Beispiel #10
0
 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)
Beispiel #11
0
 def test_load_nonexistentFile(self):
     """Should raise exception."""
     with pytest.raises(OSError):
         load('nonexistent.las')
Beispiel #12
0
 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)
Beispiel #13
0
 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)
Beispiel #15
0
 def test_containsXElement(self):
     data = load(self.test_file_path)
     self.assertIn('x', data[keys.point])
Beispiel #16
0
 def test_wrongFormat_error(self):
     with raises(ValueError):
         load(self.las_file_path, format='.PLY')
Beispiel #17
0
    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)
Beispiel #18
0
 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)
Beispiel #19
0
 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)
Beispiel #20
0
 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)
Beispiel #21
0
 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)
Beispiel #22
0
 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'])
Beispiel #23
0
 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'])
Beispiel #24
0
 def test_nonexistentFile_error(self):
     # Catch most specific subclass of FileNotFoundException (3.6) and IOError (2.7).
     with raises(Exception):
         load('nonexistentfile.ply')
Beispiel #25
0
 def test_rightNumberOfPoints(self):
     data = load(self.test_file_path)
     self.assertEqual(len(data[keys.point]['x']['data']), 3)