daavoo / pyntcloud

pyntcloud is a Python library for working with 3D point clouds.
http://pyntcloud.readthedocs.io
MIT License
1.39k stars 221 forks source link

Added missing laz extension #288

Closed SBCV closed 3 years ago

SBCV commented 3 years ago

The laspy library allows to read not only las but also laz files (assuming that laszip is installed)

Btw: Are you aware of the pylas / lazperf libraries? They also allow to read las/laz files and can be installed using pip (which is more convenient than the installation of laspy and laszip)

SBCV commented 3 years ago

I've just made a simple timing comparison and it looks like there is a drastic performance difference between laspy and pylas when reading laz files

laspy: elapsed time: 14.988102674484253
pylas: elapsed time: 0.7680809497833252

I think that difference stems from the fact that laspy calls the command line tool of laszip

daavoo commented 3 years ago

Hola @SBCV !

I've just made a simple timing comparison and it looks like there is a drastic performance difference between laspy and pylas when reading laz files

laspy: elapsed time: 14.988102674484253
pylas: elapsed time: 0.7680809497833252

I think that difference stems from the fact that laspy calls the command line tool of laszip

Nice!. I did not know about the existence of pylas (I think it did not exist back when the .las reader was added). It looks like a good and more active alternative, would be nice for a P.R.

SBCV commented 3 years ago

In order to add the requested test to test_from_file.py , I opened diamond.las with Cloudcompare and stored the imported point cloud as diamond.laz. When running the tests the following error message is thrown:

tests/integration/io/test_from_file.py:51: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

data = PyntCloud
6 points with 10 scalar fields
0 faces in mesh
0 kdtrees
0 voxelgrids
Centroid: 0.5, 0.5, 0.5
Other attributes:
     las_header: <class 'laspy.header.HeaderManager'>

    def assert_points_xyz(data):
        assert np.isclose(data.points['x'][0], 0.5)
        assert np.isclose(data.points['y'][0], 0)
        assert np.isclose(data.points['z'][0], 0.5)

>       assert str(data.points["x"].dtype) == 'float32'
E       AssertionError: assert 'float64' == 'float32'
E         - float64
E         + float32

tests/integration/io/test_from_file.py:13: AssertionError

Do you know, if it is it possible to create laz files with 32 bit floats? Or should we change the assertions? Any recommendations?

daavoo commented 3 years ago

In order to add the requested test to test_from_file.py , I opened diamond.las with Cloudcompare and stored the imported point cloud as diamond.laz. When running the tests the following error message is thrown:

tests/integration/io/test_from_file.py:51: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

data = PyntCloud
6 points with 10 scalar fields
0 faces in mesh
0 kdtrees
0 voxelgrids
Centroid: 0.5, 0.5, 0.5
Other attributes:
   las_header: <class 'laspy.header.HeaderManager'>

    def assert_points_xyz(data):
        assert np.isclose(data.points['x'][0], 0.5)
        assert np.isclose(data.points['y'][0], 0)
        assert np.isclose(data.points['z'][0], 0.5)

>       assert str(data.points["x"].dtype) == 'float32'
E       AssertionError: assert 'float64' == 'float32'
E         - float64
E         + float32

tests/integration/io/test_from_file.py:13: AssertionError

Do you know, if it is it possible to create laz files with 32 bit floats? Or should we change the assertions? Any recommendations?

I'm guessing that CloudCompare is exporting with float64: http://www.danielgm.net/cc/forum/viewtopic.php?t=4167#p18933

I don't know if you can change the exported precission.

Rather than changing assertions, I think that the best option would be to cast the point coordinates to float32 (maybe using a default argument in order to let someone get float64 if needed):

https://github.com/daavoo/pyntcloud/blob/master/pyntcloud/io/las.py#L28

SBCV commented 3 years ago

Rather than changing assertions, I think that the best option would be to cast the point coordinates to float32 (maybe using a default argument in order to let someone get float64 if needed):

Added default arguments for float and color. The test case for pytest runs now successfully (including color information). Squashed the commits to keep it in a clean state.

SBCV commented 3 years ago

Thank you for merging.

Regarding pylas/ lazperf: Do think it would be better to provide an alternative to laspy or should we replace it entirely?