Change EnergyDispersion by EnergyDispersion2D in CTAPerf class
from __future__ import absolute_import, division, print_function, unicode_literals
import numpy as np
from astropy.io import fits
-from astropy.table import Table
+from astropy import units as u
from ..utils.fits import fits_table_to_table
from ..utils.scripts import make_path
from ..utils.nddata import NDDataArray, BinnedDataAxis
from ..irf import EffectiveAreaTable2D, EffectiveAreaTable
from ..background import FOVCube
-from ..irf import EnergyDispersion2D, EnergyDispersion
+from ..irf import EnergyDispersion2D
from ..irf import EnergyDependentMultiGaussPSF
-
+from ..utils.energy import EnergyBounds
__all__ = [
'CTAIrf',
@@ -382,7 +382,7 @@ class CTAPerf(object):
----------
aeff : `~gammapy.irf.EffectiveAreaTable`
Effective area
- edisp : `~gammapy.irf.EnergyDispersion`
+ edisp_2d : `~gammapy.irf.EnergyDispersion2D`
Energy dispersion
psf : `~gammapy.scripts.Psf68Table`
Point spread function
@@ -392,9 +392,9 @@ class CTAPerf(object):
Sensitivity
"""
- def __init__(self, aeff=None, edisp=None, psf=None, bkg=None, sens=None):
+ def __init__(self, aeff=None, edisp_2d=None, psf=None, bkg=None, sens=None):
self.aeff = aeff
- self.edisp = edisp
+ self.edisp_2d = edisp_2d
self.psf = psf
self.bkg = bkg
self.sens = sens
@@ -413,7 +413,7 @@ class CTAPerf(object):
hdulist = fits.open(filename)
aeff = EffectiveAreaTable.from_hdulist(hdulist=hdulist)
- edisp = EnergyDispersion.from_hdulist(hdulist=hdulist)
+ edisp_2d = EnergyDispersion2D.read(filename, hdu='ENERGY DISPERSION')
bkg = BgRateTable.from_hdulist(hdulist=hdulist)
psf = Psf68Table.from_hdulist(hdulist=hdulist)
sens = SensitivityTable.from_hdulist(hdulist=hdulist)
@@ -421,7 +421,7 @@ class CTAPerf(object):
return cls(
aeff=aeff,
bkg=bkg,
- edisp=edisp,
+ edisp_2d=edisp_2d,
psf=psf,
sens=sens
)
@@ -439,16 +439,20 @@ class CTAPerf(object):
self.bkg.plot(ax=ax_bkg)
self.aeff.plot(ax=ax_area).set_yscale('log')
- self.aeff.plot(ax=ax_area)
self.sens.plot(ax=ax_sens)
self.psf.plot(ax=ax_psf)
- self.edisp.plot_matrix(ax=ax_resol)
+ self.edisp_2d.plot_bias(ax=ax_resol,
+ offset=0.5 * u.degree, # hacked for now
+ e_true=EnergyBounds.equal_log_spacing(0.02,
+ 300,
+ 100,
+ 'TeV'),
+ migra=np.linspace(0., 3, 80))
ax_bkg.grid(which='both')
ax_area.grid(which='both')
ax_sens.grid(which='both')
ax_psf.grid(which='both')
- ax_resol.grid(which='both')
plt.tight_layout()
plt.show()
return fig
