ApertureStats#

class photutils.aperture.ApertureStats(data, aperture, *, error=None, mask=None, wcs=None, sigma_clip=None, sum_method='exact', subpixels=5, ddof=0, local_bkg=None, segmentation_image=None, labels=None, mask_method='none', n_threads=1)[source]#

Bases: object

Class to create a catalog of statistics for pixels within an aperture.

Note that this class returns the statistics of the input data values within the aperture. It does not convert data in surface brightness units to flux or counts. Conversion from surface-brightness units should be performed before using this class.

Parameters:
data2D ndarray, Quantity, NDData

The 2D array from which to calculate the source properties. For accurate source properties, data should be background-subtracted. Nonfinite data values (NaN and inf) are automatically masked. If data is an NDData object, its mask, wcs, unit, and uncertainty are used. The error, mask, and wcs keywords are then ignored, and an AstropyUserWarning is issued for each one that is input. The uncertainty is used as error only if it is a StdDevUncertainty. Any other uncertainty type is ignored.

apertureAperture or supported Region

The aperture or region to apply to the data. The aperture or region object may contain more than one position. If the input aperture is a SkyAperture or SkyRegion object, then a WCS must be input using the wcs keyword. Region objects are converted to aperture objects.

error2D ndarray or Quantity, optional

The total error array corresponding to the input data array. 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 array then error must be a Quantity array (and vice versa) with identical units. Nonfinite error values (NaN and +/- inf) are not automatically masked, unless they are at the same position of nonfinite values in the input data array. Such pixels can be masked using the mask keyword.

mask2D ndarray (bool), 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. Nonfinite values (NaN and inf) in the input data are automatically masked.

wcsWCS object or None, optional

A world coordinate system (WCS) transformation that supports the astropy shared interface for WCS (e.g., astropy.wcs.WCS, gwcs.wcs.WCS). wcs is required if the input aperture is a SkyAperture or SkyRegion object. If None, then all sky-based properties will be set to None.

sigma_clipNone or astropy.stats.SigmaClip instance, optional

A SigmaClip object that defines the sigma clipping parameters. If None then no sigma clipping will be performed.

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

The method used to determine the pixel weights (the fraction of the pixel area covered by the aperture). This method is used only for calculating the sum, sum_err, sum_aper_area, data_sum_cutout, and error_sum_cutout properties. All other properties use the “center” aperture mask method. The following methods are available:

  • '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.

ddofint, optional

The delta degrees of freedom used when computing the var and std properties. The divisor used in the calculation is N - ddof, where N is the number of unmasked pixels within the aperture. The default is ddof=0, which gives the population variance and standard deviation. Use ddof=1 to obtain the sample (unbiased) variance and standard deviation. This keyword affects only the var and std properties. All other properties are unaffected, including the mean_err and median_err standard errors, which are always computed using the sample standard deviation. Apertures with N <= ddof unmasked pixels have an undefined var and std and are set to NaN.

local_bkgfloat, ndarray, Quantity, or None, optional

The per-pixel local background values to subtract from the data before performing measurements. If input as an array, the order of local_bkg values corresponds to the order of the input aperture positions. local_bkg must have the same length as the input aperture or must be a scalar value, which will be broadcast to all apertures. If None, then no local background subtraction is performed. If the input data has units, then local_bkg must be a Quantity with the same units. A ValueError is raised if local_bkg contains any nonfinite values (NaN or inf).

segmentation_imageSegmentationImage or None, optional

A segmentation image with the same shape as data, where background pixels have a value of 0 and sources are labeled with positive integers. It is used to mask or correct neighboring sources within each aperture according to the mask_method keyword. This keyword is required if mask_method is not 'none' and is ignored if mask_method is 'none' (the default). The labels keyword must also be input for the 'mask', 'source_only', and 'correct' methods so that the correct target source is used for each aperture.

labelsint, 1D array_like, or None, optional

The source label(s) in segmentation_image associated with the aperture position(s). labels is required if segmentation_image is input and mask_method is 'mask', 'source_only', or 'correct'. It is not used if mask_method is 'none' or 'background_only'. labels must have the same length as the number of aperture positions, and each nonzero label must be present in the segmentation_image (unless mask_method is 'none' or 'background_only'). A label of 0 disables the segmentation masking for that aperture.

mask_method{‘none’, ‘mask’, ‘source_only’, ‘background_only’, ‘correct’}, optional

The method used to handle neighboring sources within each aperture using the segmentation_image:

  • 'none' (default): The segmentation_image is ignored and all pixels within the aperture are included.

  • 'mask': Pixels belonging to neighboring sources (i.e., labeled but not the target source) are excluded.

  • 'source_only': Only pixels belonging to the target source are included. Both neighboring sources and background pixels are excluded.

  • 'background_only': Only background pixels are included. Pixels belonging to any source are excluded, including the source at the aperture position (if any). This method is intended for estimating the local background, e.g., within an annulus aperture. The labels keyword is not used.

  • 'correct': Pixels belonging to neighboring sources are replaced by the values of the pixels mirrored across the aperture center. If a mirror pixel is unavailable, the pixel is excluded.

n_threadsint, optional

The number of threads to use to gather the aperture pixel values, compute the aperture sums, and reduce the per-source statistics (e.g., the sorts, order statistics, robust estimators, and moments). The default is 1 (no multithreading). When n_threads > 1, the aperture positions are divided into chunks and processed concurrently. The per-source results are independent, so they are identical to the single-threaded computation. The underlying kernels release the Python global interpreter lock (GIL), so multithreading can significantly speed up the statistics for many aperture positions. Multithreading is used only on the fast batch code path. Otherwise, the computation is serial.

Notes

data should be background-subtracted for accurate source properties. In addition to global background subtraction, local background subtraction can be performed using the local_bkg keyword values.

Region objects are converted to Aperture objects using the region_to_aperture() function.

The returned statistics are measured for the pixels within the input aperture at its input position. This class does not change the position of the input aperture. This class returns the centroid value of the pixels within the input aperture, but the input aperture is not recentered at the measured centroid position when making the measurements. If desired, you can create a new Aperture object using the measured centroid and then rerun ApertureStats.

All properties other than the sum-related ones described below are calculated using the “center” aperture-mask method, which assigns aperture weights of either 0 or 1, so the data pixel values are used directly and without weighting. This choice reflects a fundamental limitation because, unlike the mean or variance, order statistics (min, max, median) and robust estimators (mad_std, biweight_location, biweight_midvariance) have no standard, unambiguous definition for pixels with fractional (partial) aperture weights. Accordingly, these quantities cannot be rigorously computed from a weighted aperture footprint.

The input sum_method and subpixels keywords are used to determine the aperture-mask method only for the sum-related properties: sum, sum_err, sum_aper_area, data_sum_cutout, and error_sum_cutout (also listed in the SUM_FOOTPRINT_PROPERTIES class attribute). All other properties, including mean, median, std, and the morphological properties, always use the “center” aperture-mask method regardless of sum_method. The default is sum_method='exact', which produces exact aperture-weighted photometry.

The centroid and the morphological (shape) properties are calculated from image moments of the data values, including negative values. This differs from SourceCatalog, which sets negative values to zero for these properties. A source segment contains only pixels above the detection threshold, so its few negative values can safely be ignored. In contrast, the sky pixels within an aperture on background-subtracted data are negative about half of the time. Including them lets the positive and negative noise cancel on average, which keeps the centroid and the shape properties nearly unbiased. Setting them to zero would leave a positive noise pedestal across the aperture that pulls the centroid toward the aperture center and inflates the measured source size. The cost is that the image moments of a faint source can be too noisy to define a shape. If the net flux within the aperture is not positive, the 'undefined_shape' flag is set. If the second-order moments are not positive semidefinite, the covariance-derived shape properties are NaN.

The flags property reports quality conditions from both the “center”-method footprint and the sum_method footprint (see the flags docstring for the per-bit details).

The calculated statistics are always float64, regardless of the input data dtype (Quantity values with float64 dtype if the input data has units). The compiled code reads C-contiguous data and error arrays directly, without a copy, when they are both float32 or both float64 (or when data is float32 or float64 and no error is input). Otherwise they are converted to C-contiguous copies (float32 if every array is a floating-point array of at most 4 bytes per value, and float64 otherwise), which are kept for the lifetime of the ApertureStats object. All calculations are performed in float64, so float32 inputs give the same results as the same values input as float64 (to within floating-point rounding).

The pixel values within the apertures are gathered into temporary buffers. When the input contains many or large apertures, the sources are processed in blocks so that the size of these buffers does not grow with the number of sources. The results are identical.

Examples

>>> from photutils.datasets import make_4gaussians_image
>>> from photutils.aperture import CircularAperture, ApertureStats
>>> data = make_4gaussians_image()
>>> aper = CircularAperture((150, 25), 8)
>>> aperstats = ApertureStats(data, aper)
>>> print(aperstats.x_centroid)
149.99080259251238
>>> print(aperstats.y_centroid)
24.97484633000507
>>> print(aperstats.centroid)
[149.99080259  24.97484633]
>>> print(aperstats.mean, aperstats.median)
47.76300955780609 31.913789514433084
>>> print(aperstats.std)
39.193655383492974
>>> print(aperstats.sum)
9286.709206410273
>>> print(aperstats.sum_aper_area)
201.0619298297468 pix2
>>> # More than one aperture position
>>> aper2 = CircularAperture(((150, 25), (90, 60)), 10)
>>> aperstats2 = ApertureStats(data, aper2)
>>> print(aperstats2.x_centroid)
[149.98470724  89.97893946]
>>> print(aperstats2.sum)
[10177.62548482 36653.97704059]

Attributes Summary

SUM_FOOTPRINT_PROPERTIES

bbox

The BoundingBox of the aperture.

bbox_xmax

The maximum x-pixel index of the bounding box.

bbox_xmin

The minimum x-pixel index of the bounding box.

bbox_ymax

The maximum y-pixel index of the bounding box.

bbox_ymin

The minimum y-pixel index of the bounding box.

biweight_location

The biweight location of the unmasked pixel values within the aperture.

biweight_midvariance

The biweight midvariance of the unmasked pixel values within the aperture.

center_aper_area

The total area of the unmasked pixels within the aperture using the "center" aperture mask method.

centroid

The (x, y) coordinate of the centroid.

covariance

The covariance matrix of the 2D Gaussian function that has the same second-order moments as the source.

covariance_eigvals

The two eigenvalues of the covariance matrix in decreasing order.

covariance_xx

The (0, 0) element of the covariance matrix, representing \(\sigma_x^2\), in units of pixel**2.

covariance_xy

The (0, 1) and (1, 0) elements of the covariance matrix, representing \(\sigma_{xy}\) (the covariance of x and y), in units of pixel**2.

covariance_yy

The (1, 1) element of the covariance matrix, representing \(\sigma_y^2\), in units of pixel**2.

cutout_centroid

The (x, y) coordinate, relative to the cutout data, of the centroid within the aperture.

data_cutout

A 2D aperture-weighted cutout from the data using the aperture mask with the "center" method as a MaskedArray.

data_sum_cutout

A 2D aperture-weighted cutout from the data using the aperture mask with the input sum_method method as a MaskedArray.

eccentricity

The eccentricity of the 2D Gaussian function that has the same second-order moments as the source.

ellipse_cxx

Coefficient for x**2 in the generalized ellipse equation in units of pixel**(-2).

ellipse_cxy

Coefficient for x * y in the generalized ellipse equation in units of pixel**(-2).

ellipse_cyy

Coefficient for y**2 in the generalized ellipse equation in units of pixel**(-2).

ellipticity

1.0 minus the ratio of the lengths of the semiminor and semimajor axes (or 1.0 divided by the elongation, subtracted from 1.0).

elongation

The ratio of the lengths of the semimajor and semiminor axes.

error_sum_cutout

A 2D aperture-weighted error cutout using the aperture mask with the input sum_method method as a MaskedArray.

flags

The bitwise quality flags.

fwhm

The circularized full width at half maximum (FWHM) of the 2D Gaussian function that has the same second-order central moments as the source.

gini

The Gini coefficient of the unmasked pixel values within the aperture.

id

The aperture identification number(s).

ids

inertia_tensor

isscalar

Whether the instance is scalar (e.g., a single aperture position).

mad_std

The standard deviation of the unmasked pixel values within the aperture, calculated using the median absolute deviation (MAD).

max

The maximum of the unmasked pixel values within the aperture.

mean

The mean of the unmasked pixel values within the aperture.

mean_err

The standard error of the mean.

median

The median of the unmasked pixel values within the aperture.

median_err

The standard error of the median.

min

The minimum of the unmasked pixel values within the aperture.

mode

The mode of the unmasked pixel values within the aperture.

moments

Spatial moments up to 3rd order of the source.

moments_central

Central moments (translation invariant) of the source up to 3rd order.

n_apertures

n_positions

The number of positions for the input aperture.

orientation

The angle between the x-axis and the major axis of the 2D Gaussian function that has the same second-order moments as the source.

properties

A sorted list of the names of the built-in per-source properties.

semimajor_axis

The 1-sigma standard deviation along the semimajor axis of the 2D Gaussian function that has the same second-order central moments as the source.

semiminor_axis

The 1-sigma standard deviation along the semiminor axis of the 2D Gaussian function that has the same second-order central moments as the source.

sky_centroid

The sky coordinate of the centroid of the unmasked pixels within the aperture, returned as a SkyCoord object.

sky_centroid_icrs

The sky coordinate in the International Celestial Reference System (ICRS) frame of the centroid of the unmasked pixels within the aperture, returned as a SkyCoord object.

sky_orientation

The position angle on the sky of the major axis of the 2D Gaussian function that has the same second-order moments as the source.

std

The standard deviation of the unmasked pixel values within the aperture.

sum

The sum of the unmasked data values within the aperture, weighted by the aperture overlap fractions.

sum_aper_area

The total area of the unmasked pixels within the aperture using the input sum_method aperture mask method.

sum_err

The uncertainty of sum, propagated from the input error array.

var

The variance of the unmasked pixel values within the aperture.

x_centroid

The x coordinate of the centroid.

y_centroid

The y coordinate of the centroid.

Methods Summary

copy()

Return a deep copy of this object.

decode_flags(*[, return_bit_values])

Decode the source quality flags into individual components.

select_id(id_num)

Return a new ApertureStats object for the input ID number only.

select_ids(id_nums)

Return a new ApertureStats object for the input ID numbers only.

to_table(*[, columns])

Create a QTable of source properties.

Attributes Documentation

SUM_FOOTPRINT_PROPERTIES = ('sum', 'sum_err', 'sum_aper_area', 'data_sum_cutout', 'error_sum_cutout')#
bbox[source]#

The BoundingBox of the aperture.

Note that the aperture bounding box is calculated using the exact size of the aperture, so it may be slightly larger than the region of nonzero weights in the aperture mask calculated using the “center” method.

bbox_xmax[source]#

The maximum x-pixel index of the bounding box.

Note that this value is inclusive, unlike numpy slice indices.

bbox_xmin[source]#

The minimum x-pixel index of the bounding box.

bbox_ymax[source]#

The maximum y-pixel index of the bounding box.

Note that this value is inclusive, unlike numpy slice indices.

bbox_ymin[source]#

The minimum y-pixel index of the bounding box.

biweight_location[source]#

The biweight location of the unmasked pixel values within the aperture.

The tuning constant is fixed at c=6, the default value used by astropy.stats.biweight_location.

biweight_midvariance[source]#

The biweight midvariance of the unmasked pixel values within the aperture.

The tuning constant is fixed at c=9, the default value used by astropy.stats.biweight_midvariance.

center_aper_area[source]#

The total area of the unmasked pixels within the aperture using the “center” aperture mask method.

centroid[source]#

The (x, y) coordinate of the centroid.

The centroid is computed as the center of mass of the unmasked pixels within the aperture.

covariance[source]#

The covariance matrix of the 2D Gaussian function that has the same second-order moments as the source.

The variance along each principal axis is at least 1/12 pixel**2 (to within floating-point rounding), the variance of a uniform distribution across a single pixel. For a source that is unresolved along an axis (e.g., a point-like or a very thin source), the variance along that axis is raised to 1/12 while the orientation and the variance along a resolved axis are unchanged. A source that is unresolved along both axes is isotropic, with an orientation of zero. The covariance is NaN if the second-order moments are not positive semidefinite.

covariance_eigvals[source]#

The two eigenvalues of the covariance matrix in decreasing order.

covariance_xx[source]#

The (0, 0) element of the covariance matrix, representing \(\sigma_x^2\), in units of pixel**2.

covariance_xy[source]#

The (0, 1) and (1, 0) elements of the covariance matrix, representing \(\sigma_{xy}\) (the covariance of x and y), in units of pixel**2.

covariance_yy[source]#

The (1, 1) element of the covariance matrix, representing \(\sigma_y^2\), in units of pixel**2.

cutout_centroid[source]#

The (x, y) coordinate, relative to the cutout data, of the centroid within the aperture.

The centroid is computed as the center of mass of the unmasked pixels within the aperture.

data_cutout[source]#

A 2D aperture-weighted cutout from the data using the aperture mask with the “center” method as a MaskedArray.

The local_bkg value is subtracted from the cutout data values. If mask_method='correct', the corrected neighbor pixels hold their mirrored values.

The cutout does not have units due to current limitations of masked quantity arrays.

The mask is True for pixels from the input mask, nonfinite data values (NaN and inf), pixels excluded by the segmentation masking (mask_method), sigma-clipped pixels within the aperture, and pixels where the aperture mask has zero weight.

For more than one aperture position, a list with one cutout for each position is returned. If the aperture does not overlap the data, the cutout is a one-element array containing NaN.

data_sum_cutout[source]#

A 2D aperture-weighted cutout from the data using the aperture mask with the input sum_method method as a MaskedArray.

The local_bkg value is subtracted from the data values before the aperture weights are applied. If mask_method='correct', the corrected neighbor pixels hold their mirrored values.

The cutout does not have units due to current limitations of masked quantity arrays.

The mask is True for pixels from the input mask, nonfinite data values (NaN and inf), pixels excluded by the segmentation masking (mask_method), sigma-clipped pixels within the aperture, and pixels where the aperture mask has zero weight.

For more than one aperture position, a list with one cutout for each position is returned. If the aperture does not overlap the data, the cutout is a one-element array containing NaN.

eccentricity[source]#

The eccentricity of the 2D Gaussian function that has the same second-order moments as the source.

The eccentricity is the fraction of the distance along the semimajor axis at which the focus lies.

\[e = \sqrt{1 - \frac{b^2}{a^2}}\]

where \(a\) and \(b\) are the lengths of the semimajor and semiminor axes, respectively.

ellipse_cxx[source]#

Coefficient for x**2 in the generalized ellipse equation in units of pixel**(-2).

The ellipse is defined as

\[cxx (x - \bar{x})^2 + cxy (x - \bar{x}) (y - \bar{y}) + cyy (y - \bar{y})^2 = R^2\]

where \(R\) is a parameter which scales the ellipse (in units of the axes lengths).

The isophotal limit of a source is well represented by \(R \approx 3\).

ellipse_cxy[source]#

Coefficient for x * y in the generalized ellipse equation in units of pixel**(-2).

The ellipse is defined as

\[cxx (x - \bar{x})^2 + cxy (x - \bar{x}) (y - \bar{y}) + cyy (y - \bar{y})^2 = R^2\]

where \(R\) is a parameter which scales the ellipse (in units of the axes lengths).

The isophotal limit of a source is well represented by \(R \approx 3\).

ellipse_cyy[source]#

Coefficient for y**2 in the generalized ellipse equation in units of pixel**(-2).

The ellipse is defined as

\[cxx (x - \bar{x})^2 + cxy (x - \bar{x}) (y - \bar{y}) + cyy (y - \bar{y})^2 = R^2\]

where \(R\) is a parameter which scales the ellipse (in units of the axes lengths).

The isophotal limit of a source is well represented by \(R \approx 3\).

ellipticity[source]#

1.0 minus the ratio of the lengths of the semiminor and semimajor axes (or 1.0 divided by the elongation, subtracted from 1.0).

\[\mathrm{ellipticity} = \frac{a - b}{a} = 1 - \frac{b}{a} = 1 - \frac{1}{\mathrm{elongation}}\]

where \(a\) and \(b\) are the lengths of the semimajor and semiminor axes, respectively.

elongation[source]#

The ratio of the lengths of the semimajor and semiminor axes.

\[\mathrm{elongation} = \frac{a}{b}\]

where \(a\) and \(b\) are the lengths of the semimajor and semiminor axes, respectively.

error_sum_cutout[source]#

A 2D aperture-weighted error cutout using the aperture mask with the input sum_method method as a MaskedArray.

The cutout values are the pixel errors multiplied by the aperture mask weights, so the quadrature sum of the unmasked cutout values equals sum_err. If mask_method='correct', the corrected neighbor pixels hold their mirrored error values.

The cutout does not have units due to current limitations of masked quantity arrays.

The mask is True for pixels from the input mask, nonfinite data values (NaN and inf), pixels excluded by the segmentation masking (mask_method), sigma-clipped pixels within the aperture, and pixels where the aperture mask has zero weight.

For more than one aperture position, a list with one cutout for each position is returned. If the aperture does not overlap the data, the cutout is a one-element array containing NaN.

None if error is not input (an array of None values for more than one aperture position).

flags[source]#

The bitwise quality flags.

The footprint-based flags (e.g., 'masked_pixels', 'non_finite_data', and the overlap flags) are evaluated on the union of the “center”-method footprint used by the value statistics and the sum_method footprint used by the sum properties. The 'no_overlap' flag is set only if neither footprint overlaps the data. The 'non_finite_error' flag is evaluated on the sum_method footprint. The 'sigma_clipped', 'all_clipped', and 'too_few_pixels' flags are evaluated on the value-statistics footprint. The 'too_few_pixels' flag is set when the aperture has a single valid pixel (after any sigma clipping), for which mean_err and median_err are undefined, or when ddof is greater than zero and the number of valid pixels is not larger than ddof. The 'undefined_shape', 'singular_covariance', and 'centroid_outside_bbox' flags are always evaluated. Accessing flags computes the moment and covariance properties if they have not already been computed (the results are cached and shared with the corresponding shape properties).

See decode_aperture_flags for decoding flag values. The flags are:

  • 0 : No flags set.

  • 1 ('no_overlap') : The aperture is fully outside the data array: no pixel with nonzero aperture weight falls inside the data.

  • 2 ('partial_overlap') : The aperture is partially outside the data array: one or more pixels with nonzero aperture weight fall outside the data.

  • 4 ('no_pixels') : The aperture contains zero pixels with nonzero weight inside the data, e.g., a fully off-image aperture or a tiny aperture that contains no pixel (or subpixel) centers with the “center” or “subpixel” methods.

  • 8 ('masked_pixels') : One or more input-masked pixels (mask keyword) have nonzero aperture weight.

  • 16 ('non_finite_data') : One or more unmasked data values with nonzero aperture weight are nonfinite (NaN or inf).

  • 32 ('non_finite_error') : One or more unmasked error values with nonzero aperture weight are nonfinite (NaN or inf).

  • 64 ('neighbor_pixels') : One or more pixels within the aperture were excluded, restricted, or corrected due to neighboring sources in the segmentation image.

  • 128 ('uncorrected_pixels') : With mask_method="correct", one or more neighbor-source pixels could not be corrected (the mirror pixel was unavailable) and were excluded instead.

  • 256 ('all_masked') : The aperture contains pixels, but none are valid: every nonzero-weight pixel inside the data is masked, nonfinite, or excluded by segmentation masking.

  • 512 ('sigma_clipped') : One or more pixels within the aperture were rejected by sigma clipping.

  • 1024 ('all_clipped') : All valid pixels within the aperture were rejected by sigma clipping.

  • 2048 ('too_few_pixels') : There are too few valid pixels within the aperture to compute a requested statistic (e.g., the standard errors are undefined for a single valid pixel, and the variance and standard deviation are undefined when the number of valid pixels is not larger than ddof).

  • 4096 ('undefined_shape') : The net flux within the aperture (the zeroth image moment of the unmasked “center”-method pixels) is not positive, so the centroid and the covariance-derived shape properties (e.g., centroid, semimajor_axis, orientation) are undefined or unreliable. The flag is also set when the second-order moments are not positive semidefinite (e.g., from negative pixel values), in which case the covariance-derived shape properties are NaN. Fully masked sources have a zero net flux, so they are also flagged. Sources with no overlap and fully sigma-clipped sources are not flagged here. They are reported by the overlap and clipping flags.

  • 8192 ('singular_covariance') : The source covariance matrix is singular or nearly singular (the minor-axis variance is below 1/12, the variance of a uniform distribution across a single pixel), so covariance-derived shape properties (e.g., semimajor_axis, orientation, eccentricity) are ill-defined and have been regularized.

  • 16384 ('centroid_outside_bbox') : The centroid lies outside the bounding box of the aperture. The image moments include negative pixel values, so the centroid is not bounded by the aperture when the net flux is small compared to the noise. The centroid and the shape properties are unreliable.

fwhm[source]#

The circularized full width at half maximum (FWHM) of the 2D Gaussian function that has the same second-order central moments as the source.

\[\begin{split}\mathrm{FWHM} & = 2 \sqrt{2 \ln(2)} \sqrt{0.5 (a^2 + b^2)} \\ & = 2 \sqrt{\ln(2) \ (a^2 + b^2)}\end{split}\]

where \(a\) and \(b\) are the 1-sigma lengths of the semimajor (semimajor_axis) and semiminor (semiminor_axis) axes, respectively.

gini[source]#

The Gini coefficient of the unmasked pixel values within the aperture.

The Gini coefficient of the distribution of absolute flux values is calculated using the prescription from Lotz et al. 2004 (Eq. 6) as:

\[G = \frac{1}{\overline{|x|} \, n \, (n - 1)} \sum_{i=1}^{n} (2i - n - 1) \left | x_i \right |\]

where the \(n\) pixel values \(x_i\) are sorted in order of increasing absolute value and \(\overline{|x|}\) is the mean of their absolute values. If all pixel values are zero, the Gini coefficient is zero.

Negative pixel values are used via their absolute value. Invalid values (NaN and inf) in the input are automatically excluded from the calculation. If only a single finite pixel remains after filtering, the Gini coefficient is 0.0. If no unmasked pixels remain, the Gini coefficient is NaN.

id#

The aperture identification number(s).

ids#

Deprecated since version 3.1: This function was deprecated in version 3.1 and will be removed in version 4.0. Use the ‘id’ attribute instead.

The aperture identification number(s).

inertia_tensor#

Deprecated since version 3.1: This function was deprecated in version 3.1 and will be removed in version 4.0.

The inertia tensor of the source for the rotation around its center of mass.

Deprecated since version 3.1: The inertia tensor carries no information beyond the covariance matrix. Use the covariance matrix and the shape properties that are derived from it instead.

The rows and columns of the (2, 2) tensor are ordered (y, x), the reverse of the covariance matrix. The diagonal elements are the moments of inertia about the y- and x-axes and the off-diagonal elements are the negative of the product of inertia. The tensor is not normalized by the total flux.

isscalar[source]#

Whether the instance is scalar (e.g., a single aperture position).

mad_std[source]#

The standard deviation of the unmasked pixel values within the aperture, calculated using the median absolute deviation (MAD).

The standard deviation estimator is given by:

\[\sigma \approx \frac{\textrm{MAD}}{\Phi^{-1}(3/4)} \approx 1.4826 \ \textrm{MAD}\]

where \(\Phi^{-1}(P)\) is the normal inverse cumulative distribution function evaluated at probability \(P = 3/4\).

max[source]#

The maximum of the unmasked pixel values within the aperture.

mean[source]#

The mean of the unmasked pixel values within the aperture.

mean_err[source]#

The standard error of the mean.

mean_err is the standard deviation of the sampling distribution of the mean:

\[\sigma_{\bar{x}} = \frac{s}{\sqrt{N}}\]

where \(s\) is the sample standard deviation (computed with N - 1 in the denominator) and \(N\) is the number of unmasked pixels within the aperture (center_aper_area).

Apertures with fewer than two unmasked pixels have an undefined standard error and are set to NaN.

median[source]#

The median of the unmasked pixel values within the aperture.

median_err[source]#

The standard error of the median.

median_err is the large-sample approximation of the standard error of the median:

\[\sigma_{\mathrm{med}} \approx \sqrt{\frac{\pi}{2}} \ \frac{s}{\sqrt{N}}\]

where \(s\) is the sample standard deviation (computed with N - 1 in the denominator) and \(N\) is the number of unmasked pixels within the aperture (center_aper_area).

This approximation assumes that the pixel values are approximately normally distributed. Apertures with fewer than two unmasked pixels have an undefined standard error and are set to NaN.

min[source]#

The minimum of the unmasked pixel values within the aperture.

mode[source]#

The mode of the unmasked pixel values within the aperture.

The mode is estimated as (3 * median) - (2 * mean).

moments[source]#

Spatial moments up to 3rd order of the source.

The result is a (4, 4) array for each aperture position, where element [i, j] is the sum of y**i * x**j times the pixel values. The coordinates are relative to the origin of the cutout (see cutout_centroid). The moments are NaN if the aperture does not overlap the data.

moments_central[source]#

Central moments (translation invariant) of the source up to 3rd order.

The result is a (4, 4) array for each aperture position, where element [i, j] is the sum of (y - yc)**i * (x - xc)**j times the pixel values and (xc, yc) is the centroid (see cutout_centroid). The moments are NaN if the aperture does not overlap the data. If no unmasked pixels remain, the moments are NaN except for the [0, 0] element, which is zero.

n_apertures#

Deprecated since version 3.1: This function was deprecated in version 3.1 and will be removed in version 4.0. Use the ‘n_positions’ attribute instead.

The number of positions for the input aperture.

n_positions[source]#

The number of positions for the input aperture.

orientation[source]#

The angle between the x-axis and the major axis of the 2D Gaussian function that has the same second-order moments as the source.

The angle increases in the counterclockwise direction and is in the range (-90, 90] degrees.

properties#

A sorted list of the names of the built-in per-source properties.

The id property is not included.

semimajor_axis[source]#

The 1-sigma standard deviation along the semimajor axis of the 2D Gaussian function that has the same second-order central moments as the source.

semiminor_axis[source]#

The 1-sigma standard deviation along the semiminor axis of the 2D Gaussian function that has the same second-order central moments as the source.

sky_centroid[source]#

The sky coordinate of the centroid of the unmasked pixels within the aperture, returned as a SkyCoord object.

The output coordinate frame is the same as the input wcs.

None if wcs is not input (an array of None values for more than one aperture position).

sky_centroid_icrs[source]#

The sky coordinate in the International Celestial Reference System (ICRS) frame of the centroid of the unmasked pixels within the aperture, returned as a SkyCoord object.

None if wcs is not input (an array of None values for more than one aperture position).

sky_orientation[source]#

The position angle on the sky of the major axis of the 2D Gaussian function that has the same second-order moments as the source.

The pixel covariance matrix is transported to the local tangent plane with the WCS Jacobian evaluated at each source centroid, which accounts for the WCS rotation, parity, and any local distortion. The position angle is measured from North toward East (i.e., counterclockwise on the sky) in the celestial frame of the input wcs and is in the range (-90, 90] degrees. This is the same convention as the theta parameter of the sky-based apertures (e.g., SkyEllipticalAperture).

None if wcs is not input (an array of None values for more than one aperture position).

std[source]#

The standard deviation of the unmasked pixel values within the aperture.

The divisor used in the calculation is N - ddof, where N is the number of unmasked pixels within the aperture and ddof is the value of the ddof keyword (default 0).

sum[source]#

The sum of the unmasked data values within the aperture, weighted by the aperture overlap fractions.

\[F = \sum_{i \in A} w_i I_i\]

where \(F\) is sum, \(w_i\) are the aperture overlap fractions (1 for pixels entirely within the aperture), \(I_i\) is the background-subtracted data, and \(A\) are the unmasked pixels in the aperture.

Nonfinite pixel values (NaN and inf) are excluded (automatically masked). If sigma_clip is input, the sigma-clipped pixels are also excluded.

sum_aper_area[source]#

The total area of the unmasked pixels within the aperture using the input sum_method aperture mask method.

sum_err[source]#

The uncertainty of sum, propagated from the input error array.

Because sum is the sum of the pixel values weighted by their aperture overlap fractions, sum_err is the quadrature sum of the total errors over the unmasked pixels within the aperture, with each pixel variance weighted by the squared overlap fraction:

\[\Delta F = \sqrt{\sum_{i \in A} w_i^2 \sigma_{\mathrm{tot}, i}^2}\]

where \(\Delta F\) is the sum_err, \(w_i\) are the aperture overlap fractions (1 for pixels entirely within the aperture), \(\sigma_{\mathrm{tot}, i}\) are the pixel-wise total errors (error), and \(A\) are the unmasked pixels in the aperture.

Pixel values that are masked in the input data, including any nonfinite pixel values (NaN and inf) that are automatically masked, are also masked in the error array.

NaN if error is not input.

var[source]#

The variance of the unmasked pixel values within the aperture.

The divisor used in the calculation is N - ddof, where N is the number of unmasked pixels within the aperture and ddof is the value of the ddof keyword (default 0).

x_centroid[source]#

The x coordinate of the centroid.

The centroid is computed as the center of mass of the unmasked pixels within the aperture.

y_centroid[source]#

The y coordinate of the centroid.

The centroid is computed as the center of mass of the unmasked pixels within the aperture.

Methods Documentation

copy()[source]#

Return a deep copy of this object.

Returns:
resultApertureStats

A deep copy of this object.

decode_flags(*, return_bit_values=False)[source]#

Decode the source quality flags into individual components.

This is a convenience method that calls decode_aperture_flags with the flags property.

Parameters:
return_bit_valuesbool, optional

If True, return the decoded bit flags (integers) instead of the flag names (strings).

Returns:
decodeddict

A dictionary mapping each aperture position id to the list of its active flag names (or bit values). The entries follow the position order.

Examples

>>> import numpy as np
>>> from photutils.aperture import ApertureStats, CircularAperture
>>> data = np.ones((25, 25))
>>> mask = np.zeros(data.shape, dtype=bool)
>>> mask[12, 12] = True
>>> aper = CircularAperture([(12.0, 12.0), (0.0, 12.0)], r=3.0)
>>> aperstats = ApertureStats(data, aper, mask=mask)
>>> for source_id, names in aperstats.decode_flags().items():
...     print(source_id, names)
1 ['masked_pixels']
2 ['partial_overlap']
select_id(id_num)[source]#

Return a new ApertureStats object for the input ID number only.

Parameters:
id_numint

The aperture ID number.

Returns:
resultApertureStats

A new ApertureStats object containing only the source with the input ID number.

Raises:
TypeError

If this is a scalar ApertureStats object, which cannot be indexed.

ValueError

If the input ID number is not a valid source ID number.

select_ids(id_nums)[source]#

Return a new ApertureStats object for the input ID numbers only.

Parameters:
id_numsint, list, tuple, or ndarray of int

The aperture ID number(s).

Returns:
resultApertureStats

A new ApertureStats object containing only the sources with the input ID numbers.

Raises:
TypeError

If this is a scalar ApertureStats object, which cannot be indexed.

ValueError

If any input ID number is not a valid source ID number.

to_table(*, columns=None)[source]#

Create a QTable of source properties.

Parameters:
columnsstr, list of str, None, optional

Names of columns, in order, to include in the output QTable. The allowed column names are 'id' and the names in the properties attribute, except for the 2D cutout properties (data_cutout, data_sum_cutout, and error_sum_cutout). If columns is None, then a default list of scalar-valued properties (as defined by the default_columns attribute) will be used.

Returns:
tableQTable

A table of source properties with one row per source.

Raises:
ValueError

If any name in columns is not a valid (or deprecated) column name.