gini#

photutils.morphology.gini(data, mask=None)[source]#

Calculate the Gini coefficient of an array.

The Gini coefficient of the distribution of absolute flux values is calculated using the prescription from Lotz et al. 2004 (Eq. 6) as:

\[G = \frac{1}{\overline{|x|} \, n \, (n - 1)} \sum_{i=1}^{n} (2i - n - 1) \left | x_i \right |\]

where the \(n\) pixel values \(x_i\) are sorted in order of increasing absolute value and \(\overline{|x|}\) is the mean of their absolute values. If all pixel values are zero, the Gini coefficient is zero.

The Gini coefficient is a way of measuring the inequality in a given set of values. In the context of galaxy morphology, it measures how the light of a galaxy image is distributed among its pixels. A Gini coefficient value of 0 corresponds to a galaxy image with the light evenly distributed over all pixels while a Gini coefficient value of 1 represents a galaxy image with all its light concentrated in just one pixel.

Measuring the Gini coefficient usually requires some preprocessing to define the galaxy region in the image, based on the quality of the input data. There is no general standard for doing this, so it is left to the user.

Negative pixel values are used via their absolute value. Invalid values (NaN and inf) in the input are automatically excluded from the calculation. If only a single finite pixel remains after filtering, the Gini coefficient is 0.0. If no finite, unmasked pixels remain, NaN is returned.

Parameters:
dataarray_like

The data array or object that can be converted to an array. The array may have any dimensionality (e.g., a 1D array or a 2D image), with its values treated as a flattened set. If data is a MaskedArray, its mask is combined with the input mask.

maskarray_like (bool), optional

A boolean mask with the same shape as data where True values indicate masked pixels. Masked pixels are excluded from the calculation.

Returns:
resultfloat

The Gini coefficient of the input array. NaN is returned if there are no finite, unmasked values.

Raises:
ValueError

If mask is provided and does not have the same shape as data.