EllipticalCurveOfGrowth#

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

Bases: ProfileBase

Class to create a curve of growth using concentric elliptical apertures with a fixed axis ratio and orientation.

The elliptical curve of growth profile represents the elliptical aperture flux as a function of the semimajor axis length.

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 the ellipse semimajor-axis lengths. radii must be strictly increasing with a minimum value greater than zero, and contain at least 2 values. The spacing does not need to be constant. radii must be in pixels and cannot be a Quantity.

axis_ratiofloat

The ratio of the semiminor axis to the semimajor axis (b / a). Must be in the range 0 < axis_ratio <= 1.

thetafloat or Quantity, optional

The rotation angle as an angular quantity (Quantity or Angle) or value in radians (as a float) from the positive x-axis. The rotation angle increases counterclockwise. The default is 0.

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 value less than or equal to zero, or is not strictly increasing, if axis_ratio is not in the range 0 < axis_ratio <= 1, 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.

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 EllipticalCurveOfGrowth

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

>>> gmodel = Gaussian2D(42.1, 47.8, 52.4, 9.4, 4.7, np.deg2rad(42))
>>> 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 elliptical curve of growth with an axis ratio of 0.5 and a rotation angle of 42 degrees.

>>> xycen = centroid_2dg(data)
>>> radii = np.arange(1, 40)
>>> ecog = EllipticalCurveOfGrowth(data, xycen, radii, axis_ratio=0.5,
...                                theta=np.deg2rad(42), error=error)
>>> print(ecog.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 26 27 28 29 30 31 32 33 34 35 36 37 38 39]
>>> print(ecog.profile)
[   67.39762867   267.711181     588.47524874  1021.31994307
  1546.53867489  2152.12698084  2824.97954482  3541.64650208
  4284.363828    5040.93586551  5777.06397177  6488.33779084
  7179.10371288  7826.17773764  8418.08027957  8948.7310004
  9418.56480323  9810.0373925  10163.11467352 10477.42357537
 10731.89184641 10920.11723061 11092.34059512 11235.12552706
 11347.43721424 11454.03577845 11520.64656354 11555.89668261
 11571.27935302 11583.89774142 11605.79810845 11639.93073462
 11648.27293403 11660.34772581 11662.89065496 11643.07787619
 11630.36674411 11636.61537567 11636.60448497]
>>> print(ecog.profile_error)
[  1.82558544   4.4811361    7.21875141   9.88960965  12.44181885
  15.0767893   17.74361162  20.3959057   23.02040853  25.60886742
  28.25910457  30.93376937  33.54721095  36.14973269  38.78350009
  41.44751786  44.08722476  46.67911616  49.30783947  51.9760285
  54.61090354  57.21854088  59.84454217  62.48828381  65.14297876
  67.7591664   70.36843954  73.01750591  75.66115523  78.29244888
  80.90838345  83.53056346  86.19047387  88.82463241  91.43141788
  94.06294498  96.71101089  99.35484622 101.96990083]

Normalize the profile and plot the normalized elliptical curve of growth.

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

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

Plot three of the apertures on the data.

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

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

Attributes Summary

apertures

A list of EllipticalAperture objects used to measure the profile.

area

The unmasked area within each aperture as a 1D ndarray.

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 semimajor-axis lengths in pixels as a 1D ndarray.

Methods Summary

calc_ee_at_radius(radius)

Calculate the encircled energy at a given semimajor-axis length using a cubic interpolator based on the profile data.

calc_radius_at_ee(ee)

Calculate the semimajor-axis length 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()

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

Attributes Documentation

apertures[source]#

A list of EllipticalAperture objects used to measure the profile.

area#

The unmasked area within each aperture as a 1D ndarray.

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 semimajor-axis lengths in pixels as a 1D ndarray.

This is the same as the input radii.

Note that these are the semimajor-axis lengths of the elliptical apertures used to measure the profile. Thus, they are the semimajor-axis values that enclose the given flux.

Methods Documentation

calc_ee_at_radius(radius)[source]#

Calculate the encircled energy at a given semimajor-axis length 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 normalize method 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 input radii.

The interpolated curve passes through the measured profile values. For a noisy profile, the curve can therefore decrease with semimajor-axis length where the enclosed flux has leveled off.

Parameters:
radiusfloat or array_like

The semimajor-axis length(s) in pixels. It cannot be a Quantity.

Returns:
eendarray or Quantity

The encircled energy at each semimajor-axis length. It is a Quantity with the units of profile if the input data has units. Returns NaN for semimajor-axis lengths outside the range of the profile data.

Raises:
TypeError

If radius is a Quantity.

calc_radius_at_ee(ee)[source]#

Calculate the semimajor-axis length 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 normalize method 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 input radii.

This method returns the smallest semimajor-axis length at which the curve interpolated by calc_ee_at_radius reaches the encircled energy. Converting the result back with calc_ee_at_radius returns the input encircled energy. For a noisy profile, the curve can reach the same encircled energy again at a larger semimajor-axis length.

Where a noisy profile has leveled off, the semimajor-axis length of a given encircled energy is poorly constrained, and the maximum used by normalize is biased high by the noise. If you need the semimajor-axis length at a large encircled energy (e.g., 0.95 or more), use a profile with a high signal-to-noise ratio, or divide the input data by a known total flux instead of calling normalize.

Parameters:
eefloat, array_like, or Quantity

The encircled energy. A value without units is assumed to be in the units of profile. A Quantity is converted to the units of profile, and must be dimensionless if profile has no units.

Returns:
radiusndarray

The semimajor-axis length in pixels at each encircled energy. Returns NaN for encircled energies outside the range of the profile data.

Raises:
UnitConversionError

If ee is a Quantity with units that cannot be converted to the units of profile.

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.