Skip to content

pc: Point cloud data utilities

moraine.api.pc (source). Every name is also moraine.<name> (import moraine as mr).

pc_hix

pc_hix(gix, shape: tuple) -> ndarray

Compute the hillbert index for point cloud data.

Parameters:

Name Type Description Default
gix

grid index

required
shape tuple

(nlines, width)

required

pc_gix

pc_gix(hix, shape: tuple) -> ndarray

convert hillbert index to grid index.

Parameters:

Name Type Description Default
hix

hillbert index

required
shape tuple

(nlines, width)

required

pc_sort

pc_sort(idx: ndarray, shape: tuple = None) -> ndarray

Get the indices that sort the input.

Parameters:

Name Type Description Default
idx ndarray

unsorted gix (2D) or hix(1D)

required
shape tuple

(nline, width), faster if provided for grid index input

None

Returns:

Type Description
ndarray

indices that sort input

pc2ras

pc2ras(idx: ndarray, pc_data: ndarray, shape: tuple)

convert point cloud data to original raster, filled with nan

Parameters:

Name Type Description Default
idx ndarray

gix or hix array

required
pc_data ndarray

data, 1D or more

required
shape tuple

image shape

required

ras2pc

ras2pc(ras, gix)

pc_union

pc_union(idx1: ndarray, idx2: ndarray, shape: tuple = None) -> tuple

Get the union of two point cloud dataset. For points at their intersection, prefer idx1 rather than idx2

Parameters:

Name Type Description Default
idx1 ndarray

int array, grid index or hillbert index of the first point cloud, sorted, without duplicates

required
idx2 ndarray

int array, grid index or hillbert index of the second point cloud, sorted, without duplicates

required
shape tuple

image shape, faster if provided for grid index input

None

Returns:

Type Description
tuple
  • the union index idx
  • index of the point in output union index that originally in the first point cloud inv_iidx
  • index of the point in output union index that only exist in the second point cloud inv_iidx2
  • index of the point in the second input index that are not in the first input point cloud

pc_intersect

pc_intersect(idx1: ndarray, idx2: ndarray, shape: tuple = None) -> tuple

Get the intersection of two point cloud dataset.

Parameters:

Name Type Description Default
idx1 ndarray

int array, grid index or hillbert index of the first point cloud, sorted, without duplicates

required
idx2 ndarray

int array, grid index or hillbert index of the second point cloud, sorted, without duplicates

required
shape tuple

image shape, faster if provided for grid index input

None

Returns:

Type Description
tuple
  • the intersect index idx
  • index of the point in first point cloud index that also exist in the second point cloud
  • index of the point in second point cloud index that also exist in the first point cloud

pc_diff

pc_diff(idx1: ndarray, idx2: ndarray, shape: tuple = None) -> tuple

Get the point cloud in idx1 that are not in idx2.

Parameters:

Name Type Description Default
idx1 ndarray

int array, grid index or hillbert index of the first point cloud, sorted, without duplicates

required
idx2 ndarray

int array, grid index or hillbert index of the second point cloud, sorted, without duplicates

required
shape tuple

image shape, faster if provided for grid index input

None

Returns:

Type Description
tuple
  • the diff index idx
  • index of the point in first point cloud index that do not exist in the second point cloud

Examples

Run when this manual is built; the output follows each snippet.

import numpy as np
import moraine as mr

shape = (8, 8)                                                   # (nlines, width) of the raster
gix1 = np.array([[0, 1], [2, 3], [5, 5]], dtype=np.int32)         # (azimuth, range) of three points
hix1 = mr.pc_hix(gix1, shape)                                    # hilbert index of each point
print(hix1)
order = mr.pc_sort(hix1)                                         # point clouds are kept in hilbert order
hix1, gix1 = hix1[order], gix1[order]

gix2 = np.array([[2, 3], [7, 0]], dtype=np.int32)
hix2 = np.sort(mr.pc_hix(gix2, shape))
hix, in1, in2, new2 = mr.pc_union(hix1, hix2)                    # sorted inputs, sorted union
print(hix, mr.pc_gix(hix, shape).tolist())
print(in1, in2, new2)                                            # where the points of each input went
[ 1 11 34]
[ 1 11 34 63] [[0, 1], [2, 3], [5, 5], [7, 0]]
[0 1 2] [3] [1]
ras = mr.pc2ras(hix, np.arange(len(hix), dtype=np.float32), shape)   # point data on the raster, nan elsewhere
print(ras)
print(mr.ras2pc(ras, mr.pc_gix(hix, shape)))                          # and back
[[nan  0. nan nan nan nan nan nan]
 [nan nan nan nan nan nan nan nan]
 [nan nan nan  1. nan nan nan nan]
 [nan nan nan nan nan nan nan nan]
 [nan nan nan nan nan nan nan nan]
 [nan nan nan nan nan  2. nan nan]
 [nan nan nan nan nan nan nan nan]
 [ 3. nan nan nan nan nan nan nan]]
[0. 1. 2. 3.]