RadialProfile#

class photutils.profiles.RadialProfile(data, xycen, radii, *, error=None, mask=None, method='exact', subpixels=5)[source]#

Bases: ProfileBase

Class to create a radial profile using concentric circular annulus apertures.

The radial profile represents the azimuthally-averaged flux in circular annulus apertures as a function of radius.

For this class, the input radii represent the edges of the radial bins. This differs from the CurveOfGrowth class, where the input radii are the radii of the circular apertures used to compute the cumulative flux.

The output radius attribute represents the bin centers.

Parameters:
data2D ndarray or Quantity

The 2D data array. The data should be background-subtracted. Nonfinite values (e.g., NaN or inf) in the data or error array are automatically masked.

xycentuple of 2 floats

The (x, y) pixel coordinate of the source center.

radii1D array_like of float

An array of radii defining the edges of the radial bins. radii must be strictly increasing with a minimum value greater than or equal to zero, and contain at least 2 values. The radial spacing does not need to be constant. radii must be in pixels and cannot be a Quantity. The output radius attribute will be defined at the bin centers.

error2D ndarray or Quantity, optional

The 1-sigma errors of the input data. error is assumed to include all sources of error, including the Poisson error of the sources (see calc_total_error). error must have the same shape as the input data. If data is a Quantity, then error must have the same units. Nonfinite values (e.g., NaN or inf) in the data or error array are automatically masked.

mask2D bool ndarray, optional

A boolean mask with the same shape as data where a True value indicates the corresponding element of data is masked. Masked data are excluded from all calculations.

method{‘exact’, ‘center’, ‘subpixel’}, optional

The method used to determine the pixel weights (the fraction of the pixel area covered by the aperture):

  • 'exact' (default): Calculates the exact geometric overlap area. Weights are continuous in the range [0, 1].

  • 'center': Binary weighting based on the pixel center. Weights are either 0 or 1. A pixel is included only if its center lies strictly inside the aperture. Pixel centers lying exactly on the outer aperture boundary are excluded (weight 0). For an annulus, pixel centers lying exactly on the inner boundary are included (weight 1).

  • 'subpixel': Approximates the overlap by averaging binary samples on a subgrid. The number of samples is set by the subpixels parameter. Weights are discrete in the range [0, 1]. A subpixel is included only if its center lies strictly inside the aperture. Subpixel centers lying exactly on the outer aperture boundary are excluded (weight 0). For an annulus, subpixel centers lying exactly on the inner boundary are included.

subpixelsint, optional

The subsampling factor per axis used with the 'subpixel' method. Each pixel is divided into a grid of subpixels**2 subpixels to approximate the overlap. This parameter is ignored for other methods.

Raises:
TypeError

If radii is a Quantity.

ValueError

If data is not a 2D array, if radii is not a 1D array with at least two values, has a negative value, or is not strictly increasing, if error or mask does not have the same shape as data, if data and error do not have the same units, or if method or subpixels is invalid.

Warns:
AstropyUserWarning

If the data or error array contains nonfinite values that are not already masked by mask.

See also

CurveOfGrowth

Notes

If the minimum of radii is zero, then a circular aperture with radius equal to radii[1] will be used for the innermost aperture.

A radial bin whose pixels are all masked has zero unmasked area, and its profile and profile error values are NaN.

Examples

>>> import numpy as np
>>> from astropy.modeling.models import Gaussian2D
>>> from photutils.centroids import centroid_2dg
>>> from photutils.datasets import make_noise_image
>>> from photutils.profiles import RadialProfile

Create an artificial single source. Note that this image does not have any background.

>>> gmodel = Gaussian2D(42.1, 47.8, 52.4, 4.7, 4.7, 0)
>>> yy, xx = np.mgrid[0:100, 0:100]
>>> data = gmodel(xx, yy)
>>> bkg_sig = 2.1
>>> noise = make_noise_image(data.shape, mean=0., stddev=bkg_sig, seed=0)
>>> data += noise
>>> error = np.zeros_like(data) + bkg_sig

Create the radial profile.

>>> xycen = centroid_2dg(data)
>>> edge_radii = np.arange(25)
>>> rp = RadialProfile(data, xycen, edge_radii, error=error)
>>> print(rp.radius)
[ 0.5  1.5  2.5  3.5  4.5  5.5  6.5  7.5  8.5  9.5 10.5 11.5 12.5 13.5
 14.5 15.5 16.5 17.5 18.5 19.5 20.5 21.5 22.5 23.5]
>>> print(rp.profile)
[ 4.30187860e+01  4.02502046e+01  3.57758011e+01  3.16071235e+01
  2.61511082e+01  2.10539746e+01  1.63701300e+01  1.16674718e+01
  8.12828014e+00  5.78962699e+00  3.59342666e+00  2.35353336e+00
  1.20355937e+00  7.67093923e-01  4.24650784e-01  8.67989701e-02
  5.11484374e-02 -9.82041768e-02  2.37482124e-02 -3.66602855e-02
  6.84802299e-02  1.72239596e-01 -3.86056497e-02  7.30423743e-02]
>>> print(rp.profile_error)
[0.9901437  0.64531698 0.51234751 0.43720335 0.38782635 0.35176132
 0.32440232 0.3025968  0.28456077 0.26947982 0.25644723 0.24531375
 0.23540592 0.2266079  0.21875692 0.21164247 0.20525699 0.19930521
 0.19389598 0.18892207 0.18429087 0.1800127  0.17593986 0.17221504]

Plot the radial profile, including the raw data profile.

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

../_images/photutils-profiles-RadialProfile-1.png

Normalize the profile and plot the normalized radial profile.

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

../_images/photutils-profiles-RadialProfile-2.png

Plot three of the annulus apertures on the data.

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

../_images/photutils-profiles-RadialProfile-3.png

Fit 1D Gaussian and Moffat models to the normalized radial profile.

>>> rp.normalize()
>>> rp.gaussian_fit
<Gaussian1D(amplitude=0.98231087, mean=0., stddev=4.67512787)>
>>> rp.moffat_fit
<Moffat1D(amplitude=..., x_0=0., gamma=..., alpha=...)>
>>> print(rp.gaussian_fwhm)
11.009084813327853
>>> print(rp.moffat_fwhm)
10.868426520785151

Plot the fitted 1D Gaussian and Moffat models on the radial profile.

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

../_images/photutils-profiles-RadialProfile-4.png

Attributes Summary

apertures

A list of the circular annulus apertures used to measure the radial profile, as CircularAnnulus objects.

area

The unmasked area in each circular annulus (or aperture) as a function of radius as a 1D ndarray.

data_profile

The raw data values of the pixels at data_radius as a 1D ndarray, or a Quantity if the input data has units.

data_radius

The radial distances in pixels of the raw data points from the source center as a 1D ndarray.

gaussian_fit

The fitted 1D Gaussian to the radial profile as a Gaussian1D model.

gaussian_fwhm

The full width at half maximum (FWHM) in pixels of the 1D Gaussian fitted to the radial profile.

gaussian_profile

The fitted 1D Gaussian profile to the radial profile as a 1D ndarray, or a Quantity if the input data has units.

moffat_fit

The fitted 1D Moffat to the radial profile as a Moffat1D model.

moffat_fwhm

The full width at half maximum (FWHM) in pixels of the 1D Moffat fitted to the radial profile.

moffat_profile

The fitted 1D Moffat profile to the radial profile as a 1D ndarray, or a Quantity if the input data has units.

profile

The profile as a 1D ndarray, or a Quantity if the input data has units.

profile_error

The profile errors as a 1D ndarray, or a Quantity if the input data has units.

radius

The profile radius (bin centers) in pixels as a 1D ndarray.

Methods Summary

normalize([method])

Normalize the profile.

plot([ax])

Plot the profile.

plot_error([ax])

Plot the profile errors.

unnormalize()

Unnormalize the profile back to the original state before any calls to normalize.

Attributes Documentation

apertures[source]#

A list of the circular annulus apertures used to measure the radial profile, as CircularAnnulus objects.

If the minimum of radii is zero, then the innermost element will be a CircularAperture with radius equal to radii[1].

area[source]#

The unmasked area in each circular annulus (or aperture) as a function of radius as a 1D ndarray.

data_profile#

The raw data values of the pixels at data_radius as a 1D ndarray, or a Quantity if the input data has units.

The values reflect the current profile normalization. If normalize has been called, the raw data values are divided by the same normalization applied to profile.

data_radius[source]#

The radial distances in pixels of the raw data points from the source center as a 1D ndarray.

All unmasked pixels whose centers lie between the minimum and maximum of the input radii, inclusive, are included.

gaussian_fit#

The fitted 1D Gaussian to the radial profile as a Gaussian1D model.

The model amplitude reflects the current profile normalization (the Gaussian amplitude scales linearly with the profile values). The mean and standard deviation are independent of the normalization.

The fit uses only the finite profile values, and the Gaussian mean is fixed at zero (the source center).

Returns None if the profile is entirely nonfinite or masked.

Warns:
AstropyUserWarning

If the profile is entirely nonfinite or masked, if the sum of the profile is zero, or if the smallest bin center with a finite profile value is larger than 0.3 times the fitted standard deviation (e.g., the input radii do not extend close to the source center or the inner bins are masked). The fitter can also emit its own warning if the fit may not have converged.

gaussian_fwhm#

The full width at half maximum (FWHM) in pixels of the 1D Gaussian fitted to the radial profile.

The FWHM is independent of the profile normalization.

Returns None if the profile is entirely nonfinite or masked.

gaussian_profile#

The fitted 1D Gaussian profile to the radial profile as a 1D ndarray, or a Quantity if the input data has units.

The values reflect the current profile normalization.

Returns None if the profile is entirely nonfinite or masked.

moffat_fit#

The fitted 1D Moffat to the radial profile as a Moffat1D model.

The model amplitude reflects the current profile normalization (the Moffat amplitude scales linearly with the profile values). The core width and power index are independent of the normalization.

The fit uses only the finite profile values. The Moffat x_0 is fixed at zero (the source center) and alpha is bounded to the range [1, 25].

Returns None if the profile is entirely nonfinite or masked.

Warns:
AstropyUserWarning

If the profile is entirely nonfinite or masked, or if the sum of the profile is zero. The fitter can also emit its own warning if the fit may not have converged.

moffat_fwhm#

The full width at half maximum (FWHM) in pixels of the 1D Moffat fitted to the radial profile.

The FWHM is independent of the profile normalization.

Returns None if the profile is entirely nonfinite or masked.

moffat_profile#

The fitted 1D Moffat profile to the radial profile as a 1D ndarray, or a Quantity if the input data has units.

The values reflect the current profile normalization.

Returns None if the profile is entirely nonfinite or masked.

profile#

The profile as a 1D ndarray, or a Quantity if the input data has units.

The returned values reflect the current profile normalization (see normalize). A normalized profile of data with units is a dimensionless Quantity.

profile_error#

The profile errors as a 1D ndarray, or a Quantity if the input data has units.

The returned values reflect the current profile normalization (see normalize). If no error array was provided, an empty array with shape (0,) is returned.

radius[source]#

The profile radius (bin centers) in pixels as a 1D ndarray.

The returned radius values are defined as the arithmetic means of the input radial-bin edges (radii).

For logarithmically-spaced input radii, one could instead use a radius array defined using the geometric mean of the bin edges, i.e., np.sqrt(radii[:-1] * radii[1:]).

Methods Documentation

normalize(method='max')#

Normalize the profile.

The profile errors (profile_error) are divided by the same normalization value as the profile.

The normalization is computed from the raw (unnormalized) profile values, so repeated calls do not accumulate. The most recent call determines the normalization. Because both normalization methods scale linearly with the profile values, this is equivalent to normalizing an already-normalized profile. NaN values in the profile are ignored when computing the maximum or sum.

Parameters:
method{‘max’, ‘sum’}, optional

The method used to normalize the profile:

  • 'max' (default): The profile is normalized such that its maximum value is 1.

  • 'sum': The profile is normalized such that the sum of its values is 1.

Raises:
ValueError

If method is not 'max' or 'sum'.

Warns:
AstropyUserWarning

If the maximum or sum of the profile is not positive or is nonfinite. In that case, the current normalization is left unchanged.

plot(ax=None, **kwargs)#

Plot the profile.

Parameters:
axmatplotlib.axes.Axes or None, optional

The matplotlib axes on which to plot. If None, then the current Axes instance is used.

**kwargsdict, optional

Any keyword arguments accepted by matplotlib.pyplot.plot.

Returns:
lineslist of Line2D

A list of lines representing the plotted data.

plot_error(ax=None, **kwargs)#

Plot the profile errors.

Parameters:
axmatplotlib.axes.Axes or None, optional

The matplotlib axes on which to plot. If None, then the current Axes instance is used.

**kwargsdict, optional

Any keyword arguments accepted by matplotlib.pyplot.fill_between. If facecolor is not given, a semi-transparent gray is used.

Returns:
polymatplotlib.collections.PolyCollection or None

A PolyCollection containing the plotted polygons, or None if no errors were input.

Warns:
AstropyUserWarning

If no errors were input. In that case, nothing is plotted and None is returned.

unnormalize()#

Unnormalize the profile back to the original state before any calls to normalize.