PSFKernel#
- class gammapy.irf.PSFKernel(psf_kernel_map, normalize=True)[source]#
Bases:
object
PSF kernel for
Map
.This is a container class to store a PSF kernel that can be used to convolve
WcsNDMap
objects. It is usually computed from anPSFMap
.- Parameters:
- psf_kernel_map
Map
PSF kernel stored in a Map.
- psf_kernel_map
Examples
from gammapy.maps import Map, WcsGeom, MapAxis from gammapy.irf import PSFMap from astropy import units as u # Define energy axis energy_axis_true = MapAxis.from_energy_bounds( "0.1 TeV", "10 TeV", nbin=3, name="energy_true" ) # Create WcsGeom and map geom = WcsGeom.create(binsz=0.02 * u.deg, width=2.0 * u.deg, axes=[energy_axis_true]) some_map = Map.from_geom(geom) # Fill map at three positions some_map.fill_by_coord([[0, 0, 0], [0, 0, 0], [0.3, 1, 3]]) psf = PSFMap.from_gauss( energy_axis_true=energy_axis_true, sigma=[0.3, 0.2, 0.1] * u.deg ) kernel = psf.get_psf_kernel(geom=geom, max_radius=1*u.deg) # Do the convolution some_map_convolved = some_map.convolve(kernel) some_map_convolved.plot_grid() # doctest: +SKIP
Attributes Summary
Access the PSFKernel numpy array.
The map object holding the kernel as a
Map
.Methods Summary
from_gauss
(geom, sigma[, max_radius, factor])Create Gaussian PSF.
from_spatial_model
(model, geom[, ...])Create PSF kernel from spatial model.
Force normalisation of the kernel.
peek
([figsize])Quick-look summary plots.
plot_kernel
([ax, energy, add_cbar])Plot PSF kernel.
read
(*args, **kwargs)Read kernel Map from file.
slice_by_idx
(slices)Slice by index.
to_image
([spectrum, exposure, keepdims])Transform 3D PSFKernel into a 2D PSFKernel.
write
(*args, **kwargs)Write the Map object which contains the PSF kernel to file.
Attributes Documentation
- data#
Access the PSFKernel numpy array.
Methods Documentation
- classmethod from_gauss(geom, sigma, max_radius=None, factor=4)[source]#
Create Gaussian PSF.
This is used for testing and examples. The map geometry parameters (pixel size, energy bins) are taken from
geom
. The Gaussian widthsigma
is a scalar.TODO : support array input if it should vary along the energy axis.
- classmethod from_spatial_model(model, geom, max_radius=None, factor=4)[source]#
Create PSF kernel from spatial model.
- peek(figsize=(15, 5))[source]#
Quick-look summary plots.
- Parameters:
- figsizetuple, optional
Size of the figure. Default is (15, 5).
- plot_kernel(ax=None, energy=None, add_cbar=False, **kwargs)[source]#
Plot PSF kernel.
- Parameters:
- ax
Axes
, optional Matplotlib axes. Default is None.
- energy
Quantity
, optional If None, the PSF kernel is summed over the energy axis. Otherwise, the kernel corresponding to the energy bin including the given energy is shown.
- add_cbarbool, optional
Add a colorbar. Default is False.
- kwargs: dict
Keyword arguments passed to
imshow
.
- ax
- Returns:
- ax
Axes
Matplotlib axes.
- ax
- to_image(spectrum=None, exposure=None, keepdims=True)[source]#
Transform 3D PSFKernel into a 2D PSFKernel.
- Parameters:
- spectrum
SpectralModel
, optional Spectral model to compute the weights. Default is power-law with spectral index of 2.
- exposure
Quantity
orndarray
, optional 1D array containing exposure in each true energy bin. It must have the same size as the PSFKernel energy axis. Default is uniform exposure over energy.
- keepdimsbool, optional
If true, the resulting PSFKernel will keep an energy axis with one bin. Default is True.
- spectrum
- Returns:
- weighted_kernel
PSFKernel
The weighted kernel summed over energy.
- weighted_kernel