def test_ring_background_estimator(images): ring = RingBackgroundEstimator(0.35 * u.deg, 0.3 * u.deg) result = ring.run(images) in_fov = images["background"].data > 0 assert_allclose(result["background_ring"].data[in_fov], 2.0) assert_allclose(result["alpha"].data[in_fov].mean(), 0.003488538457592745) assert_allclose(result["exposure_off"].data[in_fov].mean(), 305.1268970794541) assert_allclose(result["off"].data[in_fov].mean(), 610.2537941589082) assert_allclose(result["off"].data[~in_fov], 0.0) assert_allclose(result["exposure_off"].data[~in_fov], 0.0) assert_allclose(result["alpha"].data[~in_fov], 0.0)
# # We'll run a spectral analysis using the classical reflected regions background estimation method, # and using the on-off (often called WSTAT) likelihood function. # # ### Extraction # # The first step is to "extract" the spectrum, i.e. 1-dimensional counts and exposure and background vectors, as well as an energy dispersion matrix from the data and IRFs. # In[24]: bkg_estimator = ReflectedRegionsBackgroundEstimator( obs_list=obs_list, on_region=on_region, exclusion_mask=exclusion_mask, ) bkg_estimator.run() bkg_estimate = bkg_estimator.result bkg_estimator.plot() # In[25]: extract = SpectrumExtraction( obs_list=obs_list, bkg_estimate=bkg_estimate, ) extract.run() # ### Model fit # # The next step is to fit a spectral model, using all data (i.e. a "global" fit, using all energies).