|
LSST Applications g00d0e8bbd7+8c5ae1fdc5,g013ef56533+603670b062,g083dd6704c+2e189452a7,g199a45376c+0ba108daf9,g1c5cce2383+bc9f6103a4,g1fd858c14a+cd69ed4fc1,g210f2d0738+c4742f2e9e,g262e1987ae+612fa42d85,g29ae962dfc+83d129e820,g2cef7863aa+aef1011c0b,g35bb328faa+8c5ae1fdc5,g3fd5ace14f+5eaa884f2a,g47891489e3+e32160a944,g53246c7159+8c5ae1fdc5,g5b326b94bb+dcc56af22d,g64539dfbff+c4742f2e9e,g67b6fd64d1+e32160a944,g74acd417e5+c122e1277d,g786e29fd12+668abc6043,g87389fa792+8856018cbb,g88cb488625+47d24e4084,g89139ef638+e32160a944,g8d7436a09f+d14b4ff40a,g8ea07a8fe4+b212507b11,g90f42f885a+e1755607f3,g97be763408+34be90ab8c,g98df359435+ec1fa61bf1,ga2180abaac+8c5ae1fdc5,ga9e74d7ce9+43ac651df0,gbf99507273+8c5ae1fdc5,gc2a301910b+c4742f2e9e,gca7fc764a6+e32160a944,gd7ef33dd92+e32160a944,gdab6d2f7ff+c122e1277d,gdb1e2cdc75+1b18322db8,ge410e46f29+e32160a944,ge41e95a9f2+c4742f2e9e,geaed405ab2+0d91c11c6d,w.2025.44
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 = tuple(shape) | |
| origin = tuple(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 | ) |