Skip to content
This repository has been archived by the owner on Aug 18, 2022. It is now read-only.

Commit

Permalink
Add function to get extra dims from a dtype & fix unpacking by using it
Browse files Browse the repository at this point in the history
  • Loading branch information
tmontaigu committed May 29, 2018
1 parent 32699c1 commit 4869f9e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/basic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ that you can use to access to the data.
.. code:: python
las = pylas.read('somefile.las')
print(np.unique(las.classification))
import s3fs
fs = s3fs.S3FileSystem()
Expand All @@ -27,7 +28,6 @@ As the name suggest, this function does not read the whole file, but opens it an
This is useful if you only need to read the header without loading the whole file in memory.



Converting
==========

Expand Down
13 changes: 13 additions & 0 deletions pylas/point/dims.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,3 +401,16 @@ def is_point_fmt_compatible_with_version(point_format_id, file_version):
return point_format_id in VERSION_TO_POINT_FMT[str(file_version)]
except KeyError:
raise errors.FileVersionNotSupported(file_version)


def is_official_dimension(dimension_name, point_fmt):
official_names_for_fmt = set(get_dtype_of_format_id(point_fmt, unpacked=True).names)
return dimension_name in official_names_for_fmt


def get_extra_dimensions_spec(np_dtype, point_format_id):
extra_dims_names = [
name for name in np_dtype.names
if not is_official_dimension(name, point_format_id) and name not in COMPOSED_FIELDS[point_format_id]
]
return [(name, np_dtype[name]) for name in extra_dims_names]
6 changes: 4 additions & 2 deletions pylas/point/packing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""
import numpy as np

from .dims import get_dtype_of_format_id, COMPOSED_FIELDS
from .dims import get_dtype_of_format_id, COMPOSED_FIELDS, get_extra_dimensions_spec


def least_significant_bit(val):
Expand Down Expand Up @@ -71,9 +71,11 @@ def unpack_sub_fields(data, point_format_id, extra_dims=None):
Returns:
A new structured array with the sub-fields de-packed
"""
composed_dims = COMPOSED_FIELDS[point_format_id]
if extra_dims is None:
extra_dims = get_extra_dimensions_spec(data.dtype, point_format_id)
dtype = get_dtype_of_format_id(
point_format_id, extra_dims=extra_dims, unpacked=True)
composed_dims = COMPOSED_FIELDS[point_format_id]
point_record = np.zeros_like(data, dtype)

for dim_name in data.dtype.names:
Expand Down
10 changes: 10 additions & 0 deletions pylastests/test_extrabytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ def las1_4():
return pylas.read(test1_4_las)


def test_extra_dim_spec():
extra_dims_specs = [('codification', 'u4')]
dtype = pylas.point.dims.get_dtype_of_format_id(0)
dtype = pylas.point.dims.dtype_append(dtype, extra_dims_specs)

found_extra_dims_spec = pylas.point.dims.get_extra_dimensions_spec(dtype, 0)

assert found_extra_dims_spec == extra_dims_specs


def test_extra_names(extrab_las):
all_dims = set(extrab_las.points_data.array.dtype.names)

Expand Down

0 comments on commit 4869f9e

Please sign in to comment.