Density.centered#

Density.centered(cutoff=0.0, order=1)[source]#

Shifts the data center of mass to the center of the data array using linear interpolation. The box size of the returned Density object is at least equal to the box size of the class instance.

Parameters:
cutofffloat, optional

Consider all elements larger than cutoff for computing the new box. Default is 0.0.

orderint, optional

Interpolation order, defaults to 1.

Returns:
Density

A centered copy of the class instance.

NDArray

The offset between array center and center of mass.

Notes

Should any axis of the class instance data array be smaller than the return value of Density.minimum_enclosing_box(), the size of the internal data array is adapted to avoid array elements larger than cutoff to fall outside the data array.

Examples

Density.centered() returns a tuple containing a centered version of the current Density instance. Centering is achieved via padding and rigid-transform of the internal Density.data attribute. centered_dens is sufficiently large to represent all rotations of the Density.data attribute.

>>> import numpy as np
>>> from tme import Density
>>> dens = Density(np.ones((5,5,5)))
>>> centered_dens = dens.centered(0)

Density.centered() extended the Density.data attribute of the current Density instance and modified Density.origin accordingly.

>>> centered_dens
Origin: (-2.0, -2.0, -2.0), sampling_rate: (1, 1, 1), Shape: (9, 9, 9)