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

Fix energy_resolution method in EnergyDispersion class #1133

merged 2 commits into from Sep 14, 2017


Copy link

@lmohrmann lmohrmann commented Sep 14, 2017

The energy_resolution method in EnergyDispersion could only handle 1-dimensional inputs so far (see also #1132). With this PR, N-dimensional inputs are allowed:

import numpy as np
import astropy.units as u
from gammapy.irf import EnergyDispersion
e_true = np.logspace(-1, 2, 30) * u.TeV
e_reco = np.logspace(-2, 2, 20) * u.TeV
edisp = EnergyDispersion.from_gauss(e_true, e_reco)
print(edisp.get_resolution([[10, 20],[30, 40]] * u.TeV))

[[ 0.20902851  0.20850442]
 [ 0.20678505  0.19102049]]
Copy link

@joleroi joleroi commented Sep 14, 2017

Thanks @lmohrmann
In the end, it would be nice to have tests for all these functions, maybe you can also have a look at #1122

Regarding this PR is does not seem to break anything, so go ahead if you'd like to merge it

pdf =
mean = self._get_mean(e_true)
erec = self.e_reco._interp_nodes()
erec = np.repeat(erec, max(np.sum(mean.shape), 1)).reshape(erec.shape + mean.shape)

This comment has been minimized.


joleroi Sep 14, 2017

If I would have to moan about something, I'd ask you to put some comments here, what all this is doing. It's kind of annoying (at least for me) to have to decipher numpy expression all the time 😄

This comment has been minimized.


lmohrmann Sep 14, 2017
Author Contributor

Yeah, this is a bit ugly, but I guess this can hardly be avoided if N-dim arrays are supposed to work. The documentation I just added should make things a bit clearer, I hope.

Copy link
Contributor Author

@lmohrmann lmohrmann commented Sep 14, 2017

Merging this now, although I agree that the tests should be improved. This is better done in line with #1122, I guess.

@lmohrmann lmohrmann merged commit 912eb78 into gammapy:master Sep 14, 2017
1 of 2 checks passed
1 of 2 checks passed
continuous-integration/travis-ci/pr The Travis CI build is in progress
continuous-integration/appveyor/pr AppVeyor build succeeded
@lmohrmann lmohrmann deleted the lmohrmann:fix-reso-comp branch Sep 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants