CurveOfGrowth#
- class photutils.profiles.CurveOfGrowth(data, xycen, radii, *, error=None, mask=None, method='exact', subpixels=5)[source]#
Bases:
ProfileBaseClass to create a curve of growth using concentric circular apertures.
The curve of growth profile represents the circular aperture flux as a function of circular radius.
- 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 the circular radii.
radiimust be strictly increasing with a minimum value greater than zero, and contain at least 2 values. The radial spacing does not need to be constant.radiimust be in pixels and cannot be aQuantity.- 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 value less than or equal to zero, 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.
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 CurveOfGrowth
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 curve of growth.
>>> xycen = centroid_2dg(data) >>> radii = np.arange(1, 26) >>> cog = CurveOfGrowth(data, xycen, radii, error=error)
>>> print(cog.radius) [ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25]
>>> print(cog.profile) [ 135.14750208 514.49674293 1076.4617132 1771.53866121 2510.94382666 3238.51695898 3907.08459943 4456.90125492 4891.00892262 5236.59326527 5473.66400376 5643.72239573 5738.24972738 5803.31693644 5842.00525018 5850.45854739 5855.76123671 5844.9631235 5847.72359025 5843.23189459 5852.05251106 5875.32009699 5869.86235184 5880.64741302 5872.16333953]
>>> print(cog.profile_error) [ 3.11062819 6.83127792 10.55630757 14.27852358 18.00330858 21.72296997 25.44442261 29.16767174 32.88949473 36.61224389 40.33235754 44.0555786 47.77789677 51.49947445 55.22141896 58.94275538 62.66630873 66.38766913 70.10917057 73.83146673 77.55360137 81.27674225 84.99747377 88.71963388 92.44198203]
Plot the curve of growth.
(
Source code,png,hires.png,pdf,svg)
Normalize the profile and plot the normalized curve of growth.
(
Source code,png,hires.png,pdf,svg)
Plot three of the apertures on the data.
(
Source code,png,hires.png,pdf,svg)
Attributes Summary
A list of
CircularApertureobjects used to measure the profile.The unmasked area within each aperture as a 1D
ndarray.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 in pixels as a 1D
ndarray.Methods Summary
calc_ee_at_radius(radius)Calculate the encircled energy at a given radius using a cubic interpolator based on the profile data.
Calculate the radius at a given encircled energy using a cubic interpolator based on the profile data.
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
CircularApertureobjects used to measure the profile.
- 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 in pixels as a 1D
ndarray.This is the same as the input
radii.Note that these are the radii of the circular apertures used to measure the profile. Thus, they are the radial values that enclose the given flux. They can be used directly to measure the encircled energy/flux at a given radius.
Methods Documentation
- calc_ee_at_radius(radius)[source]#
Calculate the encircled energy at a given radius using a cubic interpolator based on the profile data.
Note that this method assumes that the input data have been normalized such that the total enclosed flux is 1 for an infinitely large radius. You can also use the
normalizemethod before calling this method to normalize the profile such that its maximum value is 1. For noisy data, the maximum may not occur at the largest inputradii.The interpolated curve passes through the measured profile values. For a noisy profile, the curve can therefore decrease with radius where the enclosed flux has leveled off.
- Parameters:
- radiusfloat or array_like
The circular radius/radii in pixels. It cannot be a
Quantity.
- Returns:
- Raises:
- TypeError
If
radiusis aQuantity.
See also
- calc_radius_at_ee(ee)[source]#
Calculate the radius at a given encircled energy using a cubic interpolator based on the profile data.
Note that this method assumes that the input data have been normalized such that the total enclosed flux is 1 for an infinitely large radius. You can also use the
normalizemethod before calling this method to normalize the profile such that its maximum value is 1. For noisy data, the maximum may not occur at the largest inputradii.This method returns the smallest radius at which the curve interpolated by
calc_ee_at_radiusreaches the encircled energy. Converting the result back withcalc_ee_at_radiusreturns the input encircled energy. For a noisy profile, the curve can reach the same encircled energy again at a larger radius.Where a noisy profile has leveled off, the radius of a given encircled energy is poorly constrained, and the maximum used by
normalizeis biased high by the noise. If you need the radius at a large encircled energy (e.g., 0.95 or more), use a profile with a high signal-to-noise ratio, or divide the inputdataby a known total flux instead of callingnormalize.- Parameters:
- Returns:
- radius
ndarray The radius in pixels at each encircled energy. Returns NaN for encircled energies outside the range of the profile data.
- radius
- Raises:
UnitConversionErrorIf
eeis aQuantitywith units that cannot be converted to the units ofprofile.
See also
- 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.