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

Change SkyGaussian to spherical representation #2034

Conversation

luca-giunti
Copy link
Contributor

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.

@adonath adonath self-requested a review February 16, 2019 15:36
@adonath adonath added this to the 0.11 milestone Feb 16, 2019
Copy link
Member

@adonath adonath left a 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.

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
Copy link
Member

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

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")
Copy link
Member

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...

@luca-giunti
Copy link
Contributor Author

Thank you @adonath for your comment! I agree, now the .evaluate() should be more efficient. It returns a Quantity with units sr-1, similarly to what SkyDisk does

Copy link
Member

@adonath adonath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @luca-giunti!

@adonath adonath merged commit e05988c into gammapy:master Feb 18, 2019
@adonath adonath changed the title Redefine symmetric gaussian spatial model on the sphere Change symmetric gaussian spatial model to spherical representation Mar 26, 2019
@adonath adonath changed the title Change symmetric gaussian spatial model to spherical representation Change SkyGaussian to spherical representation Mar 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants