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

Add plot_interactive method for 3D maps #1543

Merged
merged 4 commits into from Jul 27, 2018

Conversation

@facero
Contributor

facero commented Jul 18, 2018

Some code started at the coding sprint now fully functional.
I had to change a bit of the 2D plotting part and duplicate some of
code. Maybe there is a more elegant way to do that but this is a first
attempt.

First attempt for an interactive plotter of 3D Map
Some code started at the coding sprint now fully functional.
I had to change a bit of the 2D plotting part and duplicate some of
code. Maybe there is a more elegant way to do that but this is a first
attempt.
@facero

This comment has been minimized.

Show comment
Hide comment
@facero

facero Jul 18, 2018

Contributor

You need to have the ipywidgets installed. They are usually installed by defaults by you might wanna check.
conda install -c conda-forge ipywidgets

Can people try this on their machine to see if it works.
A simple working example is shown below:

# This is a simple test to show how a 3D Map object is plotted
# This only works in a Jupyter notebook with inline plots

%matplotlib inline
from gammapy.maps import WcsNDMap

cubefile="$GAMMAPY_EXTRA/datasets/vela_region/gll_iem_v05_rev1_cutout.fits"
m = WcsNDMap.read(cubefile)
m.plot()

Outputs this :
capture d ecran 2018-07-18 a 17 31 47

Contributor

facero commented Jul 18, 2018

You need to have the ipywidgets installed. They are usually installed by defaults by you might wanna check.
conda install -c conda-forge ipywidgets

Can people try this on their machine to see if it works.
A simple working example is shown below:

# This is a simple test to show how a 3D Map object is plotted
# This only works in a Jupyter notebook with inline plots

%matplotlib inline
from gammapy.maps import WcsNDMap

cubefile="$GAMMAPY_EXTRA/datasets/vela_region/gll_iem_v05_rev1_cutout.fits"
m = WcsNDMap.read(cubefile)
m.plot()

Outputs this :
capture d ecran 2018-07-18 a 17 31 47

@adonath adonath added the feature label Jul 18, 2018

@adonath adonath added this to the 0.9 milestone Jul 18, 2018

@adonath adonath self-assigned this Jul 18, 2018

@adonath

Thanks @facero for working on this. I've quickly tested it and it seems to work well, even for large datasets such as the Fermi-LAT galactic diffuse model. I've left a few inline comments.

In addition I have a few general comments, we should discuss about:

  • Even if I like plotting the spectrum in addition, I think it does not generalize very well to other axes, such as time or event id. So I'm leaning towards removing it again.
  • With the interactive visualization the plot method is really large and some functionality, such as passing and returning a WCSAxes object is not possible anymore. So I tend to rather introduce a separate plot_interactive() method and keep the .plot() method unchanged. Ideally it can be even reused in .plot_interactive().
Show outdated Hide outdated gammapy/maps/wcsnd.py
Show outdated Hide outdated gammapy/maps/wcsnd.py
Show outdated Hide outdated gammapy/maps/wcsnd.py
Show outdated Hide outdated gammapy/maps/wcsnd.py
Show outdated Hide outdated gammapy/maps/wcsnd.py
Show outdated Hide outdated gammapy/maps/wcsnd.py

@cdeil cdeil added this to To do in Map analysis via automation Jul 18, 2018

@cdeil

This comment has been minimized.

Show comment
Hide comment
@cdeil

cdeil Jul 18, 2018

Member

@facero - Thanks!

Agree with all comments by @adonath .

Separate methods are better for the user (each a simpler API) and for us to maintain (e.g. review, test).

For the spectrum line plot: I would also tend to maybe not add it.

Often one wants it for a region, and that's harder to configure. I'm pretty sure that things like https://js9.si.edu/ or http://aladin.u-strasbg.fr/AladinLite/ or http://ginga.readthedocs.io/ or new astro visualisers will develop really nice Jupyter Lab plugins and become a great interactive environment. It will just take a year or two. So for now, I'd suggest to keep it really simple concerning code additions to Gammapy, and maybe put the line plot or other interactive things into a tutorial notebook. Note that there's no need to have those as methods attached to the class, one can always put them as standalone functions and take the map object as input.

That said, @facero - if you really want this feature in, if it's a separate plot method, the cost / complexity for us is really low, I'd also be OK to put it in and try it out for a while (possibly reviewing again whether to keep it in Gammapy before the v1.0 release in the fall).

Member

cdeil commented Jul 18, 2018

@facero - Thanks!

Agree with all comments by @adonath .

Separate methods are better for the user (each a simpler API) and for us to maintain (e.g. review, test).

For the spectrum line plot: I would also tend to maybe not add it.

Often one wants it for a region, and that's harder to configure. I'm pretty sure that things like https://js9.si.edu/ or http://aladin.u-strasbg.fr/AladinLite/ or http://ginga.readthedocs.io/ or new astro visualisers will develop really nice Jupyter Lab plugins and become a great interactive environment. It will just take a year or two. So for now, I'd suggest to keep it really simple concerning code additions to Gammapy, and maybe put the line plot or other interactive things into a tutorial notebook. Note that there's no need to have those as methods attached to the class, one can always put them as standalone functions and take the map object as input.

That said, @facero - if you really want this feature in, if it's a separate plot method, the cost / complexity for us is really low, I'd also be OK to put it in and try it out for a while (possibly reviewing again whether to keep it in Gammapy before the v1.0 release in the fall).

@facero

This comment has been minimized.

Show comment
Hide comment
@facero

facero Jul 19, 2018

Contributor

Thanks for the quick review. All comennts by axel are easy to implement. The only one for which I haven't found a solution is the handling of **kwargs with interact.

The two main points raised are whether to keep the 2nd plot and whether to put this function in .plot() or .plot_XXX().

  • .plot() vs .plot_XX() : I'm in favor of keeping one plot function. I understand that this complicates the routine a bit but from a user point of view, I just want to do .plot() on all my objects. Having a too large diversity of functions, we might end up in people not using them because they simply don't know that they exist. In addition, it will be strange to have .plot() that works only for 2D Maps and .plot_interactive() that works only for >3D arrays and not 2D arrays. People will get used to .smooth() and .plot() function and introducing several more will be confusing. @registerrier @AtreyeeS any opinion ?

  • For the 2nd plot, I have no strong opinion, regarding @adonath comment, this will work if axes is a time dimension and will show a light curve. The 2nd plot could be an option set to False by default.

Contributor

facero commented Jul 19, 2018

Thanks for the quick review. All comennts by axel are easy to implement. The only one for which I haven't found a solution is the handling of **kwargs with interact.

The two main points raised are whether to keep the 2nd plot and whether to put this function in .plot() or .plot_XXX().

  • .plot() vs .plot_XX() : I'm in favor of keeping one plot function. I understand that this complicates the routine a bit but from a user point of view, I just want to do .plot() on all my objects. Having a too large diversity of functions, we might end up in people not using them because they simply don't know that they exist. In addition, it will be strange to have .plot() that works only for 2D Maps and .plot_interactive() that works only for >3D arrays and not 2D arrays. People will get used to .smooth() and .plot() function and introducing several more will be confusing. @registerrier @AtreyeeS any opinion ?

  • For the 2nd plot, I have no strong opinion, regarding @adonath comment, this will work if axes is a time dimension and will show a light curve. The 2nd plot could be an option set to False by default.

@AtreyeeS

This comment has been minimized.

Show comment
Hide comment
@AtreyeeS

AtreyeeS Jul 19, 2018

Contributor

This looks nice @facero !
I really like the adjoining line plot, so I will not vote for removing it completely.
We do need to think about how to handle this in case of hypercube maps though.

I have no strong opinion regarding point (1), ie, whether it should be one function or two separate functions. If the user is not in a jypyter notebook, but running a normal ipython session, trying to plot 3D maps will also give weird errors, no? Maybe then it would be better to have it as separate functions?

Contributor

AtreyeeS commented Jul 19, 2018

This looks nice @facero !
I really like the adjoining line plot, so I will not vote for removing it completely.
We do need to think about how to handle this in case of hypercube maps though.

I have no strong opinion regarding point (1), ie, whether it should be one function or two separate functions. If the user is not in a jypyter notebook, but running a normal ipython session, trying to plot 3D maps will also give weird errors, no? Maybe then it would be better to have it as separate functions?

Separated plot() for 2D and plot_interactive() for 3D maps
Added the possibility to handle **kwargs
@facero

This comment has been minimized.

Show comment
Hide comment
@facero

facero Jul 26, 2018

Contributor

I've modified the routine to separate the 2D and 3D parts. **kwargs can now be handled.
Minimal example is :

%matplotlib inline
from gammapy.maps import WcsNDMap

cubefile="$GAMMAPY_EXTRA/datasets/vela_region/gll_iem_v05_rev1_cutout.fits"
m = WcsNDMap.read(cubefile)

m.plot_interactive(cmap='gnuplot2')
Contributor

facero commented Jul 26, 2018

I've modified the routine to separate the 2D and 3D parts. **kwargs can now be handled.
Minimal example is :

%matplotlib inline
from gammapy.maps import WcsNDMap

cubefile="$GAMMAPY_EXTRA/datasets/vela_region/gll_iem_v05_rev1_cutout.fits"
m = WcsNDMap.read(cubefile)

m.plot_interactive(cmap='gnuplot2')

facero and others added some commits Jul 26, 2018

@cdeil

This comment has been minimized.

Show comment
Hide comment
@cdeil

cdeil Jul 27, 2018

Member

I tried this out locally; initially the stretch widget didn't work for me, not sure why, now it does. I did some edits in bb13faf . Merging this now. If anyone has an issue or wants to improve further, please open a new issue or PR.

@facero - Thanks!

Member

cdeil commented Jul 27, 2018

I tried this out locally; initially the stretch widget didn't work for me, not sure why, now it does. I did some edits in bb13faf . Merging this now. If anyone has an issue or wants to improve further, please open a new issue or PR.

@facero - Thanks!

@cdeil cdeil merged commit c6175ac into gammapy:master Jul 27, 2018

0 of 2 checks passed

continuous-integration/appveyor/pr Waiting for AppVeyor build to complete
Details
continuous-integration/travis-ci/pr The Travis CI build is in progress
Details

Map analysis automation moved this from To do to Done Jul 27, 2018

@cdeil cdeil changed the title from First attempt for an interactive plotter of 3D Map to Add plot_interactive method for 3D maps Aug 15, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment