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
dataorerrorarrays are automatically masked. The final mask is a logical OR combination of the inputmask, the automatically generated mask for non-finite values, and the mask of the inputdataif it is aMaskedArray. The centroid is calculated using only the unmasked data values.- Parameters:
- data2D array_like
The 2D image data.
datacan be aMaskedArray. 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 aTruevalue indicates the corresponding element ofdatais masked. Ifdatais aMaskedArray, its mask will be combined (using bitwise OR) with the inputmask.
- Returns:
- centroid
ndarray The
x, ycoordinates of the centroid.
- 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)