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 gallery example for grdclip #1396

Merged
merged 13 commits into from
Aug 4, 2021
35 changes: 35 additions & 0 deletions examples/gallery/images/grdclip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
Clipping grid values
--------------------
The :meth:`pygmt.grdclip` method allows to clip defined ranges of grid values.
In the example shown below we set all elevation values (grid points) smaller
than 0 m (in general the bathymetric part of the grid) to a common value of
-2000 m via the ``below`` parameter.
"""

import pygmt

fig = pygmt.Figure()

# Define region of interest around Iceland
region = [-28, -10, 62, 68]

# Load sample grid (3 arc minute global relief) in target area
grid = pygmt.datasets.load_earth_relief(resolution="03m", region=region)

# Plot original grid
fig.basemap(region=region, projection="M12c", frame=["f", '+t"original grid"'])
fig.grdimage(grid=grid, cmap="oleron")

# Shift plot origin for second map 12.5 cm in x direction
fig.shift_origin(xshift="12.5c")
michaelgrund marked this conversation as resolved.
Show resolved Hide resolved

# Set all grid points < 0 m to a value of -2000 m.
grid = pygmt.grdclip(grid, below=[0, -2000])

# Plot clipped grid
fig.basemap(region=region, projection="M12c", frame=["f", '+t"clipped grid"'])
fig.grdimage(grid=grid)
fig.colorbar(frame=["x+lElevation", "y+lm"], position="JMR+o0.5c/0c+w8c")

fig.show()