TablePSF¶
-
class
gammapy.irf.TablePSF(rad, dp_domega, spline_kwargs={'k': 1, 's': 0})[source]¶ Bases:
objectRadially-symmetric table PSF.
This PSF represents a \(PSF(r)=dP / d\Omega(r)\) spline interpolation curve for a given set of offset \(r\) and \(PSF\) points.
Uses
scipy.interpolate.UnivariateSpline.Parameters: rad :
Quantitywith angle unitsOffset wrt source position
dp_domega :
Quantitywith sr^-1 unitsPSF value array
spline_kwargs : dict
Keyword arguments passed to
UnivariateSplineNotes
- This PSF class works well for model PSFs of arbitrary shape (represented by a table),
but might give unstable results if the PSF has noise.
E.g. if
dp_domegawas estimated from histograms of real or simulated event data with finite statistics, it will have noise and it is your responsibility to check that the interpolating spline is reasonable. - To customize the spline, pass keyword arguments to
UnivariateSplineinspline_kwargs. E.g. passingdict(k=1)changes from the default cubic to linear interpolation. - TODO: evaluate spline for
(log(rad), log(PSF))for numerical stability? - TODO: merge morphology.theta class functionality with this class.
- TODO: add FITS I/O methods
- TODO: add
normalizeargument to__init__with defaultTrue? - TODO:
__call__doesn’t show up in the html API docs, but it should: https://github.com/astropy/astropy/pull/2135
Methods Summary
__call__(lon, lat)Evaluate PSF at a 2D position. broaden(factor[, normalize])Broaden PSF by scaling the offset array. containment_radius(fraction)Containment radius. evaluate(rad[, quantity])Evaluate PSF. from_shape(shape, width, rad)Make TablePSF objects with commonly used shapes. info()Print basic info. integral([rad_min, rad_max])Compute PSF integral, aka containment fraction. kernel(reference, rad_max[, normalize, …])Make a 2-dimensional kernel image. normalize()Normalize PSF to unit integral. plot_psf_vs_rad([ax, quantity])Plot PSF vs radius. Methods Documentation
-
__call__(lon, lat)[source]¶ Evaluate PSF at a 2D position.
The PSF is centered on
(0, 0).Parameters: lon, lat :
AngleLongitude / latitude position
Returns: psf_value :
QuantityPSF value
-
broaden(factor, normalize=True)[source]¶ Broaden PSF by scaling the offset array.
For a broadening factor \(f\) and the offset array \(r\), the offset array scaled in the following way:
\[r_{new} = f \times r_{old} \frac{dP}{dr}(r_{new}) = \frac{dP}{dr}(r_{old})\]Parameters: factor : float
Broadening factor
normalize : bool
Normalize PSF after broadening
-
containment_radius(fraction)[source]¶ Containment radius.
Parameters: fraction : array_like
Containment fraction (range 0 .. 1)
Returns: rad :
AngleContainment radius angle
-
evaluate(rad, quantity='dp_domega')[source]¶ Evaluate PSF.
The following PSF quantities are available:
‘dp_domega’: PDF per 2-dim solid angle \(\Omega\) in sr^-1
\[\frac{dP}{d\Omega}\]‘dp_dr’: PDF per 1-dim offset \(r\) in radian^-1
\[\frac{dP}{dr} = 2 \pi r \frac{dP}{d\Omega}\]
Parameters: rad :
AngleOffset wrt source position
quantity : {‘dp_domega’, ‘dp_dr’}
Which PSF quantity?
Returns: psf_value :
QuantityPSF value
-
classmethod
from_shape(shape, width, rad)[source]¶ Make TablePSF objects with commonly used shapes.
This function is mostly useful for examples and testing.
Parameters: shape : {‘disk’, ‘gauss’}
PSF shape.
width :
Quantitywith angle unitsPSF width angle (radius for disk, sigma for Gauss).
rad :
Quantitywith angle unitsOffset angle
Returns: psf :
TablePSFTable PSF
Examples
>>> import numpy as np >>> from astropy.coordinates import Angle >>> from gammapy.irf import TablePSF >>> TablePSF.from_shape(shape='gauss', width='0.2 deg', ... rad=Angle(np.linspace(0, 0.7, 100), 'deg'))
-
integral(rad_min=None, rad_max=None)[source]¶ Compute PSF integral, aka containment fraction.
Parameters: rad_min, rad_max :
Quantitywith angle unitsOffset angle range
Returns: integral : float
PSF integral
-
kernel(reference, rad_max, normalize=True, discretize_model_kwargs={'factor': 10})[source]¶ Make a 2-dimensional kernel image.
The kernel image is evaluated on a cartesian grid defined by the reference sky image.
Parameters: reference :
SkyImageorSkyCubeReference sky image or sky cube defining the spatial grid.
rad_max :
AngleRadial size of the kernel
normalize : bool
Whether to normalize the kernel.
Returns: kernel :
QuantityKernel 2D image of Quantities
- This PSF class works well for model PSFs of arbitrary shape (represented by a table),
but might give unstable results if the PSF has noise.
E.g. if