Adding a further test
@@ -1366,6 +1366,7 @@ def test_downsample_onoff():
def test_compute_flux_spatial():
center = SkyCoord("0 deg", "0 deg", frame="galactic")
region = RectangleSkyRegion(center=center, width = 0.5 * u.deg, height=0.5 * u.deg)
+ region_1sigma = CircleSkyRegion(center=center, radius=0.1 * u.deg)
energy_axis_true = MapAxis.from_energy_bounds(".1 TeV", "10 TeV", nbin=10, name="energy_true")
energy_axis = MapAxis.from_energy_bounds(".1 TeV", "10 TeV", nbin=10, name="energy")
@@ -1375,11 +1376,9 @@ def test_compute_flux_spatial():
model = SkyModel(spectral_model=spectral_model, spatial_model=spatial_model)
- psf = PSFMap.from_gauss(energy_axis_true)
+ psf = PSFMap.from_gauss(energy_axis_true, sigma=0.1*u.deg)
# for a region
- geom = RegionGeom(region)
-
exposure_region = RegionNDMap.create(region, axes=[energy_axis_true])
exposure_region.data += 1e8
exposure_region.unit = "m2 s"
@@ -1391,10 +1390,25 @@ def test_compute_flux_spatial():
dataset_region.models = [model]
npred_region = dataset_region.npred()
+ npred_region = np.reshape(npred_region.data,(10))
+
+ # for a 1sigma psf size region
+ exposure_region_1sigma = RegionNDMap.create(region_1sigma, axes=[energy_axis_true])
+ exposure_region_1sigma.data += 1e8
+ exposure_region_1sigma.unit = "m2 s"
+
+ background_region_1sigma = RegionNDMap.create(region_1sigma, axes=[energy_axis])
+ background_region_1sigma.data += 2
+
+ dataset_region_1sigma = MapDataset(psf=psf, exposure=exposure_region_1sigma, background=background_region_1sigma)
+ dataset_region_1sigma.models = [model]
+
+ npred_region_1sigma = dataset_region_1sigma.npred()
+ npred_region_1sigma = np.reshape(npred_region_1sigma.data,(10))
# for a WCSmap
exposure_wcs = WcsNDMap.create(skydir=center, axes=[energy_axis_true], frame='galactic', binsz=0.01, width=(0.5*u.deg,0.5*u.deg))
- exposure_wcs.data += 10e8
+ exposure_wcs.data += 9.945e8
exposure_wcs.unit = "m2 s"
background_wcs = WcsNDMap.create(skydir=center, axes=[energy_axis], frame='galactic', binsz=0.01, width=(0.5*u.deg,0.5*u.deg))
@@ -1407,4 +1421,7 @@ def test_compute_flux_spatial():
npred_wcs_stacked = npred_wcs.data.sum(axis=1).sum(axis=1)
assert_allclose(np.reshape(npred_region.data,(10)),
- npred_wcs_stacked, atol=22)
+ npred_wcs_stacked, atol=0.04)
+
+ assert_allclose(npred_region_1sigma/npred_wcs_stacked,
+ 0.70, atol=0.02)
