def test_cant_create_scaled_extra_bytes_without_both_offsets_and_scales(): las = pylas.create() with pytest.raises(ValueError): las.add_extra_dim( pylas.ExtraBytesParams("must fail", "int64", scales=np.array([0.1])) ) with pytest.raises(ValueError): las.add_extra_dim( pylas.ExtraBytesParams("must fail", "int64", offsets=np.array([0.1])) )
def test_scaled_extra_byte_array_type(simple_las_path): """ To make sure we handle scaled extra bytes """ las = pylas.read(simple_las_path) las.add_extra_dim( pylas.ExtraBytesParams( name="test_dim", type="3int32", scales=np.array([1.0, 2.0, 3.0], np.float64), offsets=np.array([10.0, 20.0, 30.0], np.float64), ) ) assert np.allclose(las.test_dim[..., 0], 10.0) assert np.allclose(las.test_dim[..., 1], 20.0) assert np.allclose(las.test_dim[..., 2], 30.0) las.test_dim[..., 0][:] = 42.0 las.test_dim[..., 1][:] = 82.0 las.test_dim[..., 2][:] = 123.0 assert np.allclose(las.test_dim[..., 0], 42.0) assert np.allclose(las.test_dim[..., 1], 82.0) assert np.allclose(las.test_dim[..., 2], 123.0) las = write_then_read_again(las) assert np.allclose(las.test_dim[..., 0], 42.0) assert np.allclose(las.test_dim[..., 1], 82.0) assert np.allclose(las.test_dim[..., 2], 123.0)
def test_creating_extra_byte_with_invalid_type(simple_las_path): """ Test the error message when creating extra bytes with invalid type """ las = pylas.read(simple_las_path) with pytest.raises(TypeError): las.add_extra_dim(pylas.ExtraBytesParams("just_a_test", "i16"))
def test_creating_bytes_with_name_too_long(simple_las_path): """ Test error thrown when creating extra bytes with a name that is too long """ las = pylas.read(simple_las_path) with pytest.raises(ValueError) as error: las.add_extra_dim( pylas.ExtraBytesParams( name="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus", type="int32", ) ) assert str(error.value) == "bytes too long (70, maximum length 32)"
def test_extra_bytes_with_spaces_in_name(simple_las_path): """ Test that we can create extra bytes with spaces in their name and that they can be accessed using __getitem__ ( [] ) as de normal '.name' won't work """ las = pylas.read(simple_las_path) las.add_extra_dim(pylas.ExtraBytesParams(name="Name With Spaces", type="int32")) assert np.alltrue(las["Name With Spaces"] == 0) las["Name With Spaces"][:] = 789_464 las = write_then_read_again(las) np.alltrue(las["Name With Spaces"] == 789_464)
def test_cant_create_scaled_extra_bytes_with_scales_array_smaller(num_elements): las = pylas.create() with pytest.raises(ValueError) as error: las.add_extra_dim( pylas.ExtraBytesParams( "must fail", f"{num_elements}int64", scales=np.array([0.1] * (num_elements - 1)), offsets=np.array([0.0] * num_elements), ) ) assert ( str(error.value) == f"len(scales) ({num_elements - 1}) is not the same as the number of elements ({num_elements})" )
def test_point_record_setitem_scaled_view(): las = pylas.read(simple_las) las.add_extra_dim( pylas.ExtraBytesParams( 'lol', 'uint64', scales=np.array([2.0]), offsets=np.array([0.0]) ) ) new_values = np.ones(len(las.points)) * 4 las.lol = new_values assert np.allclose(las.lol, new_values)
def test_creating_scaled_extra_bytes(extra_bytes_params, simple_las_path): las = pylas.read(simple_las_path) try: num_elements = int(extra_bytes_params.type[0]) except ValueError: num_elements = 1 params = pylas.ExtraBytesParams( extra_bytes_params.name, extra_bytes_params.type, offsets=np.array([2.0] * num_elements), scales=np.array([1.0] * num_elements), ) las.add_extra_dim(params) assert np.allclose(las[extra_bytes_params.name], 2.0) las[params.name][:] = 42.0 assert np.allclose(las[extra_bytes_params.name], 42.0) las = write_then_read_again(las) assert np.allclose(las[extra_bytes_params.name], 42.0)
def extra_bytes_params(request): return pylas.ExtraBytesParams(name="just_a_name", type=request.param, description="pylas test ExtraBytes")