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
orerror
arrays are automatically masked. These masks are combined.- Parameters:
- data2D
ndarray
The 2D image data. 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 aTrue
value indicates the corresponding element ofdata
is masked.
- data2D
- Returns:
- centroid
ndarray
The
x, y
coordinates 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.98519436 20.0149016 ]
(
Source code
,png
,hires.png
,pdf
,svg
)