Skip to content

Commit

Permalink
Added the axes consistency check in ExtendedSourceResponse.get_expect…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
hiyoneda committed Oct 22, 2024
1 parent a57736a commit c99b1e1
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions cosipy/response/ExtendedSourceResponse.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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):
"""
Expand Down

0 comments on commit c99b1e1

Please sign in to comment.