{{ message }}

# gammapy / gammapy Public

Merged
Merged

## Conversation

### luca-giunti commented Feb 21, 2019

 Added elliptical model defined and normalized on the sphere. The doc includes an example that produces an illustrative plot The text was updated successfully, but these errors were encountered:
added 2 commits Feb 21, 2019
 Added new model and a test 
 01637a1 
 Removed trailing whitespaces 
 fc5d861 
self-requested a review Feb 22, 2019
self-assigned this Feb 22, 2019
added this to In progress in gammapy.modeling via automation Feb 22, 2019
added this to the 0.11 milestone Feb 22, 2019
requested changes

Thanks @luca-giunti! I've left a few in-line comments mainly concerning the code style. I really like the example plot. It's very illustrative. We should consider adding one for the other models as well.

My main comment would be to add a second test, using a larger ellipse radius to better check the normalization.

 :math:\text{lon}_0: lon coordinate for the center of the ellipse. lat_0 : ~astropy.coordinates.Latitude :math:\text{lat}_0: lat coordinate for the center of the ellipse. semi_major : ~astropy.coordinates.Angle

Maybe it's an option to rename it to r_0 to be consistent with SkyDisk model, for e = 0...I have no strong opinion here.

### luca-giunti Feb 22, 2019

Thank you for all your comments! So yes, using r_0 might be an option. I think it might lead to some confusion, however. Indeed, if the model is wrongly passed the minor semiaxis it misbehaves

 Eccentricity of the ellipse (:math:0< e< 1). theta : ~astropy.coordinates.Angle :math:\theta: Rotation angle of the major semiaxis. The

Here is a bad line break...

 Examples --------

The title and underline have to be aligned to be correctly rendered by sphinx...

 :include-source: import numpy as np from gammapy.image.models.core import *

Please replace by the explicit import from gammapy.image.models import SkyEllipse. In Python it's actually never recommended to use the * import, because it can silently overwrite variable and function names. Imagine you would use from math import * and from numpy import *, this would lead to a completely messy namespace...

### luca-giunti Feb 22, 2019

Thank you! very instructive

 from gammapy.maps import Map, WcsGeom import matplotlib.pyplot as plt from matplotlib import rc rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})

This modifies the global rc state of matplotlib, that means if a user does a second plot in the same Python session, those changes will also apply to the second one, which might not be desired. Instead you could use the rc_context context manager. You'll find examples on the linked page, as well as in the Gammapy code e.g. https://github.com/gammapy/gammapy/blob/master/gammapy/maps/base.py#L998

 ] ) def find_foci(lon_0, lat_0, semi_major, e, theta):

I think it's not super-useful to have this as a separate method, just because I don't think it will be called by users. It could be in the .evaluate() method as well...do as you prefer.

 assert_allclose( np.sum(mymap.quantity * u.sr ** -1 * m_allsky.solid_angle()), 1, rtol=5.0e-4 )

Maybe add a second test case with an even larger radius for the ellipse (~10 deg) to check that the normalisation is correct?

### luca-giunti Feb 22, 2019

Yes sure! I'll do that. Altough I think it may somewhat increase the computation time for the test

Of course, you can choose a coarser pixel size to limit the computation time...

 norm = u.Quantity( SkyEllipse.compute_norm(semi_major, e), unit="sr-1", copy=False ) result = np.select([in_ellipse], [norm])

I think np.select() does not work properly with Quantity, that's probably why the instance check is needed later. You could simplify the code as following:

norm = SkyEllipse.compute_norm()
return u.Quantity(norm * in_ellipse, "sr-1", copy=False)


This implicitly does the type-cast of the bool array in_ellipse, but it works correctly with Quantity as well.

 vals=ell(lon,lat) mymap=Map.from_geom(m_geom,data=vals.value) fig,ax,_=mymap.plot()

Please reformat the example according to PEP8 standards (https://www.python.org/dev/peps/pep-0008/). There is probably a plugin avalaible for your editor...

and others added 10 commits Feb 26, 2019
 Applied suggested changes 
 c937e70 
 Improved test 
 2adb887 
 Added a test and an exception 
 f6167d5 
 Fixed reimport issue 
 72a3ec1 
 Removed static method from evaluate 
 842deb8 
 Improved test 
 e337939 
 Modified exception 
 1d83d6b 
 improved exception 
 f709b7e 
 Removed unused import 
 2109689 
 Simplify SkyEllipse example plot 
 85726b2 
approved these changes
merged commit dd8b9f9 into gammapy:master Feb 28, 2019
2 of 8 checks passed
gammapy.modeling automation moved this from In progress to Done Feb 28, 2019
changed the title Add elliptical model defined on the sphere Add SkyEllipse model Mar 26, 2019