centroid_2dg#

photutils.centroids.centroid_2dg(data, error=None, mask=None)[source]#

Calculate the centroid of a 2D array by fitting a 2D Gaussian to the array.

Non-finite values (e.g., NaN or inf) in the data or error arrays are automatically masked. The final mask is a logical OR combination of the input mask, the automatically generated mask for non-finite values, and the mask of the input data if it is a MaskedArray. The centroid is calculated using only the unmasked data values.

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.

error2D ndarray, optional

The 2D array of the 1-sigma errors of the input data.

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.

Returns:
centroidndarray

The x, y coordinates of the centroid.

Examples

>>> import numpy as np
>>> from photutils.datasets import make_4gaussians_image
>>> from photutils.centroids import centroid_2dg
>>> data = make_4gaussians_image()
>>> data -= np.median(data[0:30, 0:125])
>>> data = data[40:80, 70:110]
>>> x1, y1 = centroid_2dg(data)
>>> print(np.array((x1, y1)))
[19.9851944  20.01490157]

(Source code, png, hires.png, pdf, svg)

../_images/photutils-centroids-centroid_2dg-1.png