Density.adjust_box#
- Density.adjust_box(box, pad_kwargs={})[source]#
Adjusts
Density.data
andDensity.origin
according to the provided box.- Parameters:
- boxtuple of slices
Description of how each axis of
Density.data
should be sliced.- pad_kwargs: dict, optional
Parameter dictionary passed to
numpy.pad
.
See also
Examples
The following demonstrates the ability of
Density.adjust_box()
to extract a subdensity from the currentDensity
instance.Density.adjust_box()
not only operats onDensity.data
, but also modifiesDensity.origin
according tobox
.>>> import numpy as np >>> from tme import Density >>> dens = Density(np.ones((5, 5))) >>> box = (slice(1, 4), slice(2, 5)) >>> dens.adjust_box(box) >>> dens Origin: (1.0, 2.0), sampling_rate: (1, 1), Shape: (3, 3)
Density.adjust_box()
can also extend the box of the currentDensity
instance. This is achieved by negative start or stops that exceed the dimension of the currentDensity.data
array.>>> box = (slice(-1, 10), slice(2, 10)) >>> dens.adjust_box(box) >>> dens Origin: (0.0, 4.0), sampling_rate: (1, 1), Shape: (11, 8)
However, do note that only the start coordinate of each slice in
box
can be negative.>>> box = (slice(-1, 10), slice(2, -10)) >>> dens.adjust_box(box) >>> dens Origin: (-1.0, 6.0), sampling_rate: (1, 1), Shape: (11, 0)