ImageDepth#
- class photutils.utils.ImageDepth(aper_radius, *, n_sigma=5.0, mask_pad=0, n_apertures=1000, n_iters=10, overlap=True, overlap_maxiters=100, seed=None, zeropoint=0.0, sigma_clip=<default: SigmaClip(sigma=3.0, maxiters=10)>, progress_bar=True)[source]#
Bases:
objectClass to calculate the limiting flux and magnitude of an image.
- Parameters:
- aper_radiusfloat
The radius (in pixels) of the circular apertures used to compute the image depth.
- n_sigmafloat, optional
The number of standard deviations at which to compute the image depths.
Deprecated since version 3.0: The
nsigmakeyword is deprecated. Usen_sigmainstead.- mask_padfloat, optional
An additional padding (in pixels) to apply when dilating the input mask. The dilation radius is
aper_radiusplusmask_pad, rounded up to the nearest integer.- n_aperturesint, optional
The number of circular apertures used to compute the image depth.
Deprecated since version 3.0: The
naperskeyword is deprecated. Usen_aperturesinstead.- n_itersint, optional
The number of iterations, each with randomly-generated apertures, for which the image depth will be calculated.
Deprecated since version 3.0: The
niterskeyword is deprecated. Usen_itersinstead.- overlapbool, optional
Whether to allow the apertures to overlap. If
False, fewer thann_aperturesapertures may be used when the unmasked area is too small, in which case a warning is issued (see then_apertures_usedattribute).- overlap_maxitersint, optional
This keyword is unused and has no effect.
Deprecated since version 3.1: The
overlap_maxiterskeyword is deprecated and will be removed in version 4.0.- seedint, optional
A seed to initialize the
numpy.random.BitGenerator. IfNone, then fresh, unpredictable entropy will be pulled from the OS. Each call to the object creates a fresh generator initialized withseed, so all calls with the sameseedgenerate identical results.- zeropointfloat, optional
The zeropoint used to calculate the magnitude limit from the flux limit:
\[m_{\mathrm{lim}} = -2.5 \log_{10} f_{\mathrm{lim}} + \mathrm{zeropoint}\]- sigma_clip
astropy.stats.SigmaClip, optional A
SigmaClipobject that defines the sigma clipping parameters to use when computing the limiting flux. The default is aSigmaClipinstance withsigma=3.0andmaxiters=10. IfNonethen no sigma clipping will be performed.- progress_barbool, optional
Whether to display a progress bar. The progress bar requires that the tqdm optional dependency be installed.
- Attributes:
- apertureslist of
CircularAperture A list of circular apertures for each iteration.
- napers_used1D
ndarray Deprecated since version 3.0: Use
n_apertures_usedinstead.- n_apertures_used1D
ndarray An array of the number of apertures used for each iteration.
- fluxeslist of
ndarray A list of arrays containing the flux measurements for each iteration.
- flux_limits1D
ndarray An array of the flux limits for each iteration.
- mag_limits1D
ndarray An array of the magnitude limits for each iteration.
- apertureslist of
Notes
The image depth is calculated by placing random circular apertures with the specified radius on blank regions of the image. The number of apertures is specified by the
n_apertureskeyword. The blank regions are calculated from an input mask, which should mask both sources in the image and areas without image coverage. The input mask will be dilated with a circular footprint with a radius equal to the inputaper_radiusplusmask_pad, rounded up to the nearest integer. The image border is also masked with the same radius.The flux limit is calculated as the standard deviation of the aperture fluxes times the input
n_sigmasignificance level. The aperture flux values can be sigma clipped prior to computing the standard deviation using thesigma_clipkeyword.The flux limit is calculated
n_iterstimes, each with a randomly-generated set of circular apertures. The returned flux limit is the average of these flux limits.The magnitude limit is calculated from the flux limit using the input
zeropointkeyword as:\[m_{\mathrm{lim}} = -2.5 \log_{10} f_{\mathrm{lim}} + \mathrm{zeropoint}\]Instances are safe to call concurrently from multiple threads. Each call uses only local state, including a fresh random generator initialized with
seed. The result attributes (apertures,n_apertures_used,fluxes,flux_limits, andmag_limits) reflect the most recently completed call.A
ValueErroris raised if no unmasked pixels remain after dilating the mask and masking the border, or ifn_aperturesexceeds the number of unmasked pixels. A warning is issued if fewer thann_aperturesnonoverlapping apertures could be placed, or if any flux limit is zero.Examples
>>> import numpy as np >>> from astropy.convolution import convolve >>> from photutils.datasets import make_100gaussians_image >>> from photutils.segmentation import SourceFinder, make_2dgaussian_kernel >>> from photutils.utils import ImageDepth >>> bkg = 5.0 >>> data = make_100gaussians_image() - bkg >>> kernel = make_2dgaussian_kernel(3.0, size=5) >>> convolved_data = convolve(data, kernel) >>> n_pixels = 10 >>> threshold = 3.2 >>> finder = SourceFinder(n_pixels=n_pixels) >>> segment_map = finder(convolved_data, threshold) >>> mask = segment_map.make_source_mask() >>> radius = 4 >>> depth = ImageDepth(radius, n_sigma=5.0, n_apertures=500, ... n_iters=2, mask_pad=5, overlap=False, ... seed=123, zeropoint=23.9, ... progress_bar=False) >>> limits = depth(data, mask) >>> print(np.array(limits)) [68.7403149 19.30697121]
# Plot the random apertures for the first iteration import matplotlib.pyplot as plt from astropy.convolution import convolve from astropy.visualization import simple_norm from photutils.datasets import make_100gaussians_image from photutils.segmentation import SourceFinder, make_2dgaussian_kernel from photutils.utils import ImageDepth bkg = 5.0 data = make_100gaussians_image() - bkg kernel = make_2dgaussian_kernel(3.0, size=5) convolved_data = convolve(data, kernel) n_pixels = 10 threshold = 3.2 finder = SourceFinder(n_pixels=n_pixels) segment_map = finder(convolved_data, threshold) mask = segment_map.make_source_mask() radius = 4 depth = ImageDepth(radius, n_sigma=5.0, n_apertures=500, n_iters=2, mask_pad=5, overlap=False, seed=123, zeropoint=23.9, progress_bar=False) limits = depth(data, mask) fig, ax = plt.subplots(nrows=2, figsize=(5, 7)) norm = simple_norm(data, 'sqrt', percent=99.5) ax[0].imshow(data, norm=norm, origin='lower') color = 'white' depth.apertures[0].plot(ax=ax[0], color=color) ax[0].set_title('Data with blank apertures') ax[1].imshow(mask, origin='lower') depth.apertures[0].plot(ax=ax[1], color=color) ax[1].set_title('Mask with blank apertures') fig.tight_layout()
(
Source code,png,hires.png,pdf,svg)
Methods Summary
__call__(data, mask)Calculate the limiting flux and magnitude of an image.
Methods Documentation
- __call__(data, mask)[source]#
Calculate the limiting flux and magnitude of an image.
- Parameters:
- data2D
ndarrayorQuantity The 2D array, which should be in flux units (not surface brightness units).
- mask2D bool
ndarray A 2D mask array with the same shape as
datawhere aTruevalue indicates the corresponding element ofdatais masked. The input array should mask both sources (e.g., from a segmentation image) and regions without image coverage. IfNone, then the entire image will be used, apart from the masked image border.
- data2D
- Returns:
- flux_limitfloat or
Quantity The flux limit, in the same units as the input
data.- mag_limitfloat
The magnitude limit, calculated from the flux limit and the input
zeropoint.
- flux_limitfloat or