diff --git a/cosipy/response/ExtendedSourceResponse.py b/cosipy/response/ExtendedSourceResponse.py index 425c4d62..9cf06930 100644 --- a/cosipy/response/ExtendedSourceResponse.py +++ b/cosipy/response/ExtendedSourceResponse.py @@ -1,5 +1,6 @@ from histpy import Histogram, Axes, Axis import numpy as np +import astropy.units as u from .functions import get_integrated_extended_model @@ -84,8 +85,19 @@ def get_expectation(self, allsky_image_model): Histogram A histogram representing the calculated expectation. """ - return Histogram(edges=self.axes[2:], - contents=np.tensordot(allsky_image_model.contents, self.contents, axes=([0,1], [0,1])) * self.axes[0].pixarea()) + if self.axes[0].label == allsky_image_model.axes[0].label \ + and self.axes[1].label == allsky_image_model.axes[1].label \ + and np.all(self.axes[0].edges == allsky_image_model.axes[0].edges) \ + and np.all(self.axes[1].edges == allsky_image_model.axes[1].edges) \ + and allsky_image_model.unit == u.Unit('1/(s*cm*cm*sr)'): + + contents = np.tensordot(allsky_image_model.contents, self.contents, axes=([0,1], [0,1])) + contents *= self.axes[0].pixarea() + + return Histogram(edges=self.axes[2:], contents=contents) + + else: + raise ValueError(f"The input allskymodel mismatches with the extended source response.") def get_expectation_from_astromodel(self, source): """