LocalBackground#
- class photutils.background.LocalBackground(inner_radius, outer_radius, bkg_estimator=None)[source]#
Bases:
objectClass to compute a local background using a circular annulus aperture.
- Parameters:
- inner_radiusfloat
The inner radius of the circular annulus in pixels.
- outer_radiusfloat
The outer radius of the circular annulus in pixels.
- bkg_estimatorcallable, optional
A callable object (a function or e.g., an instance of any
BackgroundBasesubclass) used to estimate the background in each aperture. The callable object must take in a 1DndarrayorMaskedArray. The default is an instance ofMedianBackgroundwith sigma clipping (i.e., sigma-clipped median).
Examples
>>> import numpy as np >>> from photutils.background import LocalBackground >>> data = np.ones((101, 101)) >>> local_bkg = LocalBackground(5, 10) >>> bkg = local_bkg(data, 50, 50) >>> print(bkg) 1.0
>>> # Multiple positions >>> x = [30, 50, 70] >>> y = [30, 50, 70] >>> bkg = local_bkg(data, x, y) >>> print(bkg) [1. 1. 1.]
Methods Summary
__call__(data, x, y[, mask])Measure the local background in a circular annulus.
to_aperture(x, y)Return a
CircularAnnulusinstance representing the local background annulus at the given positions.Methods Documentation
- __call__(data, x, y, mask=None)[source]#
Measure the local background in a circular annulus.
- Parameters:
- data2D
ndarray The 2D array on which to measure the local background.
- x, yfloat or 1D float
ndarray The aperture center (x, y) position(s) at which to measure the local background.
- mask2D bool
ndarray, optional A boolean mask with the same shape as
datawhere aTruevalue indicates the corresponding element ofdatais masked. Masked data are excluded from all calculations.
- data2D
- Returns:
- valuefloat or 1D float
ndarray The local background values. If all pixels in an annulus are masked or outside the data bounds, the corresponding value will be NaN.
- valuefloat or 1D float
Examples
>>> import numpy as np >>> from photutils.background import LocalBackground >>> data = np.ones((101, 101)) >>> local_bkg = LocalBackground(5, 10) >>> bkg = local_bkg(data, 50, 50) >>> print(bkg) 1.0
>>> # Multiple positions >>> bkg = local_bkg(data, [30, 50], [40, 60]) >>> print(bkg) [1. 1.]
>>> # Position outside data returns NaN >>> bkg = local_bkg(data, -50, -50) >>> print(np.isnan(bkg)) True
- to_aperture(x, y)[source]#
Return a
CircularAnnulusinstance representing the local background annulus at the given positions.- Parameters:
- x, yfloat or 1D float
ndarray The aperture center (x, y) position(s) at which to create the annulus aperture.
- x, yfloat or 1D float
- Returns:
- apertures
CircularAnnulusinstance The circular annulus aperture(s) at the given position(s).
- apertures
Examples
>>> from photutils.background import LocalBackground >>> local_bkg = LocalBackground(5, 10) >>> aperture = local_bkg.to_aperture(50, 50) >>> aperture <CircularAnnulus([[50., 50.]], r_in=5.0, r_out=10.0)>
>>> # Multiple positions >>> aperture = local_bkg.to_aperture([30, 70], [40, 80]) >>> aperture <CircularAnnulus([[30., 40.], [70., 80.]], r_in=5.0, r_out=10.0)> >>> print(len(aperture.positions)) 2