from gammapy.modeling import Fit from gammapy.modeling.models import PowerLawSpectralModel from gammapy.maps import Map # Load simulated photon counts data counts_map = Map.read('sim_counts.fits') # Create a PowerLawSpectralModel with initial parameters model = PowerLawSpectralModel(amplitude='1e-11 cm-2 s-1 TeV-1', index=2.3) # Fit the model to the data fit = Fit([counts_map], model) result = fit.run() # Plot the best-fit curve result.plot_fit()
from gammapy.utils.energy import Energy # Create an Energy object with a value of 1 TeV energy = Energy(1, 'TeV') # Evaluate the PowerLawSpectralModel at the given energy value model = PowerLawSpectralModel(amplitude='1e-11 cm-2 s-1 TeV-1', index=2.3) flux = model.evaluate(energy) # Print out the flux value print(f'Flux at {energy.to("TeV").value:.1f} TeV: {flux:.2e} cm-2 s-1 TeV-1')Package library: gammapy.modeling.models