Density.adjust_box#
- Density.adjust_box(box, pad_kwargs={})[source]#
Adjusts
Density.dataandDensity.originaccording to the provided box.- Parameters:
- boxtuple of slices
Description of how each axis of
Density.datashould 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 currentDensityinstance.Density.adjust_box()not only operats onDensity.data, but also modifiesDensity.originaccording 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 currentDensityinstance. This is achieved by negative start or stops that exceed the dimension of the currentDensity.dataarray.>>> 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
boxcan 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)