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 width of the rectangle.

heightfloat

The height of the rectangle.

thetafloat

The position angle of the rectangle in radians (counterclockwise).

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 sub-pixel 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 sub-pixel sampling method. Each pixel is resampled by this factor in each dimension; thus, each pixel is divided into subpixels ** 2 subpixels.

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.