centroid_1dg#
- photutils.centroids.centroid_1dg(data, error=None, mask=None)[source]#
Calculate the centroid of a 2D array by fitting 1D Gaussians to the marginal
x
andy
distributions of 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_1dg >>> data = make_4gaussians_image() >>> data -= np.median(data[0:30, 0:125]) >>> data = data[40:80, 70:110] >>> x1, y1 = centroid_1dg(data) >>> print(np.array((x1, y1))) [19.96553246 20.04952841]
(
Source code
,png
,hires.png
,pdf
,svg
)