Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

to_spectrum_dataset() loses background model #5173

Open
LukasNickel opened this issue Mar 19, 2024 · 0 comments
Open

to_spectrum_dataset() loses background model #5173

LukasNickel opened this issue Mar 19, 2024 · 0 comments

Comments

@LukasNickel
Copy link

LukasNickel commented Mar 19, 2024

Gammapy version
1.1, 1.2

Bug description
Running to_spectrum_dataset() on a Mapdataset with a background model produces a spectrum dataset, that is constructed with just the IRF bkg and not the fitted model.

Expected behavior
It should take the fit into account. This is the case, when the mapdataset is first stacked / to_masked is run, because then the model is correctly applied.

Compare these two code pieces:

if self.stat_type == "cash":
if self.background and other.background:
background = self.npred_background()
background.stack(
other.npred_background(),
weights=other.mask_safe,
nan_to_num=nan_to_num,
)
self.background = background

if self.stat_type == "cash" and self.background:
kwargs["background"] = self.background.to_region_nd_map(
region, func=np.sum, weights=self.mask_safe
)

As the background does not know of the model, it is not applied.

From my understanding of the intended behavior, the first case is correct and the second one should be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants