CentroidQuadratic#
- class photutils.centroids.CentroidQuadratic(*, fit_boxsize=5)[source]#
Bases:
objectClass to calculate the centroid of a 2D array by fitting a 2D quadratic polynomial.
This class provides a callable interface to the
centroid_quadraticfunction, allowing a centroid function with specific fit parameters to be defined and reused. This is useful, for example, when using a customized centroid function withcentroid_sources.- Parameters:
- fit_boxsizeint or tuple of int, optional
The size (in pixels) of the box used to define the fitting region. If
fit_boxsizehas two elements, they must be in(ny, nx)order. Iffit_boxsizeis a scalar then a square box of sizefit_boxsizewill be used.fit_boxsizemust 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
dataarray are automatically masked. The automatically masked values are combined (using bitwise OR) with the inputmask. Ifdatais aMaskedArray, its mask will also be combined (using bitwise OR) with the inputmask.- Parameters:
- data2D array_like
The 2D image data.
datacan be aMaskedArray. 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 aTruevalue indicates the corresponding element ofdatais masked. Ifdatais aMaskedArray, its mask will be combined (using bitwise OR) with the inputmask. Masked data are excluded from calculations.
- Returns:
- centroid
ndarray The
x, ycoordinates of the centroid.
- centroid
Notes
Unlike
centroid_1dgandcentroid_2dg, this method does not support an error array.