RadialProfile#
- class photutils.profiles.RadialProfile(data, xycen, radii, *, error=None, mask=None, method='exact', subpixels=5)[source]#
Bases:
ProfileBaseClass 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
CurveOfGrowthclass, where the input radii are the radii of the circular apertures used to compute the cumulative flux.The output
radiusattribute represents the bin centers.- Parameters:
- data2D
ndarrayorQuantity The 2D data array. The data should be background-subtracted. Nonfinite values (e.g., NaN or inf) in the
dataorerrorarray 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.
radiimust 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.radiimust be in pixels and cannot be aQuantity. The outputradiusattribute will be defined at the bin centers.- error2D
ndarrayorQuantity, optional The 1-sigma errors of the input
data.erroris assumed to include all sources of error, including the Poisson error of the sources (seecalc_total_error).errormust have the same shape as the inputdata. Ifdatais aQuantity, thenerrormust have the same units. Nonfinite values (e.g., NaN or inf) in thedataorerrorarray are automatically masked.- mask2D bool
ndarray, optional A boolean mask with the same shape as
datawhere aTruevalue indicates the corresponding element ofdatais 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 thesubpixelsparameter. 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 ofsubpixels**2subpixels to approximate the overlap. This parameter is ignored for other methods.
- data2D
- Raises:
- TypeError
If
radiiis aQuantity.- ValueError
If
datais not a 2D array, ifradiiis not a 1D array with at least two values, has a negative value, or is not strictly increasing, iferrorormaskdoes not have the same shape asdata, ifdataanderrordo not have the same units, or ifmethodorsubpixelsis invalid.
- Warns:
AstropyUserWarningIf the
dataorerrorarray contains nonfinite values that are not already masked bymask.
See also
Notes
If the minimum of
radiiis zero, then a circular aperture with radius equal toradii[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)
Normalize the profile and plot the normalized radial profile.
(
Source code,png,hires.png,pdf,svg)
Plot three of the annulus apertures on the data.
(
Source code,png,hires.png,pdf,svg)
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)
Attributes Summary
A list of the circular annulus apertures used to measure the radial profile, as
CircularAnnulusobjects.The unmasked area in each circular annulus (or aperture) as a function of radius as a 1D
ndarray.The raw data values of the pixels at
data_radiusas a 1Dndarray, or aQuantityif the inputdatahas units.The radial distances in pixels of the raw data points from the source center as a 1D
ndarray.The fitted 1D Gaussian to the radial profile as a
Gaussian1Dmodel.The full width at half maximum (FWHM) in pixels of the 1D Gaussian fitted to the radial profile.
The fitted 1D Gaussian profile to the radial profile as a 1D
ndarray, or aQuantityif the inputdatahas units.The fitted 1D Moffat to the radial profile as a
Moffat1Dmodel.The full width at half maximum (FWHM) in pixels of the 1D Moffat fitted to the radial profile.
The fitted 1D Moffat profile to the radial profile as a 1D
ndarray, or aQuantityif the inputdatahas units.The profile as a 1D
ndarray, or aQuantityif the inputdatahas units.The profile errors as a 1D
ndarray, or aQuantityif the inputdatahas units.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 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
CircularAnnulusobjects.If the minimum of
radiiis zero, then the innermost element will be aCircularAperturewith radius equal toradii[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_radiusas a 1Dndarray, or aQuantityif the inputdatahas units.The values reflect the current profile normalization. If
normalizehas been called, the raw data values are divided by the same normalization applied toprofile.
- 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
Gaussian1Dmodel.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
Noneif the profile is entirely nonfinite or masked.- Warns:
AstropyUserWarningIf 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
Noneif the profile is entirely nonfinite or masked.
- gaussian_profile#
The fitted 1D Gaussian profile to the radial profile as a 1D
ndarray, or aQuantityif the inputdatahas units.The values reflect the current profile normalization.
Returns
Noneif the profile is entirely nonfinite or masked.
- moffat_fit#
The fitted 1D Moffat to the radial profile as a
Moffat1Dmodel.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_0is fixed at zero (the source center) andalphais bounded to the range [1, 25].Returns
Noneif the profile is entirely nonfinite or masked.- Warns:
AstropyUserWarningIf 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
Noneif the profile is entirely nonfinite or masked.
- moffat_profile#
The fitted 1D Moffat profile to the radial profile as a 1D
ndarray, or aQuantityif the inputdatahas units.The values reflect the current profile normalization.
Returns
Noneif the profile is entirely nonfinite or masked.
- profile#
The profile as a 1D
ndarray, or aQuantityif the inputdatahas units.The returned values reflect the current profile normalization (see
normalize). A normalized profile of data with units is a dimensionlessQuantity.
- profile_error#
The profile errors as a 1D
ndarray, or aQuantityif the inputdatahas units.The returned values reflect the current profile normalization (see
normalize). If noerrorarray 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
methodis not'max'or'sum'.
- Warns:
AstropyUserWarningIf 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:
- ax
matplotlib.axes.AxesorNone, optional The matplotlib axes on which to plot. If
None, then the currentAxesinstance is used.- **kwargsdict, optional
Any keyword arguments accepted by
matplotlib.pyplot.plot.
- ax
- Returns:
- lineslist of
Line2D A list of lines representing the plotted data.
- lineslist of
- plot_error(ax=None, **kwargs)#
Plot the profile errors.
- Parameters:
- ax
matplotlib.axes.AxesorNone, optional The matplotlib axes on which to plot. If
None, then the currentAxesinstance is used.- **kwargsdict, optional
Any keyword arguments accepted by
matplotlib.pyplot.fill_between. Iffacecoloris not given, a semi-transparent gray is used.
- ax
- Returns:
- poly
matplotlib.collections.PolyCollectionorNone A
PolyCollectioncontaining the plotted polygons, orNoneif no errors were input.
- poly
- Warns:
AstropyUserWarningIf no errors were input. In that case, nothing is plotted and
Noneis returned.