SphereCrop#
- class SphereCrop(point_max=80000, sample_rate=None, mode='random')[source]#
Bases:
objectCrop 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(orsample_rate-fraction) points closest to it – a spherical crop – subsampling every per-point key inindex_valid_keysviaindex_operator. Smaller clouds are returned unchanged. The center is a random point (mode="random") or the middle-indexed point (mode="center"). Requirescoord(asserted). Registered asSphereCrop– use this string as thetypein atransform=[...]config list.- Parameters:
point_max (int) – maximum number of points to keep when
sample_rateisNone. Defaults to80000.sample_rate (float, optional) – if set, the budget is
sample_rate * num_pointsinstead ofpoint_max. Defaults toNone.mode (str) – center selection, one of
"random","center", or"all". Defaults to"random".
Note
mode="all"is accepted by the constructor but raisesNotImplementedErrorif 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)