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

Commit

Permalink
Adding some type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
tmontaigu committed Oct 5, 2020
1 parent 23a5e7c commit 2542a8a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 39 deletions.
8 changes: 4 additions & 4 deletions pylas/headers/rawheader.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,13 @@ def offsets(self, value):
def write_to(self, out_stream):
hdr_bytes = bytearray(self)

slc = hdr_bytes[26: 26+32]
slc = hdr_bytes[26 : 26 + 32]
i = slc.find(b"\0")
slc[i:] = b'\x00'
slc[i:] = b"\x00"

slc = hdr_bytes[58: 58+32]
slc = hdr_bytes[58 : 58 + 32]
i = slc.find(b"\0")
slc[i:] = b'\x00'
slc[i:] = b"\x00"

out_stream.write(hdr_bytes)

Expand Down
24 changes: 14 additions & 10 deletions pylas/lasdatas/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ def __getattr__(self, item):
try:
return self.points[item]
except ValueError:
raise AttributeError(f"{self.__class__.__name__} object has no attribute '{item}'") from None
raise AttributeError(
f"{self.__class__.__name__} object has no attribute '{item}'"
) from None

def __setattr__(self, key, value):
"""This is called on every access to an attribute of the instance.
Expand Down Expand Up @@ -194,7 +196,7 @@ def update_header(self):
self.header.number_of_points_by_return = counts

def write_to(
self, out_stream, do_compress=False, laz_backend=LazBackend.detect_available()
self, out_stream, do_compress=False, laz_backend=LazBackend.detect_available()
):
"""writes the data to a stream
Expand All @@ -208,12 +210,12 @@ def write_to(
By default, pylas detect available backends
"""
with LasWriter(
out_stream,
self.header,
self.vlrs,
do_compress=do_compress,
closefd=False,
laz_backend=laz_backend,
out_stream,
self.header,
self.vlrs,
do_compress=do_compress,
closefd=False,
laz_backend=laz_backend,
) as writer:
writer.write(self.points)

Expand All @@ -226,7 +228,9 @@ def _raise_if_not_expected_pos(stream, expected_pos):
)
)

def write_to_file(self, filename: Union[str, pathlib.Path], do_compress: Optional[bool] = None) -> None:
def write_to_file(
self, filename: Union[str, pathlib.Path], do_compress: Optional[bool] = None
) -> None:
"""Writes the las data into a file
Parameters
Expand All @@ -246,7 +250,7 @@ def write_to_file(self, filename: Union[str, pathlib.Path], do_compress: Optiona
self.write_to(out, do_compress=do_compress)

def write(
self, destination, do_compress=None, laz_backend=LazBackend.detect_available()
self, destination, do_compress=None, laz_backend=LazBackend.detect_available()
):
"""Writes to a stream or file
Expand Down
52 changes: 27 additions & 25 deletions pylas/point/dims.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
Mapping,
TypeVar,
Generic,
List,
)

import numpy as np
Expand All @@ -27,8 +28,8 @@


class PointFormatDict(UserDict, Generic[ValueType]):
"""Simple wrapper around a dict that
changes the exception raised when accessing a key that is not-present
"""Simple wrapper around a dict that changes
the exception raised when accessing a key that is not-present
"""

Expand All @@ -45,12 +46,11 @@ def __getitem__(self, key: int) -> ValueType:
class SubField(NamedTuple):
name: str
mask: int
type: str


def _point_format_to_dtype(
point_format: Iterable[str], dimensions_to_type: Mapping[str, str]
):
) -> np.dtype:
"""build the numpy.dtype for a point format
Parameters:
Expand All @@ -72,7 +72,7 @@ def _point_format_to_dtype(
def _build_point_formats_dtypes(
point_format_dimensions: Mapping[int, Tuple[str]],
dimensions_dict: Mapping[str, str],
):
) -> Dict[int, np.dtype]:
"""Builds the dict mapping point format id to numpy.dtype
In the dtypes, bit fields are still packed, and need to be unpacked each time
you want to access them
Expand Down Expand Up @@ -195,33 +195,35 @@ def _build_point_formats_dtypes(
SCAN_DIRECTION_FLAG_MASK_6 = 0b01000000
EDGE_OF_FLIGHT_LINE_MASK_6 = 0b10000000

COMPOSED_FIELDS_0 = {
COMPOSED_FIELDS_0: Dict[str, List[SubField]] = {
"bit_fields": [
SubField("return_number", RETURN_NUMBER_MASK_0, "u1"),
SubField("number_of_returns", NUMBER_OF_RETURNS_MASK_0, "u1"),
SubField("scan_direction_flag", SCAN_DIRECTION_FLAG_MASK_0, "bool"),
SubField("edge_of_flight_line", EDGE_OF_FLIGHT_LINE_MASK_0, "bool"),
SubField("return_number", RETURN_NUMBER_MASK_0),
SubField("number_of_returns", NUMBER_OF_RETURNS_MASK_0),
SubField("scan_direction_flag", SCAN_DIRECTION_FLAG_MASK_0),
SubField("edge_of_flight_line", EDGE_OF_FLIGHT_LINE_MASK_0),
],
"raw_classification": [
SubField("classification", CLASSIFICATION_MASK_0, "u1"),
SubField("synthetic", SYNTHETIC_MASK_0, "bool"),
SubField("key_point", KEY_POINT_MASK_0, "bool"),
SubField("withheld", WITHHELD_MASK_0, "bool"),
SubField("classification", CLASSIFICATION_MASK_0),
SubField("synthetic", SYNTHETIC_MASK_0),
SubField("key_point", KEY_POINT_MASK_0),
SubField("withheld", WITHHELD_MASK_0),
],
}
COMPOSED_FIELDS_6 = {


COMPOSED_FIELDS_6: Dict[str, List[SubField]] = {
"bit_fields": [
SubField("return_number", RETURN_NUMBER_MASK_6, "u1"),
SubField("number_of_returns", NUMBER_OF_RETURNS_MASK_6, "u1"),
SubField("return_number", RETURN_NUMBER_MASK_6),
SubField("number_of_returns", NUMBER_OF_RETURNS_MASK_6),
],
"classification_flags": [
SubField("synthetic", SYNTHETIC_MASK_6, "bool"),
SubField("key_point", KEY_POINT_MASK_6, "bool"),
SubField("withheld", WITHHELD_MASK_6, "bool"),
SubField("overlap", OVERLAP_MASK_6, "bool"),
SubField("scanner_channel", SCANNER_CHANNEL_MASK_6, "u1"),
SubField("scan_direction_flag", SCAN_DIRECTION_FLAG_MASK_6, "bool"),
SubField("edge_of_flight_line", EDGE_OF_FLIGHT_LINE_MASK_6, "bool"),
SubField("synthetic", SYNTHETIC_MASK_6),
SubField("key_point", KEY_POINT_MASK_6),
SubField("withheld", WITHHELD_MASK_6),
SubField("overlap", OVERLAP_MASK_6),
SubField("scanner_channel", SCANNER_CHANNEL_MASK_6),
SubField("scan_direction_flag", SCAN_DIRECTION_FLAG_MASK_6),
SubField("edge_of_flight_line", EDGE_OF_FLIGHT_LINE_MASK_6),
],
}

Expand All @@ -242,7 +244,7 @@ def _build_point_formats_dtypes(
}
)

VERSION_TO_POINT_FMT = {
VERSION_TO_POINT_FMT: Dict[str, Tuple[int, ...]] = {
"1.2": (0, 1, 2, 3),
"1.3": (0, 1, 2, 3, 4, 5),
"1.4": (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
Expand Down

0 comments on commit 2542a8a

Please sign in to comment.