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

Add an gallery example/tutorial for interactive data visualization using Panel? #2455

Closed
seisman opened this issue Mar 23, 2023 · 8 comments · Fixed by #2498
Closed

Add an gallery example/tutorial for interactive data visualization using Panel? #2455

seisman opened this issue Mar 23, 2023 · 8 comments · Fixed by #2498
Labels
documentation Improvements or additions to documentation
Milestone

Comments

@seisman
Copy link
Member

seisman commented Mar 23, 2023

The EGU22 PyGMT short course provides an example showing how to use Panel for interactive data visualization with PyGMT (https://www.generic-mapping-tools.org/egu22pygmt/ecosystem.html#interactive-data-visualization-with-xarray-panel-and-pygmt).

I just tried it and found it sometimes useful to explore the effects of different GMT parameters (especially before we implement the movie method #1347).

For example, here is an example to show how the azimuth can affect grid shading (modified from https://www.pygmt.org/dev/gallery/images/grdgradient_shading.html):

import numpy as np
import panel as pn
import xarray as xr
import pygmt

pn.extension()

# Make a panel widget for controlling the depth plotted
az_slider = pn.widgets.DiscreteSlider(name='Azimuth', options=list(np.arange(0, 360, 15)), value=0)

grid = pygmt.datasets.load_earth_relief(resolution="03m", region=[35, 50, 35, 45])

@pn.depends(az=az_slider)
def view(az):
    fig = pygmt.Figure()
    pygmt.makecpt(cmap="terra", series=[-7000, 7000])
    shade = pygmt.grdgradient(grid=grid, azimuth=az, normalize="e2")
    fig.grdimage(
        grid=grid,
        shading=shade,
        projection="M15c",
        frame=["a4f2", f"+tazimuth={az}"],
        cmap=True,
    )
    fig.colorbar(frame="af")
    return fig

pn.Column(az_slider, view)

Here is a screencast showing how it works locally:

Screencast.from.2023-03-23.16-55-53.webm

Although the interactive widget doesn't work on our static HTML documentation, users can still copy-and-paste the codes to try it on their own Jupyter notebooks. So I think such a tutorial is still very useful.

@seisman seisman added the question Further information is requested label Mar 23, 2023
@yvonnefroehlich
Copy link
Member

yvonnefroehlich commented Mar 26, 2023

I just tried it and found it sometimes useful to explore the effects of different GMT parameters (especially before we implement the movie method #1347).

Yep, this is a quite nice way to show or test the variation of one parameter or quantity, while the rest of the map / plot remains the same. Also tried this already based on this EGU ShortCourse example 🙂.

@seisman
Copy link
Member Author

seisman commented Apr 10, 2023

Ping @maxrjones for thoughts/comments on the potential gallery example using "Panel" before someone takes the time to work on it.

@maxrjones
Copy link
Member

Yes, I think this is a good idea. I'll be happy to provide a review.

@seisman seisman added documentation Improvements or additions to documentation help wanted Helping hands are appreciated and removed question Further information is requested labels Apr 10, 2023
@seisman seisman added this to the 0.10.0 milestone Apr 10, 2023
@yvonnefroehlich
Copy link
Member

I would be happy to give this a try. @GenericMappingTools/pygmt-maintainers is there a parameter of a plotting method you have in mind to highlight in this example? Currently, I am wondering whether pygmt.meca is suitable (looking at dip, strike, or rake). Or should we better show a quantity which is not directly related to a PyGMT parameter, like in the EGU Short Course example?

@seisman
Copy link
Member Author

seisman commented Apr 11, 2023

Currently, I am wondering whether pygmt.meca is suitable (looking at dip, strike, or rake).

I'm afraid this is not a good example, because (1) three variables (strike, dip and rake) may make the example slightly more complicated (2) non-seismologists may find it hard to understand the example.

Or should we better show a quantity which is not directly related to a PyGMT parameter, like in the EGU Short Course example?

Some simpler examples in my mind:

  1. A global map with varying central longitude (similar to this animation https://docs.generic-mapping-tools.org/latest/animations/anim07.html but coastlines are enough)
  2. Day-night terminator line which depends on the datetime (dynamic version of https://www.pygmt.org/dev/gallery/embellishments/solar.html)

@yvonnefroehlich
Copy link
Member

We probably have to add panel as a dependency, or? Should this be done in a seperate PR?

@seisman
Copy link
Member Author

seisman commented Apr 12, 2023

We probably have to add panel as a dependency, or? Should this be done in a seperate PR?

You can add it in the same PR as the gallery example and we will see how it works.

@yvonnefroehlich
Copy link
Member

Currently, I am wondering whether pygmt.meca is suitable (looking at dip, strike, or rake).

I'm afraid this is not a good example, because (1) three variables (strike, dip and rake) may make the example slightly more complicated (2) non-seismologists may find it hard to understand the example.

Or should we better show a quantity which is not directly related to a PyGMT parameter, like in the EGU Short Course example?

Some simpler examples in my mind:

  1. A global map with varying central longitude (similar to this animation https://docs.generic-mapping-tools.org/latest/animations/anim07.html but coastlines are enough)
  2. Day-night terminator line which depends on the datetime (dynamic version of https://www.pygmt.org/dev/gallery/embellishments/solar.html)

I started working on a tutorial in PR #2498 and used the first suggestion by @seisman.

@yvonnefroehlich yvonnefroehlich removed the help wanted Helping hands are appreciated label Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants