-
Notifications
You must be signed in to change notification settings - Fork 194
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
Change SkyGaussian to spherical representation #2034
Change SkyGaussian to spherical representation #2034
Conversation
…alization on the celestial sphere
…metric-gaussian-spatial-model-on-the-sphere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @luca-giunti! This looks very good to me. I've left two inline comments about the quantity
handling in .evaluate()
once those are addressed the PR is ready to be merged.
gammapy/image/models/core.py
Outdated
exponent = -0.5 * (sep / sigma) ** 2 | ||
return norm * np.exp(exponent) | ||
a = 1.0 - np.cos(sigma) | ||
norm = (1 / (4 * np.pi * a * (1.0 - np.exp(-1.0 / a)))) * u.sr ** -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The term (...) * u,sr ** -1
creates a new quantity object every time the method is evaluated. By default all the data will be copied, which slows down the computation a lot. Please remove it here. Here is some info about this http://docs.astropy.org/en/stable/units/index.html#astropy-units-performance
gammapy/image/models/core.py
Outdated
a = 1.0 - np.cos(sigma) | ||
norm = (1 / (4 * np.pi * a * (1.0 - np.exp(-1.0 / a)))) * u.sr ** -1 | ||
exponent = -0.5 * ((1 - np.cos(sep)) / a) | ||
return (norm * np.exp(exponent)).to("deg-2") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead creating the quantity and doing the unit conversion here could you just create a Quantity
object like so:
return u.Quantity(norm * np.exp(exponent), unit="sr1", copy=False)
The same as is done for the SkyDisk
model...
Thank you @adonath for your comment! I agree, now the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @luca-giunti!
Redefined the
SkyGaussian
spatial model. The new function is correctly normalized on the celestial sphere, and reduces to an ordinary Gaussian definition in small angle approximation.