Morphological Properties (photutils.morphology)


The data_properties() function can be used to calculate the morphological properties of a single source in a cutout image. data_properties returns a SourceProperties object. Please see SourceProperties for the list of the many properties that are calculated. Even more properties are likely to be added in the future.

If you have a segmentation image, the source_properties() function can be used to calculate the properties for all (or a specified subset) of the segmented sources. Please see Source Photometry and Properties from Image Segmentation for more details.

Getting Started

Let’s extract a single object from a synthetic dataset and find calculate its morphological properties. For this example, we will subtract the background using simple sigma-clipped statistics.

First, we create the source image and subtract its background:

>>> from photutils.datasets import make_4gaussians_image
>>> from astropy.stats import sigma_clipped_stats
>>> data = make_4gaussians_image()[43:79, 76:104]
>>> mean, median, std = sigma_clipped_stats(data, sigma=3.0, iters=5)
>>> data -= median    # subtract background

Then, calculate its properties:

>>> from photutils import data_properties, properties_table
>>> props = data_properties(data)
>>> columns = ['id', 'xcentroid', 'ycentroid', 'semimajor_axis_sigma',
...            'semiminor_axis_sigma', 'orientation']
>>> tbl = properties_table(props, columns=columns)
>>> print(tbl)
 id   xcentroid     ycentroid   ... semiminor_axis_sigma  orientation
         pix           pix      ...         pix               rad
--- ------------- ------------- ... -------------------- -------------
  1 14.0225090502 16.9901801466 ...        3.69777618702 1.04943689372

Now let’s use the measured morphological properties to define an approximate isophotal ellipse for the source:

>>> from photutils import properties_table, EllipticalAperture
>>> position = (props.xcentroid.value, props.ycentroid.value)
>>> r = 3.0    # approximate isophotal extent
>>> a = props.semimajor_axis_sigma.value * r
>>> b = props.semiminor_axis_sigma.value * r
>>> theta = props.orientation.value
>>> apertures = EllipticalAperture(position, a, b, theta=theta)
>>> plt.imshow(data, origin='lower', cmap='viridis',
...            interpolation='nearest')
>>> apertures.plot(color='#d62728')

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



This subpackage contains tools for measuring morphological properties of objects in an astronomical image.


data_properties(data[, mask, background]) Calculate the morphological properties (and centroid) of a 2D array (e.g.
gini(data) Calculate the Gini coefficient of a 2D array.