Bounding boxes
- class galsim.Bounds[source]
A class for representing image bounds as 2D rectangles.
Bounds is a base class for two slightly different kinds of bounds:
BoundsDdescribes bounds with floating point values in x and y.BoundsIdescribed bounds with integer values in x and y.The bounds are stored as four numbers in each instance, (xmin, xmax, ymin, ymax), with an additional boolean switch to say whether or not the Bounds rectangle has been defined. The rectangle is undefined if the min value > the max value in either direction.
Initialization:
A
BoundsIorBoundsDinstance can be initialized in a variety of ways. The most direct is via four scalars:>>> bounds = galsim.BoundsD(xmin, xmax, ymin, ymax) >>> bounds = galsim.BoundsI(imin, imax, jmin, jmax)
In the
BoundsIexample above,imin,imax,jminandjmaxmust all be integers to avoid a TypeError exception.Another way to initialize a
Boundsinstance is using twoPositioninstances, the first for(xmin,ymin)and the second for(xmax,ymax):>>> bounds = galsim.BoundsD(galsim.PositionD(xmin, ymin), galsim.PositionD(xmax, ymax)) >>> bounds = galsim.BoundsI(galsim.PositionI(imin, jmin), galsim.PositionI(imax, jmax))
In both the examples above, the I/D type of
PositionI/PositionDmust match that ofBoundsI/BoundsD.Finally, there are a two ways to lazily initialize a bounds instance with
xmin = xmax,ymin = ymax, which will have an undefined rectangle and the instance method isDefined() will return False. The first setsxmin = xmax = ymin = ymax = 0:>>> bounds = galsim.BoundsD() >>> bounds = galsim.BoundsI()
The second method sets both upper and lower rectangle bounds to be equal to some position:
>>> bounds = galsim.BoundsD(galsim.PositionD(xmin, ymin)) >>> bounds = galsim.BoundsI(galsim.PositionI(imin, jmin))
Once again, the I/D type of
PositionI/PositionDmust match that ofBoundsI/BoundsD.For the latter two initializations, you would typically then add to the bounds with:
>>> bounds += pos1 >>> bounds += pos2 >>> [etc.]
Then the bounds will end up as the bounding box of all the positions that were added to it.
You can also find the intersection of two bounds with the & operator:
>>> overlap = bounds1 & bounds2
This is useful for adding one image to another when part of the first image might fall off the edge of the other image:
>>> overlap = stamp.bounds & image.bounds >>> image[overlap] += stamp[overlap]
- area()[source]
Return the area of the enclosed region.
The area is a bit different for integer-type
BoundsIand float-typeBoundsDinstances. For floating point types, it is simply(xmax-xmin)*(ymax-ymin). However, for integer types, we add 1 to each size to correctly count the number of pixels being described by the bounding box.
- property center
The central position of the
Bounds.For a
BoundsI, this will return an integerPositionI, which will be above and/or to the right of the true center if the x or y ranges have an even number of pixels.For a
BoundsD, this is equivalent to true_center.
- expand(factor_x, factor_y=None)[source]
Grow the
Boundsby the supplied factor about the center.If two arguments are given, then these are separate x and y factors to expand by.
- includes(*args)[source]
Test whether a supplied
(x,y)pair,Position, orBoundslie within a definedBoundsrectangle of this instance.Examples:
>>> bounds = galsim.BoundsD(0., 100., 0., 100.) >>> bounds.includes(50., 50.) True >>> bounds.includes(galsim.PositionD(50., 50.)) True >>> bounds.includes(galsim.BoundsD(-50., -50., 150., 150.)) False
The type of the
PositionI/PositionDandBoundsI/BoundsDinstances (i.e. integer or float type) should match that of the bounds instance.
- shift(delta)[source]
Shift the
Boundsinstance by a suppliedPosition.Examples:
The shift method takes either a
PositionIorPositionDinstance, which must match the type of theBoundsinstance:>>> bounds = BoundsI(1,32,1,32) >>> bounds = bounds.shift(galsim.PositionI(3, 2)) >>> bounds = BoundsD(0, 37.4, 0, 49.9) >>> bounds = bounds.shift(galsim.PositionD(3.9, 2.1))
- class galsim.BoundsI(*args, **kwargs)[source]
Bases:
BoundsA
Boundsthat takes only integer values.Typically used to define the bounding box of an image.
See the
Boundsdoc string for more details.
- class galsim.BoundsD(*args, **kwargs)[source]
Bases:
BoundsA
Boundsthat takes floating point values.See the
Boundsdoc string for more details.