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 and the box must contain at least 6 pixels. A size larger than data along an axis is reduced to the largest odd size that fits, with a warning. The value is validated when the instance is called.

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.

Nonfinite values (e.g., NaN or inf) in the data array are automatically masked. An AstropyUserWarning is emitted if any of them is not already 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 or a Quantity. 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.

See centroid_quadratic for the cases in which a warning is emitted and NaN values or the position of the maximum pixel are returned.