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, n_threads=1, 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 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. Nonfinitedatavalues (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.convolved_datamust have the same shape as the inputdata. Ifdatais aQuantityarray thenconvolved_datamust be aQuantityarray (and vice versa) with identical units. Nonfiniteconvolved_datavalues (NaN and inf) are not automatically masked, unless they are at the same position of nonfinite values in the inputdataarray. Such pixels can be masked using themaskkeyword. A pixel with a nonfinitedatavalue and a finiteconvolved_datavalue (e.g., a NaN value thatconvolve()interpolated over) is included in the isophotal centroid and morphological properties with itsconvolved_datavalue, unlike a pixel masked with themaskkeyword. It does not contribute to the errors of the isophotal centroid. To exclude such pixels from these properties, include them in the inputmask(e.g.,mask=~np.isfinite(data)).- 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. Nonfiniteerrorvalues (NaN and inf) are not automatically masked, unless they are at the same position of nonfinite 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. Nonfinite values (NaN and inf) in the inputdataare automatically masked.- background2D
ndarrayorQuantity, optional The background level that was previously present in the input
data.backgroundmust be a 2D image with the same shape as the inputdata. Ifdatais aQuantityarray thenbackgroundmust be aQuantityarray (and vice versa) with identical units. Inputting 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. Nonfinitebackgroundvalues (NaN and inf) are not automatically masked, unless they are at the same position of nonfinite 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 windowed centroids, and
flux_radius. The options are:‘correct’: replace pixels assigned to neighboring sources with the 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_params1D sequence of 2 or 3 floats, optional
The 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. The aperture fluxes andflux_radiusare measured in the inputdatausing the detection catalog centroids and Kron apertures.flux_radiusis the radius that encloses the given fraction of the Kron flux measured in the inputdata, so it is not theflux_radiusof the detection catalog. The windowed centroids are those of the detection catalog, which uses its own half-light radius to compute them.- n_threadsint, optional
The number of threads to use for the compiled per-source measurements: the isophotal moments and their errors, the segment pixel statistics (e.g.,
segment_flux), the windowed and quadratic centroids,perimeter, the local background, the Kron radii and photometry,circular_photometry, andflux_radius, and thus every property derived from them. The default is 1 (no multithreading). Whenn_threads> 1, the sources are divided into chunks that are 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 these measurements for many sources.- progress_barbool, optional
Whether to display a progress bar when calculating properties.
Deprecated since version 3.1: This keyword argument is deprecated and will be removed in version 4.0. All property calculations are now computed for all sources at once in compiled code, so no progress bar is displayed and this keyword has no effect.
- 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. Note thatApertureStatsdoes not set negative values to zero, because an aperture on background-subtracted data contains many negative sky pixels whose removal would bias the centroid and the shape properties.Most properties are computed for all sources at once in compiled code that reads the
data,error,convolved_data, andbackgroundarrays, the segmentation array, and a uint8 mask plane. C-contiguous, native byte-order image arrays that are all float32 or all float64 are read directly, as is a C-contiguous, native byte-order int32 or intp segmentation array, so no copies of them are made. Image arrays that are not all float32 or all float64 (e.g., float32datawith a float64errorarray, or integer arrays) are converted, where needed, to working copies in a common dtype, which is float64 unless every image array is a floating-point array of at most 4 bytes per value. A segmentation array with another integer dtype is converted to intp. Any working copies are built on first use and kept for the lifetime of the catalog (they are shared with sliced catalogs). All calculations are performed in float64 regardless of the input dtype, so float32 inputs give the same results as the same values input as float64 (to within floating-point rounding). If memory is a concern, input all of the image arrays as C-contiguous, native byte-order arrays with the same float32 or float64 dtype. Otherwise, callrelease_cacheafter calculating the desired properties to free the working copies.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.For the aperture-based fluxes (e.g.,
kron_fluxandcircular_photometry), the flux is the sum of the pixel values weighted by their aperture overlap fractions. The flux error therefore weights each pixel variance by the squared overlap fraction: \(\Delta F = \sqrt{\sum_{i \in A} w_i^2 \sigma_{\mathrm{tot}, i}^2}\), where \(w_i\) are the aperture overlap fractions and \(A\) are the unmasked pixels within the aperture.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 nonfinitedatavalues (NaN and inf).Scalar vs. Multisource Catalogs
A
SourceCatalogcan represent a single source or multiple sources. Most properties adapt their return type accordingly. For a multisource 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 multisource catalog, but a single aperture object for a scalar catalog. Similarly,data_cutoutreturns a list of 2D cutout arrays for a multisource catalog, but a single 2D array for a scalar catalog. A scalar catalog is created when a multisource 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
ndarray(orQuantityif the inputdatahas units) cutout from the background array using the minimal bounding box of the source.A 2D
MaskedArraycutout from the background array using the minimal bounding box of the source.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)1-sigma errors on thecentroidposition.The
(x, y)centroid coordinate, calculated by fitting a 2D quadratic polynomial to the 3x3 pixel box centered on the peak pixel of the source segment.The
(x, y)1-sigma errors on the quadratic centroid (centroid_quad) position.A boolean array that is
Truewhere the quadratic centroid (centroid_quad) is not the maximum of a quadratic fit.The
(x, y)coordinate of the "windowed" centroid.The
(x, y)1-sigma errors on the "windowed" centroid (centroid_win) position.A boolean array that is
Truewhere the windowed centroid (centroid_win) fell back to the isophotalcentroidor is NaN.A 2D
ndarray(orQuantityif the inputdatahas units) cutout 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_{xy}\) (the covariance ofxandy), 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 3x3 pixel box centered on the peak pixel of 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
ndarray(orQuantityif the inputdatahas units) cutout 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 semiminor and semimajor 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
ndarray(orQuantityif the inputdatahas units) cutout 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 per-source bitwise quality flags.
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.
Whether the instance is scalar (i.e., a single source selected by indexing a catalog).
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 used to define the Kron aperture.
The measured 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 value of the unmasked
datapixels within 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 value of the unmasked
datapixels within 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 x-axis 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 1-sigma error on the
sky_centroidposition along the Declination direction, in arcsec.The 1-sigma errors on the
sky_centroidposition as a(east, north)Quantityin arcsec.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 3x3 pixel box centered on the peak pixel of the source segment, returned as aSkyCoordobject.The 1-sigma error on the
sky_centroid_quadposition along the Declination direction, in arcsec.The 1-sigma errors on the
sky_centroid_quadposition as a(east, north)Quantityin arcsec.The 1-sigma error on the
sky_centroid_quadposition along the Right Ascension direction, as a great-circle angle in arcsec (i.e., including the cos(dec) factor).The 1-sigma error on the
sky_centroidposition along the Right Ascension direction, as a great-circle angle in arcsec (i.e., including the cos(dec) factor).The sky coordinate of the "windowed" centroid (
centroid_win) within the source segment, returned as aSkyCoordobject.The 1-sigma error on the
sky_centroid_winposition along the Declination direction, in arcsec.The 1-sigma errors on the
sky_centroid_winposition as a(east, north)Quantityin arcsec.The 1-sigma error on the
sky_centroid_winposition along the Right Ascension direction, as a great-circle angle in arcsec (i.e., including the cos(dec) factor).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.
A tuple of slice objects defining the minimal bounding box of the source.
The
xcoordinate of thecentroidwithin the source segment.The 1-sigma error on the
xcoordinate of thecentroid.The
xcoordinate of the centroid (centroid_quad), calculated by fitting a 2D quadratic polynomial to the 3x3 pixel box centered on the peak pixel of the source segment.The 1-sigma error on the
xcoordinate of the quadratic centroid (centroid_quad).The
xcoordinate of the "windowed" centroid (centroid_win).The 1-sigma error on the
xcoordinate of the "windowed" centroid (centroid_win).The
ycoordinate of thecentroidwithin the source segment.The 1-sigma error on the
ycoordinate of thecentroid.The
ycoordinate of the centroid (centroid_quad), calculated by fitting a 2D quadratic polynomial to the 3x3 pixel box centered on the peak pixel of the source segment.The 1-sigma error on the
ycoordinate of the quadratic centroid (centroid_quad).The
ycoordinate of the "windowed" centroid (centroid_win).The 1-sigma error on 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.
decode_flags(*[, return_bit_values])Decode the source quality flags into individual components.
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 a 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.Release the cached full-image working arrays.
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[source]#
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).The area is NaN for a completely masked source. If
detection_catalogis input, then its area is returned, which reflects the mask anddataof the detection catalog.
- background_centroid[source]#
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.
If
backgroundwas not input, then the values are NaN. The value is also NaN where thecentroidis not finite.
- background_cutout[source]#
A 2D
ndarray(orQuantityif the inputdatahas units) cutout from the background array using the minimal bounding box of the source.If
backgroundwas not input, thenNoneis returned for each source.Returns a list of arrays for multisource catalogs, or a single array for a single-source catalog.
- background_cutout_masked[source]#
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 nonfinitedatavalues (NaN and inf).The masked array does not have units, even if the input
datais aQuantity.If
backgroundwas not input, thenNoneis returned for each source.Returns a list of arrays for multisource catalogs, or a single array for a single-source catalog.
- background_mean[source]#
The mean of
backgroundvalues within the source segment.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 background array.If
backgroundwas not input, then the values are NaN.
- background_sum[source]#
The sum of
backgroundvalues within the source segment.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 background array.If
backgroundwas not input, then the values are NaN.
- bbox[source]#
The
BoundingBoxof the minimal rectangular region containing the source segment.Returns a list for multisource catalogs, or a single
BoundingBoxfor a single-source catalog.
- bbox_xmax[source]#
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[source]#
The minimum
xpixel index within the minimal bounding box containing the source segment.
- bbox_ymax[source]#
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[source]#
The minimum
ypixel index within the minimal bounding box containing the source segment.
- centroid[source]#
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_err[source]#
The
(x, y)1-sigma errors on thecentroidposition.The errors are computed by propagating the input
errorarray through the center-of-mass centroid formula. Iferrorwas not input, then the errors are NaN.If a
detection_catalogwas input, then the errors are those of the detection catalog, computed from itserrorarray.For a centroid defined as \(x_c = \sum f_i x_i / F\), the variance is:
\[\text{Var}(x_c) = \frac{\sum_i (x_i - x_c)^2 \sigma_i^2}{F^2}\]The error variance along each principal axis of the error covariance matrix is at least \(\sum_i \sigma_i^2 / (12 F^2)\), the variance of a uniform distribution across a single pixel scaled by the summed pixel variance. This prevents an error close to zero along an axis where the pixels that carry the error span less than a pixel (e.g., an unresolved source). An error variance that already exceeds this value is unchanged.
- centroid_quad[source]#
The
(x, y)centroid coordinate, calculated by fitting a 2D quadratic polynomial to the 3x3 pixel box centered on the peak pixel of the source segment.Notes
The fit follows
centroid_quadraticwithfit_boxsize=3, applied to the bounding-box cutout of the source. Pixels in the cutout that are outside the source segment, masked, or nonfinite are set to zero before the peak is located. Pixels of the 3x3 box that are masked (by the inputmask) or that have a nonfinitedatavalue are left out of the fit. The other pixels of the box enter the fit with theirdatavalues, including pixels that are outside the source segment or that belong to a neighboring source.The isophotal
centroidis returned instead (NaN where the isophotal centroid is NaN) in these cases:the bounding box of the source is smaller than 3 pixels along either axis
the pixels left in the fit do not determine the quadratic polynomial, which requires at least 6 pixels that are not all in two rows or two columns of the box
the quadratic fit does not have a maximum
the quadratic fit maximum falls on or outside the outermost pixel centers of the bounding-box cutout
there are no unmasked pixels within the source segment
A fit is not performed if the peak pixel is at the edge of the bounding-box cutout. In this case, the position of the peak pixel is returned.
The
centroid_quad_fallbackproperty isTruefor sources without a quadratic-fit centroid.
- centroid_quad_err[source]#
The
(x, y)1-sigma errors on the quadratic centroid (centroid_quad) position.The errors are computed by propagating the input
errorarray through the least-squares quadratic fit and its peak solution using the delta method. Iferrorwas not input, then the errors are NaN.If a
detection_catalogwas input, then the errors are those of the detection catalog, computed from itserrorarray.Sources where the quadratic centroid fell back to the isophotal
centroidhave the isophotal centroid errors (seecentroid_err). The errors are NaN for sources where the peak pixel is at the edge of the bounding-box cutout (where the position of the peak pixel is returned instead of a fit).The delta method linearizes the peak solution at the fitted coefficients, whose curvature terms are noisy for faint peaks.
- centroid_quad_fallback[source]#
A boolean array that is
Truewhere the quadratic centroid (centroid_quad) is not the maximum of a quadratic fit.This is the case where the maximum data value is at the edge of the bounding-box cutout (the position of the maximum pixel is returned), where the fit failed (the isophotal
centroidis returned), or where the centroid is NaN. Seecentroid_quadfor details.
- centroid_win[source]#
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 radius
4 * sigmacentered on 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 predefined threshold or a maximum number of iterations is reached.The windowed centroid is reset to the isophotal
centroidif any of the following conditions hold: the centroid diverged far from the isophotal centroid and lies outside the 1-sigma ellipse, the total weighted flux is nonpositive, the windowed 2nd-order moments are negative, the windowed covariance determinant is negative, or the windowed centroid is not finite. If the half-light radius is not finite (e.g., due to a nonfinite Kron radius), thennp.nanwill be returned.
- centroid_win_err[source]#
The
(x, y)1-sigma errors on the “windowed” centroid (centroid_win) position.The errors are computed by propagating the input
errorarray through the Gaussian-weighted windowed centroid formula. Iferrorwas not input, then the errors are NaN.If a
detection_catalogwas input, then the errors are those of the detection catalog, computed from itserrorarray.Sources where the windowed centroid fell back to the isophotal
centroidhave the isophotal centroid errors (seecentroid_err). The errors are NaN where the half-light radius is not finite.
- centroid_win_fallback[source]#
A boolean array that is
Truewhere the windowed centroid (centroid_win) fell back to the isophotalcentroidor is NaN.See
centroid_winfor the fallback conditions.
- conv_data_cutout[source]#
A 2D
ndarray(orQuantityif the inputdatahas units) cutout from the convolved data using the minimal bounding box of the source.Returns a list of arrays for multisource catalogs, or a single array for a single-source catalog.
- conv_data_cutout_masked[source]#
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 nonfinitedatavalues (NaN and inf).The masked array does not have units, even if the input
datais aQuantity.Returns a list of arrays for multisource catalogs, or a single array for a single-source catalog.
- 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/12pixel**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 to1/12while 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 net flux of the source is not positive (e.g., a completely masked source or a source with no positive data values) or if the second-order moments are not positive semidefinite.
- covariance_eigvals[source]#
The two eigenvalues of the
covariancematrix in decreasing order.
- covariance_xx[source]#
The
(0, 0)element of thecovariancematrix, representing \(\sigma_x^2\), in units of pixel**2.
- covariance_xy[source]#
The
(0, 1)and(1, 0)elements of thecovariancematrix, representing \(\sigma_{xy}\) (the covariance ofxandy), in units of pixel**2.
- covariance_yy[source]#
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[source]#
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[source]#
The
(x, y)centroid coordinate, relative to the cutout data, calculated by fitting a 2D quadratic polynomial to the 3x3 pixel box centered on the peak pixel of the source segment.Notes
The fit follows
centroid_quadraticwithfit_boxsize=3, applied to the bounding-box cutout of the source. Pixels in the cutout that are outside the source segment, masked, or nonfinite are set to zero before the peak is located. Pixels of the 3x3 box that are masked (by the inputmask) or that have a nonfinitedatavalue are left out of the fit. The other pixels of the box enter the fit with theirdatavalues, including pixels that are outside the source segment or that belong to a neighboring source.The isophotal centroid (
cutout_centroid) is returned instead (NaN where the isophotal centroid is NaN) in these cases:the bounding box of the source is smaller than 3 pixels along either axis
the pixels left in the fit do not determine the quadratic polynomial, which requires at least 6 pixels that are not all in two rows or two columns of the box
the quadratic fit does not have a maximum
the quadratic fit maximum falls on or outside the outermost pixel centers of the bounding-box cutout
there are no unmasked pixels within the source segment
A fit is not performed if the peak pixel is at the edge of the bounding-box cutout. In this case, the position of the peak pixel is returned.
- cutout_centroid_win[source]#
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. See
centroid_winfor further details about the algorithm.
- cutout_max_value_index[source]#
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.
The coordinates are integers. If any source in the catalog is completely masked, then the coordinates are returned as floats and are
np.nanfor that source.
- cutout_min_value_index[source]#
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.
The coordinates are integers. If any source in the catalog is completely masked, then the coordinates are returned as floats and are
np.nanfor that source.
- data_cutout[source]#
A 2D
ndarray(orQuantityif the inputdatahas units) cutout from the data using the minimal bounding box of the source.Returns a list of arrays for multisource catalogs, or a single array for a single-source catalog.
- data_cutout_masked[source]#
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 nonfinitedatavalues (NaN and inf).The masked array does not have units, even if the input
datais aQuantity.Returns a list of arrays for multisource catalogs, or a single array for a single-source catalog.
- 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**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[source]#
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[source]#
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[source]#
1.0 minus the ratio of the lengths of the semiminor and semimajor 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[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_cutout[source]#
A 2D
ndarray(orQuantityif the inputdatahas units) cutout from the error array using the minimal bounding box of the source.If
errorwas not input, thenNoneis returned for each source.Returns a list of arrays for multisource catalogs, or a single array for a single-source catalog.
- error_cutout_masked[source]#
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 nonfinitedatavalues (NaN and inf).The masked array does not have units, even if the input
datais aQuantity.If
errorwas not input, thenNoneis returned for each source.Returns a list of arrays for multisource catalogs, or a single array for a single-source catalog.
- flags[source]#
The per-source bitwise quality flags.
The flags combine deblending-provenance flags carried by the input segmentation image with measurement-time flags computed from this catalog’s
data,convolved_data,mask,error, and segmentation image. Usedecode_segmentation_flagsto decode the values.If a
detection_catalogwas input, the shape (undefined_shape,singular_covariance) and Kron aperture geometry (kron_undefined,kron_minimum_radius) flags derive from the detection catalog. Thekron_undefinedflag is also set for a source that is completely masked in this catalog, whose Kron flux is NaN. The Kron photometry-loop flags (kron_no_overlap,kron_partial_overlap,kron_masked_pixels,kron_non_finite_data,kron_non_finite_error,kron_neighbor_pixels,kron_uncorrected_pixels), like the segment-level edge, mask, nonfinite,all_masked, andlocal_bkg_too_few_pixelsflags, are evaluated on this catalog’s own inputs.Accessing
flagscomputes the moment, covariance, local background, and Kron-aperture properties if they have not already been computed (the results are cached and reused by those properties). The windowed and quadratic centroid fallbacks are reported by thecentroid_win_fallbackandcentroid_quad_fallbackproperties instead of by flags, so that the flags do not require computing those centroids.The flags are:
0 : No flags set.
1 (
'masked_pixels') : One or more input-masked pixels (maskkeyword) are within the source segment.2 (
'non_finite_data') : One or more data values within the source segment are nonfinite (NaN or inf).4 (
'non_finite_error') : One or more error values within the source segment are nonfinite (NaN or inf).8 (
'all_masked') : Every pixel within the source segment is masked or nonfinite, so the measured source properties are undefined.16 (
'edge_touch') : The source segment touches one or more image boundaries, so the source may be truncated and its measured properties may be unreliable.32 (
'deblended') : The source was produced by deblending a parent source withdeblend_sources.64 (
'deblend_non_positive_min') : The deblending mode for the input source (the parent source, or the source itself if it was not deblended) was changed to “sinh” because of a nonpositive minimum data value within the input source segment.128 (
'deblend_too_many_markers') : The deblending mode for the input source (the parent source, or the source itself if it was not deblended) was changed to “linear” because the input source had too many potential deblended sources.256 (
'undefined_shape') : The net source flux (the zeroth image moment over the source segment) 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, in which case the covariance-derived shape properties are NaN. Fully masked sources have a zero net flux, so they are also flagged.512 (
'singular_covariance') : The source covariance matrix is singular or nearly singular (the minor-axis variance is below1/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.1024 (
'kron_undefined') : The Kron aperture could not be defined (e.g., the source is fully masked) or the Kron photometry was skipped (e.g., the aperture was too large), so the Kron flux is NaN. The photometry-loop flags (kron_no_overlap,kron_partial_overlap,kron_masked_pixels,kron_non_finite_data,kron_non_finite_error,kron_neighbor_pixels,kron_uncorrected_pixels) are not evaluated for these sources, butkron_minimum_radiusis computed independently from the radii and can still be set.2048 (
'kron_minimum_radius') : The measured unscaled Kron radius was at or below the minimum unscaled Kron radius (kron_params[1]) or could not be measured (nonpositive Kron numerator or denominator), so the minimum was used, or the minimum circular aperture (kron_params[2]) was used instead of the Kron ellipse.4096 (
'kron_no_overlap') : The Kron aperture is fully outside the data array: no pixel with nonzero aperture weight falls inside the data.8192 (
'kron_partial_overlap') : The Kron aperture is partially outside the data array: one or more pixels with nonzero aperture weight fall outside the data.16384 (
'kron_masked_pixels') : One or more input-masked pixels (maskkeyword) have nonzero aperture weight within the Kron aperture.32768 (
'kron_non_finite_data') : One or more unmasked data values with nonzero aperture weight within the Kron aperture are nonfinite (NaN or inf).65536 (
'kron_non_finite_error') : One or more unmasked error values with nonzero aperture weight within the Kron aperture are nonfinite (NaN or inf), so the Kron flux error is NaN.131072 (
'kron_neighbor_pixels') : One or more pixels within the Kron aperture were excluded or corrected due to neighboring sources in the segmentation image (aperture_mask_methodof “mask” or “correct”).262144 (
'kron_uncorrected_pixels') : Withaperture_mask_method="correct", one or more neighbor-source pixels within the Kron aperture could not be corrected (the mirror pixel was unavailable) and were set to zero instead.524288 (
'local_bkg_too_few_pixels') : The local background annulus (local_bkg_width> 0) contains fewer than 10 usable pixels (not masked, finite, and not within any source segment), so the local background is set to zero instead of being estimated (NaN for a fully masked source).
- 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 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 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. The Gini coefficient is NaN for a completely masked source.
- 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
covariancematrix. Use thecovariancematrix 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 thecovariancematrix. 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 (i.e., a single source selected by indexing a catalog).
- kron_aperture[source]#
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, elliptical shape parameters, orkron_radiusare 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 multisource catalogs, or a single aperture for a single-source catalog.
- kron_flux[source]#
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, elliptical shape parameters, orkron_radiusare not finite or where the source is completely masked. NaN is also returned where the aperture contains no unmasked pixels within the data.
- kron_flux_err[source]#
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, elliptical shape parameters, orkron_radiusare not finite or where the source is completely masked. NaN is also returned where the aperture contains no unmasked pixels within the data. Iferrorwas not input, then the errors are NaN.The error is the quadrature sum of the input
errorvalues over the pixels in the Kron aperture, each weighted by its aperture overlap fraction, with the aperture treated as fixed. The aperture center, shape, and radius are themselves measured from the data, and the flux variation from that aperture uncertainty is not propagated. The error is therefore a lower bound. The missing contribution is negligible when the aperture extends into the sky background, where the source surface brightness at the aperture boundary is small.
- kron_radius[source]#
The unscaled first-moment Kron radius used to define the Kron aperture.
The measured 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 unscaled, meaning that it is not multiplied by thekron_params[0]scaling parameter. It is the measured value given above after the following adjustments are applied. The measured value without these adjustments is available inkron_radius_measured.If the measured value is less than the minimum unscaled Kron radius (
kron_params[1]), or if either the numerator or denominator above is less than or equal to 0, thenkron_radiusis set to the minimum unscaled Kron radius.If
kron_params[0]*kron_radius* sqrt(semimajor_axis*semiminor_axis) is less than or equal to the minimum circular radius (kron_params[2]), thenkron_radiusis set to zero and the Kron aperture will be a circle with this minimum radius.If the measured value exceeds 6.0 (the measurement aperture scale factor), then
kron_radiusis set tonp.nan. Such values are unphysical, typically caused by near-cancellation in the denominator of the Kron formula due to outlier pixels or noise.
Sources affected by either of the first two adjustments have the
kron_minimum_radiusflag set inflags.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 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.
- kron_radius_measured[source]#
The measured unscaled first-moment Kron radius.
This is the first-moment Kron radius as measured from the data (see
kron_radiusfor the definition), before any of thekron_paramsminimum values are applied. It is not multiplied by thekron_params[0]scaling parameter.The
kron_radiusproperty is the value used to define the Kron aperture. The two differ for sources that have thekron_minimum_radiusflag set, wherekron_radiusis either the minimum unscaled Kron radius (kron_params[1]) or zero (if the minimum circular aperture is used). They also differ where the measured value exceeds 6.0 (the measurement aperture scale factor). The measured value is returned here, whilekron_radiusisnp.nan.If either the numerator or denominator of the first-moment Kron radius is less than or equal to 0, then the measured Kron radius is undefined and
np.nanwill be returned.If the source is completely masked, then
np.nanwill be returned.If a
detection_catalogwas input toSourceCatalog, then itskron_radius_measuredwill be returned.
- label#
The source label number(s).
This label number corresponds to the assigned pixel value in the
SegmentationImage.Returns an array for multisource 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[source]#
The local background value (per pixel) estimated using a rectangular annulus aperture around the source.
Pixels are masked where the input
maskisTrue, where the inputdatais nonfinite, and within any nonzero pixel label in the segmentation image.The value is the
SExtractorBackgroundestimate of the usable annulus pixel values with aSigmaClip(sigma=3.0, cenfunc='median', maxiters=20)sigma clip, matching it to within rounding. It is zero for a source with fewer than 10 usable annulus pixels, which sets thelocal_bkg_too_few_pixelsflag (seeflags). The sources are measured concurrently whenn_threads> 1.The local background is zero if
local_bkg_widthis zero. It is NaN for a source that is completely masked (for anylocal_bkg_width).
- local_background_aperture[source]#
The
RectangularAnnulusaperture used to estimate the local background.Noneiflocal_bkg_widthis zero.Returns a list of apertures for multisource catalogs, or a single aperture for a single-source catalog.
- max_value[source]#
The maximum value of the unmasked
datapixels within the source segment.The local background, if computed (
local_bkg_width> 0), is subtracted. The value is NaN for a completely masked source.
- max_value_index[source]#
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.
The coordinates are integers. If any source in the catalog is completely masked, then the coordinates are returned as floats and are
np.nanfor that source.
- max_value_xindex[source]#
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[source]#
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[source]#
The minimum value of the unmasked
datapixels within the source segment.The local background, if computed (
local_bkg_width> 0), is subtracted. The value is NaN for a completely masked source.
- min_value_index[source]#
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.
The coordinates are integers. If any source in the catalog is completely masked, then the coordinates are returned as floats and are
np.nanfor that source.
- min_value_xindex[source]#
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[source]#
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.
- 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.
- perimeter[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.
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[source]#
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[source]#
A 2D
ndarraycutout of the segmentation image using the minimal bounding box of the source.Returns a list of arrays for multisource catalogs, or a single array for a single-source catalog.
- segment_cutout_masked[source]#
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 nonfinitedatavalues (NaN and inf).Returns a list of arrays for multisource catalogs, or a single array for a single-source catalog.
- segment_flux[source]#
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.Nonfinite pixel values (NaN and inf) are excluded (automatically masked).
If
local_bkg_width> 0, the local background times the number of unmasked pixels is also subtracted. The flux is NaN for a completely masked source.
- segment_flux_err[source]#
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 nonfinite pixel values (NaN and inf) that are automatically masked, are also masked in the error array.If
errorwas not input, then the errors are NaN.
- 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_bbox_ll[source]#
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[source]#
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[source]#
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[source]#
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[source]#
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_dec_err[source]#
The 1-sigma error on the
sky_centroidposition along the Declination direction, in arcsec.If the celestial frame of the
wcsis not equatorial, this is the error along the latitude direction of that frame.Noneifwcsis not input.
- sky_centroid_err[source]#
The 1-sigma errors on the
sky_centroidposition as a(east, north)Quantityin arcsec.The pixel error covariance of the
centroidis transported to the local tangent plane with the WCS Jacobian evaluated at each source position. The first column is the error along East (the Right Ascension direction as a great-circle angle, i.e., including the cos(dec) factor) and the second is along North (Declination).The directions are those of the longitude and latitude axes of the celestial frame of the
wcs. They are Right Ascension and Declination only for an equatorial frame (e.g., ICRS). For another frame (e.g., Galactic), the errors are along the longitude and latitude of that frame.Noneifwcsis not input. NaN where the pixel errors are unavailable (e.g., noerrorinput).
- sky_centroid_icrs[source]#
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[source]#
The sky coordinate of the centroid (
centroid_quad), calculated by fitting a 2D quadratic polynomial to the 3x3 pixel box centered on the peak pixel of the source segment, returned as aSkyCoordobject.The output coordinate frame is the same as the input
wcs.Noneifwcsis not input.
- sky_centroid_quad_dec_err[source]#
The 1-sigma error on the
sky_centroid_quadposition along the Declination direction, in arcsec.If the celestial frame of the
wcsis not equatorial, this is the error along the latitude direction of that frame.Noneifwcsis not input.
- sky_centroid_quad_err[source]#
The 1-sigma errors on the
sky_centroid_quadposition as a(east, north)Quantityin arcsec.The pixel error covariance of the
centroid_quadis transported to the local tangent plane with the WCS Jacobian evaluated at each source position. The first column is the error along East (the Right Ascension direction as a great-circle angle, i.e., including the cos(dec) factor) and the second is along North (Declination). Sources where the quadratic centroid fell back to the isophotalcentroiduse the isophotal centroid error covariance. The errors are NaN for sources where the peak pixel position is returned instead of a fit.The directions are those of the longitude and latitude axes of the celestial frame of the
wcs. They are Right Ascension and Declination only for an equatorial frame (e.g., ICRS). For another frame (e.g., Galactic), the errors are along the longitude and latitude of that frame.Noneifwcsis not input. NaN where the pixel errors are unavailable (e.g., noerrorinput).
- sky_centroid_quad_ra_err[source]#
The 1-sigma error on the
sky_centroid_quadposition along the Right Ascension direction, as a great-circle angle in arcsec (i.e., including the cos(dec) factor).If the celestial frame of the
wcsis not equatorial, this is the error along the longitude direction of that frame.Noneifwcsis not input.
- sky_centroid_ra_err[source]#
The 1-sigma error on the
sky_centroidposition along the Right Ascension direction, as a great-circle angle in arcsec (i.e., including the cos(dec) factor).If the celestial frame of the
wcsis not equatorial, this is the error along the longitude direction of that frame.Noneifwcsis not input.
- sky_centroid_win[source]#
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.
- sky_centroid_win_dec_err[source]#
The 1-sigma error on the
sky_centroid_winposition along the Declination direction, in arcsec.If the celestial frame of the
wcsis not equatorial, this is the error along the latitude direction of that frame.Noneifwcsis not input.
- sky_centroid_win_err[source]#
The 1-sigma errors on the
sky_centroid_winposition as a(east, north)Quantityin arcsec.The pixel error covariance of the
centroid_winis transported to the local tangent plane with the WCS Jacobian evaluated at each source position. The first column is the error along East (the Right Ascension direction as a great-circle angle, i.e., including the cos(dec) factor) and the second is along North (Declination). Fallback sources use the isophotal centroid error covariance.The directions are those of the longitude and latitude axes of the celestial frame of the
wcs. They are Right Ascension and Declination only for an equatorial frame (e.g., ICRS). For another frame (e.g., Galactic), the errors are along the longitude and latitude of that frame.Noneifwcsis not input. NaN where the pixel errors are unavailable (e.g., noerrorinput).
- sky_centroid_win_ra_err[source]#
The 1-sigma error on the
sky_centroid_winposition along the Right Ascension direction, as a great-circle angle in arcsec (i.e., including the cos(dec) factor).If the celestial frame of the
wcsis not equatorial, this is the error along the longitude direction of that frame.Noneifwcsis not input.
- 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
covariancematrix is transported to the local tangent plane with the WCS Jacobian evaluated at each sourcecentroid, 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 inputwcsand is in the range (-90, 90] degrees.Noneifwcsis not input.
- slices#
A tuple of slice objects defining the minimal bounding box of the source.
Returns a list for multisource catalogs, or a single tuple for a single-source catalog.
- x_centroid[source]#
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_err[source]#
The 1-sigma error on the
xcoordinate of thecentroid.See
centroid_errfor details. Iferrorwas not input, then the errors are NaN.
- x_centroid_quad[source]#
The
xcoordinate of the centroid (centroid_quad), calculated by fitting a 2D quadratic polynomial to the 3x3 pixel box centered on the peak pixel of the source segment.
- x_centroid_quad_err[source]#
The 1-sigma error on the
xcoordinate of the quadratic centroid (centroid_quad).See
centroid_quad_errfor details. Iferrorwas not input, then the errors are NaN.
- x_centroid_win[source]#
The
xcoordinate of the “windowed” centroid (centroid_win).The window centroid is computed using an iterative algorithm to derive a more accurate centroid.
- x_centroid_win_err[source]#
The 1-sigma error on the
xcoordinate of the “windowed” centroid (centroid_win).See
centroid_win_errfor details. Iferrorwas not input, then the errors are NaN.
- y_centroid[source]#
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_err[source]#
The 1-sigma error on the
ycoordinate of thecentroid.See
centroid_errfor details. Iferrorwas not input, then the errors are NaN.
- y_centroid_quad[source]#
The
ycoordinate of the centroid (centroid_quad), calculated by fitting a 2D quadratic polynomial to the 3x3 pixel box centered on the peak pixel of the source segment.
- y_centroid_quad_err[source]#
The 1-sigma error on the
ycoordinate of the quadratic centroid (centroid_quad).See
centroid_quad_errfor details. Iferrorwas not input, then the errors are NaN.
- y_centroid_win[source]#
The
ycoordinate of the “windowed” centroid (centroid_win).The window centroid is computed using an iterative algorithm to derive a more accurate centroid.
- y_centroid_win_err[source]#
The 1-sigma error on the
ycoordinate of the “windowed” centroid (centroid_win).See
centroid_win_errfor details. Iferrorwas not input, then the errors are NaN.
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 the property. The name must not conflict with any of the built-in property names or attributes.
- valuearray_like or float
The value to assign. It must have one element per source (the same length as the catalog), or be a scalar for a single-source (scalar) catalog.
- overwritebool, optional
If
True, overwrite an existing user-defined propertyname. Built-in attributes can never be overwritten.
- Raises:
- ValueError
If
nameis a built-in attribute, ifnamealready exists andoverwriteisFalse, or ifvaluedoes not have the same number of elements as the catalog.
- 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 attributes
[name]_fluxand[name]_flux_errif they exist.
- Returns:
- flux, flux_errfloat,
ndarray, orQuantity The aperture fluxes and flux errors, in the units of the input
data. NaN will be returned where the aperture isNone(e.g., where the sourcecentroidposition is not finite or the source is completely masked). Iferrorwas not input, then the flux errors are NaN.
- flux, flux_errfloat,
- copy()[source]#
Return a deep copy of this SourceCatalog.
- Returns:
- result
SourceCatalog A deep copy of this object.
- result
- decode_flags(*, return_bit_values=False)[source]#
Decode the source quality flags into individual components.
This is a convenience method that calls
decode_segmentation_flagswith theflagsproperty.- 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 source label to the list of its active flag names (or bit values). The entries follow the catalog order.
Examples
>>> import numpy as np >>> from astropy.modeling.models import Gaussian2D >>> from photutils.segmentation import SourceCatalog, detect_sources >>> yy, xx = np.mgrid[0:51, 0:51] >>> data = (Gaussian2D(100, 25, 25, 3, 3)(xx, yy) ... + Gaussian2D(100, 2, 40, 3, 3)(xx, yy)) >>> segm = detect_sources(data, 10, 5) >>> cat = SourceCatalog(data, segm) >>> for label, names in cat.decode_flags().items(): ... print(label, names) 1 [] 2 ['edge_touch', 'kron_partial_overlap']
- 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.The radius is measured in the
dataof this catalog, after subtracting its local background, in circular apertures centered on the sourcecentroid. It encloses the given fraction of thekron_fluxof this catalog. The largest radius that is searched is the semimajor axis of the Kron aperture (or its radius for a circular Kron aperture).If a
detection_catalogwas input toSourceCatalog, the radius is still measured in thedataof this catalog, with its local background, as a fraction of its ownkron_flux. Only the sourcecentroidand the Kron aperture, which define the aperture centers and the largest radius, are taken from the detection catalog. The radius is therefore not theflux_radiusof the detection catalog.- 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:
- radius
Quantity The circular radius, in pixels, that encloses the specified fraction of the Kron flux. A scalar is returned for a single-source catalog. NaN is returned where no solution was found or where the Kron flux is zero or nonfinite.
- radius
- 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
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 attributes
[name]_fluxand[name]_flux_errif they exist.
- Returns:
- flux, flux_errfloat,
ndarray, orQuantity The aperture fluxes and flux errors, in the units of the input
data. NaN will be returned where the aperture isNone(e.g., where the sourcecentroidposition, elliptical shape parameters, orkron_radiusare not finite or where the source is completely masked). NaN is also returned where the aperture contains no unmasked pixels within the data. Iferrorwas not input, then the flux errors are NaN.
- flux, flux_errfloat,
- make_circular_apertures(radius)[source]#
Make a 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 or 1D
ndarray The radius of the circle in pixels, either a single value or one value per source.
- radiusfloat or 1D
- 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, optional 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.fill_valuewill be changed to have the samedtypeas thearrayarray, with one exception. Ifarrayhas 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, elliptical shape parameters, orkron_radiusare 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, elliptical shape parameters, orkron_radiusare 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:
- release_cache()[source]#
Release the cached full-image working arrays.
The compiled routines that calculate the source properties read the input
data,error,background, andconvolved_dataarrays and the segmentation image directly when they are C-contiguous with native byte order, the image arrays are allfloat32or allfloat64, and the segmentation array isint32ornumpy.intp. Otherwise, working copies are created the first time they are needed and are then cached for the lifetime of the catalog, so that they are shared by all of the source properties. A 1 byte per pixel mask array is always cached.Call this method after calculating the desired properties to free that memory. Source properties that were already calculated are unaffected. The working arrays are recreated on demand if another property is later requested.
The cache is shared with catalogs created by slicing this catalog, so it is also released for them. A catalog input as the
detection_cataloghas its own cache, which is not released by this method.Notes
No copies are needed, and only the mask array is cached, when the conditions above are met. The image arrays are converted to
float64copies, which need 8 bytes per pixel each, when their dtypes differ from each other (e.g.,float32data with afloat64error array) or when any of them has another dtype (e.g., an integer dtype). For example, a 4096 x 4096float32image input withfloat64errorandfloat32convolved_dataarrays caches about 285 MB. Big-endian arrays (e.g., data read from a FITS file) andfloat16arrays are converted to native copies of the common dtype, which need 4 bytes per pixel forfloat32and 8 bytes per pixel forfloat64.Calling this method is worthwhile when all of the following are true:
The image is large and working copies are needed (see above), so the cache is a significant amount of memory.
All of the desired properties have been calculated, e.g., after calling
to_tableor after accessing the last property that is needed.The catalog object stays alive while other memory-intensive work is performed. The cache is freed along with the catalog when the catalog is deleted or goes out of scope, so there is no need to call this method on a catalog that is about to be discarded.
Avoid calling this method between property calculations. The working arrays are then recreated for the next property, which costs a full-image copy of each input and does not lower the peak memory.
The simplest way to avoid the working copies is to input all of the image arrays as C-contiguous arrays with the same
float32orfloat64dtype. The results do not depend on the input dtype (to within floating-point rounding), because all calculations are performed infloat64.Examples
>>> from photutils.datasets import make_4gaussians_image >>> from photutils.segmentation import (SourceCatalog, ... detect_sources) >>> data = make_4gaussians_image().astype('float32') >>> segment_img = detect_sources(data, 50.0, n_pixels=10) >>> cat = SourceCatalog(data, segment_img) >>> tbl = cat.to_table() >>> cat.release_cache()
- 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.
- Raises:
- ValueError
If any name in
namesis not a user-defined property.
- 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.
- Raises:
- ValueError
If
nameis not a user-defined property.
- 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
- Raises:
- ValueError
If
labelis not a label in this catalog.
- select_labels(labels)[source]#
Return a new
SourceCatalogobject for the inputlabelsonly.- Parameters:
- labelsint, list, tuple, or
ndarrayof int The source label(s).
- labelsint, list, tuple, or
- Returns:
- cat
SourceCatalog A new
SourceCatalogobject containing only the sources with the inputlabels.
- cat
- Raises:
- ValueError
If any of the input
labelsis not a label in this catalog.
- 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 the names in thepropertiesattribute, except for the 2D cutout image properties (e.g.,data_cutout), and any 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 source properties with one row per source.
- table
- Raises:
- ValueError
If any name in
columnsis not a valid (or deprecated) column name.