Box#
- class lsst.images.Box(y, x)#
Bases:
objectAn axis-aligned 2-d rectangular region.
Boxes should generally be constructed by a classmethod factory (e.g.
from_shape,from_float_bounds,from_sky_circle) or thefactoryslicing proxy:box = Box.factory[y_a:y_b, x_a:x_b]
unless the
yandxintervals are already available.- Parameters:
- Raises:
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 number of pixels in the box (
int).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).The inclusive maximum bounds of the box, ordered
(y, x)(YX[int]).The inclusive minimum bounds of the box, ordered
(y, x)(YX[int]).Tuple holding the sizes of the intervals, ordered
(y, x)(YX[int]).Tuple holding the inclusive
Interval.startbvound, ordered(y, x)(YX[int]).Tuple holding the exclusive
Interval.stopbound, 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([other, y, x])Test whether this box fully contains another or one or more points.
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_float_bounds(*, x_min, x_max, y_min, y_max)Construct a box from floating-point bounds ensuring that all the are contained in the new box.
from_legacy(legacy)Convert from an
lsst.geom.Box2Iinstance.from_shape(shape[, start])Construct a box from its shape and optional start.
from_sky_circle(sky_projection, center, radius)Calculate a bounding box from a sky projection and a circular sky region.
intersection(other)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.Convert the box to a polygon with floating-point vertices.
transform(transform)Apply a coordinate transform to the box, returning a polygon.
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.
- start#
Tuple holding the inclusive
Interval.startbvound, ordered(y, x)(YX[int]).This is an alias for
min, typically paired withstopfor half-exclusive ranges.
- stop#
Tuple holding the exclusive
Interval.stopbound, ordered(y, x)(YX[int]).The values in this tuple are one greater than those in
max. It is typically paired withstartfor half-exclusive ranges.
Methods Documentation
- boundary()#
Iterate over the corners of the box as
(y, x)tuples.
- contains(other=None, /, *, y=None, x=None)#
Test whether this box fully contains another or one or more points.
- Parameters:
other (
Union[Box,XY[Any],YX[Any],None], default:None) – Another box, or anXYorYXcoordinate pair, to compare to. Mutually exclusive withxandy.y (
Any, default:None) – One or more Y coordinates to test for containment, as a scalar or any array-like. Results are broadcast againstx. Mutually exclusive withother.x (
Any, default:None) – One or more X coordinates to test for containment, as a scalar or any array-like. Results are broadcast againsty. Mutually exclusive withother.
- Returns:
If
otherwas passed orxandyare both scalars, a singleboolvalue. Ifxandyare array-like, a boolean array with their broadcasted shape.- Return type:
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”.
- deserialize()#
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.- Return type:
- dilated_by(padding)#
Return a new box padded by the given amount on all sides.
- classmethod from_float_bounds(*, x_min, x_max, y_min, y_max)#
Construct a box from floating-point bounds ensuring that all the are contained in the new box.
- Parameters:
- Return type:
Notes
Uses the same rounding convention as
lsst.images.Region.bbox, so that pixels whose centers lie within the bounds are included.
- classmethod from_legacy(legacy)#
Convert from an
lsst.geom.Box2Iinstance.- Parameters:
legacy (
Any) – Legacylsst.geom.Box2Ito convert.- Return type:
- classmethod from_shape(shape, start=None)#
Construct a box from its shape and optional start.
- classmethod from_sky_circle(sky_projection, center, radius)#
Calculate a bounding box from a sky projection and a circular sky region.
- Parameters:
sky_projection (
SkyProjection) – The sky projection mapping pixels to sky.center (
SkyCoord) – The center of the circle, as a scalarastropy.coordinates.SkyCoordin any frame.radius (
Angle) – Radius of the circle, as a scalarastropy.coordinates.Angle.
- Returns:
Bounding box enclosing the circle based on the sky projection.
- Return type:
- Raises:
ValueError – Raised if
centerorradiusis not scalar, or if this image has no sky projection.
- intersection(other)#
Return a bounds object that is contained by both
selfandother.When there is no overlap,
NoOverlapErroris raised.
- meshgrid(n=None, *, step=None)#
Return a pair of 2-d arrays of the coordinate values of the box.
- Parameters:
n (
int|Sequence[int] |None, default:None) – Number of points in each dimension. If a sequence, points are assumed to be ordered(x, y)unless aYXinstance is provided.step (
float|None, default:None) – Setnsuch that the distance between points is equal to or just less than this in each dimension. Mutually exclusive withn.
- Returns:
A pair of arrays, each of which is 2-d with floating-point values.
- Return type:
See also
- padded(padding)#
Return a new box expanded by the given padding on all sides.
- serialize()#
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.- Return type:
- slice_within(other)#
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()#
Convert to an
lsst.geom.BoxIinstance.- Return type:
- to_polygon()#
Convert the box to a polygon with floating-point vertices.
- Return type:
Notes
Because the integer min and max coordinates of a box are interpreted as pixel centers, these are expanded by 0.5 on all sides before using them to form the polygon vertices.
- transform(transform)#
Apply a coordinate transform to the box, returning a polygon.
- Parameters:
transform (
Transform[Any,Any]) – Coordinate transform to apply (in the forward direction).- Return type:
Notes
This transforms the polygon representation of the box (see
to_polygon), which expands its vertices by 0.5 on all sides to cover full pixels before transforming them.