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.


kernel_src : numpy.ndarray

Source kernel as a numpy array.

kernel_bkg : numpy.ndarray

Background convolution kernel as a numpy array.

significance_threshold : float

Significance threshold above which regions are excluded.

mask_dilation_radius : Angle

Radius by which mask is dilated with each iteration.

keep_record : bool

Keep record of intermediate results while the algorithm runs?


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) += 42[50][50] = 1000
source_kernel = Tophat2DKernel(3)
bkg_kernel = Ring2DKernel(radius_in=4, width=2)
kbe = KernelBackgroundEstimator(kernel_src=source_kernel.array,
result ={'counts':counts})

(png, hires.png, pdf)


Methods Summary

run(images[, niter_min, niter_max]) Run iterations until mask does not change (stopping condition).
run_iteration(images) Run one iteration.

Methods Documentation

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

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


images : dict

Input sky images: counts, background, exclusion

niter_min : int

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

niter_max : int

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


images : dict

Sky images: background, exclusion, significance


Run one iteration.


images : dict

Input sky images