LSST Applications g0f08755f38+9c285cab97,g1635faa6d4+13f3999e92,g1653933729+a8ce1bb630,g1a0ca8cf93+bf6eb00ceb,g28da252d5a+0829b12dee,g29321ee8c0+5700dc9eac,g2bbee38e9b+9634bc57db,g2bc492864f+9634bc57db,g2cdde0e794+c2c89b37c4,g3156d2b45e+41e33cbcdc,g347aa1857d+9634bc57db,g35bb328faa+a8ce1bb630,g3a166c0a6a+9634bc57db,g3e281a1b8c+9f2c4e2fc3,g414038480c+077ccc18e7,g41af890bb2+fde0dd39b6,g5fbc88fb19+17cd334064,g781aacb6e4+a8ce1bb630,g80478fca09+55a9465950,g82479be7b0+d730eedb7d,g858d7b2824+9c285cab97,g9125e01d80+a8ce1bb630,g9726552aa6+10f999ec6a,ga5288a1d22+2a84bb7594,gacf8899fa4+c69c5206e8,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+9634bc57db,gcf0d15dbbd+4b7d09cae4,gda3e153d99+9c285cab97,gda6a2b7d83+4b7d09cae4,gdaeeff99f8+1711a396fd,ge2409df99d+5e831397f4,ge79ae78c31+9634bc57db,gf0baf85859+147a0692ba,gf3967379c6+41c94011de,gf3fb38a9a8+8f07a9901b,gfb92a5be7c+9c285cab97,w.2024.46
LSST Data Management Base Package
|
Public Member Functions | |
__init__ (self, tuple[int,...] shape, tuple[int,...]|None origin=None) | |
bool | contains (self, Sequence[int] p) |
int | ndim (self) |
tuple[int,...] | start (self) |
tuple[int,...] | stop (self) |
tuple[float,...] | center (self) |
tuple[tuple[int, int],...] | bounds (self) |
tuple[slice,...] | slices (self) |
Box | grow (self, int|tuple[int,...] radius) |
Box | shifted_by (self, Sequence[int] shift) |
bool | intersects (self, Box other) |
tuple[tuple[slice,...], tuple[slice,...]] | overlapped_slices (self, Box other) |
Box | __or__ (self, Box other) |
Box | __and__ (self, Box other) |
Box | __getitem__ (self, int|slice|tuple[int,...] index) |
str | __repr__ (self) |
Box | __add__ (self, int|Sequence[int] offset) |
Box | __sub__ (self, int|Sequence[int] offset) |
Box | __matmul__ (self, Box bbox) |
Box | __copy__ (self) |
Box | copy (self) |
bool | __eq__ (self, object other) |
int | __hash__ (self) |
Static Public Member Functions | |
Box | from_bounds (*tuple[int,...] bounds) |
Box | from_data (np.ndarray x, float threshold=0) |
Public Attributes | |
shape | |
origin | |
ndim | |
Protected Member Functions | |
tuple[int,...] | _offset_to_tuple (self, int|Sequence[int] offset) |
Bounding Box for an object A Bounding box describes the location of a data unit in the global/model coordinate system, using the row-major (default numpy/C++) ordering convention. So, for example, a 2D image will have shape ``(height, width)``, however the bounding `Box` code is agnostic as to number of dimensions or the meaning of those dimensions. Examples -------- At a minimum a new `Box` can be initialized using the ``shape`` of the region it describes: >>> from lsst.scarlet.lite import Box >>> bbox = Box((3, 4, 5, 6)) >>> print(bbox) Box(shape=(3, 4, 5, 6), origin=(0, 0, 0, 0)) If the region described by the `Box` is offset from the zero origin, a new ``origin`` can be passed to the constructor >>> bbox = Box((3, 4, 5, 6), (2, 4, 7, 9)) >>> print(bbox) Box(shape=(3, 4, 5, 6), origin=(2, 4, 7, 9)) It is also possible to initialize a `Box` from a collection of tuples, where tuple is a pair of integers representing the first and last index in each dimension. For example: >>> bbox = Box.from_bounds((3, 6), (11, 21)) >>> print(bbox) Box(shape=(3, 10), origin=(3, 11)) It is also possible to initialize a `Box` by thresholding a numpy array and including only the region of the image above the threshold in the resulting `Box`. For example >>> from lsst.scarlet.lite.utils import integrated_circular_gaussian >>> data = integrated_circular_gaussian(sigma=1.0) >>> bbox = Box.from_data(data, 1e-2) >>> print(bbox) Box(shape=(5, 5), origin=(5, 5)) The `Box` class contains a number of convenience methods that can be used to extract subsets of an array, combine bounding boxes, etc. For example, using the ``data`` and ``bbox`` from the end of the previous section, the portion of the data array that is contained in the bounding box can be extraced usng the `Box.slices` method: >>> subset = data[bbox.slices] The intersection of two boxes can be calcualted using the ``&`` operator, for example >>> bbox = Box((5, 5)) & Box((5, 5), (2, 2)) >>> print(bbox) Box(shape=(3, 3), origin=(2, 2)) Similarly, the union of two boxes can be calculated using the ``|`` operator: >>> bbox = Box((5, 5)) | Box((5, 5), (2, 2)) >>> print(bbox) Box(shape=(7, 7), origin=(0, 0)) To find out of a point is located in a `Box` use >>> contains = bbox.contains((3, 3)) >>> print(contains) True To find out if two boxes intersect (in other words ``box1 & box2`` has a non-zero size) use >>> intersects = bbox.intersects(Box((10, 10), (100, 100))) >>> print(intersects) False It is also possible to shift a box by a vector (sequence): >>> bbox = bbox + (50, 60) >>> print(bbox) Box(shape=(7, 7), origin=(50, 60)) which can also be negative >>> bbox = bbox - (5, -5) >>> print(bbox) Box(shape=(7, 7), origin=(45, 65)) Boxes can also be converted into higher dimensions using the ``@`` operator: >>> bbox1 = Box((10,), (3, )) >>> bbox2 = Box((101, 201), (18, 21)) >>> bbox = bbox1 @ bbox2 >>> print(bbox) Box(shape=(10, 101, 201), origin=(3, 18, 21)) Boxes are equal when they have the same shape and the same origin, so >>> print(Box((10, 10), (5, 5)) == Box((10, 10), (5, 5))) True >>> print(Box((10, 10), (5, 5)) == Box((10, 10), (4, 4))) False Finally, it is common to insert one array into another when their bounding boxes only partially overlap. In order to correctly insert the overlapping portion of the array it is convenient to calculate the slices from each array that overlap. For example: >>> import numpy as np >>> x = np.arange(12).reshape(3, 4) >>> y = np.arange(9).reshape(3, 3) >>> print(x) [[ 0 1 2 3] [ 4 5 6 7] [ 8 9 10 11]] >>> print(y) [[0 1 2] [3 4 5] [6 7 8]] >>> x_box = Box.from_data(x) + (3, 4) >>> y_box = Box.from_data(y) + (1, 3) >>> slices = x_box.overlapped_slices(y_box) >>> x[slices[0]] += y[slices[1]] >>> print(x) [[ 7 9 2 3] [ 4 5 6 7] [ 8 9 10 11]] Parameters ---------- shape: Size of the box in each dimension. origin: Minimum corner coordinate of the box. This defaults to ``(0, ...)``.
lsst.scarlet.lite.bbox.Box.__init__ | ( | self, | |
tuple[int, ...] | shape, | ||
tuple[int, ...] | None | origin = None ) |
Definition at line 177 of file bbox.py.
Box lsst.scarlet.lite.bbox.Box.__add__ | ( | self, | |
int | Sequence[int] | offset ) |
Generate a new Box with a shifted offset Parameters ---------- offset: The amount to shift the current offset Returns ------- result: The shifted box.
Definition at line 416 of file bbox.py.
Intersection of two bounding boxes If there is no intersection between the two bounding boxes then an empty bounding box is returned. Parameters ---------- other: The other bounding box in the intersection Returns ------- result: The rectangular box that is in the overlap region of both boxes.
Definition at line 355 of file bbox.py.
Box lsst.scarlet.lite.bbox.Box.__copy__ | ( | self | ) |
bool lsst.scarlet.lite.bbox.Box.__eq__ | ( | self, | |
object | other ) |
Check for equality. Two boxes are equal when they have the same shape and origin.
Definition at line 473 of file bbox.py.
Box lsst.scarlet.lite.bbox.Box.__getitem__ | ( | self, | |
int | slice | tuple[int, ...] | index ) |
Definition at line 380 of file bbox.py.
int lsst.scarlet.lite.bbox.Box.__hash__ | ( | self | ) |
Combine two Boxes into a higher dimensional box Parameters ---------- bbox: The box to append to this box. Returns ------- result: The combined Box.
Definition at line 448 of file bbox.py.
Union of two bounding boxes Parameters ---------- other: The other bounding box in the union Returns ------- result: The smallest rectangular box that contains *both* boxes.
Definition at line 335 of file bbox.py.
str lsst.scarlet.lite.bbox.Box.__repr__ | ( | self | ) |
Box lsst.scarlet.lite.bbox.Box.__sub__ | ( | self, | |
int | Sequence[int] | offset ) |
Generate a new Box with a shifted offset in the negative direction Parameters ---------- offset: The amount to shift the current offset Returns ------- result: The shifted box.
Definition at line 431 of file bbox.py.
|
protected |
Expand an integer offset into a tuple Parameters ---------- offset: The offset to (potentially) convert into a tuple. Returns ------- offset: The offset as a tuple.
Definition at line 397 of file bbox.py.
tuple[tuple[int, int], ...] lsst.scarlet.lite.bbox.Box.bounds | ( | self | ) |
tuple[float, ...] lsst.scarlet.lite.bbox.Box.center | ( | self | ) |
bool lsst.scarlet.lite.bbox.Box.contains | ( | self, | |
Sequence[int] | p ) |
Whether the box contains a given coordinate `p`
Definition at line 236 of file bbox.py.
Box lsst.scarlet.lite.bbox.Box.copy | ( | self | ) |
|
static |
Initialize a box from its bounds Parameters ---------- bounds: Min/Max coordinate for every dimension Returns ------- bbox: A new box bounded by the input bounds.
Definition at line 188 of file bbox.py.
|
static |
Define range of `x` above `min_value`. This method creates the smallest `Box` that contains all of the elements in `x` that are above `min_value`. Parameters ---------- x: Data to threshold to specify the shape/dimensionality of `x`. threshold: Threshold for the data. The box is trimmed so that all elements bordering `x` smaller than `min_value` are ignored. Returns ------- bbox: Bounding box for the thresholded `x`
Definition at line 206 of file bbox.py.
Box lsst.scarlet.lite.bbox.Box.grow | ( | self, | |
int | tuple[int, ...] | radius ) |
Grow the Box by the given radius in each direction
Definition at line 278 of file bbox.py.
bool lsst.scarlet.lite.bbox.Box.intersects | ( | self, | |
Box | other ) |
Check if two boxes overlap Parameters ---------- other: The boxes to check for overlap Returns ------- result: True when the two boxes overlap.
Definition at line 302 of file bbox.py.
int lsst.scarlet.lite.bbox.Box.ndim | ( | self | ) |
tuple[tuple[slice, ...], tuple[slice, ...]] lsst.scarlet.lite.bbox.Box.overlapped_slices | ( | self, | |
Box | other ) |
Return `slice` for the box that contains the overlap of this and another `Box` Parameters ---------- other: Returns ------- slices: The slice of an array bounded by `self` and the slice of an array bounded by `other` in the overlapping region.
Definition at line 318 of file bbox.py.
Box lsst.scarlet.lite.bbox.Box.shifted_by | ( | self, | |
Sequence[int] | shift ) |
Generate a shifted copy of this box Parameters ---------- shift: The amount to shift each axis to create the new box Returns ------- result: The resulting bounding box.
Definition at line 286 of file bbox.py.
tuple[slice, ...] lsst.scarlet.lite.bbox.Box.slices | ( | self | ) |
Bounds of the box as slices
Definition at line 272 of file bbox.py.
tuple[int, ...] lsst.scarlet.lite.bbox.Box.start | ( | self | ) |
tuple[int, ...] lsst.scarlet.lite.bbox.Box.stop | ( | self | ) |