ProfileBase#
- class photutils.profiles.ProfileBase(data, xycen, radii, *, error=None, mask=None, method='exact', subpixels=5)[source]#
Bases:
objectAbstract base class for profile classes.
- 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 profile apertures.
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. See the subclass documentation for details on howradiiis interpreted.- 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.- 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.
Attributes Summary
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
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
- 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.
Methods Documentation
- normalize(method='max')[source]#
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)[source]#
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)[source]#
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.