Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_from_file(data_path, extension, color, mesh):
cloud = PyntCloud.from_file(str(data_path / "diamond{}".format(extension)))
assert_points_xyz(cloud)
if color:
assert_points_color(cloud)
if mesh:
assert_mesh(cloud)
def test_read_color_off():
color_off = PyntCloud.from_file(data_path + '_color.off')
assert_points_xyz(color_off)
assert_points_color(color_off)
def test_read_bin():
arr = PyntCloud.from_file(data_path + '.bin')
assert_points_xyz(arr)
def test_write_npz():
data = PyntCloud.from_file(data_path + '.ply')
data.to_file(data_path + 'written_npz.npz', also_save=["mesh"])
written_npz = PyntCloud.from_file(data_path + 'written_npz.npz')
assert all(data.points == written_npz.points)
assert all(data.mesh == written_npz.mesh)
os.remove(data_path + 'written_npz.npz')
def test_xyz_filters():
"""filters.f_xyz.
- Manually check known result.
"""
cloud = PyntCloud.from_file(path + "/data/test_data_filters.ply")
bbox = {
"min_x": 0.4,
"max_x": 0.6,
"min_y": 0.4,
"max_y": 0.6
}
f = cloud.get_filter("BBOX", and_apply=True, **bbox)
assert f.argmax() == 3
assert len(cloud.points == 1)
def test_sf_xyz():
cloud = PyntCloud.from_file(path + "/data/plane.npz")
# fit with default values (max_dist=1e-4)
is_plane = cloud.add_scalar_field("plane_fit")
assert sorted(cloud.points[is_plane].value_counts()) == [1, 4]
# fit with higher tolerance -> include outlier
is_plane = cloud.add_scalar_field("plane_fit", max_dist=0.4)
assert sorted(cloud.points[is_plane].value_counts()) == [5]
cloud = PyntCloud.from_file(path + "/data/sphere.ply")
is_sphere = cloud.add_scalar_field("sphere_fit")
assert sorted(cloud.points[is_sphere].value_counts()) == [1, 2928]
is_sphere = cloud.add_scalar_field("sphere_fit", max_dist=26)
assert sorted(cloud.points[is_sphere].value_counts()) == [2929]
def test_split_on(data_path):
"""PyntCloud.split_on.
- Raise KeyError on invalid scalar field
- Raise ValueError on invalid save_format
- and_return should return list of PyntClouds
- Implicitily check save_path is working
"""
cloud = PyntCloud.from_file(str(data_path / "mnist.npz"))
vg_id = cloud.add_structure("voxelgrid", n_x=2, n_y=2, n_z=2)
voxel_n = cloud.add_scalar_field("voxel_n", voxelgrid_id=vg_id)
with pytest.raises(KeyError):
cloud.split_on("bad_sf")
with pytest.raises(ValueError):
cloud.split_on(voxel_n, save_format="bad_format")
output = cloud.split_on(voxel_n, save_path="tmp_out")
assert output is None
output = cloud.split_on(voxel_n, and_return=True, save_path="tmp_out")
def test_voxelgrid_sampling_return_type(simple_pyntcloud, sampling_method):
voxelgrid_id = simple_pyntcloud.add_structure("voxelgrid")
sample = simple_pyntcloud.get_sample(
sampling_method,
voxelgrid_id=voxelgrid_id)
assert type(sample) == DataFrame
sample = simple_pyntcloud.get_sample(
sampling_method,
voxelgrid_id=voxelgrid_id,
as_PyntCloud=True)
assert type(sample) == PyntCloud
def test_regular_bounding_box_changes_the_shape_of_the_bounding_box(x, y, z):
cloud = PyntCloud(pd.DataFrame(
data={
"x": np.array(x, dtype=np.float32),
"y": np.array(y, dtype=np.float32),
"z": np.array(z, dtype=np.float32)
}))
voxelgrid = VoxelGrid(points=cloud.xyz, n_x=2, n_y=2, n_z=2, regular_bounding_box=False)
voxelgrid.compute()
irregular_last_centroid = voxelgrid.voxel_centers[-1]
voxelgrid = VoxelGrid(points=cloud.xyz, n_x=2, n_y=2, n_z=2)
voxelgrid.compute()
regular_last_centroid = voxelgrid.voxel_centers[-1]
def test_to_file(tmpdir, diamond, extension, color, mesh):
extra_write_args = {}
if mesh:
extra_write_args["also_save"] = ["mesh"]
if extension == ".ply":
extra_write_args["as_text"] = False
if extension == "_ascii.ply":
extra_write_args["as_text"] = True
diamond.to_file(str(tmpdir.join("written{}".format(extension))), **extra_write_args)
written_file = PyntCloud.from_file(str(tmpdir.join("written{}".format(extension))))
assert_points_xyz(written_file)
if color:
assert_points_color(written_file)
if mesh:
assert_mesh(written_file)