Skip to content

Commit

Permalink
refacto test
Browse files Browse the repository at this point in the history
  • Loading branch information
alavenant committed Sep 25, 2024
1 parent 653e198 commit 51cda27
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
2 changes: 1 addition & 1 deletion pdaltools/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "1.7.4"
__version__ = "1.7.3"


if __name__ == "__main__":
Expand Down
45 changes: 21 additions & 24 deletions test/test_standardize_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,22 @@ def test_standardize_malformed_laz():
assert os.path.isfile(output_file)


def get_pipeline_metadata_cross_plateform(pipeline):
try:
metadata = json.loads(pipeline.metadata)
except TypeError:
d_metadata = json.dumps(pipeline.metadata)
metadata = json.loads(d_metadata)
return metadata

def get_statistics_from_las_points(points):
pipeline = pdal.Pipeline(arrays=[points])
pipeline |= pdal.Filter.stats(dimensions="Classification", enumerate="Classification")
pipeline.execute()
metadata = get_pipeline_metadata_cross_plateform(pipeline)
statistic = metadata["metadata"]["filters.stats"]["statistic"]
return statistic[0]["count"], statistic[0]["values"]

@pytest.mark.parametrize(
"classes_to_remove",
[
Expand All @@ -131,36 +147,17 @@ def test_remove_points_from_class(classes_to_remove):
input_file = os.path.join(TEST_PATH, "data/classified_laz/test_data_77050_627755_LA93_IGN69.laz")
output_file = os.path.join(TMP_PATH, "test_remove_points_from_class.laz")

def get_pipeline_metadata(pipeline):
try:
metadata = json.loads(pipeline.metadata)
except TypeError:
d_metadata = json.dumps(pipeline.metadata)
metadata = json.loads(d_metadata)
return metadata

def get_statistics(points):
pipeline = pdal.Pipeline(arrays=[points])
pipeline |= pdal.Filter.stats(dimensions="Classification", enumerate="Classification")
pipeline.execute()
metadata = get_pipeline_metadata(pipeline)
statistic = metadata["metadata"]["filters.stats"]["statistic"]
return statistic[0]["count"], statistic[0]["values"]

# count points of class not in classes_to_remove (get the point we should have in fine)
pipeline = pdal.Pipeline() | pdal.Reader.las(input_file)
where = ""
for cl in classes_to_remove:
where += "Classification != " + str(cl)
if cl != classes_to_remove[-1]:
where += " && "

where = ' && '.join(["CLassification != " + str(cl) for cl in classes_to_remove])
pipeline |= pdal.Filter.stats(dimensions="Classification", enumerate="Classification", where=where)
pipeline.execute()

points = pipeline.arrays[0]
nb_points_before, class_before = get_statistics(points)
nb_points_before, class_before = get_statistics_from_las_points(points)

metadata = get_pipeline_metadata(pipeline)
metadata = get_pipeline_metadata_cross_plateform(pipeline)
statistic = metadata["metadata"]["filters.stats"]["statistic"]
nb_points_to_get = statistic[0]["count"]

Expand All @@ -170,7 +167,7 @@ def get_statistics(points):
assert nb_points_to_get == 0
return

nb_points_after, class_after = get_statistics(points)
nb_points_after, class_after = get_statistics_from_las_points(points)

assert nb_points_before > 0
assert nb_points_before > nb_points_after
Expand Down

0 comments on commit 51cda27

Please sign in to comment.