RandomShift#

class RandomShift(shift=((-0.2, 0.2), (-0.2, 0.2), (0, 0)))[source]#

Bases: object

Translate coord by a uniform random per-axis offset.

Draws an independent uniform offset for each axis from its configured range and adds the resulting vector to coord in place; the same offset is applied to v3 vertex metadata. Requires coord; a no-op if coord is absent. Registered as RandomShift – use this string as the type in a transform=[...] config list.

Parameters:

shift (tuple[tuple[float, float], ...]) – per-axis (low, high) ranges for the uniform offset along x, y, z. Defaults to ((-0.2, 0.2), (-0.2, 0.2), (0, 0)) (no z shift).

Example

>>> import numpy as np
>>> from pimm.datasets.transform import RandomShift
>>> np.random.seed(0)
>>> data = {"coord": np.zeros((2, 3), dtype="f4")}
>>> out = RandomShift(shift=((-0.1, 0.1), (-0.1, 0.1), (0, 0)))(data)
>>> bool(np.abs(out["coord"][:, :2]).max() <= 0.1)  # x,y shifted within +/-0.1
True
>>> out["coord"][:, 2].tolist()  # z range is (0, 0): no shift
[0.0, 0.0]