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
merged 2 commits into from Sep 14, 2017

Conversation

@lmohrmann
Copy link
Contributor

@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))
print(edisp.get_resolution(10*u.TeV))
print(edisp.get_resolution(20*u.TeV))
print(edisp.get_resolution(30*u.TeV))
print(edisp.get_resolution(40*u.TeV))

[[ 0.20902851  0.20850442]
 [ 0.20678505  0.19102049]]
0.209028510522
0.208504420638
0.206785053106
0.191020494988
@joleroi
Copy link
Contributor

@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 = self.data.evaluate(e_true=e_true)
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

joleroi Sep 14, 2017
Contributor

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

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.

@lmohrmann
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
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
@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
Labels
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants