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

Commit

Permalink
use np.round to avoid 'breaking' coordinates & add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tmontaigu committed Sep 13, 2018
1 parent cc15bdd commit edde1b4
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
11 changes: 10 additions & 1 deletion pylas/lasdatas/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def scale_dimension(array_dim, scale, offset):


def unscale_dimension(array_dim, scale, offset):
return (np.array(array_dim) - offset) / scale
return np.round((np.array(array_dim) - offset) / scale)


class LasBase(object):
Expand Down Expand Up @@ -66,14 +66,23 @@ def z(self):

@x.setter
def x(self, value):
if self.header.x_offset == 0.0:
self.header.x_offset = np.min(value)
# self.header.x_offset = max(np.min(value), self.header.x_offset)
self.X = unscale_dimension(value, self.header.x_scale, self.header.x_offset)

@y.setter
def y(self, value):
if self.header.y_offset == 0.0:
self.header.y_offset = np.min(value)
# self.header.y_offset = max(np.min(value), self.header.y_offset)
self.Y = unscale_dimension(value, self.header.y_scale, self.header.y_offset)

@z.setter
def z(self, value):
if self.header.z_offset == 0.0:
self.header.z_offset = np.min(value)
# self.header.z_offset = max(np.min(value), self.header.z_offset)
self.Z = unscale_dimension(value, self.header.z_scale, self.header.z_offset)

@property
Expand Down
3 changes: 3 additions & 0 deletions pylas/point/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ def __int__(self):
def __repr__(self):
return "<PointFormat({})>".format(self.id)

def is_supported(self):
return self.id in dims.ALL_POINT_FORMATS_DIMENSIONS


def lost_dimensions(point_fmt_in, point_fmt_out):
""" Returns a list of the names of the dimensions that will be lost
Expand Down
42 changes: 41 additions & 1 deletion pylastests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
test1_4_las = os.path.dirname(__file__) + "/" + "test1_4.las"
extra_bytes_las = os.path.dirname(__file__) + "/extrabytes.las"
extra_bytes_laz = os.path.dirname(__file__) + "/extra.laz"
plane_laz = os.path.dirname(__file__) + "/plane.laz"


def write_then_read_again(las, do_compress=False):
Expand All @@ -23,7 +24,7 @@ def write_then_read_again(las, do_compress=False):
return pylas.read(out)


@pytest.fixture(params=[simple_las, simple_laz, vegetation1_3_las, test1_4_las])
@pytest.fixture(params=[simple_las, simple_laz, vegetation1_3_las, test1_4_las, plane_laz])
def las(request):
return pylas.read(request.param)

Expand Down Expand Up @@ -155,3 +156,42 @@ def test_rw_all_set_one(las):
assert np.alltrue(las[dim_name] == las2[dim_name]), "{} not equal".format(
dim_name
)


def test_coords_do_not_break(las):
xs, ys, zs = las.x, las.y, las.z

las.x = xs
las.y = ys
las.z = zs

assert np.allclose(xs, las.x)
assert np.allclose(ys, las.y)
assert np.allclose(zs, las.z)


def test_coords_when_setting_offsets_and_scales(las):
new_las = pylas.create()

new_las.header.offsets = las.header.offsets
new_las.header.scales = las.header.scales

new_las.x = las.x
new_las.y = las.y
new_las.z = las.z

assert np.allclose(las.x, new_las.x)
assert np.allclose(las.y, new_las.y)
assert np.allclose(las.z, new_las.z)


def test_coords_when_using_create_from_header(las):
new_las = pylas.create_from_header(las.header)

new_las.x = las.x
new_las.y = las.y
new_las.z = las.z

assert np.allclose(las.x, new_las.x)
assert np.allclose(las.y, new_las.y)
assert np.allclose(las.z, new_las.z)

0 comments on commit edde1b4

Please sign in to comment.