CentroidQuadratic#

class photutils.centroids.CentroidQuadratic(*, fit_boxsize=5)[source]#

Bases: object

Class to calculate the centroid of a 2D array by fitting a 2D quadratic polynomial.

This class provides a callable interface to the centroid_quadratic function, allowing a centroid function with specific fit parameters to be defined and reused. This is useful, for example, when using a customized centroid function with centroid_sources.

Parameters:
fit_boxsizeint or tuple of int, optional

The size (in pixels) of the box used to define the fitting region. If fit_boxsize has two elements, they must be in (ny, nx) order. If fit_boxsize is a scalar then a square box of size fit_boxsize will be used. fit_boxsize must have odd values for both axes.

Examples

>>> import numpy as np
>>> from photutils.datasets import make_4gaussians_image
>>> from photutils.centroids import CentroidQuadratic
>>> data = make_4gaussians_image()
>>> data -= np.median(data[0:30, 0:125])
>>> data = data[40:80, 70:110]
>>> centroid_func = CentroidQuadratic(fit_boxsize=5)
>>> x1, y1 = centroid_func(data)
>>> print(np.array((x1, y1)))
[19.94009505 20.06884997]

Using with centroid_sources:

>>> from photutils.centroids import centroid_sources
>>> data = make_4gaussians_image()
>>> data -= np.median(data[0:30, 0:125])
>>> x_init = (25, 91, 151, 160)
>>> y_init = (40, 61, 24, 71)
>>> centroid_func = CentroidQuadratic(fit_boxsize=3)
>>> x, y = centroid_sources(data, x_init, y_init, box_size=25,
...                         centroid_func=centroid_func)

Methods Summary

__call__(data, *[, mask])

Calculate the centroid.

Methods Documentation

__call__(data, *, mask=None)[source]#

Calculate the centroid.

Non-finite values (e.g., NaN or inf) in the data array are automatically masked. The automatically masked values are combined (using bitwise OR) with the input mask. If data is a MaskedArray, its mask will also be combined (using bitwise OR) with the input mask.

Parameters:
data2D array_like

The 2D image data. data can be a MaskedArray. The image should be a background-subtracted cutout image containing a single source.

mask2D bool ndarray, optional

A boolean mask, with the same shape as data, where a True value indicates the corresponding element of data is masked. If data is a MaskedArray, its mask will be combined (using bitwise OR) with the input mask. Masked data are excluded from calculations.

Returns:
centroidndarray

The x, y coordinates of the centroid.

Notes

Unlike centroid_1dg and centroid_2dg, this method does not support an error array.