phot.background.sky_fit

phot.background.sky_fit(
    ccd,
    annulus=None,
    mask=None,
    method='sex',
    sky_clipper=sigma_clipper,
    std_ddof=1,
    to_table=True,
    return_skyarr=False,
    **kwargs,
)

Estimate sky values from an image or one or more annuli.

Parameters

ccd : ~astropy.nddata.CCDData, HDU, or ndarray

Image data from which to extract sky values.

annulus : annulus object = None

Annulus used for the estimate. If None (default), use the whole image.

method : (sex, IRAF, MMM, mean, median) = "sex"

Sky estimator. Names are case-insensitive:

  • "mean"/"median": simple nanmean/nanmedian.
  • "sex": (med_factor, mean_factor) = (2.5, 1.5).
  • "IRAF": (med_factor, mean_factor) = (3, 2), or the mean when the mean is below the median.
  • "MMM": (med_factor, mean_factor) = (3, 2).

The three compound estimators use msky = med_factor * med - mean_factor * mean. "MMM" uses the same formula as visualization’s statistic="mode"; it is not the iterative mmm_dao algorithm. For "sex", use the median instead when (mean - median) / std > 0.3, matching SExtractor.

A callable must have signature func(skyarr, ssky) -> msky. It receives the 1-D clipped values and their sample standard deviation. Example: method = lambda x, s: np.median(x). Default is "sex".

sky_clipper : callable, None = sigma_clipper

Function used before estimating the sky. It must have signature func(skyarr, **kwargs) -> clipped_skyarr and return a plain ndarray without NaNs: remove clipped values rather than replacing them with NaN. This is required by the reducers kernels used by _sky_fit. The default ~astroimred._core.numeric.sigma_clipper removes values and uses imcombiners rejection kernels for compatible 1-D calls. If None, apply no clipping beyond removing NaNs (lambda x: x[~np.isnan(x)]).

std_ddof : int = 1

Delta degrees of freedom for the sky standard deviation.

to_table : bool = True

Return a ~astropy.table.Table when True; otherwise return a list of dictionaries. Default is True.

return_skyarr : bool = False

Also return the 1-D sky array, or a list of arrays for multiple annuli. Default is False.

****kwargs** : = {}

Keyword arguments forwarded to sky_clipper.

Returns

skytable : ~astropy.table.Table or list of dict

One row or dictionary per annulus with the following fields:

msky : float Estimated sky value after clipping.

ssky : float Sample standard deviation after clipping.

dsky : float Standard error of msky, ssky * sqrt(c / nsky). c is the variance factor of the estimator branch used per annulus, so it can differ between rows; see _sky_var_factor for its values and derivation. NaN for a callable method, because its c is unknown.

nsky : int Number of pixels used after clipping.

nrej : int Number of pixels rejected by clipping.

skys : ndarray or list of ndarray

Returned only when return_skyarr=True: the 1-D sky values, or one array per annulus.