Skip to content

Commit 2445b9e

Browse files
willschlitzerMeghan Jones
and
Meghan Jones
authored
Add inline example for grdclip (#1711)
Example to create a new grid from an input grid using pygmt.grdclip. Shows how users can set values that are above/below a given value to a new value. Co-authored-by: Meghan Jones <[email protected]>
1 parent f476363 commit 2445b9e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

pygmt/src/grdclip.py

+20
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,26 @@ def grdclip(grid, **kwargs):
7777
- :class:`xarray.DataArray` if ``outgrid`` is not set
7878
- None if ``outgrid`` is set (grid output will be stored in file set by
7979
``outgrid``)
80+
81+
Examples
82+
--------
83+
>>> import pygmt # doctest: +SKIP
84+
>>> # Load a grid of @earth_relief_30m data, with an x-range of 10 to 30,
85+
>>> # and a y-range of 15 to 25
86+
>>> grid = pygmt.datasets.load_earth_relief(
87+
... resolution="30m", region=[10, 30, 15, 25]
88+
... ) # doctest: +SKIP
89+
>>> # Report the minimum and maximum data values
90+
>>> [grid.data.min(), grid.data.max()] # doctest: +SKIP
91+
[179.0, 2103.0]
92+
>>> # Create a new grid from an input grid. Set all values below 1,000 to
93+
>>> # 0 and all values above 1,500 to 10,000
94+
>>> new_grid = pygmt.grdclip(
95+
... grid=grid, below=[1000, 0], above=[1500, 10000]
96+
... ) # doctest: +SKIP
97+
>>> # Report the minimum and maximum data values
98+
>>> [new_grid.data.min(), new_grid.data.max()] # doctest: +SKIP
99+
[0.0, 10000.0]
80100
"""
81101
with GMTTempFile(suffix=".nc") as tmpfile:
82102
with Session() as lib:

0 commit comments

Comments
 (0)