KernelBackgroundEstimator

class gammapy.detect.KernelBackgroundEstimator(kernel_src, kernel_bkg, significance_threshold=5, mask_dilation_radius='0.02 deg', keep_record=False)[source]

Bases: object

Estimate background and exclusion mask iteratively.

Starting from an initial background estimate and exclusion mask (both provided, optionally) the algorithm works as follows:

  1. Compute significance image

  2. Create exclusion mask by thresholding significance image

  3. Compute improved background estimate based on new exclusion mask

The steps are executed repeatedly until the exclusion mask does not change anymore.

For flexibility the algorithm takes arbitrary source and background kernels.

Parameters
kernel_srcnumpy.ndarray

Source kernel as a numpy array.

kernel_bkgnumpy.ndarray

Background convolution kernel as a numpy array.

significance_thresholdfloat

Significance threshold above which regions are excluded.

mask_dilation_radiusAngle

Radius by which mask is dilated with each iteration.

keep_recordbool

Keep record of intermediate results while the algorithm runs?

See also

gammapy.cube.RingBackgroundEstimator
gammapy.cube.AdaptiveRingBackgroundEstimator

Examples

import numpy as np
from gammapy.maps import Map
from astropy.convolution import Ring2DKernel, Tophat2DKernel
from gammapy.detect import KernelBackgroundEstimator

counts = Map.create(npix=100, binsz=1)
counts.data += 42
counts.data[50][50] = 1000
source_kernel = Tophat2DKernel(3)
bkg_kernel = Ring2DKernel(radius_in=4, width=2)
kbe = KernelBackgroundEstimator(kernel_src=source_kernel.array,
                                kernel_bkg=bkg_kernel.array)
result = kbe.run({'counts':counts})
result['exclusion'].plot()

(png, hires.png, pdf)

../_images/gammapy-detect-KernelBackgroundEstimator-1.png

Methods Summary

run(self, images[, niter_min, niter_max])

Run iterations until mask does not change (stopping condition).

run_iteration(self, images)

Run one iteration.

Methods Documentation

run(self, images, niter_min=2, niter_max=10)[source]

Run iterations until mask does not change (stopping condition).

Parameters
imagesdict

Input sky images: counts, background, exclusion

niter_minint

Minimum number of iterations, to prevent early termination of the algorithm.

niter_maxint

Maximum number of iterations after which the algorithm is terminated, if the termination condition (no change of mask between iterations) is not already satisfied.

Returns
imagesdict

Sky images: background, exclusion, significance

run_iteration(self, images)[source]

Run one iteration.

Parameters
imagesdict

Input sky images