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

Fix bug in LightCurveEstimator #1347

Merged
merged 2 commits into from Mar 22, 2018

Conversation

Projects
None yet
3 participants
@lmohrmann
Contributor

lmohrmann commented Mar 22, 2018

Due to this bug, the energy threshold is not applied when calculating the expected counts.

@lmohrmann lmohrmann requested a review from cdeil Mar 22, 2018

@jlenain

This comment has been minimized.

Contributor

jlenain commented Mar 22, 2018

Hi @lmohrmann,
Actually, @bkhelifi raised this issue also, and he rather suggested the attached fix.

@cdeil cdeil added the bug label Mar 22, 2018

@cdeil cdeil added this to the 0.8 milestone Mar 22, 2018

@cdeil

This comment has been minimized.

Member

cdeil commented Mar 22, 2018

@lmohrmann @jlenain @bkhelifi - Any preference on which fix to put?

diff --git a/gammapy/time/lightcurve.py b/gammapy/time/lightcurve.py
index 7d227ff9..28c6b1dd 100644
--- a/gammapy/time/lightcurve.py
+++ b/gammapy/time/lightcurve.py
@@ -428,7 +428,7 @@ class LightCurveEstimator(object):
                 model=spectral_model
             )
             counts_predictor.run()
-            counts_predicted_excess = counts_predictor.npred.data.data[e_idx[:-1]]
+            counts_predicted_excess = counts_predictor.npred.data.data[e_idx[:]]
 
             obs_predicted_excess = np.sum(counts_predicted_excess)
 

@lmohrmann - Can you please add a regression test, i.e. an assert that would change the reference value with this fix?

@lmohrmann

This comment has been minimized.

Contributor

lmohrmann commented Mar 22, 2018

Any preference on which fix to put?

I definitively think the fix I proposed is the correct one. The fix proposed by @bkhelifi will raise an IndexError whenever the upper threshold is above the specified energy binning.

Can you please add a regression test, i.e. an assert that would change the reference value with this fix?

Turns out the tests were already covering this. I fixed them.

@cdeil

cdeil approved these changes Mar 22, 2018

@cdeil cdeil merged commit 62e2cc6 into gammapy:master Mar 22, 2018

1 of 2 checks passed

continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
@cdeil

This comment has been minimized.

Member

cdeil commented Mar 22, 2018

@lmohrmann - Thanks!

@bkhelifi @jlenain - Please try again with Gammapy master, and please do open issues in the tracker when you find them.

@lmohrmann lmohrmann deleted the lmohrmann:fix-lightcurve branch Mar 22, 2018

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