-
Notifications
You must be signed in to change notification settings - Fork 228
Add intro tutorial section for creating contour map #2126
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
Merged
Merged
Changes from 17 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
e475966
create first section of contour map tutorial
willschlitzer dd2641b
add planned future sections
willschlitzer 6087e93
add colorbar tutorial
willschlitzer bb28247
add grdcontour example
willschlitzer 4af17a9
add coast example
willschlitzer e47099a
add additional exercises
willschlitzer da73066
change Sphinx thumbnail
willschlitzer 1db87f0
Merge branch 'main' into tutorial/contour-map
willschlitzer 2e1ad58
Merge remote-tracking branch 'origin/tutorial/contour-map' into tutor…
willschlitzer 9b53fca
wording fix
willschlitzer 32d55bc
Update examples/get-started/contour-map.py
willschlitzer 65ada4e
Merge branch 'main' into tutorial/contour-map
willschlitzer d342fbf
add N00E135.earth_relief_30s_g.nc to cache in testing.py
willschlitzer c7bc845
uncomment pull_request in cache_data.yaml
willschlitzer a7acfbf
Merge branch 'main' into tutorial/contour-map
willschlitzer 36bf020
Update examples/get-started/contour-map.py
willschlitzer 583c0fd
Merge branch 'main' into tutorial/contour-map
willschlitzer c992f1b
Apply suggestions from code review
willschlitzer f907536
Merge branch 'main' into tutorial/contour-map
willschlitzer c531c1e
add link for available resolutions
willschlitzer 5e22a4f
change from haxby to oleron
willschlitzer d119112
Merge branch 'main' into tutorial/contour-map
willschlitzer 9b45d71
Update .github/workflows/cache_data.yaml
seisman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
""" | ||
2. Create a contour map | ||
======================= | ||
|
||
This tutorial page covers the basics of creating a figure of Earth relief, | ||
using a remote dataset hosted by GMT, using the method | ||
:meth:`pygmt.datasets.load_earth_relief`. It will use | ||
:meth:`pygmt.Figure.grdimage`, :meth:`pygmt.Figure.grdcontour`, | ||
:meth:`pygmt.Figure.colorbar`, and :meth:`pygmt.Figure.coast` methods for | ||
plotting. | ||
""" | ||
|
||
# sphinx_gallery_thumbnail_number = 4 | ||
import pygmt | ||
|
||
############################################################################### | ||
# Loading the Earth relief dataset | ||
# -------------------------------- | ||
# | ||
# The first step is to import :meth:`pygmt.datasets.load_earth_relief`. | ||
willschlitzer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# The ``resolution`` parameter sets the resolution of the remote grid file, | ||
# which will affect the resolution of the plot made later in the tutorial. | ||
# The ``registration`` parameter determines the grid registration. | ||
# | ||
# This grid region covers the islands of Guam and Rota in the western Pacific | ||
# Ocean. | ||
|
||
grid = pygmt.datasets.load_earth_relief( | ||
resolution="30s", region=[144.5, 145.5, 13, 14.5], registration="gridline" | ||
) | ||
seisman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
############################################################################### | ||
# Plotting Earth relief | ||
# --------------------- | ||
# | ||
# To plot Earth relief data, the method :meth:`pygmt.Figure.grdimage` can be | ||
# used to plot a color-coded figure to display the topography and bathymetry | ||
# in the grid file. The ``grid`` parameter accepts the input grid, which in | ||
# this case is the remote file downloaded in the previous step. If the | ||
# ``region`` parameter is not set, the region boundaries of the input grid are | ||
# used. | ||
# | ||
# The ``cmap`` parameter sets the color palette table (CPT) used for | ||
# portraying Earth relief. The :meth:`pygmt.Figure.grdimage` method uses the | ||
# input grid to apply Earth relief values to a specific color within the CPT. | ||
# In this case, the CPT used is "haxby"; a full list of CPTs can be found | ||
# at :gmt-docs:`cookbook/cpts.html`. | ||
|
||
fig = pygmt.Figure() | ||
fig.grdimage(grid=grid, frame="a", projection="M10c", cmap="haxby") | ||
weiji14 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fig.show() | ||
|
||
############################################################################### | ||
# Adding a colorbar | ||
# ----------------- | ||
# | ||
# To show how the plotted colors relate to the Earth relief, a colorbar can be | ||
# added using the :meth:`pygmt.Figure.colorbar` method. | ||
# | ||
# To control the labels on the colorbar, a list is passed to the ``frame`` | ||
# parameter. The value beginning with "a" sets the interval for annotation on | ||
# the colorbar, in this case every 1,000 meters. To set the label for an axis | ||
# on the colorbar, the value begins with either "x+l" (x-axis) or "y+l" | ||
# (y-axis), followed by the intended label. | ||
# | ||
# By default, the CPT for the colorbar is the same as the one set | ||
# in :meth:`pygmt.Figure.grdimage`. | ||
|
||
fig = pygmt.Figure() | ||
fig.grdimage(grid=grid, frame="a", projection="M10c", cmap="haxby") | ||
fig.colorbar(frame=["a1000", "x+lElevation", "y+lm"]) | ||
fig.show() | ||
|
||
############################################################################### | ||
# Adding contour lines | ||
# -------------------- | ||
# | ||
# To add contour lines to the color coded figured, the | ||
# :meth:`pygmt.Figure.grdcontour` method is used. The ``frame`` and | ||
# ``projection`` are already set using :meth:`pygmt.Figure.grdimage` and are | ||
# not needed again. However, the same input for ``grid`` (in this case, the | ||
# variable named "grid") must be input again. The ``interval`` parameter sets | ||
# the spacing between lines (in this case, 500 meters), and the ``annotation`` | ||
# parameter draws darker lines that are annotated with the elevation or | ||
# bathymetry. | ||
|
||
fig = pygmt.Figure() | ||
fig.grdimage(grid=grid, frame="a", projection="M10c", cmap="haxby") | ||
fig.grdcontour(grid=grid, interval=500, annotation=1000) | ||
fig.colorbar(frame=["a1000", "x+lElevation (m)"]) | ||
fig.show() | ||
|
||
############################################################################### | ||
# Color in land | ||
# ------------- | ||
# | ||
# To make it clear where the islands are located, the | ||
# :meth:`pygmt.Figure.coast` method can be used to color in the land. The | ||
# ``land`` is colored in as "lightgray", and the ``shorelines`` parameters | ||
# draws a border around the islands. | ||
|
||
fig = pygmt.Figure() | ||
fig.grdimage(grid=grid, frame="a", projection="M10c", cmap="haxby") | ||
fig.grdcontour(grid=grid, interval=500, annotation=1000) | ||
fig.coast(shorelines="2p", land="lightgray") | ||
fig.colorbar(frame=["a1000", "x+lElevation (m)"]) | ||
fig.show() | ||
|
||
############################################################################### | ||
# Additional exercises | ||
# -------------------- | ||
# | ||
# This is the end of the second tutorial. Here are some additional exercises | ||
# for the concepts that were discussed: | ||
# | ||
# 1. Change the resolution of the grid file to either "01m" (lower resolution) | ||
# or "15s" (higher resolution). Note that higher resolution grids will have | ||
# larger file sizes. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe link to https://www.generic-mapping-tools.org/remote-datasets/earth-relief.html#usage so users know what are the possible spatial resolutions, and mention explicitly that |
||
# | ||
# 2. Create a contour map of the area around Mt. Rainier. A suggestion for the | ||
# ``region`` would be ``[-122, -121, 46.5, 47.5]``. Adjust the | ||
# :meth:`pygmt.Figure.grdcontour` and :meth:`pygmt.Figure.colorbar` | ||
# settings as needed to make the figure look good. | ||
# | ||
# 3. Create a contour map of São Miguel Island in the Azores; a suggested | ||
# ``region`` is ``[-26, -25, 37.5, 38]``. Instead of coloring in ``land``, | ||
# set ``water`` to "lightblue" to only display Earth relief information for | ||
# the land. | ||
# | ||
# 4. Try other CPTs, such as "jet" and "geo". | ||
willschlitzer marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.