SphereCrop#

class SphereCrop(point_max=80000, sample_rate=None, mode='random')[source]#

Bases: object

Crop to the nearest points around a center to cap the point count.

When the cloud exceeds the point budget, picks a center and keeps the point_max (or sample_rate-fraction) points closest to it – a spherical crop – subsampling every per-point key in index_valid_keys via index_operator. Smaller clouds are returned unchanged. The center is a random point (mode="random") or the middle-indexed point (mode="center"). Requires coord (asserted). Registered as SphereCrop – use this string as the type in a transform=[...] config list.

Parameters:
  • point_max (int) – maximum number of points to keep when sample_rate is None. Defaults to 80000.

  • sample_rate (float, optional) – if set, the budget is sample_rate * num_points instead of point_max. Defaults to None.

  • mode (str) – center selection, one of "random", "center", or "all". Defaults to "random".

Note

mode="all" is accepted by the constructor but raises NotImplementedError if the crop branch is reached (i.e. when the cloud is over budget).

Example

>>> import numpy as np
>>> from pimm.datasets.transform import SphereCrop
>>> np.random.seed(0)
>>> data = {"coord": np.random.rand(100, 3).astype("f4"),
...         "energy": np.random.rand(100, 1).astype("f4")}
>>> # over budget (100 > 10): keep the 10 points nearest the chosen center
>>> out = SphereCrop(point_max=10, mode="center")(data)
>>> len(out["coord"]), len(out["energy"])  # cropped together, aligned
(10, 10)