SourceCatalog#
- class photutils.segmentation.SourceCatalog(data, segmentation_image, *, convolved_data=None, error=None, mask=None, background=None, wcs=None, local_bkg_width=0, aperture_mask_method='correct', kron_params=(2.5, 1.4, 0.0), detection_catalog=None, progress_bar=False)[source]#
Bases:
objectClass to create a catalog of photometry and morphological properties for sources defined by a segmentation image.
- Parameters:
- data2D
ndarrayorQuantity, optional The 2D array from which to calculate the source photometry and properties. If
convolved_datais input, then a convolved version ofdatawill be used instead ofdatato calculate the source centroid and morphological properties. Source photometry is always measured fromdata. For accurate source properties and photometry,datashould be background-subtracted. Non-finitedatavalues (NaN and inf) are automatically masked.- segmentation_image
SegmentationImage A
SegmentationImageobject defining the sources.- convolved_data2D
ndarrayorQuantity, optional The 2D array used to calculate the source centroid and morphological properties. Typically,
convolved_datashould be the inputdataarray convolved by the same smoothing kernel that was applied to the detection image when deriving the source segments (e.g., seedetect_sources()). Ifconvolved_dataisNone, then the unconvolveddatawill be used instead. Non-finiteconvolved_datavalues (NaN and inf) are not automatically masked, unless they are at the same position of non-finite values in the inputdataarray. Such pixels can be masked using themaskkeyword.- error2D
ndarrayorQuantity, optional The total error array corresponding to the input
dataarray.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 aQuantityarray thenerrormust be aQuantityarray (and vice versa) with identical units. Non-finiteerrorvalues (NaN and inf) are not automatically masked, unless they are at the same position of non-finite values in the inputdataarray. Such pixels can be masked using themaskkeyword. See the Notes section below for details on the error propagation.- mask2D
ndarray(bool), optional A boolean mask with the same shape as
datawhere aTruevalue indicates the corresponding element ofdatais masked. Masked data are excluded from all calculations. Non-finite values (NaN and inf) in the inputdataare automatically masked.- backgroundfloat, 2D
ndarray, orQuantity, optional The background level that was previously present in the input
data.backgroundmay either be a scalar value or a 2D image with the same shape as the inputdata. Ifdatais aQuantityarray thenbackgroundmust be aQuantityarray (and vice versa) with identical units. Inputing thebackgroundmerely allows for its properties to be measured within each source segment. The inputbackgrounddoes not get subtracted from the inputdata, which should already be background-subtracted. Non-finitebackgroundvalues (NaN and inf) are not automatically masked, unless they are at the same position of non-finite values in the inputdataarray. Such pixels can be masked using themaskkeyword.- 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). IfNone, then all sky-based properties will be set toNone. This keyword will be ignored ifdetection_catalogis input.- local_bkg_widthint, optional
The width of the rectangular annulus used to compute a local background around each source. If zero, then no local background subtraction is performed. The local background affects the
min_value,max_value,segment_flux,kron_flux, andflux_radiusproperties. It is also used when calculating circular and Kron aperture photometry (i.e.,circular_photometryandkron_photometry). It does not affect the moment-based morphological properties of the source.- aperture_mask_method{‘correct’, ‘mask’, ‘none’}, optional
The method used to handle neighboring sources when performing aperture photometry (e.g., circular apertures or elliptical Kron apertures). This parameter also affects the Kron radius. The options are:
‘correct’: replace pixels assigned to neighboring sources by replacing them with pixels on the opposite side of the source center (equivalent to MASK_TYPE=CORRECT in SourceExtractor).
‘mask’: mask pixels assigned to neighboring sources (equivalent to MASK_TYPE=BLANK in SourceExtractor).
‘none’: do not mask any pixels (equivalent to MASK_TYPE=NONE in SourceExtractor).
This keyword will be ignored if
detection_catalogis input. In that case, theaperture_mask_methodset in thedetection_catalogwill be used.- kron_paramstuple of 2 or 3 floats, optional
A list of parameters used to determine the Kron aperture. The first item is the scaling parameter of the unscaled Kron radius and the second item represents the minimum value for the unscaled Kron radius in pixels. The optional third item is the minimum circular radius in pixels. If
kron_params[0]*kron_radius* sqrt(semimajor_axis*semiminor_axis) is less than or equal to this radius, then the Kron aperture will be a circle with this minimum radius. This keyword will be ignored ifdetection_catalogis input.- detection_catalog
SourceCatalog, optional A
SourceCatalogobject for the detection image. The segmentation image used to create the detection catalog must be the same one input tosegmentation_image. If input, then the detection catalog source centroids and morphological/shape properties will be returned instead of calculating them from the inputdata. The detection catalog centroids and shape properties will also be used to perform aperture photometry (i.e., circular and Kron). Ifdetection_catalogis input, then the inputwcs,aperture_mask_method, andkron_paramskeywords will be ignored. This keyword affectscircular_photometry(including returned apertures), all Kron parameters (Kron radius, flux, flux errors, apertures, and customkron_photometry), andflux_radius(which is based on the Kron flux).- progress_barbool, optional
Whether to display a progress bar when calculating some properties (e.g.,
kron_radius,kron_flux,flux_radius,circular_photometry,centroid_win,centroid_quad). The progress bar requires that the tqdm optional dependency be installed.
- data2D
Notes
datashould be background-subtracted for accurate source photometry and properties. The previously-subtracted background can be passed into this class to calculate properties of the background for each source.Note that this class does not convert input data in surface-brightness units to flux or counts. Conversion from surface-brightness units should be performed before using this class.
SourceExtractor’s centroid and morphological parameters are always calculated from a convolved, or filtered, “detection” image (
convolved_data), i.e., the image used to define the segmentation image. The usual downside of the filtering is the sources will be made more circular than they actually are. If you wish to reproduce SourceExtractor centroid and morphology results, then input theconvolved_data. Ifconvolved_dataisNone, then the unfiltereddatawill be used for the source centroid and morphological parameters.Negative data values within the source segment are set to zero when calculating morphological properties based on image moments. Negative values could occur, for example, if the segmentation image was defined from a different image (e.g., different bandpass) or if the background was oversubtracted. However,
segment_fluxalways includes the contribution of negativedatavalues.The input
errorarray is assumed to include all sources of error, including the Poisson error of the sources.segment_flux_erris simply the quadrature sum of the pixel-wise total errors over the unmasked pixels within the source segment:\[\Delta F = \sqrt{\sum_{i \in S} \sigma_{\mathrm{tot}, i}^2}\]where \(\Delta F\) is
segment_flux_err, \(S\) are the unmasked pixels in the source segment, and \(\sigma_{\mathrm{tot}, i}\) is the inputerrorarray.Custom errors for source segments can be calculated using the
error_cutout_maskedandbackground_cutout_maskedproperties, which are 2DMaskedArraycutout versions of the inputerrorandbackgroundarrays. The mask isTruefor pixels outside the source segment, masked pixels from themaskinput, or any non-finitedatavalues (NaN and inf).Scalar vs. Multi-source Catalogs
A
SourceCatalogcan represent a single source or multiple sources. Most properties adapt their return type accordingly: for a multi-source catalog, properties return arrays or lists (one element per source); for a single-source (scalar) catalog, the same properties return a scalar value or a single object. For example,kron_aperturereturns a list of aperture objects for a multi-source catalog, but a single aperture object for a scalar catalog. Similarly,data_cutoutreturns a list of 2D cutout arrays for a multi-source catalog, but a single 2D array for a scalar catalog. A scalar catalog is created when the a multi-source catalog is indexed to select a single source.Attributes Summary
The total unmasked area of the source in units of pixels**2.
The value of the per-pixel
backgroundat the position of the isophotal (center-of-mass)centroid.A 2D
ndarraycutout from the background array using the minimal bounding box of the source.A 2D
MaskedArraycutout from the background array.The mean of
backgroundvalues within the source segment.The sum of
backgroundvalues within the source segment.The
BoundingBoxof the minimal rectangular region containing the source segment.The maximum
xpixel index within the minimal bounding box containing the source segment.The minimum
xpixel index within the minimal bounding box containing the source segment.The maximum
ypixel index within the minimal bounding box containing the source segment.The minimum
ypixel index within the minimal bounding box containing the source segment.The
(x, y)coordinate of the centroid within the isophotal source segment.The
(x, y)centroid coordinate, calculated by fitting a 2D quadratic polynomial to the unmasked pixels in the source segment.The
(x, y)coordinate of the "windowed" centroid.A 2D
ndarraycutout from the convolved data using the minimal bounding box of the source.A 2D
MaskedArraycutout from the convolved data using the minimal bounding box of the source.The covariance matrix of the 2D Gaussian function that has the same second-order moments as the source.
The two eigenvalues of the
covariancematrix in decreasing order.The
(0, 0)element of thecovariancematrix, representing \(\sigma_x^2\), in units of pixel**2.The
(0, 1)and(1, 0)elements of thecovariancematrix, representing \(\sigma_x \sigma_y\), in units of pixel**2.The
(1, 1)element of thecovariancematrix, representing \(\sigma_y^2\), in units of pixel**2.A list of the user-defined source properties.
The
(x, y)coordinate, relative to the cutout data, of the centroid within the isophotal source segment.The
(x, y)centroid coordinate, relative to the cutout data, calculated by fitting a 2D quadratic polynomial to the unmasked pixels in the source segment.The
(x, y)coordinate, relative to the cutout data, of the "windowed" centroid.The
(y, x)coordinate, relative to the cutout data, of the maximum pixel value of thedatawithin the source segment.The
(y, x)coordinate, relative to the cutout data, of the minimum pixel value of thedatawithin the source segment.A 2D
ndarraycutout from the data using the minimal bounding box of the source.A 2D
MaskedArraycutout from the data using the minimal bounding box of the source.The eccentricity of the 2D Gaussian function that has the same second-order moments as the source.
Coefficient for
x**2in the generalized ellipse equation in units of pixel**(-2).Coefficient for
x * yin the generalized ellipse equation in units of pixel**(-2).Coefficient for
y**2in the generalized ellipse equation in units of pixel**(-2).1.0 minus the ratio of the lengths of the semimajor and semiminor axes.
The ratio of the lengths of the semimajor and semiminor axes.
The radius of a circle with the same
areaas the source segment.A 2D
ndarraycutout from the error array using the minimal bounding box of the source.A 2D
MaskedArraycutout from the error array using the minimal bounding box of the 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.
The Gini coefficient of the source.
The inertia tensor of the source for the rotation around its center of mass.
Whether the instance is scalar (e.g., a single source).
The elliptical (or circular) Kron aperture.
The flux in the Kron aperture.
The flux error in the Kron aperture.
The unscaled first-moment Kron radius.
The source label number(s).
The source label number(s), always as an iterable
ndarray.The local background value (per pixel) estimated using a rectangular annulus aperture around the source.
The
RectangularAnnulusaperture used to estimate the local background.The maximum pixel value of the
datawithin the source segment.The
(y, x)coordinate of the maximum pixel value of thedatawithin the source segment.The
xcoordinate of the maximum pixel value of thedatawithin the source segment.The
ycoordinate of the maximum pixel value of thedatawithin the source segment.The minimum pixel value of the
datawithin the source segment.The
(y, x)coordinate of the minimum pixel value of thedatawithin the source segment.The
xcoordinate of the minimum pixel value of thedatawithin the source segment.The
ycoordinate of the minimum pixel value of thedatawithin the source segment.Spatial moments up to 3rd order of the source.
Central moments (translation invariant) of the source up to 3rd order.
The number of source labels.
The angle between the
xaxis and the major axis of the 2D Gaussian function that has the same second-order moments as the source.The perimeter of the source segment, approximated as the total length of lines connecting the centers of the border pixels defined by a 4-pixel connectivity.
A list of built-in source properties.
The total area of the source segment in units of pixels**2.
A 2D
ndarraycutout of the segmentation image using the minimal bounding box of the source.A 2D
MaskedArraycutout of the segmentation image using the minimal bounding box of the source.The sum of the unmasked
datavalues within the source segment.The uncertainty of
segment_flux, propagated from the inputerrorarray.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.
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.
The sky coordinates of the lower-left corner vertex of the minimal bounding box of the source segment, returned as a
SkyCoordobject.The sky coordinates of the lower-right corner vertex of the minimal bounding box of the source segment, returned as a
SkyCoordobject.The sky coordinates of the upper-left corner vertex of the minimal bounding box of the source segment, returned as a
SkyCoordobject.The sky coordinates of the upper-right corner vertex of the minimal bounding box of the source segment, returned as a
SkyCoordobject.The sky coordinate of the
centroidwithin the source segment, returned as aSkyCoordobject.The sky coordinate in the International Celestial Reference System (ICRS) frame of the
centroidwithin the source segment, returned as aSkyCoordobject.The sky coordinate of the centroid (
centroid_quad), calculated by fitting a 2D quadratic polynomial to the unmasked pixels in the source segment.The sky coordinate of the "windowed" centroid (
centroid_win) within the source segment, returned as aSkyCoordobject.A tuple of slice objects defining the minimal bounding box of the source.
The
xcoordinate of thecentroidwithin the source segment.The
xcoordinate of the centroid (centroid_quad), calculated by fitting a 2D quadratic polynomial to the unmasked pixels in the source segment.The
xcoordinate of the "windowed" centroid (centroid_win).The
ycoordinate of thecentroidwithin the source segment.The
ycoordinate of the centroid (centroid_quad), calculated by fitting a 2D quadratic polynomial to the unmasked pixels in the source segment.The
ycoordinate of the "windowed" centroid (centroid_win).Methods Summary
add_property(name, value[, overwrite])Add a user-defined property as a new attribute.
circular_photometry(radius[, name, overwrite])Perform circular aperture photometry for each source.
copy()Return a deep copy of this SourceCatalog.
flux_radius(fraction[, name, overwrite])Calculate the circular radius that encloses the specified fraction of the Kron flux.
kron_photometry(kron_params[, name, overwrite])Perform photometry for each source using an elliptical Kron aperture.
make_circular_apertures(radius)Make circular aperture for each source.
make_cutouts(shape, *[, array, mode, fill_value])Make cutout arrays for each source.
make_kron_apertures([kron_params])Make Kron apertures for each source.
plot_circular_apertures(radius[, ax, origin])Plot circular apertures for each source on a matplotlib
Axesinstance.plot_kron_apertures([kron_params, ax, origin])Plot Kron apertures for each source on a matplotlib
Axesinstance.remove_properties(names)Remove user-defined properties.
remove_property(name)Remove a user-defined property.
rename_property(name, new_name)Rename a user-defined property.
select_label(label)Return a new
SourceCatalogobject for the inputlabelonly.select_labels(labels)Return a new
SourceCatalogobject for the inputlabelsonly.to_table([columns])Create a
QTableof source properties.Attributes Documentation
- area#
The total unmasked area of the source in units of pixels**2.
Note that the source area may be smaller than its
segment_areaif a mask is input toSourceCatalogor if thedatawithin the segment contains invalid values (NaN and inf).
- background_centroid#
The value of the per-pixel
backgroundat the position of the isophotal (center-of-mass)centroid.If
detection_catalogis input, then itscentroidwill be used.The background values at fractional position values are determined using bilinear interpolation.
- background_cutout#
A 2D
ndarraycutout from the background array using the minimal bounding box of the source.Returns a list of arrays for multi-source catalogs, or a single array for a single-source catalog.
- background_cutout_masked#
A 2D
MaskedArraycutout from the background array. using the minimal bounding box of the source.The mask is
Truefor pixels outside the source segment (labeled region of interest), masked pixels from themaskinput, or any non-finitedatavalues (NaN and inf).Returns a list of arrays for multi-source catalogs, or a single array for a single-source catalog.
- background_mean#
The mean of
backgroundvalues within the source segment.Pixel values that are masked in the input
data, including any non-finite pixel values (NaN and inf) that are automatically masked, are also masked in the background array.
- background_sum#
The sum of
backgroundvalues within the source segment.Pixel values that are masked in the input
data, including any non-finite pixel values (NaN and inf) that are automatically masked, are also masked in the background array.
- bbox#
The
BoundingBoxof the minimal rectangular region containing the source segment.Returns a list for multi-source catalogs, or a single
BoundingBoxfor a single-source catalog.
- bbox_xmax#
The maximum
xpixel index within the minimal bounding box containing the source segment.Note that this value is inclusive, unlike numpy slice indices.
- bbox_xmin#
The minimum
xpixel index within the minimal bounding box containing the source segment.
- bbox_ymax#
The maximum
ypixel index within the minimal bounding box containing the source segment.Note that this value is inclusive, unlike numpy slice indices.
- bbox_ymin#
The minimum
ypixel index within the minimal bounding box containing the source segment.
- centroid#
The
(x, y)coordinate of the centroid within the isophotal source segment.The centroid is computed as the center of mass of the unmasked pixels within the source segment.
- centroid_quad#
The
(x, y)centroid coordinate, calculated by fitting a 2D quadratic polynomial to the unmasked pixels in the source segment.Notes
centroid_quadraticis used to calculate the centroid withfit_boxsize=3.Because this centroid is based on fitting data, it can fail for many reasons, returning (np.nan, np.nan):
quadratic fit failed
quadratic fit does not have a maximum
quadratic fit maximum falls outside image
not enough unmasked data points (6 are required)
Also note that a fit is not performed if the maximum data value is at the edge of the source segment. In this case, the position of the maximum pixel will be returned.
- centroid_win#
The
(x, y)coordinate of the “windowed” centroid.The window centroid is computed using an iterative algorithm to derive a more accurate centroid. It is equivalent to SourceExtractor’s XWIN_IMAGE and YWIN_IMAGE parameters.
Notes
During each iteration, the centroid is calculated using all pixels within a circular aperture of
4 * sigmafrom the current position, weighting pixel values with a 2D Gaussian with a standard deviation ofsigma.sigmais the half-light radius (i.e.,flux_radius(0.5)) times (2.0 / 2.35). A minimum half-light radius of 0.5 pixels is used. Iteration stops when the change in centroid position falls below a pre-defined threshold or a maximum number of iterations is reached.If the windowed centroid falls outside the 1-sigma ellipse shape based on the image moments, then the isophotal
centroidwill be used instead. If the half-light radius is not finite (e.g., due to a non-finite Kron radius), thennp.nanwill be returned.
- conv_data_cutout#
A 2D
ndarraycutout from the convolved data using the minimal bounding box of the source.Returns a list of arrays for multi-source catalogs, or a single array for a single-source catalog.
- conv_data_cutout_masked#
A 2D
MaskedArraycutout from the convolved data using the minimal bounding box of the source.The mask is
Truefor pixels outside the source segment (labeled region of interest), masked pixels from themaskinput, or any non-finitedatavalues (NaN and inf).Returns a list of arrays for multi-source catalogs, or a single array for a single-source catalog.
- 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
covariancematrix in decreasing order.
- covariance_xx#
The
(0, 0)element of thecovariancematrix, representing \(\sigma_x^2\), in units of pixel**2.
- covariance_xy#
The
(0, 1)and(1, 0)elements of thecovariancematrix, representing \(\sigma_x \sigma_y\), in units of pixel**2.
- covariance_yy#
The
(1, 1)element of thecovariancematrix, representing \(\sigma_y^2\), in units of pixel**2.
- custom_properties#
A list of the user-defined source properties.
- cutout_centroid#
The
(x, y)coordinate, relative to the cutout data, of the centroid within the isophotal source segment.The centroid is computed as the center of mass of the unmasked pixels within the source segment.
- cutout_centroid_quad#
The
(x, y)centroid coordinate, relative to the cutout data, calculated by fitting a 2D quadratic polynomial to the unmasked pixels in the source segment.Notes
centroid_quadraticis used to calculate the centroid withfit_boxsize=3.Because this centroid is based on fitting data, it can fail for many reasons including:
quadratic fit failed
quadratic fit does not have a maximum
quadratic fit maximum falls outside image
not enough unmasked data points (6 are required)
In these cases, then the isophotal
centroidwill be used instead.Also note that a fit is not performed if the maximum data value is at the edge of the source segment. In this case, the position of the maximum pixel will be returned.
- cutout_centroid_win#
The
(x, y)coordinate, relative to the cutout data, of the “windowed” centroid.The window centroid is computed using an iterative algorithm to derive a more accurate centroid. It is equivalent to SourceExtractor’s XWIN_IMAGE and YWIN_IMAGE parameters. See
centroid_winfor further details about the algorithm.
- cutout_max_value_index#
The
(y, x)coordinate, relative to the cutout data, of the maximum pixel value of thedatawithin the source segment.If there are multiple occurrences of the maximum value, only the first occurrence is returned.
- cutout_min_value_index#
The
(y, x)coordinate, relative to the cutout data, of the minimum pixel value of thedatawithin the source segment.If there are multiple occurrences of the minimum value, only the first occurrence is returned.
- data_cutout#
A 2D
ndarraycutout from the data using the minimal bounding box of the source.Returns a list of arrays for multi-source catalogs, or a single array for a single-source catalog.
- data_cutout_masked#
A 2D
MaskedArraycutout from the data using the minimal bounding box of the source.The mask is
Truefor pixels outside the source segment (labeled region of interest), masked pixels from themaskinput, or any non-finitedatavalues (NaN and inf).Returns a list of arrays for multi-source catalogs, or a single array for a single-source catalog.
- eccentricity#
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#
Coefficient for
x**2in 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).
SourceExtractor reports that the isophotal limit of a source is well represented by \(R \approx 3\).
- ellipse_cxy#
Coefficient for
x * yin 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).
SourceExtractor reports that the isophotal limit of a source is well represented by \(R \approx 3\).
- ellipse_cyy#
Coefficient for
y**2in 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).
SourceExtractor reports that the isophotal limit of a source is well represented by \(R \approx 3\).
- ellipticity#
1.0 minus the ratio of the lengths of the semimajor and semiminor axes.
\[\mathrm{ellipticity} = \frac{a - b}{a} = 1 - \frac{b}{a}\]where \(a\) and \(b\) are the lengths of the semimajor and semiminor axes, respectively.
- elongation#
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_cutout#
A 2D
ndarraycutout from the error array using the minimal bounding box of the source.Returns a list of arrays for multi-source catalogs, or a single array for a single-source catalog.
- error_cutout_masked#
A 2D
MaskedArraycutout from the error array using the minimal bounding box of the source.The mask is
Truefor pixels outside the source segment (labeled region of interest), masked pixels from themaskinput, or any non-finitedatavalues (NaN and inf).Returns a list of arrays for multi-source catalogs, or a single array for a single-source catalog.
- 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.
\[\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#
The Gini coefficient of the source.
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^{n}_{i} (2i - n - 1) \left | x_i \right |\]where \(\overline{|x|}\) is the mean of the absolute value of all pixel values \(x_i\). If the sum of all pixel values is 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.
- inertia_tensor#
The inertia tensor of the source for the rotation around its center of mass.
- isscalar#
Whether the instance is scalar (e.g., a single source).
- kron_aperture#
The elliptical (or circular) Kron aperture.
The Kron aperture is calculated for each source using its shape parameters,
kron_radius, and thekron_paramsscaling and minimum values input intoSourceCatalog. The Kron aperture is used to compute the Kron photometry.If
kron_params[0]*kron_radius* sqrt(semimajor_axis*semiminor_axis) is less than or equal to the minimum circular radius (kron_params[2]), then the Kron aperture will be a circle with this minimum radius.The aperture will be
Nonewhere the sourcecentroidposition or elliptical shape parameters are not finite or where the source is completely masked.If a
detection_catalogwas input toSourceCatalog, then itskron_aperturewill be returned.Returns a list of apertures for multi-source catalogs, or a single aperture for a single-source catalog.
- kron_flux#
The flux in the Kron aperture.
See the
SourceCatalogaperture_mask_methodkeyword for options to mask neighboring sources.If the Kron aperture is
None, thennp.nanwill be returned. This will occur where the sourcecentroidposition or elliptical shape parameters are not finite or where the source is completely masked.
- kron_flux_err#
The flux error in the Kron aperture.
See the
SourceCatalogaperture_mask_methodkeyword for options to mask neighboring sources.If the Kron aperture is
None, thennp.nanwill be returned. This will occur where the sourcecentroidposition or elliptical shape parameters are not finite or where the source is completely masked.
- kron_radius#
The unscaled first-moment Kron radius.
The unscaled first-moment Kron radius is given by:
\[r_k = \frac{\sum_{i \in A} \ r_i I_i}{\sum_{i \in A} I_i}\]where \(I_i\) are the data values and the sum is over pixels in an elliptical aperture whose axes are defined by six times the semimajor (
semimajor_axis) and semiminor axes (semiminor_axis) at the calculatedorientation(all properties derived from the central image moments of the source). \(r_i\) is the elliptical “radius” to the pixel given by:\[r_i^2 = cxx (x_i - \bar{x})^2 + cxy (x_i - \bar{x})(y_i - \bar{y}) + cyy (y_i - \bar{y})^2\]where \(\bar{x}\) and \(\bar{y}\) represent the source
centroidand the coefficients are based on image moments (ellipse_cxx,ellipse_cxy, andellipse_cyy).The
kron_radiusvalue is the unscaled moment value. The minimum unscaled radius can be set using the second element of theSourceCatalogkron_paramskeyword. If the measured unscaled Kron radius exceeds 6.0 (the measurement aperture scale factor),np.nanwill be returned. Such values are unphysical, typically caused by near-cancellation in the denominator of the Kron formula due to outlier pixels or noise.If either the numerator or denominator above is less than or equal to 0, then the minimum unscaled Kron radius (
kron_params[1]) will be used.The Kron aperture is calculated for each source using its shape parameters,
kron_radius, and thekron_paramsscaling and minimum values input intoSourceCatalog. The Kron aperture is used to compute the Kron photometry.If
kron_params[0]*kron_radius* sqrt(semimajor_axis*semiminor_axis) is less than or equal to the minimum circular radius (kron_params[2]), then the Kron radius will be set to zero and the Kron aperture will be a circle with this minimum radius.If the source is completely masked, then
np.nanwill be returned for both the Kron radius and Kron flux (the Kron aperture will beNone).If a
detection_catalogwas input toSourceCatalog, then itskron_radiuswill be returned.See the
SourceCatalogaperture_mask_methodkeyword for options to mask neighboring sources.
- label#
The source label number(s).
This label number corresponds to the assigned pixel value in the
SegmentationImage.Returns an array for multi-source catalogs, or a scalar for a single-source catalog.
- labels#
The source label number(s), always as an iterable
ndarray.This label number corresponds to the assigned pixel value in the
SegmentationImage.
- local_background#
The local background value (per pixel) estimated using a rectangular annulus aperture around the source.
- local_background_aperture#
The
RectangularAnnulusaperture used to estimate the local background.Returns a list of apertures for multi-source catalogs, or a single aperture for a single-source catalog.
- max_value#
The maximum pixel value of the
datawithin the source segment.
- max_value_index#
The
(y, x)coordinate of the maximum pixel value of thedatawithin the source segment.If there are multiple occurrences of the maximum value, only the first occurrence is returned.
- max_value_xindex#
The
xcoordinate of the maximum pixel value of thedatawithin the source segment.If there are multiple occurrences of the maximum value, only the first occurrence is returned.
- max_value_yindex#
The
ycoordinate of the maximum pixel value of thedatawithin the source segment.If there are multiple occurrences of the maximum value, only the first occurrence is returned.
- min_value#
The minimum pixel value of the
datawithin the source segment.
- min_value_index#
The
(y, x)coordinate of the minimum pixel value of thedatawithin the source segment.If there are multiple occurrences of the minimum value, only the first occurrence is returned.
- min_value_xindex#
The
xcoordinate of the minimum pixel value of thedatawithin the source segment.If there are multiple occurrences of the minimum value, only the first occurrence is returned.
- min_value_yindex#
The
ycoordinate of the minimum pixel value of thedatawithin the source segment.If there are multiple occurrences of the minimum value, only the first occurrence is returned.
- moments#
Spatial moments up to 3rd order of the source.
- moments_central#
Central moments (translation invariant) of the source up to 3rd order.
- n_labels#
The number of source labels.
- orientation#
The angle between the
xaxis and the major axis of the 2D Gaussian function that has the same second-order moments as the source.The angle increases in the counter-clockwise direction and will be in the range [0, 360) degrees.
- perimeter#
The perimeter of the source segment, approximated as the total length of lines connecting the centers of the border pixels defined by a 4-pixel connectivity.
If any masked pixels make holes within the source segment, then the perimeter around the inner hole (e.g., an annulus) will also contribute to the total perimeter.
References
[1]K. Benkrid, D. Crookes, and A. Benkrid. “Design and FPGA Implementation of a Perimeter Estimator”. Proceedings of the Irish Machine Vision and Image Processing Conference, pp. 51-57 (2000).
- properties#
A list of built-in source properties.
- segment_area#
The total area of the source segment in units of pixels**2.
This area is simply the area of the source segment from the input
segmentation_image. It does not take into account any data masking (i.e., amaskinput toSourceCatalogor invaliddatavalues).
- segment_cutout#
A 2D
ndarraycutout of the segmentation image using the minimal bounding box of the source.Returns a list of arrays for multi-source catalogs, or a single array for a single-source catalog.
- segment_cutout_masked#
A 2D
MaskedArraycutout of the segmentation image using the minimal bounding box of the source.The mask is
Truefor pixels outside the source segment (labeled region of interest), masked pixels from themaskinput, or any non-finitedatavalues (NaN and inf).Returns a list of arrays for multi-source catalogs, or a single array for a single-source catalog.
- segment_flux#
The sum of the unmasked
datavalues within the source segment.\[F = \sum_{i \in S} I_i\]where \(F\) is
segment_flux, \(I_i\) is the background-subtracteddata, and \(S\) are the unmasked pixels in the source segment.Non-finite pixel values (NaN and inf) are excluded (automatically masked).
- segment_flux_err#
The uncertainty of
segment_flux, propagated from the inputerrorarray.segment_flux_erris the quadrature sum of the total errors over the unmasked pixels within the source segment:\[\Delta F = \sqrt{\sum_{i \in S} \sigma_{\mathrm{tot}, i}^2}\]where \(\Delta F\) is the
segment_flux_err, \(\sigma_{\mathrm{tot, i}}\) are the pixel-wise total errors (error), and \(S\) are the unmasked pixels in the source segment.Pixel values that are masked in the input
data, including any non-finite pixel values (NaN and inf) that are automatically masked, are also masked in the error array.
- 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_bbox_ll#
The sky coordinates of the lower-left corner vertex of the minimal bounding box of the source segment, returned as a
SkyCoordobject.The bounding box encloses all the source segment pixels in their entirety, thus the vertices are at the pixel corners, not their centers.
Noneifwcsis not input.
- sky_bbox_lr#
The sky coordinates of the lower-right corner vertex of the minimal bounding box of the source segment, returned as a
SkyCoordobject.The bounding box encloses all the source segment pixels in their entirety, thus the vertices are at the pixel corners, not their centers.
Noneifwcsis not input.
- sky_bbox_ul#
The sky coordinates of the upper-left corner vertex of the minimal bounding box of the source segment, returned as a
SkyCoordobject.The bounding box encloses all the source segment pixels in their entirety, thus the vertices are at the pixel corners, not their centers.
Noneifwcsis not input.
- sky_bbox_ur#
The sky coordinates of the upper-right corner vertex of the minimal bounding box of the source segment, returned as a
SkyCoordobject.The bounding box encloses all the source segment pixels in their entirety, thus the vertices are at the pixel corners, not their centers.
Noneifwcsis not input.
- sky_centroid#
The sky coordinate of the
centroidwithin the source segment, returned as aSkyCoordobject.The output coordinate frame is the same as the input
wcs.Noneifwcsis not input.
- sky_centroid_icrs#
The sky coordinate in the International Celestial Reference System (ICRS) frame of the
centroidwithin the source segment, returned as aSkyCoordobject.Noneifwcsis not input.
- sky_centroid_quad#
The sky coordinate of the centroid (
centroid_quad), calculated by fitting a 2D quadratic polynomial to the unmasked pixels in the source segment.The output coordinate frame is the same as the input
wcs.Noneifwcsis not input.
- sky_centroid_win#
The sky coordinate of the “windowed” centroid (
centroid_win) within the source segment, returned as aSkyCoordobject.The output coordinate frame is the same as the input
wcs.Noneifwcsis not input.
- slices#
A tuple of slice objects defining the minimal bounding box of the source.
Returns a list for multi-source catalogs, or a single tuple for a single-source catalog.
- x_centroid#
The
xcoordinate of thecentroidwithin the source segment.The centroid is computed as the center of mass of the unmasked pixels within the source segment.
- x_centroid_quad#
The
xcoordinate of the centroid (centroid_quad), calculated by fitting a 2D quadratic polynomial to the unmasked pixels in the source segment.
- x_centroid_win#
The
xcoordinate of the “windowed” centroid (centroid_win).The window centroid is computed using an iterative algorithm to derive a more accurate centroid. It is equivalent to SourceExtractor’s XWIN_IMAGE parameters.
- y_centroid#
The
ycoordinate of thecentroidwithin the source segment.The centroid is computed as the center of mass of the unmasked pixels within the source segment.
- y_centroid_quad#
The
ycoordinate of the centroid (centroid_quad), calculated by fitting a 2D quadratic polynomial to the unmasked pixels in the source segment.
- y_centroid_win#
The
ycoordinate of the “windowed” centroid (centroid_win).The window centroid is computed using an iterative algorithm to derive a more accurate centroid. It is equivalent to SourceExtractor’s YWIN_IMAGE parameters.
Methods Documentation
- add_property(name, value, overwrite=False)[source]#
Add a user-defined property as a new attribute.
For example, the property
namecan then be included in theto_tablecolumnskeyword list to output the results in the table.The complete list of user-defined properties is stored in the
custom_propertiesattribute.- Parameters:
- namestr
The name of property. The name must not conflict with any of the built-in property names or attributes.
- valuearray_like or float
The value to assign.
- overwritebool, option
If
True, will overwrite the existing propertyname.
- circular_photometry(radius, name=None, overwrite=False)[source]#
Perform circular aperture photometry for each source.
The circular aperture for each source will be centered at its
centroidposition. If adetection_catalogwas input toSourceCatalog, then itscentroidvalues will be used.See the
SourceCatalogaperture_mask_methodkeyword for options to mask neighboring sources.- Parameters:
- radiusfloat
The radius of the circle in pixels.
- namestr or
None, optional The prefix name which will be used to define attribute names for the flux and flux error. The attribute names
[name]_fluxand[name]_flux_errwill store the photometry results. For example, these names can then be included in theto_tablecolumnskeyword list to output the results in the table.- overwritebool, optional
If True, overwrite the attribute
nameif it exists.
- Returns:
- copy()[source]#
Return a deep copy of this SourceCatalog.
- Returns:
- result
SourceCatalog A deep copy of this object.
- result
- flux_radius(fraction, name=None, overwrite=False)[source]#
Calculate the circular radius that encloses the specified fraction of the Kron flux.
To estimate the half-light radius, use
fraction = 0.5.- Parameters:
- fractionfloat
The fraction of the Kron flux at which to find the circular radius.
- namestr or
None, optional The attribute name which will be assigned to the value of the output array. For example, this name can then be included in the
to_tablecolumnskeyword list to output the results in the table.- overwritebool, optional
If True, overwrite the attribute
nameif it exists.
- Returns:
- radius1D
ndarray The circular radius that encloses the specified fraction of the Kron flux. NaN is returned where no solution was found or where the Kron flux is zero or non-finite.
- radius1D
- kron_photometry(kron_params, name=None, overwrite=False)[source]#
Perform photometry for each source using an elliptical Kron aperture.
This method can be used to calculate the Kron photometry using alternate
kron_params(e.g., different scalings of the Kron radius).See the
SourceCatalogaperture_mask_methodkeyword for options to mask neighboring sources.- Parameters:
- kron_paramslist of 2 or 3 floats, optional
A list of parameters used to determine the Kron aperture. The first item is the scaling parameter of the unscaled Kron radius and the second item represents the minimum value for the unscaled Kron radius in pixels. The optional third item is the minimum circular radius in pixels. If
kron_params[0]*kron_radius* sqrt(semimajor_axis*semiminor_axis) is less than or equal to this radius, then the Kron aperture will be a circle with this minimum radius.- namestr or
None, optional The prefix name which will be used to define attribute names for the Kron flux and flux error. The attribute names
[name]_fluxand[name]_flux_errwill store the photometry results. For example, these names can then be included in theto_tablecolumnskeyword list to output the results in the table.- overwritebool, optional
If True, overwrite the attribute
nameif it exists.
- Returns:
- make_circular_apertures(radius)[source]#
Make circular aperture for each source.
The aperture for each source will be centered at its
centroidposition. If adetection_catalogwas input toSourceCatalog, then itscentroidvalues will be used.- Parameters:
- radiusfloat
The radius of the circle in pixels.
- Returns:
- result
CircularApertureor list ofCircularAperture The circular aperture for each source. The aperture will be
Nonewhere the sourcecentroidposition is not finite or where the source is completely masked.
- result
- make_cutouts(shape, *, array=None, mode='partial', fill_value=nan)[source]#
Make cutout arrays for each source.
The cutout for each source will be centered at its
centroidposition. If adetection_catalogwas input toSourceCatalog, then itscentroidvalues will be used.- Parameters:
- shape2-tuple
The cutout shape along each axis in
(ny, nx)order.- array
Noneor 2Dndarray A 2D array with the same shape as the
dataarray input toSourceCatalog. IfNonethen thedataarray will be used. If any cutout arrays are not fully contained within thearrayarray andmode='partial'withfill_value=np.nan, then the inputarraymust have a float data type.- mode{‘partial’, ‘trim’}, optional
The mode used for extracting the cutout array. In
'partial'mode, positions in the cutout array that do not overlap with the large array will be filled withfill_value. In'trim'mode, only the overlapping elements are returned, thus the resulting small array may be smaller than the requestedshape.- fill_valuenumber, optional
If
mode='partial', the value to fill pixels in the extracted cutout array that do not overlap with the inputarray_large.fill_valuewill be changed to have the samedtypeas thearray_largearray, with one exception. Ifarray_largehas integer type andfill_valueisnp.nan, then aValueErrorwill be raised.
- Returns:
- cutouts
CutoutImageor list ofCutoutImage The
CutoutImagefor each source. The cutout will beNonewhere the sourcecentroidposition is not finite or where the source is completely masked.
- cutouts
- make_kron_apertures(kron_params=None)[source]#
Make Kron apertures for each source.
The aperture for each source will be centered at its
centroidposition. If adetection_catalogwas input toSourceCatalog, then itscentroidvalues will be used.Note that changing
kron_paramsfrom the values input intoSourceCatalogdoes not change the Kron apertures (kron_aperture) and photometry (kron_fluxandkron_flux_err) in the source catalog. This method should be used only to explore alternativekron_paramswith a detection image.- Parameters:
- kron_paramslist of 2 or 3 floats or
None, optional A list of parameters used to determine the Kron aperture. The first item is the scaling parameter of the unscaled Kron radius and the second item represents the minimum value for the unscaled Kron radius in pixels. The optional third item is the minimum circular radius in pixels. If
kron_params[0]*kron_radius* sqrt(semimajor_axis*semiminor_axis) is less than or equal to this radius, then the Kron aperture will be a circle with this minimum radius. IfNone, then thekron_paramsinput intoSourceCatalogwill be used (the apertures will be the same as those inkron_aperture).
- kron_paramslist of 2 or 3 floats or
- Returns:
- result
PixelApertureor list ofPixelAperture The Kron apertures for each source. Each aperture will either be a
EllipticalAperture,CircularAperture, orNone. The aperture will beNonewhere the sourcecentroidposition or elliptical shape parameters are not finite or where the source is completely masked.
- result
- plot_circular_apertures(radius, ax=None, origin=(0, 0), **kwargs)[source]#
Plot circular apertures for each source on a matplotlib
Axesinstance.The aperture for each source will be centered at its
centroidposition. If adetection_catalogwas input toSourceCatalog, then itscentroidvalues will be used.An aperture will not be plotted for sources where the source
centroidposition is not finite or where the source is completely masked.- Parameters:
- radiusfloat
The radius of the circle in pixels.
- ax
matplotlib.axes.AxesorNone, optional The matplotlib axes on which to plot. If
None, then the currentAxesinstance is used.- originarray_like, optional
The
(x, y)position of the origin of the displayed image.- **kwargsdict, optional
Any keyword arguments accepted by
matplotlib.patches.Patch.
- Returns:
- plot_kron_apertures(kron_params=None, ax=None, origin=(0, 0), **kwargs)[source]#
Plot Kron apertures for each source on a matplotlib
Axesinstance.The aperture for each source will be centered at its
centroidposition. If adetection_catalogwas input toSourceCatalog, then itscentroidvalues will be used.An aperture will not be plotted for sources where the source
centroidposition or elliptical shape parameters are not finite or where the source is completely masked.Note that changing
kron_paramsfrom the values input intoSourceCatalogdoes not change the Kron apertures (kron_aperture) and photometry (kron_fluxandkron_flux_err) in the source catalog. This method should be used only to visualize/explore alternativekron_paramswith a detection image.- Parameters:
- kron_paramslist of 2 or 3 floats or
None, optional A list of parameters used to determine the Kron aperture. The first item is the scaling parameter of the unscaled Kron radius and the second item represents the minimum value for the unscaled Kron radius in pixels. The optional third item is the minimum circular radius in pixels. If
kron_params[0]*kron_radius* sqrt(semimajor_axis*semiminor_axis) is less than or equal to this radius, then the Kron aperture will be a circle with this minimum radius. IfNone, then thekron_paramsinput intoSourceCatalogwill be used (the apertures will be the same as those inkron_aperture).- ax
matplotlib.axes.AxesorNone, optional The matplotlib axes on which to plot. If
None, then the currentAxesinstance is used.- originarray_like, optional
The
(x, y)position of the origin of the displayed image.- **kwargsdict, optional
Any keyword arguments accepted by
matplotlib.patches.Patch.
- kron_paramslist of 2 or 3 floats or
- Returns:
- patchlist of
Patch A list of matplotlib patches for the plotted aperture. The patches can be used, for example, when adding a plot legend.
- patchlist of
- remove_properties(names)[source]#
Remove user-defined properties.
The properties must have been defined using
add_property. The complete list of user-defined properties is stored in thecustom_propertiesattribute.- Parameters:
- nameslist of str or str
The names of the properties to remove.
- remove_property(name)[source]#
Remove a user-defined property.
The property must have been defined using
add_property. The complete list of user-defined properties is stored in thecustom_propertiesattribute.- Parameters:
- namestr
The name of the property to remove.
- rename_property(name, new_name)[source]#
Rename a user-defined property.
The renamed property will remain at the same index in the
custom_propertieslist.- Parameters:
- namestr
The old attribute name.
- new_namestr
The new attribute name.
- select_label(label)[source]#
Return a new
SourceCatalogobject for the inputlabelonly.- Parameters:
- labelint
The source label.
- Returns:
- cat
SourceCatalog A new
SourceCatalogobject containing only the source with the inputlabel.
- cat
- select_labels(labels)[source]#
Return a new
SourceCatalogobject for the inputlabelsonly.- Parameters:
- labelslist, tuple, or
ndarrayof int The source label(s).
- labelslist, tuple, or
- Returns:
- cat
SourceCatalog A new
SourceCatalogobject containing only the sources with the inputlabels.
- cat
- to_table(columns=None)[source]#
Create a
QTableof 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 any of theSourceCatalogproperties or custom properties added usingadd_property. IfcolumnsisNone, then a default list of scalar-valued properties (as defined by thedefault_columnsattribute) will be used.
- columnsstr, list of str,
- Returns:
- table
QTable A table of sources properties with one row per source.
- table