decode_segmentation_flags#
- photutils.segmentation.decode_segmentation_flags(flags, *, return_bit_values=False)[source]#
Decode segmentation bitwise flag values into individual components.
This function takes integer flag values from segmentation operations and returns a list of human-readable names of the conditions that were detected. This is useful for understanding what problems were encountered without needing to manually perform bitwise operations.
- Parameters:
- flagsint or array-like of int
Integer flag value(s) to decode. Each bit in the flag represents a specific condition that was detected when processing the segmentation.
- return_bit_valuesbool, optional
If
True, return the decoded bit flags (integers) instead of the flag names (strings). Default isFalse.
- Returns:
- decodedlist of str, list of int, or nested list
List of active flag names (or bit values) for a scalar input. For an array input, a nested list with the same shape as the input is returned, where each innermost element is the list of active flag names (or bit values) for the corresponding flag. If no flags are set, an empty list is returned. Possible 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).
Examples
Decode a single flag value:
>>> from photutils.segmentation import decode_segmentation_flags >>> issues = decode_segmentation_flags(48) # bits 16 and 32 set >>> print(issues) ['edge_touch', 'deblended'] >>> 'edge_touch' in issues True >>> 'deblended' in issues True
Decode multiple flag values:
>>> flags = [0, 1, 33] # 0, bit 1, bits 1+32 >>> decoded_list = decode_segmentation_flags(flags) >>> decoded_list[0] # No issues [] >>> decoded_list[1] ['masked_pixels'] >>> decoded_list[2] ['masked_pixels', 'deblended']
Return the bit values instead of the names:
>>> decode_segmentation_flags(48, return_bit_values=True) [16, 32]