Skip to content

Commit

Permalink
Update the pytest for the new attribute schema
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoledoux committed Jun 3, 2024
1 parent 7a6a379 commit 99d4fd6
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 39 deletions.
45 changes: 18 additions & 27 deletions tests/test_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,58 +19,49 @@ def dt_5_points():
def small_laz_intensity():
las = laspy.read("data/small.laz")
d = np.vstack((las.x, las.y, las.z, las.intensity)).transpose()
dt = startinpy.DT(extra_attributes=True)
dt = startinpy.DT(np.dtype([("intensity", np.float64)]))
for each in d:
dt.insert_one_pt(each[:3], intensity=each[3])
return dt

def test_schema():
dt = small_laz_intensity()
dtype = np.dtype([("intensity", np.float64)])
assert dtype == dt.get_attributes_schema()


def test_las_reading():
dt = small_laz_intensity()
a = json.loads(dt.get_vertex_attributes(11))
a = dt.get_vertex_attributes(11)
assert a['intensity'] == pytest.approx(533.0)
with pytest.raises(KeyError):
assert a['blue']
with pytest.raises(IndexError):
dt.get_vertex_attributes(55555)

def test_set_vertex_attributes_1by1():
dt = startinpy.DT(extra_attributes=True)
dt = startinpy.DT(np.dtype([("humidity", np.float64)]))
dt.insert_one_pt([0.0, 0.0, 12.5], humidity=33.3);
dt.insert_one_pt([1.0, 0.0, 7.65]);
dt.insert_one_pt([1.0, 1.0, 33.0]);
dt.insert_one_pt([0.0, 1.0, 21.0]);
a = json.loads(dt.get_vertex_attributes(1))
a = dt.get_vertex_attributes(1)
assert a['humidity'] == pytest.approx(33.3)
i = dt.attribute('humidity')
i = dt.attributes
assert i.shape[0] == 5
i = dt.attribute('smthelse')
assert i.shape[0] == 0

def test_list_attributes():
dt = startinpy.DT(extra_attributes=True)
dt.insert_one_pt([0.0, 0.0, 12.5], a1=33.3);
dt.insert_one_pt([1.0, 0.0, 7.65], a2=33.3);
dt.insert_one_pt([1.0, 0.0, 7.65]);
dt.insert_one_pt([1.0, 1.0, 33.0], a3=33.3);
dt.insert_one_pt([0.0, 1.0, 21.0], a4=33.3, a1=33.3);
l = dt.list_attributes()
assert len(l) == 4

def test_set_vertex_attributes():
dt = small_laz_intensity()
new_a = {'intensity': 155.5, 'reflectance': 222.2, 'extra': 3}
assert dt.set_vertex_attributes(11, json.dumps(new_a)) == True
new2 = json.loads(dt.get_vertex_attributes(11))
assert new2['intensity'] == pytest.approx(155.5)
assert new2['reflectance'] == pytest.approx(222.2)
assert new2['extra'] == 3
with pytest.raises(KeyError):
new2['hugo'] == 3
dt.set_vertex_attributes(11, intensity=66.6)
assert dt.attributes['intensity'][11] == 66.6
dt.set_vertex_attributes(11, allo=22.2)
assert dt.attributes['intensity'][11] == 66.6


def test_no_attribute():
dt = dt_5_points()
with pytest.raises(Exception):
a = json.loads(dt.get_vertex_attributes(2))
a = dt.get_vertex_attributes(2)
with pytest.raises(Exception):
a = json.loads(dt.get_vertex_attributes(12))
a = dt.get_vertex_attributes(12)

46 changes: 34 additions & 12 deletions tests/test_duplicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@
import numpy as np


def test_attributes():
dt = startinpy.DT(np.dtype([('classification', int)]))
dt.insert_one_pt([0.0, 0.0, 1.0], classification=1);
dt.insert_one_pt([10.0, 0.0, 2.0], classification=2);
dt.insert_one_pt([10.0, 10.0, 3.0], classification=3);
dt.insert_one_pt([0.0, 10.0, 4.0], classification=4);
dt.insert_one_pt([5.0, 5.0, 10.0], classification=5);
dt.insert_one_pt([5.0, 5.0, 11.0], classification=11)
assert(dt.points[5][2] == 10.0)
assert(dt.attributes[5][0] == 5)
dt.duplicates_handling = "Highest"
dt.insert_one_pt([5.0, 5.0, 11.0], classification=11)
assert(dt.points[5][2] == 11.0)
assert(dt.attributes[5][0] == 11)



def test_duplicates():
dt = startinpy.DT()
dt.insert_one_pt([0.0, 0.0, 1.0]);
Expand All @@ -11,25 +28,30 @@ def test_duplicates():
dt.insert_one_pt([0.0, 10.0, 4.0]);
dt.insert_one_pt([5.0, 5.0, 10.0]);

(i, b) = dt.insert_one_pt([5.0, 5.0, 20.0]);
(i, b, bz) = dt.insert_one_pt([5.0, 5.0, 20.0]);
assert i == 5
assert b == False
assert bz == False
assert dt.get_point(5)[2] == 10.0

dt.duplicates_handling = 'Highest'
(i, b) = dt.insert_one_pt([5.0, 5.0, 20.0]);
(i, b, bz) = dt.insert_one_pt([5.0, 5.0, 20.0]);
assert bz == True
assert dt.get_point(5)[2] == 20.0

dt.duplicates_handling = 'Lowest'
(i, b) = dt.insert_one_pt([5.0, 5.0, 10.0]);
(i, b, bz) = dt.insert_one_pt([5.0, 5.0, 10.0]);
assert bz == True
assert dt.get_point(5)[2] == 10.0

dt.duplicates_handling = 'Last'
(i, b) = dt.insert_one_pt([5.0, 5.0, 5.0]);
(i, b, bz) = dt.insert_one_pt([5.0, 5.0, 5.0]);
assert bz == True
assert dt.get_point(5)[2] == 5.0

dt.duplicates_handling = 'First'
(i, b) = dt.insert_one_pt([5.0, 5.0, 15.0]);
(i, b, bz) = dt.insert_one_pt([5.0, 5.0, 15.0]);
assert bz == False
assert dt.get_point(5)[2] == 5.0

def test_snap_tolerance():
Expand All @@ -41,22 +63,22 @@ def test_snap_tolerance():
dt.insert_one_pt([5.0, 5.0, 10.0]);

assert dt.snap_tolerance == pytest.approx(0.001)
(i, b) = dt.insert_one_pt([5.0001, 5.0, 20.0]);
(i, b, bz) = dt.insert_one_pt([5.0001, 5.0, 20.0]);
assert b == False
(i, b) = dt.insert_one_pt([5.000999, 5.0, 20.0]);
(i, b, bz) = dt.insert_one_pt([5.000999, 5.0, 20.0]);
assert b == False
(i, b) = dt.insert_one_pt([5.001, 5.0, 20.01]);
(i, b, bz) = dt.insert_one_pt([5.001, 5.0, 20.01]);
assert b == True

dt.snap_tolerance = 0.1
assert dt.snap_tolerance == pytest.approx(0.1)
(i, b) = dt.insert_one_pt([10.0, 0.0, 20.0]);
(i, b, bz) = dt.insert_one_pt([10.0, 0.0, 20.0]);
assert b == False
(i, b) = dt.insert_one_pt([10.09, 0.0, 20.0]);
(i, b, bz) = dt.insert_one_pt([10.09, 0.0, 20.0]);
assert b == False
(i, b) = dt.insert_one_pt([10.10, 0.0, 20.0]);
(i, b, bz) = dt.insert_one_pt([10.10, 0.0, 20.0]);
assert b == False
(i, b) = dt.insert_one_pt([10.11, 0.0, 20.0]);
(i, b, bz) = dt.insert_one_pt([10.11, 0.0, 20.0]);
assert b == True


5 changes: 5 additions & 0 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ def test_init():
dt = startinpy.DT()
assert dt.number_of_vertices() == 0
assert dt.number_of_triangles() == 0
assert dt.get_attributes_schema() == []
dt = startinpy.DT(np.dtype([('classification', np.float32), ('visited', bool)]))
assert dt.number_of_vertices() == 0
assert dt.number_of_triangles() == 0
assert dt.get_attributes_schema() == np.dtype([('classification', np.float32), ('visited', bool)])

def test_wrong_array_size():
dt = startinpy.DT()
Expand Down

0 comments on commit 99d4fd6

Please sign in to comment.