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
Densityobject 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:
DensityA 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 currentDensityinstance. Centering is achieved via padding and rigid-transform of the internalDensity.dataattribute. centered_dens is sufficiently large to represent all rotations of theDensity.dataattribute.>>> import numpy as np >>> from tme import Density >>> dens = Density(np.ones((5,5,5))) >>> centered_dens = dens.centered(0)
Density.centered()extended theDensity.dataattribute of the currentDensityinstance and modifiedDensity.originaccordingly.>>> centered_dens Origin: (-2.0, -2.0, -2.0), sampling_rate: (1, 1, 1), Shape: (9, 9, 9)