rectangular_overlap_grid#

photutils.geometry.rectangular_overlap_grid(xmin, xmax, ymin, ymax, nx, ny, width, height, theta, use_exact, subpixels)#

Calculate the fractional overlap between a rectangle and a pixel grid.

The rectangle is centered on the origin.

Parameters:
xmin, xmax, ymin, ymaxfloat

The extent of the grid in the x and y direction. The grid is defined by the rectangle with corners (xmin, ymin) and (xmax, ymax).

nx, nyint

The grid dimensions in the x and y direction. The grid is defined by the rectangle with corners (xmin, ymin) and (xmax, ymax) and is divided into nx and ny pixels in the x and y direction, respectively.

widthfloat

The full extent of the rectangle along its rotated x-axis (the direction given by theta).

heightfloat

The full extent of the rectangle perpendicular to width.

thetafloat

The rotation angle of the width side in radians, measured counterclockwise from the positive x-axis.

use_exact0 or 1

Set to 1 to use an exact method to calculate the overlap between the rectangle and each pixel. Set to 0 to use a subpixel sampling method to calculate the overlap, where each pixel is divided into subpixels ** 2 subpixels and the fraction of subpixels that are within the rectangle is used to estimate the overlap.

subpixelsint

The number of subpixels to use in each dimension when using the subpixel sampling method (use_exact=0). It must be at least 1 in that case. It is ignored when use_exact=1. Each pixel is resampled by this factor in each dimension, so each pixel is divided into subpixels ** 2 subpixels.

A subpixel is included only if its center lies strictly inside the rectangle. Subpixel centers lying exactly on the rectangle boundary are excluded (weight 0).

Returns:
resultndarray (float)

A 2D array of shape (ny, nx) giving the fraction of each pixel’s area that overlaps with the rectangle, ranging from 0 to 1. The element at index (j, i) corresponds to the pixel with corners at (xmin + i * dx, ymin + j * dy) and (xmin + (i + 1) * dx, ymin + (j + 1) * dy), where dx and dy are the width of each pixel in the x and y direction, respectively.

Raises:
ValueError

If use_exact is not 0 or 1, or if subpixels is less than 1 when use_exact=0.