# In[ ]: pwl = PowerLaw(index=2.3, amplitude=1e-11 * u.Unit("cm-2 s-1 TeV-1"), reference=1 * u.TeV) print(pwl) # In[ ]: livetime = 2 * u.h sim = SpectrumSimulation(aeff=aeff, edisp=edisp, source_model=pwl, livetime=livetime) sim.simulate_obs(seed=2309, obs_id=1) print(sim.obs) # In[ ]: fit = SpectrumFit(obs_list=sim.obs, model=pwl.copy(), stat="cash") fit.fit_range = [1, 10] * u.TeV fit.run() print(fit.result[0]) # ## Include background # # In this section we will include a background component. Furthermore, we will also simulate more than one observation and fit each one individuallt in order to get average fit results. # In[ ]:
edisp = edisp.to_energy_dispersion(offset=offset) aeff = aeff.to_effective_area_table(offset=offset) #fig, axes = plt.subplots(1, 2, figsize=(12, 6)) #edisp.plot_matrix(ax=axes[0]) #aeff.plot(ax=axes[1]) #plt.show() aeff.lo_threshold = lo_threshold aeff.hi_threshold = hi_threshold sim = SpectrumSimulation(aeff=aeff, edisp=edisp, source_model=model, livetime=livetime) sim.simulate_obs(seed=42, obs_id=0) sim.obs.peek() print sim.obs plt.show() fit = SpectrumFit(obs_list=sim.obs, model=model, stat='cash') fit.run() result = fit.result[0] print result energy_range = [0.1, 100] * u.TeV model.plot(energy_range=energy_range, energy_power=2) result.model.plot(energy_range=energy_range, energy_power=2) result.model.plot_error(energy_range=energy_range, energy_power=2)