fix npred_background
@@ -179,6 +179,7 @@ class MapDataset(Dataset):
self.counts = counts
self.exposure = exposure
self.background = background
+ self._background_cached = None
self.mask_fit = mask_fit
if psf and not isinstance(psf, (PSFMap, HDULocation)):
@@ -408,10 +409,16 @@ class MapDataset(Dataset):
Predicted counts from the background.
"""
background = self.background
-
if self.background_model and background:
values = self.background_model.evaluate_geom(geom=self.background.geom)
- background = background * values
+ if self._background_cached is None:
+ self._background_cached = background * values
+ else:
+ self._background_cached.data = background.data * values.data
+ self._background_cached.unit = background.unit
+ return self._background_cached
+ else:
+ return background
return background
