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 tutorial to show interactive data visualization via 'panel' #2498

Merged
merged 54 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
f3e496b
Add basic code for tutorial showing the 'panel'
yvonnefroehlich Apr 16, 2023
8e0e0dd
Remove section 'Add a grid'
yvonnefroehlich Apr 16, 2023
9274b85
Fix code style - add blank line
yvonnefroehlich Apr 16, 2023
0133512
[format-command] fixes
actions-bot Apr 16, 2023
d55d7cf
Adjust thumbnail_number
yvonnefroehlich Apr 16, 2023
dccdf74
Add 'panel' as a dependency
yvonnefroehlich Apr 16, 2023
fdf180e
Add 'panel' as dependency
yvonnefroehlich Apr 16, 2023
8a50bde
Fix typos
yvonnefroehlich Apr 16, 2023
b548efa
Add missing comma
yvonnefroehlich Apr 16, 2023
c5d3e82
Fix highlighting
yvonnefroehlich Apr 16, 2023
5149655
Fix link
yvonnefroehlich Apr 16, 2023
28a72df
Improve docs
yvonnefroehlich Apr 16, 2023
bde882b
Add more docs
yvonnefroehlich Apr 16, 2023
3919f03
Adjust thubnail_number
yvonnefroehlich Apr 16, 2023
b046aac
Add code for third part (add grid)
yvonnefroehlich Apr 16, 2023
c9b213e
Fix coding style
yvonnefroehlich Apr 16, 2023
a4c7c2a
Remove blank line
yvonnefroehlich Apr 16, 2023
1cec47e
Do not include 'panel' as an optional dependency in 'pyproject.py'
yvonnefroehlich Apr 17, 2023
55b7203
Do not include 'panel' as an optional dependency in 'install.rst'
yvonnefroehlich Apr 17, 2023
0f25508
Improve link to 'panel'
yvonnefroehlich Apr 17, 2023
66b0087
Move 'panel' to 'Dev dependencies (building documentation)'
yvonnefroehlich Apr 17, 2023
d004415
Fix list - add blank line
yvonnefroehlich Apr 17, 2023
cea4021
Move 'panel' to 'Dev dependencies (building documentation)'
yvonnefroehlich Apr 17, 2023
84541a4
Remove 'panel' from 'conf.py'
yvonnefroehlich Apr 17, 2023
8a5c31a
Fix typo (code review)
yvonnefroehlich Apr 17, 2023
8f93932
Rename 'panel_extension.py' -> 'working_with_panel.py'
Apr 18, 2023
8de8053
Merge branch 'main' into add-tutorial-panel
yvonnefroehlich Apr 19, 2023
7a8a5aa
Improve and add documentation
yvonnefroehlich Apr 22, 2023
8dcd549
Merge branch 'main' into add-tutorial-panel
yvonnefroehlich Apr 22, 2023
99a1fec
Adjust G projection for static map
yvonnefroehlich Apr 22, 2023
afbf83f
Add docs for grid section
yvonnefroehlich Apr 22, 2023
b862ba6
Improve docs for dynamic section
yvonnefroehlich Apr 22, 2023
36d6931
Use alwaysthe same size
yvonnefroehlich Apr 22, 2023
3a050bc
Add docs for static section
yvonnefroehlich Apr 22, 2023
def14dd
Improve docs for introduction
yvonnefroehlich Apr 22, 2023
e314ea6
Improve docs
yvonnefroehlich Apr 22, 2023
be31019
Use 'note' highlighting (code review)
yvonnefroehlich Apr 23, 2023
15dbff7
Fix line length
yvonnefroehlich Apr 23, 2023
009228a
Add 'panel' as a dependency in 'ci_docs.yml'
yvonnefroehlich Apr 23, 2023
4469d2e
Merge branch 'main' into add-tutorial-panel
yvonnefroehlich Apr 25, 2023
ed45c1e
Change 'dynamic' -> 'interactive'
yvonnefroehlich Apr 25, 2023
656b0f5
Change 'dynamic' -> 'interactive'
yvonnefroehlich Apr 25, 2023
5b7eff9
Change 'dynamic' -> 'interactive'
yvonnefroehlich Apr 25, 2023
d830c28
Calculate min and max without numpy
yvonnefroehlich Apr 25, 2023
f3431e0
Adjust building string for projection argument
yvonnefroehlich Apr 25, 2023
40589ec
Adjust building string for projection argument
yvonnefroehlich Apr 25, 2023
3e3ea36
Remove white spaces around "/"
yvonnefroehlich Apr 25, 2023
ea81b1d
Update file name in introduction
yvonnefroehlich Apr 25, 2023
c3fd8e7
Fix length of underline of title
yvonnefroehlich Apr 25, 2023
fe456aa
Adjust 'series' parameter of 'makecpt'
yvonnefroehlich Apr 25, 2023
49c0eb2
Fix line length
yvonnefroehlich Apr 25, 2023
0e6ef65
Remove file name in introduction
yvonnefroehlich Apr 25, 2023
68ba2e5
Fix coding style - 'series' argument seems to fit in one line
yvonnefroehlich Apr 25, 2023
71ddb12
Remove 'r' at the beginning of the docstrings (code review)
yvonnefroehlich Apr 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ci/requirements/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies:
# Optional dependencies
- contextily
- geopandas
- panel
seisman marked this conversation as resolved.
Show resolved Hide resolved
- rioxarray
# Development dependencies (general)
- build
Expand Down
1 change: 1 addition & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"numpy": ("https://numpy.org/doc/stable/", None),
"python": ("https://docs.python.org/3/", None),
"pandas": ("https://pandas.pydata.org/pandas-docs/stable/", None),
"panel": ("https://panel.holoviz.org/index.html", None),
yvonnefroehlich marked this conversation as resolved.
Show resolved Hide resolved
"rasterio": ("https://rasterio.readthedocs.io/en/stable/", None),
"rioxarray": ("https://corteva.github.io/rioxarray/stable/", None),
"xarray": ("https://docs.xarray.dev/en/stable/", None),
Expand Down
1 change: 1 addition & 0 deletions doc/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ The following are optional dependencies:
* `IPython <https://ipython.org>`__: For embedding the figures in Jupyter notebooks (recommended).
* `Contextily <https://contextily.readthedocs.io>`__: For retrieving tile maps from the internet.
* `GeoPandas <https://geopandas.org>`__: For using and plotting GeoDataFrame objects.
* `Panel <https://panel.holoviz.org/index.html>`__: For creating interactive dashboards.
yvonnefroehlich marked this conversation as resolved.
Show resolved Hide resolved
* `RioXarray <https://corteva.github.io/rioxarray>`__: For saving multi-band rasters to GeoTIFFs.

Installing GMT and other dependencies
Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dependencies:
- contextily
- geopandas
- ipython
- panel
yvonnefroehlich marked this conversation as resolved.
Show resolved Hide resolved
- rioxarray
# Development dependencies (general)
- build
Expand Down
121 changes: 121 additions & 0 deletions examples/tutorials/advanced/panel_extension.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
r"""
yvonnefroehlich marked this conversation as resolved.
Show resolved Hide resolved
Dynamic data visualization using ``Panel``
==========================================
*Please run the following code examples in a notebook environment otherwise
the interactive parts of this tutorial will not work. You can use the button
"Download Jupyter notebook: panel_extension.ipynb" at the bottom of this page
to download this script as a Jupyter notebook.*

The library ``Panel`` (https://panel.holoviz.org/index.html) can be used to
yvonnefroehlich marked this conversation as resolved.
Show resolved Hide resolved
create interactive dashboards by connecting user-defined widgets to plots.
``Panel`` can be used as an extension to Jupyter notebook / lab.

This tutorial is split into three parts:
- Make a static map
- Make a dynamic map
- Add a grid for Earth relief
"""

# sphinx_gallery_thumbnail_number = 1


# Import the requiered packages
import numpy as np
import panel as pn
import pygmt

pn.extension()


###############################################################################
# Make a static map
# -----------------

# Create figure instance
fig = pygmt.Figure()
fig.coast(
projection="G30/15/10c", # Orthographic projection
region="g", # global
frame="g30", # Add gridlines in steps of 30 degrees on top
land="gray",
water="lightblue",
shorelines="1/0.25p,gray50",
)
fig.show()


###############################################################################
# Make a dynamic map
# ------------------
# Vary the central longitude used for the Orthographic projection to create
# a rotation of the Earth around the vertical axis.

# Create a slider
slider_lon = pn.widgets.DiscreteSlider(
name="Central longitude",
options=list(np.arange(0, 361, 10)),
value=0,
)


# Define a function for plotting the single slices
@pn.depends(central_lon=slider_lon)
def view(central_lon):
# Create figure instance
fig = pygmt.Figure()
fig.coast(
# Vary the central longitude used for the Orthographic projection
projection="G" + str(central_lon) + "/15/12c",
region="g",
frame="g30", # Add gridlines in steps of 30 degrees on top
land="gray",
water="lightblue",
shorelines="1/0.25p,gray50",
)
return fig


# Make an interactive dashboard
pn.Column(slider_lon, view)


###############################################################################
# Add a grid for Earth relief
# ---------------------------

# Download a grid for Earth relief
grd_relief = pygmt.datasets.load_earth_relief(resolution="10m")

# Create a slider
slider_lon = pn.widgets.DiscreteSlider(
name="Central longitude",
options=list(np.arange(0, 361, 10)),
value=0,
)


# Define a function for plotting the single slices
@pn.depends(central_lon=slider_lon)
def view(central_lon):
# Create figure instance
fig = pygmt.Figure()
# Set up a colormap for the elevation
pygmt.makecpt(
cmap="oleron",
series=[int(np.min(grd_relief)), int(np.max(grd_relief)) + 1, 100],
)
# Plot the grid for the elevation
fig.grdimage(
projection="G" + str(central_lon) + "/15/12c",
region="g",
grid=grd_relief, # Use gird downloaded above
yvonnefroehlich marked this conversation as resolved.
Show resolved Hide resolved
cmap=True, # Use colormap defined above
frame="g30", # Add gridlines in steps of 30 degrees on top
)
# Add a colorbar for the elevation
fig.colorbar(frame=["a2000f1000", "x+lElevation", "y+lm"])
return fig


# Make an interactive dashboard
pn.Column(slider_lon, view)
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ all = [
"contextily",
"geopandas",
"ipython",
"panel",
yvonnefroehlich marked this conversation as resolved.
Show resolved Hide resolved
"rioxarray",
]

Expand Down