Allow for MapDataset.model=None in npred computation
@@ -230,14 +230,15 @@ class MapDataset(Dataset):
@property
def parameters(self):
"""List of parameters (`~gammapy.utils.fitting.Parameters`)"""
+ parameters = []
+
+ if self.model:
+ parameters += self.model.parameters.parameters
+
if self.background_model:
- parameters = Parameters(
- self.model.parameters.parameters
- + self.background_model.parameters.parameters
- )
- else:
- parameters = Parameters(self.model.parameters.parameters)
- return parameters
+ parameters += self.background_model.parameters.parameters
+
+ return Parameters(parameters)
@property
def _geom(self):
@@ -253,11 +254,12 @@ class MapDataset(Dataset):
def npred(self):
"""Predicted source and background counts (`~gammapy.maps.Map`)."""
- if self.background_model:
- npred_total = self.background_model.evaluate()
- else:
npred_total = Map.from_geom(self._geom)
+ if self.background_model:
+ npred_total += self.background_model.evaluate()
+
+ if self.model:
for evaluator in self._evaluators:
# if the model component drifts out of its support the evaluator has
# has to be updated
