Box#
- class lsst.images.Box(y: Interval, x: Interval)#
Bases:
objectAn axis-aligned 2-d rectangular region.
Parameters#
- y
Interval for the y dimension.
- x
Interval for the x dimension.
Notes#
Boximplements the necessary hooks to be included directly in apydantic.BaseModel, even though it is neither a built-in type nor a Pydantic model itself.Attributes Summary
A factory for constructing a contained
Boxusing slice syntax and absolute coordinates.The box itself (
Box).A factory for creating boxes using slice syntax.
A factory for constructing a contained
Intervalusing a slice relative to the start of this one (BoxSliceFactory).Tuple holding the sizes of the intervals ordered
(y, x)(YX[int]).Tuple holding the starts of the intervals ordered
(y, x)(YX[int]).The x-dimension interval (
int).The y-dimension interval (
int).Methods Summary
boundary()Iterate over the corners of the box as
(y, x)tuples.contains()Test whether this box fully contains another or one or more points.
deserialize(serialized)Deserialize a bounds object on the assumption it is a
Box.dilated_by(padding)Return a new box padded by the given amount on all sides.
from_legacy(legacy)Convert from an
lsst.geom.Box2Iinstance.from_shape(shape[, start])Construct a box from its shape and optional start.
Return a bounds object that is contained by both
selfandother.meshgrid([n, step])Return a pair of 2-d arrays of the coordinate values of the box.
padded(padding)Return a new box expanded by the given padding on all sides.
Return a Pydantic-friendly representation of this object.
slice_within(other)Return a
tupleofsliceobjects that correspond to the positions in this box when the items of the container being sliced correspond toother.Convert to an
lsst.geom.BoxIinstance.Attributes Documentation
- absolute#
A factory for constructing a contained
Boxusing slice syntax and absolute coordinates.Notes#
Slice bounds that are absent are replaced with the bounds of
self.
- factory: ClassVar[BoxSliceFactory] = <lsst.images._geom.BoxSliceFactory object>#
A factory for creating boxes using slice syntax.
For example:
box = Box.factory[2:5, 3:9]
- local#
A factory for constructing a contained
Intervalusing a slice relative to the start of this one (BoxSliceFactory).Notes#
This factory interprets slices as “local” coordinates, in which
0corresponds toself.start. Negative bounds are relative toself.stop, as is usually the case for Python sequences.
- x#
The x-dimension interval (
int).
- y#
The y-dimension interval (
int).
Methods Documentation
- contains(other: Box, /) bool#
- contains(*, y: int, x: int) bool
- contains(*, y: ndarray, x: ndarray) ndarray
Test whether this box fully contains another or one or more points.
Parameters#
- other
Another box to compare to. Not compatible with the
yandxarguments.- y
One or more integer Y coordinates to test for containment. If an array, an array of results will be returned.
- x
One or more integer X coordinates to test for containment. If an array, an array of results will be returned.
Returns#
bool|numpy.ndarrayIf
otherwas passed orxandyare both scalars, a singleboolvalue. Ifxandyare arrays, a boolean array with their broadcasted shape.
Notes#
In order to yield the desired behavior for floating-point arguments, points are actually tested against an interval that is 0.5 larger on both sides: this makes positions within the outer boundary of pixels (but beyond the centers of those pixels, which have integer positions) appear “on the image”.
- classmethod deserialize(serialized: SerializableBounds) Box#
Deserialize a bounds object on the assumption it is a
Box.This method just returns the
Boxitself, since that already provides Pydantic serialization hooks. It exists for compatibility with theBoundsprotocol.
- classmethod from_legacy(legacy: Any) Box#
Convert from an
lsst.geom.Box2Iinstance.
- classmethod from_shape(shape: Sequence[int], start: Sequence[int] | None = None) Box#
Construct a box from its shape and optional start.
Parameters#
- intersection(other: Box) Box#
- intersection(other: Bounds) Bounds
Return a bounds object that is contained by both
selfandother.When there is no overlap,
NoOverlapErroris raised.
- meshgrid(n: int | Sequence[int] | None = None, *, step: float | None = None) XY[ndarray]#
Return a pair of 2-d arrays of the coordinate values of the box.
Parameters#
- n
Number of points in each dimension. If a sequence, points are assumed to be ordered
(x, y)unless aYXinstance is provided.- step
Set
nsuch that the distance between points is equal to or just less than this in each dimension. Mutually exclusive withn.
Returns#
XY[numpy.ndarray]A pair of arrays, each of which is 2-d with floating-point values.
See Also#
numpy.meshgrid
- serialize() Box#
Return a Pydantic-friendly representation of this object.
This method just returns the
Boxitself, since that already provides Pydantic serialization hooks. It exists for compatibility with theBoundsprotocol.
- slice_within(other: Box) YX[slice]#
Return a
tupleofsliceobjects that correspond to the positions in this box when the items of the container being sliced correspond toother.This assumes
other.contains(self).
- to_legacy() Any#
Convert to an
lsst.geom.BoxIinstance.