RandomShift#
- class RandomShift(shift=((-0.2, 0.2), (-0.2, 0.2), (0, 0)))[source]#
Bases:
objectTranslate
coordby a uniform random per-axis offset.Draws an independent uniform offset for each axis from its configured range and adds the resulting vector to
coordin place; the same offset is applied to v3vertexmetadata. Requirescoord; a no-op ifcoordis absent. Registered asRandomShift– use this string as thetypein atransform=[...]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]