def make_test_arf(): from gammapy.irf import np_to_arf from gammapy.irf import abramowski_effective_area effective_area = abramowski_effective_area(np.diff(EBOUNDS)) arf = np_to_arf(effective_area, EBOUNDS) filename = 'xspec_test_arf.fits' logging.info('Writing {0}'.format(filename)) arf.writeto(filename, clobber=True)
from gammapy.spectrum.models import PowerLaw from gammapy.spectrum import calculate_predicted_counts, SpectrumExtraction, PHACountsSpectrum, SpectrumObservation from gammapy.utils.random import get_random_state import numpy as np import astropy.units as u import matplotlib.pyplot as plt e_true = SpectrumExtraction.DEFAULT_TRUE_ENERGY e_reco = SpectrumExtraction.DEFAULT_RECO_ENERGY # EDISP edisp = EnergyDispersion.from_gauss(e_true=e_true, e_reco=e_true, sigma=0.2) # AEFF nodes = np.sqrt(e_true[:-1] * e_true[1:]) data = abramowski_effective_area(energy=nodes) aeff = EffectiveAreaTable(data=data, energy=e_true) lo_threshold = aeff.find_energy(0.1 * aeff.max_area) # MODEL model = PowerLaw(index=2.3 * u.Unit(""), amplitude=2.5 * 1e-12 * u.Unit("cm-2 s-1 TeV-1"), reference=1 * u.TeV) # COUNTS livetime = 2 * u.h npred = calculate_predicted_counts(model=model, aeff=aeff, edisp=edisp, livetime=livetime) bkg = 0.2 * npred.data alpha = 0.1 counts_kwargs = dict( energy=npred.energy,
"""Plot approximate effective area for HESS, HESS2 and CTA.""" import numpy as np import matplotlib.pyplot as plt from astropy.units import Quantity from gammapy.irf import abramowski_effective_area energy = Quantity(np.logspace(-3, 3, 100), 'TeV') for instrument in ['HESS', 'HESS2', 'CTA']: a_eff = abramowski_effective_area(energy, instrument) plt.plot(energy.value, a_eff.value, label=instrument) plt.loglog() plt.xlabel('Energy (TeV)') plt.ylabel('Effective Area (cm^2)') plt.xlim([1e-3, 1e3]) plt.ylim([1e3, 1e12]) plt.legend(loc='best') plt.show()
from gammapy.spectrum import (calculate_predicted_counts, SpectrumExtraction, PHACountsSpectrum, SpectrumObservation) from gammapy.utils.random import get_random_state import numpy as np import astropy.units as u import matplotlib.pyplot as plt e_true = SpectrumExtraction.DEFAULT_TRUE_ENERGY e_reco = SpectrumExtraction.DEFAULT_RECO_ENERGY # EDISP edisp = EnergyDispersion.from_gauss(e_true=e_true, e_reco=e_true, sigma=0.2) # AEFF nodes = np.sqrt(e_true[:-1] * e_true[1:]) data = abramowski_effective_area(energy=nodes) aeff = EffectiveAreaTable(data=data, energy=e_true) lo_threshold = aeff.find_energy(0.1 * aeff.max_area) # MODEL model = PowerLaw(index=2.3 * u.Unit(''), amplitude=2.5 * 1e-12 * u.Unit('cm-2 s-1 TeV-1'), reference=1 * u.TeV) # COUNTS livetime = 2 * u.h npred = calculate_predicted_counts(model=model, aeff=aeff, edisp=edisp, livetime=livetime)
# Licensed under a 3-clause BSD style license - see LICENSE.rst """Plot approximate effective area for HESS, HESS2 and CTA. """ import numpy as np import matplotlib.pyplot as plt from astropy.units import Quantity from gammapy.irf import abramowski_effective_area energy = Quantity(np.logspace(-3, 3, 100), 'TeV') for instrument in ['HESS', 'HESS2', 'CTA']: a_eff = abramowski_effective_area(energy, instrument) plt.plot(energy.value, a_eff.value, label=instrument) plt.loglog() plt.xlabel('Energy (TeV)') plt.ylabel('Effective Area (cm^2)') plt.xlim([1e-3, 1e3]) plt.ylim([1e3, 1e12]) plt.legend(loc='best') plt.show()