def test_create_fmt_0(file): new = pylas.create(point_format_id=0) dim_names_fmt_0 = PointFormat(0).dimension_names for dim_name in dim_names_fmt_0: new[dim_name] = file[dim_name] for dim_name in dim_names_fmt_0: assert np.allclose(new[dim_name], file[dim_name]) with pytest.raises(ValueError): new.red = file.red with pytest.raises(ValueError): new.red = file.green with pytest.raises(ValueError): new.red = file.blue with pytest.raises(ValueError): new.gps_time = file.gps_time new = write_then_read_again(new) for dim_name in dim_names_fmt_0: assert np.allclose(new[dim_name], file[dim_name]), "{} not equal".format(dim_name)
def test_classification(las): las.classification[:] = 234 assert np.alltrue(las.classification == 234) res = write_then_read_again(las) assert np.alltrue(las.classification == res.classification)
def test_set_uuid(): import uuid las = pylas.read(test_common.simple_las) u = uuid.uuid4() las.header.uuid = u las = test_common.write_then_read_again(las) assert las.header.uuid == u
def test_extra_bytes_well_saved(extrab_las): extrab_las.Time = np.zeros_like(extrab_las.Time) assert np.alltrue(extrab_las.points_data["Time"] == 0) extrab_las = write_then_read_again(extrab_las) assert np.alltrue(extrab_las.Time == 0)
def test_classification_change(las, do_compress): c = las.classification c[:] = 10 las.classification = c assert np.allclose(c, las.classification) las = write_then_read_again(las, do_compress=do_compress) assert np.allclose(c, las.classification)
def test_key_point_change(las, do_compress): kp = las.key_point kp[:] = False kp[25] = True las.key_point = kp assert np.allclose(kp, las.key_point) las = write_then_read_again(las, do_compress=do_compress) assert np.allclose(kp, las.key_point)
def test_synthetic_change(las, do_compress): s = las.synthetic s[:] = False s[17] = True las.synthetic = s assert np.allclose(s, las.synthetic) las = write_then_read_again(las, do_compress=do_compress) assert np.allclose(s, las.synthetic)
def test_withheld_changes(las, do_compress): withheld = las.withheld withheld[:] = False withheld[180] = True las.withheld = withheld assert np.allclose(withheld, las.withheld) las = write_then_read_again(las, do_compress=do_compress) assert np.allclose(withheld, las.withheld)
def test_writing_las_with_evlrs(): las = pylas.read(test1_4_las) assert las.evlrs == [] evlr = pylas.VLR(user_id="pylastest", record_id=42, description="Just a test", record_data=b"And so he grinds his own hands") las.evlrs.append(evlr) las_1 = write_then_read_again(las, do_compress=False) assert las_1.evlrs == [evlr]
def test_xyz(): las = pylas.create() shape = (150, ) las.X = np.zeros(shape, dtype=np.int32) las.Y = np.ones(shape, dtype=np.int32) las.Z = np.zeros(shape, dtype=np.int32) las.Z[:] = -152 las = write_then_read_again(las) assert np.alltrue(las.X == 0) assert np.alltrue(las.Y == 1) assert np.alltrue(las.Z == -152)
def test_nb_points_return_1_4(): las = pylas.read(test_common.test1_4_las) r = las.return_number for i in range(15): r[i] = i + 1 r[15:] = 15 las = test_common.write_then_read_again(las) assert tuple(las.header.number_of_points_by_return) == ( (1, ) * 14) + (len(las.points) - 14, )
def test_extraction(file): new = pylas.create(point_format_id=0) assert file.points_data.point_format_id == 3 # automatic promotion of point format new.points = file.points[file.classification == 2] assert new.points_data.point_format_id == 3 assert new.header.point_format_id == 3 assert len(new.points) == sum(file.classification == 2) assert np.alltrue(new.classification == 2) file = write_then_read_again(new) assert np.alltrue(file.classification == 2)
def test_adding_classification_lookup(): simple = pylas.read(test_common.simple_las) classification_lookup = pylas.vlrs.known.ClassificationLookupVlr() assert len(classification_lookup.lookups) == 0 classification_lookup[20] = "computer" assert len(classification_lookup.lookups) == 1 classification_lookup[17] = "car" simple.vlrs.append(classification_lookup) simple = test_common.write_then_read_again(simple) classification_lookups = simple.vlrs.get("ClassificationLookupVlr")[0] assert classification_lookups[20] == "computer" assert classification_lookups[17] == "car"
def test_create_fmt_1(file): new = pylas.create(point_format_id=1) with pytest.raises(ValueError): new.red = file.red with pytest.raises(ValueError): new.red = file.green with pytest.raises(ValueError): new.red = file.blue new.gps_time = file.gps_time assert np.allclose(new.gps_time, file.gps_time) new = write_then_read_again(new) assert np.allclose(new.gps_time, file.gps_time)
def test_create_fmt_6(file1_4): new = pylas.create(point_format_id=6) assert new.header.version == "1.4" dim_names_fmt_6 = pylas.point.dims.get_dtype_of_format_id(6).names for dim_name in dim_names_fmt_6: new[dim_name] = file1_4[dim_name] for dim_name in dim_names_fmt_6: assert np.allclose(new[dim_name], file1_4[dim_name]), "{} not equal".format(dim_name) new = write_then_read_again(new) for dim_name in dim_names_fmt_6: assert np.allclose(new[dim_name], file1_4[dim_name]), "{} not equal".format(dim_name)
def test_create_fmt_6(file1_4): new = pylas.create(point_format=6) assert str(new.header.version) == "1.4" dim_names_fmt_6 = PointFormat(6).dtype().names for dim_name in dim_names_fmt_6: new[dim_name] = file1_4[dim_name] for dim_name in dim_names_fmt_6: assert np.allclose(new[dim_name], file1_4[dim_name]), "{} not equal".format(dim_name) new = write_then_read_again(new) for dim_name in dim_names_fmt_6: assert np.allclose(new[dim_name], file1_4[dim_name]), "{} not equal".format(dim_name)
def test_create_fmt_1(): new = pylas.create(point_format=1) with pytest.raises(ValueError): new.red = np.zeros(len(new.points), np.uint16) with pytest.raises(ValueError): new.red = np.zeros(len(new.points), np.uint16) with pytest.raises(ValueError): new.red = np.zeros(len(new.points), np.uint16) gps_time = np.random.uniform(0, 25641, len(new.points)) new.gps_time = gps_time assert np.allclose(new.gps_time, gps_time) new = write_then_read_again(new) assert np.allclose(new.gps_time, gps_time)
def test_create_fmt_3(file): new = pylas.create(point_format=3) new.red = file.red new.green = file.green new.blue = file.blue new.gps_time = file.gps_time assert np.allclose(new.red, file.red) assert np.allclose(new.green, file.green) assert np.allclose(new.blue, file.blue) assert np.allclose(new.gps_time, file.gps_time) new = write_then_read_again(new) assert np.allclose(new.red, file.red) assert np.allclose(new.green, file.green) assert np.allclose(new.blue, file.blue) assert np.allclose(new.gps_time, file.gps_time)
def test_create_fmt_2(file): new = pylas.create(point_format=2) with pytest.raises(ValueError): new.gps_time = file.gps_time new.red = file.red new.green = file.green new.blue = file.blue assert np.allclose(new.red, file.red) assert np.allclose(new.green, file.green) assert np.allclose(new.blue, file.blue) new = write_then_read_again(new) assert np.allclose(new.red, file.red) assert np.allclose(new.green, file.green) assert np.allclose(new.blue, file.blue)
def test_add_extra_bytes(las1_4): las1_4.add_extra_dim("test_dim", "u1") las1_4.add_extra_dim("test_array", "3f8") las1_4.test_dim[:] = 150 las1_4.test_array[:, 0] = 1.1 las1_4.test_array[:, 1] = 2.2 las1_4.test_array[:, 2] = 333.6 assert np.alltrue(las1_4.points_data["test_dim"] == 150) assert np.allclose(las1_4.points_data["test_array"][:, 0], 1.1) assert np.allclose(las1_4.points_data["test_array"][:, 1], 2.2) assert np.allclose(las1_4.points_data["test_array"][:, 2], 333.6) las1_4 = write_then_read_again(las1_4) assert np.alltrue(las1_4.test_dim == 150) assert np.allclose(las1_4.test_array[:, 0], 1.1) assert np.allclose(las1_4.test_array[:, 1], 2.2) assert np.allclose(las1_4.test_array[:, 2], 333.6)
def test_number_of_points_return_is_updated(all_las_but_1_4): las = all_las_but_1_4 nb_points = len(las.points_data) nb_slice = 3 r = las.return_number for i in reversed(range(nb_slice)): r[i * (nb_points // nb_slice):(i + 1) * (nb_points // nb_slice)] = i las.return_number = r las = test_common.write_then_read_again(las) assert (tuple( las.header.number_of_points_by_return[:nb_slice]) == (nb_points // nb_slice, ) * nb_slice) assert tuple(las.header.number_of_points_by_return[nb_slice:]) == (0, ) * ( len(las.header.number_of_points_by_return) - nb_slice)
def test_adding_classification_lookup(): simple = pylas.read(test_common.simple_las) classification_lookup = pylas.vlrs.known.ClassificationLookupVlr() assert len(classification_lookup.lookups) == 0 classification_lookup.add_lookup(20, "computer") assert len(classification_lookup.lookups) == 1 classification_lookup.add_lookup(17, "car") simple.vlrs.append(classification_lookup) simple = test_common.write_then_read_again(simple) classification_lookups = simple.vlrs.get("ClassificationLookupVlr") assert len(classification_lookups) == 1 classification_lookup = classification_lookups[0] lookups = { lookup.class_number: lookup.description for lookup in classification_lookup.lookups } assert lookups[20] == "computer" assert lookups[17] == "car"
def test_read_write_read(read_simple): _ = write_then_read_again(read_simple)
def test_read_write_read_laz(read_simple): _ = write_then_read_again(read_simple, do_compress=True)
def test_intensity(las): las.intensity[:] = 89 assert np.alltrue(las.intensity == 89) res = write_then_read_again(las) assert np.alltrue(las.intensity == res.intensity)