Skip to content

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

Closed

Description

@seisman

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.

Activity

  1. added
    question
    on Mar 23, 2023
  2. yvonnefroehlich commented on Mar 26, 2023

    @yvonnefroehlich
    Member

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

  3. seisman commented on Apr 10, 2023

    @seisman
    MemberAuthor

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

  4. maxrjones commented on Apr 10, 2023

    @maxrjones
    Member

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

  5. added
    documentation
    help wanted
    and removed
    question
    on Apr 10, 2023
  6. added this to the 0.10.0 milestone on Apr 10, 2023
  7. yvonnefroehlich commented on Apr 11, 2023

    @yvonnefroehlich
    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?

  8. seisman commented on Apr 11, 2023

    @seisman
    MemberAuthor

    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)
  9. yvonnefroehlich commented on Apr 12, 2023

    @yvonnefroehlich
    Member

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

  10. seisman commented on Apr 12, 2023

    @seisman
    MemberAuthor

    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.

  11. yvonnefroehlich commented on Apr 16, 2023

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

  12. removed
    help wanted
    on Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentation

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions