centroid_com#

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

Calculate the centroid of an n-dimensional array as its “center of mass” determined from image moments.

Non-finite values (e.g., NaN or inf) in the data array are automatically masked.

Parameters:
datandarray

The input n-dimensional array. The image should be a background-subtracted cutout image containing a single source.

maskbool ndarray, optional

A boolean mask, with the same shape as data, where a True value indicates the corresponding element of data is masked.

Returns:
centroidndarray

The coordinates of the centroid in pixel order (e.g., (x, y) or (x, y, z)), not numpy axis order.

Examples

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

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

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