CenterShift#

class CenterShift(apply_z=True, axes=('x', 'y', 'z'))[source]#

Bases: object

Center coord on the midpoint of its bounding box per axis.

For each requested axis, subtracts the bounding-box midpoint (min + max) / 2 from that coordinate column in place, centering the cloud about the origin axis-by-axis. The same per-axis shift is applied to v3 vertex metadata and to opt-in aux_position_keys. Requires coord; a no-op if coord is absent. Registered as CenterShift – use this string as the type in a transform=[...] config list.

Parameters:
  • apply_z (bool) – retained for backward compatibility; the axes actually centered are controlled by axes. Defaults to True.

  • axes (str | Sequence[str]) – which of "x", "y", "z" to center. A bare string is wrapped into a single-element tuple. Defaults to ("x", "y", "z").

Note

Each axis is centered independently using its own min/max, so the result is centered on the bounding-box center rather than the centroid.

Example

>>> import numpy as np
>>> from pimm.datasets.transform import CenterShift
>>> data = {"coord": np.array([[0., 0., 0.], [10., 4., 8.]], dtype="f4")}
>>> out = CenterShift(axes=("x", "y"))(data)  # center x,y on bbox midpoint; z untouched
>>> out["coord"]
array([[-5., -2.,  0.],
       [ 5.,  2.,  8.]], dtype=float32)