From 095c795aabd94966b40d657bfea5b0f0064db24f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Thu, 9 Apr 2026 18:33:14 +0200 Subject: [PATCH 01/42] Add first draft for gallery example or tutorial on grdmask --- examples/gallery/images/grdmask.py | 60 ++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 examples/gallery/images/grdmask.py diff --git a/examples/gallery/images/grdmask.py b/examples/gallery/images/grdmask.py new file mode 100755 index 00000000000..bdf55753b7f --- /dev/null +++ b/examples/gallery/images/grdmask.py @@ -0,0 +1,60 @@ +""" +Create grid mask from polygons +============================== +:func:`pygmt.grdmask`. + +:func:`pygmt.grdlandmask` and gallery example https://www.pygmt.org/latest/gallery/images/grdlandmask.html. +""" + +# %% +import numpy as np +import pygmt + +# Define a study region +region = [120, 135, 25, 40] + +# Define two polygons, here triangels, use nan to separate the polygons +polygon = np.array( + [ + [125, 30], + [130, 30], + [130, 35], + [125, 30], + [np.nan, np.nan], + [122, 37], + [128, 37], + [128, 39], + [122, 37], + ], +) + +# Download elevation grid +grid = pygmt.datasets.load_earth_relief(region=region, resolution="30s") + +# Create a grid mask based on the two polygons defined above, set all values +# outside the polygons to NaN +mask = pygmt.grdmask(region=region, data=polygon, spacing="30s", outside="NaN") + +# Apply the grid mask to the downloaded elevation grid by multiplying the two grids +grid_mask = grid * mask + + +fig = pygmt.Figure() +pygmt.makecpt(cmap="oleron", series=[-2000, 2000]) + +# Plot the elevation grid +fig.basemap(region=region, projection="M12c", frame=True) +fig.grdimage(grid=grid, cmap=True) +fig.basemap(frame="g1") +fig.plot(data=polygon, pen="2p,darkorange") + +fig.shift_origin(xshift="+w+2c") + +# Plot the masked elevation grid +fig.basemap(region=region, projection="M12c", frame=True) +fig.grdimage(grid=grid_mask, cmap=True) +fig.basemap(frame="g1") +fig.plot(data=polygon, pen="2p,darkorange") + +fig.colorbar(frame=True) +fig.show() From 5456a7fc2fe4d049afa0d596e44add554b538d11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Thu, 9 Apr 2026 20:20:44 +0200 Subject: [PATCH 02/42] Adjust regions --- examples/gallery/images/grdmask.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/examples/gallery/images/grdmask.py b/examples/gallery/images/grdmask.py index bdf55753b7f..32f2abe6fff 100755 --- a/examples/gallery/images/grdmask.py +++ b/examples/gallery/images/grdmask.py @@ -11,20 +11,22 @@ import pygmt # Define a study region -region = [120, 135, 25, 40] +region = [125, 135, 25, 36] -# Define two polygons, here triangels, use nan to separate the polygons +# Define two closed polygons, here a quare and a triangle. +# Use nan to separate the polygons polygon = np.array( [ - [125, 30], - [130, 30], - [130, 35], - [125, 30], + [129, 31], + [134, 31], + [134, 35], + [129, 35], + [129, 31], [np.nan, np.nan], - [122, 37], - [128, 37], - [128, 39], - [122, 37], + [126, 26], + [131, 26], + [131, 30], + [126, 26], ], ) From 31d1b74c505520515ef96eb8d2b7f1bfd873ea50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Thu, 9 Apr 2026 20:52:21 +0200 Subject: [PATCH 03/42] Try extracting a circle --- examples/gallery/images/grdmask.py | 52 ++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/examples/gallery/images/grdmask.py b/examples/gallery/images/grdmask.py index 32f2abe6fff..c65fffb6408 100755 --- a/examples/gallery/images/grdmask.py +++ b/examples/gallery/images/grdmask.py @@ -7,8 +7,14 @@ """ # %% +import geopandas import numpy as np import pygmt +from shapely.geometry import Point + +# %% +# Polygons based on NumPy arrays +# ------------------------------ # Define a study region region = [125, 135, 25, 36] @@ -60,3 +66,49 @@ fig.colorbar(frame=True) fig.show() + + +# %% +# Circle based on GeoPandas polygon geometry +# ------------------------------------------ + +# Define a study region +region = [125, 135, 25, 36] + +# Create a point and buffer it +point = geopandas.GeoSeries([Point(126.5, 33.5)]) +circle = point.buffer(0.6) # 10 is the radius + +# Download elevation grid +grid = pygmt.datasets.load_earth_relief(region=region, resolution="30s") + +# Create a grid mask based on the two polygons defined above, set all values +# outside the polygons to NaN +mask = pygmt.grdmask(region=region, data=circle, spacing="30s", outside="NaN") +mask_lonlat = mask.rename(new_name_or_name_dict={"x": "lon", "y": "lat"}) + +# Apply the grid mask to the downloaded elevation grid by multiplying the two grids +grid_mask = grid * mask_lonlat + + +fig = pygmt.Figure() +pygmt.makecpt(cmap="oleron", series=[-2000, 2000]) + +# Plot the elevation grid +fig.basemap(region=region, projection="M12c", frame=True) +fig.grdimage(grid=grid, cmap=True) +fig.basemap(frame="g1") +fig.plot(data=circle, pen="2p,darkorange") + +fig.shift_origin(xshift="+w+2c") + +# Plot the masked elevation grid +fig.basemap(region=region, projection="M12c", frame=True) +fig.grdimage(grid=grid_mask, cmap=True) +fig.basemap(frame="g1") +fig.plot(data=circle, pen="2p,darkorange") + +fig.colorbar(frame=True) +fig.show() + +# sphinx_gallery_thumbnail_number = 1 From 4584da72b5f8c79e1e1c1b432b96539b727c6fae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Thu, 9 Apr 2026 21:00:16 +0200 Subject: [PATCH 04/42] Remove execution permission --- examples/gallery/images/grdmask.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 examples/gallery/images/grdmask.py diff --git a/examples/gallery/images/grdmask.py b/examples/gallery/images/grdmask.py old mode 100755 new mode 100644 From 2b8a6321d75ec4cc468b8fe5136ea48c3da56a8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Fri, 10 Apr 2026 11:20:15 +0200 Subject: [PATCH 05/42] Select US staat --- examples/gallery/images/grdmask.py | 46 ++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/examples/gallery/images/grdmask.py b/examples/gallery/images/grdmask.py index c65fffb6408..9a7c9fc5340 100644 --- a/examples/gallery/images/grdmask.py +++ b/examples/gallery/images/grdmask.py @@ -68,26 +68,56 @@ fig.show() +# %% +# US staat based on GeoPandas polygon geometry +# -------------------------------------------- + +region = [-126, -66, 25, 49] + +provider = "https://naciscdn.org/naturalearth" +states = geopandas.read_file( + f"{provider}/50m/cultural/ne_50m_admin_1_states_provinces.zip" +) +wyoming = states[states["name"] == "Missouri"] + +grid = pygmt.datasets.load_earth_relief(region=region, resolution="01m") +mask = pygmt.grdmask(region=region, data=wyoming, spacing="01m", inside="NaN") +mask_lonlat = mask.rename(new_name_or_name_dict={"x": "lon", "y": "lat"}) +grid_mask = grid * mask_lonlat + + +fig = pygmt.Figure() +pygmt.makecpt(cmap="oleron", series=[-2000, 2000]) + +# Plot the elevation grid +fig.basemap("L-96/35/33/41/12c", region=region, frame=True) +fig.grdimage(grid=grid, cmap=True) +fig.plot(data=wyoming, pen="1p,darkorange") + +fig.shift_origin(xshift="+w+1c") + +# Plot the masked elevation grid +fig.basemap("L-96/35/33/41/12c", region=region, frame=True) +fig.grdimage(grid=grid_mask, cmap=True) +fig.plot(data=wyoming, pen="1p,darkorange") + +fig.colorbar(frame=True) +fig.show() + + # %% # Circle based on GeoPandas polygon geometry # ------------------------------------------ -# Define a study region region = [125, 135, 25, 36] # Create a point and buffer it point = geopandas.GeoSeries([Point(126.5, 33.5)]) circle = point.buffer(0.6) # 10 is the radius -# Download elevation grid grid = pygmt.datasets.load_earth_relief(region=region, resolution="30s") - -# Create a grid mask based on the two polygons defined above, set all values -# outside the polygons to NaN mask = pygmt.grdmask(region=region, data=circle, spacing="30s", outside="NaN") mask_lonlat = mask.rename(new_name_or_name_dict={"x": "lon", "y": "lat"}) - -# Apply the grid mask to the downloaded elevation grid by multiplying the two grids grid_mask = grid * mask_lonlat @@ -97,7 +127,6 @@ # Plot the elevation grid fig.basemap(region=region, projection="M12c", frame=True) fig.grdimage(grid=grid, cmap=True) -fig.basemap(frame="g1") fig.plot(data=circle, pen="2p,darkorange") fig.shift_origin(xshift="+w+2c") @@ -105,7 +134,6 @@ # Plot the masked elevation grid fig.basemap(region=region, projection="M12c", frame=True) fig.grdimage(grid=grid_mask, cmap=True) -fig.basemap(frame="g1") fig.plot(data=circle, pen="2p,darkorange") fig.colorbar(frame=True) From b936f5d5d661fe4b79c9e205fb079920391390d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Fri, 10 Apr 2026 12:58:08 +0200 Subject: [PATCH 06/42] Zoom in mask grid --- examples/gallery/images/grdmask.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/images/grdmask.py b/examples/gallery/images/grdmask.py index 9a7c9fc5340..779cccafc1b 100644 --- a/examples/gallery/images/grdmask.py +++ b/examples/gallery/images/grdmask.py @@ -132,7 +132,7 @@ fig.shift_origin(xshift="+w+2c") # Plot the masked elevation grid -fig.basemap(region=region, projection="M12c", frame=True) +fig.basemap(region=[125.5, 127.5, 32.5, 34.5], projection="M12c", frame=True) fig.grdimage(grid=grid_mask, cmap=True) fig.plot(data=circle, pen="2p,darkorange") From 2c1c2644075e10aa412744e44d34bdd2f2373fd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Fri, 10 Apr 2026 13:04:40 +0200 Subject: [PATCH 07/42] Try inside and outside --- examples/gallery/images/grdmask.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/examples/gallery/images/grdmask.py b/examples/gallery/images/grdmask.py index 779cccafc1b..05fd7337bc9 100644 --- a/examples/gallery/images/grdmask.py +++ b/examples/gallery/images/grdmask.py @@ -39,12 +39,15 @@ # Download elevation grid grid = pygmt.datasets.load_earth_relief(region=region, resolution="30s") -# Create a grid mask based on the two polygons defined above, set all values -# outside the polygons to NaN -mask = pygmt.grdmask(region=region, data=polygon, spacing="30s", outside="NaN") +# Create a grid mask based on the two polygons defined above +# Set all values outside the polygons to NaN +mask_out = pygmt.grdmask(region=region, data=polygon, spacing="30s", outside="NaN") +# Set all values inside the polygons to NaN +mask_in = pygmt.grdmask(region=region, data=polygon, spacing="30s", inside="NaN") # Apply the grid mask to the downloaded elevation grid by multiplying the two grids -grid_mask = grid * mask +grid_mask_out = grid * mask_out +grid_mask_in = grid * mask_in fig = pygmt.Figure() @@ -53,15 +56,20 @@ # Plot the elevation grid fig.basemap(region=region, projection="M12c", frame=True) fig.grdimage(grid=grid, cmap=True) -fig.basemap(frame="g1") fig.plot(data=polygon, pen="2p,darkorange") fig.shift_origin(xshift="+w+2c") -# Plot the masked elevation grid +# Plot the masked elevation grid outside fig.basemap(region=region, projection="M12c", frame=True) -fig.grdimage(grid=grid_mask, cmap=True) -fig.basemap(frame="g1") +fig.grdimage(grid=grid_mask_out, cmap=True) +fig.plot(data=polygon, pen="2p,darkorange") + +fig.shift_origin(xshift="+w+2c") + +# Plot the masked elevation grid inside +fig.basemap(region=region, projection="M12c", frame=True) +fig.grdimage(grid=grid_mask_in, cmap=True) fig.plot(data=polygon, pen="2p,darkorange") fig.colorbar(frame=True) From a62befc48f5e9c345b89afcb56239d5a087c1536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Fri, 10 Apr 2026 13:39:39 +0200 Subject: [PATCH 08/42] Adjust area for US staat, fix typo, improve code --- examples/gallery/images/grdmask.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/examples/gallery/images/grdmask.py b/examples/gallery/images/grdmask.py index 05fd7337bc9..5ecaf46b5f4 100644 --- a/examples/gallery/images/grdmask.py +++ b/examples/gallery/images/grdmask.py @@ -86,10 +86,10 @@ states = geopandas.read_file( f"{provider}/50m/cultural/ne_50m_admin_1_states_provinces.zip" ) -wyoming = states[states["name"] == "Missouri"] +missouri = states[states["name"] == "Missouri"] grid = pygmt.datasets.load_earth_relief(region=region, resolution="01m") -mask = pygmt.grdmask(region=region, data=wyoming, spacing="01m", inside="NaN") +mask = pygmt.grdmask(region=region, data=missouri, spacing="01m", outside="NaN") mask_lonlat = mask.rename(new_name_or_name_dict={"x": "lon", "y": "lat"}) grid_mask = grid * mask_lonlat @@ -98,16 +98,17 @@ pygmt.makecpt(cmap="oleron", series=[-2000, 2000]) # Plot the elevation grid -fig.basemap("L-96/35/33/41/12c", region=region, frame=True) +fig.basemap(projection="L-96/35/33/41/12c", region=region, frame=True) fig.grdimage(grid=grid, cmap=True) -fig.plot(data=wyoming, pen="1p,darkorange") +fig.plot(data=missouri, pen="1p,darkorange") fig.shift_origin(xshift="+w+1c") # Plot the masked elevation grid -fig.basemap("L-96/35/33/41/12c", region=region, frame=True) +#fig.basemap(projection="L-96/35/33/41/12c", region=region, frame=True) +fig.basemap(projection="M10c", region=[-96.5, -88.5, 35.8, 41], frame=True) fig.grdimage(grid=grid_mask, cmap=True) -fig.plot(data=wyoming, pen="1p,darkorange") +fig.plot(data=missouri, pen="1p,darkorange") fig.colorbar(frame=True) fig.show() From 9cb4b75912a170748a286297a680d70fd6f6549a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Fri, 10 Apr 2026 13:42:39 +0200 Subject: [PATCH 09/42] Fix style --- examples/gallery/images/grdmask.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/images/grdmask.py b/examples/gallery/images/grdmask.py index 5ecaf46b5f4..63cf542ec92 100644 --- a/examples/gallery/images/grdmask.py +++ b/examples/gallery/images/grdmask.py @@ -105,7 +105,7 @@ fig.shift_origin(xshift="+w+1c") # Plot the masked elevation grid -#fig.basemap(projection="L-96/35/33/41/12c", region=region, frame=True) +# fig.basemap(projection="L-96/35/33/41/12c", region=region, frame=True) fig.basemap(projection="M10c", region=[-96.5, -88.5, 35.8, 41], frame=True) fig.grdimage(grid=grid_mask, cmap=True) fig.plot(data=missouri, pen="1p,darkorange") From c0ef6115371367418128fb3886da3c791b8821d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Fri, 10 Apr 2026 14:04:46 +0200 Subject: [PATCH 10/42] Set outside parameter correctly --- examples/gallery/images/grdmask.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/gallery/images/grdmask.py b/examples/gallery/images/grdmask.py index 63cf542ec92..c9ae63dc323 100644 --- a/examples/gallery/images/grdmask.py +++ b/examples/gallery/images/grdmask.py @@ -40,10 +40,13 @@ grid = pygmt.datasets.load_earth_relief(region=region, resolution="30s") # Create a grid mask based on the two polygons defined above -# Set all values outside the polygons to NaN +# Set all grid nodes outside the polygons to NaN mask_out = pygmt.grdmask(region=region, data=polygon, spacing="30s", outside="NaN") -# Set all values inside the polygons to NaN -mask_in = pygmt.grdmask(region=region, data=polygon, spacing="30s", inside="NaN") +# Set all grid nodes inside the polygons to NaN +# Set the outside parameter to a value larger 0 to keep the nodes outside unchanged +mask_in = pygmt.grdmask( + region=region, data=polygon, spacing="30s", inside="NaN", outside=1 +) # Apply the grid mask to the downloaded elevation grid by multiplying the two grids grid_mask_out = grid * mask_out From 6326c199e9961d9e4f8c30b321ee6dabd0cca817 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Fri, 10 Apr 2026 14:18:45 +0200 Subject: [PATCH 11/42] Fix typo --- examples/gallery/images/grdmask.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/gallery/images/grdmask.py b/examples/gallery/images/grdmask.py index c9ae63dc323..f89b825bbb7 100644 --- a/examples/gallery/images/grdmask.py +++ b/examples/gallery/images/grdmask.py @@ -80,8 +80,8 @@ # %% -# US staat based on GeoPandas polygon geometry -# -------------------------------------------- +# US state Missouri based on GeoPandas polygon geometry +# ----------------------------------------------------- region = [-126, -66, 25, 49] From a4d8f5ebd2d493832e79d4fa22b3e6dcc61f63aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Fri, 10 Apr 2026 18:22:47 +0200 Subject: [PATCH 12/42] Adjust title - circles are no polygons --- examples/gallery/images/grdmask.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/gallery/images/grdmask.py b/examples/gallery/images/grdmask.py index f89b825bbb7..dbd955781ca 100644 --- a/examples/gallery/images/grdmask.py +++ b/examples/gallery/images/grdmask.py @@ -1,6 +1,6 @@ """ -Create grid mask from polygons -============================== +Create grid masks from geospatial shapes +======================================== :func:`pygmt.grdmask`. :func:`pygmt.grdlandmask` and gallery example https://www.pygmt.org/latest/gallery/images/grdlandmask.html. From 5173eff0311c16b0abe9ccde6cd0739bf7727e4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Sat, 11 Apr 2026 12:21:44 +0200 Subject: [PATCH 13/42] Change back to None --- pygmt/src/text.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/src/text.py b/pygmt/src/text.py index 9adb6e2911f..b0bec6d59f0 100644 --- a/pygmt/src/text.py +++ b/pygmt/src/text.py @@ -39,8 +39,8 @@ def text_( # noqa: PLR0912, PLR0913 y=None, position: AnchorCode | None = None, text: str | StringArrayTypes | None = None, - angle: float | Sequence[float] | bool = False, - font: str | StringArrayTypes | bool = False, + angle: float | Sequence[float] | None = None, + font: str | StringArrayTypes | None = None, fill: str | None = None, pen: str | None = None, justify: bool | None | AnchorCode | Sequence[AnchorCode] = None, From 30ae77024362b55cd3abd7272dab1f88f48782eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Sat, 11 Apr 2026 12:35:11 +0200 Subject: [PATCH 14/42] Revert "Change back to None" This reverts commit 5173eff0311c16b0abe9ccde6cd0739bf7727e4a. --- pygmt/src/text.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/src/text.py b/pygmt/src/text.py index b0bec6d59f0..9adb6e2911f 100644 --- a/pygmt/src/text.py +++ b/pygmt/src/text.py @@ -39,8 +39,8 @@ def text_( # noqa: PLR0912, PLR0913 y=None, position: AnchorCode | None = None, text: str | StringArrayTypes | None = None, - angle: float | Sequence[float] | None = None, - font: str | StringArrayTypes | None = None, + angle: float | Sequence[float] | bool = False, + font: str | StringArrayTypes | bool = False, fill: str | None = None, pen: str | None = None, justify: bool | None | AnchorCode | Sequence[AnchorCode] = None, From ac5403dd38dd932426c20c5a0ddbe22684644b2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Sat, 18 Apr 2026 21:08:35 +0200 Subject: [PATCH 15/42] Fix typo, add folder for cmaps --- examples/gallery/images/grdmask.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/gallery/images/grdmask.py b/examples/gallery/images/grdmask.py index dbd955781ca..da299bddd81 100644 --- a/examples/gallery/images/grdmask.py +++ b/examples/gallery/images/grdmask.py @@ -19,8 +19,8 @@ # Define a study region region = [125, 135, 25, 36] -# Define two closed polygons, here a quare and a triangle. -# Use nan to separate the polygons +# Define two closed polygons, here a square and a triangle. +# Use an np.nan to separate the polygons polygon = np.array( [ [129, 31], @@ -54,7 +54,7 @@ fig = pygmt.Figure() -pygmt.makecpt(cmap="oleron", series=[-2000, 2000]) +pygmt.makecpt(cmap="SCM/oleron", series=[-2000, 2000]) # Plot the elevation grid fig.basemap(region=region, projection="M12c", frame=True) @@ -98,7 +98,7 @@ fig = pygmt.Figure() -pygmt.makecpt(cmap="oleron", series=[-2000, 2000]) +pygmt.makecpt(cmap="SCM/oleron", series=[-2000, 2000]) # Plot the elevation grid fig.basemap(projection="L-96/35/33/41/12c", region=region, frame=True) @@ -134,7 +134,7 @@ fig = pygmt.Figure() -pygmt.makecpt(cmap="oleron", series=[-2000, 2000]) +pygmt.makecpt(cmap="SCM/oleron", series=[-2000, 2000]) # Plot the elevation grid fig.basemap(region=region, projection="M12c", frame=True) From 1b54365c40574f9016f2345229432c102f98597f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Mon, 20 Apr 2026 21:44:42 +0200 Subject: [PATCH 16/42] Add first version of intro text --- examples/gallery/images/grdmask.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/examples/gallery/images/grdmask.py b/examples/gallery/images/grdmask.py index da299bddd81..3ea6208d2f5 100644 --- a/examples/gallery/images/grdmask.py +++ b/examples/gallery/images/grdmask.py @@ -1,9 +1,15 @@ """ -Create grid masks from geospatial shapes -======================================== -:func:`pygmt.grdmask`. +Create grid masks from spatial shapes +===================================== -:func:`pygmt.grdlandmask` and gallery example https://www.pygmt.org/latest/gallery/images/grdlandmask.html. +The functionn :func:`pygmt.grdmask` allows to create a grid mask based on spatial +shapes given as closed polygons. These polygons can be provided as NumPy arrays or +GeoPandas DataFrame. For the nodes falling inside, outside, and on the edges, different +values can be defined. The create mask can then be applied to a desired grid. + +To create a land-water mask based on the GMT built-in shoreline data you can directly +use the function :func:`pygmt.grdlandmask` explained in the gallery example +:doc:` Create 'wet-dry' mask grid `. """ # %% From 544fc0746d409338a529ecafc47872474b5ef42a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Thu, 18 Jun 2026 22:01:44 +0200 Subject: [PATCH 17/42] Remove white space to fix link to grdlandmask gallery example --- examples/gallery/images/grdmask.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/images/grdmask.py b/examples/gallery/images/grdmask.py index 3ea6208d2f5..d1dfa512cbc 100644 --- a/examples/gallery/images/grdmask.py +++ b/examples/gallery/images/grdmask.py @@ -9,7 +9,7 @@ To create a land-water mask based on the GMT built-in shoreline data you can directly use the function :func:`pygmt.grdlandmask` explained in the gallery example -:doc:` Create 'wet-dry' mask grid `. +:doc:`Create 'wet-dry' mask grid `. """ # %% From 667fbb52d029bfc93fd36b2aeca8c25e0c832b5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Thu, 18 Jun 2026 22:10:32 +0200 Subject: [PATCH 18/42] Fix typo --- examples/gallery/images/grdmask.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/images/grdmask.py b/examples/gallery/images/grdmask.py index d1dfa512cbc..f38f0d2c9ea 100644 --- a/examples/gallery/images/grdmask.py +++ b/examples/gallery/images/grdmask.py @@ -9,7 +9,7 @@ To create a land-water mask based on the GMT built-in shoreline data you can directly use the function :func:`pygmt.grdlandmask` explained in the gallery example -:doc:`Create 'wet-dry' mask grid `. +:doc:`Create 'wet-dry' mask grid `. """ # %% From 1a579880a5b10f0bf6bf7360dad7df1f54222860 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= <94163266+yvonnefroehlich@users.noreply.github.com> Date: Wed, 24 Jun 2026 17:03:02 +0200 Subject: [PATCH 19/42] Improve formulation Co-authored-by: Dongdong Tian --- examples/gallery/images/grdmask.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/images/grdmask.py b/examples/gallery/images/grdmask.py index f38f0d2c9ea..c072a7499ae 100644 --- a/examples/gallery/images/grdmask.py +++ b/examples/gallery/images/grdmask.py @@ -26,7 +26,7 @@ region = [125, 135, 25, 36] # Define two closed polygons, here a square and a triangle. -# Use an np.nan to separate the polygons +# Use a record with np.nan to separate the polygons polygon = np.array( [ [129, 31], From c95623c0b1853ed3d008c8b444ea2e6c09abb063 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Thu, 25 Jun 2026 10:54:00 +0200 Subject: [PATCH 20/42] Fix typo --- examples/gallery/images/grdmask.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/images/grdmask.py b/examples/gallery/images/grdmask.py index c072a7499ae..592e6f90825 100644 --- a/examples/gallery/images/grdmask.py +++ b/examples/gallery/images/grdmask.py @@ -5,7 +5,7 @@ The functionn :func:`pygmt.grdmask` allows to create a grid mask based on spatial shapes given as closed polygons. These polygons can be provided as NumPy arrays or GeoPandas DataFrame. For the nodes falling inside, outside, and on the edges, different -values can be defined. The create mask can then be applied to a desired grid. +values can be defined. The created mask can then be applied to a desired grid. To create a land-water mask based on the GMT built-in shoreline data you can directly use the function :func:`pygmt.grdlandmask` explained in the gallery example From 114ec892e0a7c0cea3bb7b3c46103e45b46b53a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Thu, 25 Jun 2026 11:10:40 +0200 Subject: [PATCH 21/42] Adjust color for outline --- examples/gallery/images/grdmask.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/gallery/images/grdmask.py b/examples/gallery/images/grdmask.py index 592e6f90825..64cc1894725 100644 --- a/examples/gallery/images/grdmask.py +++ b/examples/gallery/images/grdmask.py @@ -65,21 +65,21 @@ # Plot the elevation grid fig.basemap(region=region, projection="M12c", frame=True) fig.grdimage(grid=grid, cmap=True) -fig.plot(data=polygon, pen="2p,darkorange") +fig.plot(data=polygon, pen="2p,cyan") fig.shift_origin(xshift="+w+2c") # Plot the masked elevation grid outside fig.basemap(region=region, projection="M12c", frame=True) fig.grdimage(grid=grid_mask_out, cmap=True) -fig.plot(data=polygon, pen="2p,darkorange") +fig.plot(data=polygon, pen="2p,cyan") fig.shift_origin(xshift="+w+2c") # Plot the masked elevation grid inside fig.basemap(region=region, projection="M12c", frame=True) fig.grdimage(grid=grid_mask_in, cmap=True) -fig.plot(data=polygon, pen="2p,darkorange") +fig.plot(data=polygon, pen="2p,cyan") fig.colorbar(frame=True) fig.show() @@ -109,7 +109,7 @@ # Plot the elevation grid fig.basemap(projection="L-96/35/33/41/12c", region=region, frame=True) fig.grdimage(grid=grid, cmap=True) -fig.plot(data=missouri, pen="1p,darkorange") +fig.plot(data=missouri, pen="1p,cyan") fig.shift_origin(xshift="+w+1c") @@ -117,7 +117,7 @@ # fig.basemap(projection="L-96/35/33/41/12c", region=region, frame=True) fig.basemap(projection="M10c", region=[-96.5, -88.5, 35.8, 41], frame=True) fig.grdimage(grid=grid_mask, cmap=True) -fig.plot(data=missouri, pen="1p,darkorange") +fig.plot(data=missouri, pen="1p,cyan") fig.colorbar(frame=True) fig.show() @@ -145,14 +145,14 @@ # Plot the elevation grid fig.basemap(region=region, projection="M12c", frame=True) fig.grdimage(grid=grid, cmap=True) -fig.plot(data=circle, pen="2p,darkorange") +fig.plot(data=circle, pen="2p,cyan") fig.shift_origin(xshift="+w+2c") # Plot the masked elevation grid fig.basemap(region=[125.5, 127.5, 32.5, 34.5], projection="M12c", frame=True) fig.grdimage(grid=grid_mask, cmap=True) -fig.plot(data=circle, pen="2p,darkorange") +fig.plot(data=circle, pen="2p,cyan") fig.colorbar(frame=True) fig.show() From bfb24021cfb083da1868066966e9992ff746f8ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= <94163266+yvonnefroehlich@users.noreply.github.com> Date: Thu, 25 Jun 2026 15:37:46 +0200 Subject: [PATCH 22/42] Remove colorbar Co-authored-by: Dongdong Tian --- examples/gallery/images/grdmask.py | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/gallery/images/grdmask.py b/examples/gallery/images/grdmask.py index 64cc1894725..c2f7f602237 100644 --- a/examples/gallery/images/grdmask.py +++ b/examples/gallery/images/grdmask.py @@ -81,7 +81,6 @@ fig.grdimage(grid=grid_mask_in, cmap=True) fig.plot(data=polygon, pen="2p,cyan") -fig.colorbar(frame=True) fig.show() From 4bf910228b0466d0d386b2bff2959e19296533e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Sun, 28 Jun 2026 10:52:49 +0200 Subject: [PATCH 23/42] Move to advaced tutorials --- examples/{gallery/images => tutorials/advanced}/grdmask.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/{gallery/images => tutorials/advanced}/grdmask.py (100%) mode change 100644 => 100755 diff --git a/examples/gallery/images/grdmask.py b/examples/tutorials/advanced/grdmask.py old mode 100644 new mode 100755 similarity index 100% rename from examples/gallery/images/grdmask.py rename to examples/tutorials/advanced/grdmask.py From 7cd4495f85cb57b435c8f8c5d69a7f7203047618 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Sun, 28 Jun 2026 11:17:52 +0200 Subject: [PATCH 24/42] Remove execution permission --- examples/tutorials/advanced/grdmask.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 examples/tutorials/advanced/grdmask.py diff --git a/examples/tutorials/advanced/grdmask.py b/examples/tutorials/advanced/grdmask.py old mode 100755 new mode 100644 From 70afe2906f1126dd8544be7e16d41e770485106d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Mon, 29 Jun 2026 20:00:40 +0200 Subject: [PATCH 25/42] Reduce resolution of grid, reduce size of subplots --- examples/tutorials/advanced/grdmask.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) mode change 100755 => 100644 examples/tutorials/advanced/grdmask.py diff --git a/examples/tutorials/advanced/grdmask.py b/examples/tutorials/advanced/grdmask.py old mode 100755 new mode 100644 index c2f7f602237..a8948052e70 --- a/examples/tutorials/advanced/grdmask.py +++ b/examples/tutorials/advanced/grdmask.py @@ -43,15 +43,15 @@ ) # Download elevation grid -grid = pygmt.datasets.load_earth_relief(region=region, resolution="30s") +grid = pygmt.datasets.load_earth_relief(region=region, resolution="01m") # Create a grid mask based on the two polygons defined above # Set all grid nodes outside the polygons to NaN -mask_out = pygmt.grdmask(region=region, data=polygon, spacing="30s", outside="NaN") +mask_out = pygmt.grdmask(region=region, data=polygon, spacing="01m", outside="NaN") # Set all grid nodes inside the polygons to NaN # Set the outside parameter to a value larger 0 to keep the nodes outside unchanged mask_in = pygmt.grdmask( - region=region, data=polygon, spacing="30s", inside="NaN", outside=1 + region=region, data=polygon, spacing="01m", inside="NaN", outside=1 ) # Apply the grid mask to the downloaded elevation grid by multiplying the two grids @@ -63,21 +63,21 @@ pygmt.makecpt(cmap="SCM/oleron", series=[-2000, 2000]) # Plot the elevation grid -fig.basemap(region=region, projection="M12c", frame=True) +fig.basemap(region=region, projection="M10c", frame=True) fig.grdimage(grid=grid, cmap=True) fig.plot(data=polygon, pen="2p,cyan") fig.shift_origin(xshift="+w+2c") # Plot the masked elevation grid outside -fig.basemap(region=region, projection="M12c", frame=True) +fig.basemap(region=region, projection="M10c", frame=True) fig.grdimage(grid=grid_mask_out, cmap=True) fig.plot(data=polygon, pen="2p,cyan") fig.shift_origin(xshift="+w+2c") # Plot the masked elevation grid inside -fig.basemap(region=region, projection="M12c", frame=True) +fig.basemap(region=region, projection="M10c", frame=True) fig.grdimage(grid=grid_mask_in, cmap=True) fig.plot(data=polygon, pen="2p,cyan") From 11ef76875ec09a05f7b4bd1faa00a14bf39272ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Mon, 29 Jun 2026 20:07:31 +0200 Subject: [PATCH 26/42] Make file name more descriptive --- examples/tutorials/advanced/{grdmask.py => create_grid_masks.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/tutorials/advanced/{grdmask.py => create_grid_masks.py} (100%) diff --git a/examples/tutorials/advanced/grdmask.py b/examples/tutorials/advanced/create_grid_masks.py similarity index 100% rename from examples/tutorials/advanced/grdmask.py rename to examples/tutorials/advanced/create_grid_masks.py From ffd2aecf0011f02ef0e3502f0eda7e4cd8469a06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Tue, 30 Jun 2026 11:00:09 +0200 Subject: [PATCH 27/42] Add higlighting --- examples/tutorials/advanced/create_grid_masks.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/tutorials/advanced/create_grid_masks.py b/examples/tutorials/advanced/create_grid_masks.py index a8948052e70..c108f4f8b51 100644 --- a/examples/tutorials/advanced/create_grid_masks.py +++ b/examples/tutorials/advanced/create_grid_masks.py @@ -19,8 +19,8 @@ from shapely.geometry import Point # %% -# Polygons based on NumPy arrays -# ------------------------------ +# Polygons based on :class:`numpy` arrays +# --------------------------------------- # Define a study region region = [125, 135, 25, 36] @@ -85,8 +85,8 @@ # %% -# US state Missouri based on GeoPandas polygon geometry -# ----------------------------------------------------- +# US state Missouri based on a :class:`geopandas.GeoDataFrame` polygon geometry +# ----------------------------------------------------------------------------- region = [-126, -66, 25, 49] From 6e1792799f888a3cfce151f64d24d8bcc3963f70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Tue, 30 Jun 2026 11:00:37 +0200 Subject: [PATCH 28/42] Adjust comment to changed value --- examples/tutorials/advanced/create_grid_masks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tutorials/advanced/create_grid_masks.py b/examples/tutorials/advanced/create_grid_masks.py index c108f4f8b51..0bcc9df248f 100644 --- a/examples/tutorials/advanced/create_grid_masks.py +++ b/examples/tutorials/advanced/create_grid_masks.py @@ -130,7 +130,7 @@ # Create a point and buffer it point = geopandas.GeoSeries([Point(126.5, 33.5)]) -circle = point.buffer(0.6) # 10 is the radius +circle = point.buffer(0.6) # 0.6 is the radius grid = pygmt.datasets.load_earth_relief(region=region, resolution="30s") mask = pygmt.grdmask(region=region, data=circle, spacing="30s", outside="NaN") From d06567e40560bc7aa7b0e629b4bcae0ef9df3481 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Tue, 30 Jun 2026 11:05:35 +0200 Subject: [PATCH 29/42] Improve comments --- examples/tutorials/advanced/create_grid_masks.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/tutorials/advanced/create_grid_masks.py b/examples/tutorials/advanced/create_grid_masks.py index 0bcc9df248f..8b297d7cb7d 100644 --- a/examples/tutorials/advanced/create_grid_masks.py +++ b/examples/tutorials/advanced/create_grid_masks.py @@ -125,6 +125,8 @@ # %% # Circle based on GeoPandas polygon geometry # ------------------------------------------ +# +# Note the distortion of the circle due the projection making it appear as an ellipse. region = [125, 135, 25, 36] @@ -132,6 +134,7 @@ point = geopandas.GeoSeries([Point(126.5, 33.5)]) circle = point.buffer(0.6) # 0.6 is the radius +# Create masked grid grid = pygmt.datasets.load_earth_relief(region=region, resolution="30s") mask = pygmt.grdmask(region=region, data=circle, spacing="30s", outside="NaN") mask_lonlat = mask.rename(new_name_or_name_dict={"x": "lon", "y": "lat"}) From 14d6f067fa528306859dd9de76585fbb1471fb00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Tue, 30 Jun 2026 11:17:00 +0200 Subject: [PATCH 30/42] Make variable names more exact even they are now longer --- .../tutorials/advanced/create_grid_masks.py | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/tutorials/advanced/create_grid_masks.py b/examples/tutorials/advanced/create_grid_masks.py index 8b297d7cb7d..f466d099781 100644 --- a/examples/tutorials/advanced/create_grid_masks.py +++ b/examples/tutorials/advanced/create_grid_masks.py @@ -47,16 +47,16 @@ # Create a grid mask based on the two polygons defined above # Set all grid nodes outside the polygons to NaN -mask_out = pygmt.grdmask(region=region, data=polygon, spacing="01m", outside="NaN") +mask_outside = pygmt.grdmask(region=region, data=polygon, spacing="01m", outside="NaN") # Set all grid nodes inside the polygons to NaN # Set the outside parameter to a value larger 0 to keep the nodes outside unchanged -mask_in = pygmt.grdmask( +mask_inside = pygmt.grdmask( region=region, data=polygon, spacing="01m", inside="NaN", outside=1 ) # Apply the grid mask to the downloaded elevation grid by multiplying the two grids -grid_mask_out = grid * mask_out -grid_mask_in = grid * mask_in +grid_masked_outside = grid * mask_outside +grid_masked_inside = grid * mask_inside fig = pygmt.Figure() @@ -71,14 +71,14 @@ # Plot the masked elevation grid outside fig.basemap(region=region, projection="M10c", frame=True) -fig.grdimage(grid=grid_mask_out, cmap=True) +fig.grdimage(grid=grid_masked_outside, cmap=True) fig.plot(data=polygon, pen="2p,cyan") fig.shift_origin(xshift="+w+2c") # Plot the masked elevation grid inside fig.basemap(region=region, projection="M10c", frame=True) -fig.grdimage(grid=grid_mask_in, cmap=True) +fig.grdimage(grid=grid_masked_inside, cmap=True) fig.plot(data=polygon, pen="2p,cyan") fig.show() @@ -99,7 +99,7 @@ grid = pygmt.datasets.load_earth_relief(region=region, resolution="01m") mask = pygmt.grdmask(region=region, data=missouri, spacing="01m", outside="NaN") mask_lonlat = mask.rename(new_name_or_name_dict={"x": "lon", "y": "lat"}) -grid_mask = grid * mask_lonlat +grid_masked = grid * mask_lonlat fig = pygmt.Figure() @@ -115,7 +115,7 @@ # Plot the masked elevation grid # fig.basemap(projection="L-96/35/33/41/12c", region=region, frame=True) fig.basemap(projection="M10c", region=[-96.5, -88.5, 35.8, 41], frame=True) -fig.grdimage(grid=grid_mask, cmap=True) +fig.grdimage(grid=grid_masked, cmap=True) fig.plot(data=missouri, pen="1p,cyan") fig.colorbar(frame=True) @@ -138,7 +138,7 @@ grid = pygmt.datasets.load_earth_relief(region=region, resolution="30s") mask = pygmt.grdmask(region=region, data=circle, spacing="30s", outside="NaN") mask_lonlat = mask.rename(new_name_or_name_dict={"x": "lon", "y": "lat"}) -grid_mask = grid * mask_lonlat +grid_masked = grid * mask_lonlat fig = pygmt.Figure() @@ -153,7 +153,7 @@ # Plot the masked elevation grid fig.basemap(region=[125.5, 127.5, 32.5, 34.5], projection="M12c", frame=True) -fig.grdimage(grid=grid_mask, cmap=True) +fig.grdimage(grid=grid_masked, cmap=True) fig.plot(data=circle, pen="2p,cyan") fig.colorbar(frame=True) From 5341e34699a507c9b91666f0db521d5020478bb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Tue, 30 Jun 2026 11:28:13 +0200 Subject: [PATCH 31/42] Fix highlighting --- examples/tutorials/advanced/create_grid_masks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tutorials/advanced/create_grid_masks.py b/examples/tutorials/advanced/create_grid_masks.py index f466d099781..8a781953f97 100644 --- a/examples/tutorials/advanced/create_grid_masks.py +++ b/examples/tutorials/advanced/create_grid_masks.py @@ -19,7 +19,7 @@ from shapely.geometry import Point # %% -# Polygons based on :class:`numpy` arrays +# Polygons based on :class:`numpy.array`s # --------------------------------------- # Define a study region From a4c27ac32b6aee625a21b8bfac1630d2dba1c4c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Tue, 30 Jun 2026 11:48:33 +0200 Subject: [PATCH 32/42] Fix highlighting --- examples/tutorials/advanced/create_grid_masks.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/tutorials/advanced/create_grid_masks.py b/examples/tutorials/advanced/create_grid_masks.py index 8a781953f97..a2ab7de5443 100644 --- a/examples/tutorials/advanced/create_grid_masks.py +++ b/examples/tutorials/advanced/create_grid_masks.py @@ -19,8 +19,8 @@ from shapely.geometry import Point # %% -# Polygons based on :class:`numpy.array`s -# --------------------------------------- +# Polygons based on a :class:`numpy.ndarray` +# ------------------------------------------ # Define a study region region = [125, 135, 25, 36] From 9d67e16718197c638c96f411c2948019941dd1eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Tue, 30 Jun 2026 12:45:08 +0200 Subject: [PATCH 33/42] Add more highlighting --- examples/tutorials/advanced/create_grid_masks.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/tutorials/advanced/create_grid_masks.py b/examples/tutorials/advanced/create_grid_masks.py index a2ab7de5443..cb64e393376 100644 --- a/examples/tutorials/advanced/create_grid_masks.py +++ b/examples/tutorials/advanced/create_grid_masks.py @@ -3,9 +3,9 @@ ===================================== The functionn :func:`pygmt.grdmask` allows to create a grid mask based on spatial -shapes given as closed polygons. These polygons can be provided as NumPy arrays or -GeoPandas DataFrame. For the nodes falling inside, outside, and on the edges, different -values can be defined. The created mask can then be applied to a desired grid. +shapes given as closed polygons. These polygons can be provided as :class:`numpy.ndarray` +or :class:`geopandas.GeoDataFrame`. For the nodes falling inside, outside, and on the edges, +different values can be defined. The created mask can then be applied to a desired grid. To create a land-water mask based on the GMT built-in shoreline data you can directly use the function :func:`pygmt.grdlandmask` explained in the gallery example From d4d060cd7348aced4b8d072f49e87a764dc226ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Tue, 30 Jun 2026 12:53:35 +0200 Subject: [PATCH 34/42] Fix line length --- examples/tutorials/advanced/create_grid_masks.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/tutorials/advanced/create_grid_masks.py b/examples/tutorials/advanced/create_grid_masks.py index cb64e393376..b9210ce1418 100644 --- a/examples/tutorials/advanced/create_grid_masks.py +++ b/examples/tutorials/advanced/create_grid_masks.py @@ -3,9 +3,10 @@ ===================================== The functionn :func:`pygmt.grdmask` allows to create a grid mask based on spatial -shapes given as closed polygons. These polygons can be provided as :class:`numpy.ndarray` -or :class:`geopandas.GeoDataFrame`. For the nodes falling inside, outside, and on the edges, -different values can be defined. The created mask can then be applied to a desired grid. +shapes given as closed polygons. These polygons can be provided as +:class:`numpy.ndarray` or :class:`geopandas.GeoDataFrame`. For the nodes falling inside, +outside, and on the edges, different values can be defined. The created mask can then be +applied to a desired grid. To create a land-water mask based on the GMT built-in shoreline data you can directly use the function :func:`pygmt.grdlandmask` explained in the gallery example From 8ebbfc8b64804931168df4dff7f7878b4df35d54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Tue, 30 Jun 2026 13:23:56 +0200 Subject: [PATCH 35/42] Remove colorbars --- examples/tutorials/advanced/create_grid_masks.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/tutorials/advanced/create_grid_masks.py b/examples/tutorials/advanced/create_grid_masks.py index b9210ce1418..1cbed4ea42d 100644 --- a/examples/tutorials/advanced/create_grid_masks.py +++ b/examples/tutorials/advanced/create_grid_masks.py @@ -119,7 +119,6 @@ fig.grdimage(grid=grid_masked, cmap=True) fig.plot(data=missouri, pen="1p,cyan") -fig.colorbar(frame=True) fig.show() @@ -157,7 +156,6 @@ fig.grdimage(grid=grid_masked, cmap=True) fig.plot(data=circle, pen="2p,cyan") -fig.colorbar(frame=True) fig.show() # sphinx_gallery_thumbnail_number = 1 From b372fce6dfdf61a1af824c330f4db959a9a07462 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Tue, 30 Jun 2026 13:58:40 +0200 Subject: [PATCH 36/42] Add note regarding not adding colorbars --- examples/tutorials/advanced/create_grid_masks.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/tutorials/advanced/create_grid_masks.py b/examples/tutorials/advanced/create_grid_masks.py index 1cbed4ea42d..6f14a3f5166 100644 --- a/examples/tutorials/advanced/create_grid_masks.py +++ b/examples/tutorials/advanced/create_grid_masks.py @@ -7,6 +7,8 @@ :class:`numpy.ndarray` or :class:`geopandas.GeoDataFrame`. For the nodes falling inside, outside, and on the edges, different values can be defined. The created mask can then be applied to a desired grid. +As the focus of this tutorial is on creating a grid mask and a related masked grid, no +colorbars for the elevation grids are added to the maps. To create a land-water mask based on the GMT built-in shoreline data you can directly use the function :func:`pygmt.grdlandmask` explained in the gallery example From 77508741b4eccd23a0143ccc55b63684c3a71dc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Tue, 30 Jun 2026 14:33:39 +0200 Subject: [PATCH 37/42] Adjust structure of intro text --- examples/tutorials/advanced/create_grid_masks.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/tutorials/advanced/create_grid_masks.py b/examples/tutorials/advanced/create_grid_masks.py index 6f14a3f5166..0ac53e266d7 100644 --- a/examples/tutorials/advanced/create_grid_masks.py +++ b/examples/tutorials/advanced/create_grid_masks.py @@ -7,11 +7,11 @@ :class:`numpy.ndarray` or :class:`geopandas.GeoDataFrame`. For the nodes falling inside, outside, and on the edges, different values can be defined. The created mask can then be applied to a desired grid. -As the focus of this tutorial is on creating a grid mask and a related masked grid, no -colorbars for the elevation grids are added to the maps. -To create a land-water mask based on the GMT built-in shoreline data you can directly -use the function :func:`pygmt.grdlandmask` explained in the gallery example +As the focus of this tutorial is on creating a grid mask and a related masked grid, no +colorbars for the elevation grids are added to the maps. To create a land-water mask +based on the GMT built-in shoreline data you can directly use the function +:func:`pygmt.grdlandmask` explained in the gallery example :doc:`Create 'wet-dry' mask grid `. """ From ff6e86165080fe7baf5d71e925be1831d76a4cc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Tue, 30 Jun 2026 15:39:09 +0200 Subject: [PATCH 38/42] Explain values for nodes in intro text --- examples/tutorials/advanced/create_grid_masks.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/examples/tutorials/advanced/create_grid_masks.py b/examples/tutorials/advanced/create_grid_masks.py index 0ac53e266d7..54cf62663d6 100644 --- a/examples/tutorials/advanced/create_grid_masks.py +++ b/examples/tutorials/advanced/create_grid_masks.py @@ -2,11 +2,17 @@ Create grid masks from spatial shapes ===================================== -The functionn :func:`pygmt.grdmask` allows to create a grid mask based on spatial -shapes given as closed polygons. These polygons can be provided as -:class:`numpy.ndarray` or :class:`geopandas.GeoDataFrame`. For the nodes falling inside, -outside, and on the edges, different values can be defined. The created mask can then be -applied to a desired grid. +The functionn :func:`pygmt.grdmask` allows to create a grid mask based on spatial shapes +given as closed polygons. These polygons can be provided as :class:`numpy.ndarray` or +:class:`geopandas.GeoDataFrame`. For the nodes falling inside, outside, and on the +edges, different values can be defined, The created mask can then be applied to a +desired grid. + +This value can be any number, or one of ``None``, ``"NaN"``, and ``np.nan`` for NaN. The +defaults are ``0`` for ``outside``, ``0`` for ``edge``, and ``1`` for ``inside``. To +treat edges as inside, use the same value as ``inside``. When setting these values, keep +in mind you are creating the grid mask which is thought to be applied to a real grid in +a second step. As the focus of this tutorial is on creating a grid mask and a related masked grid, no colorbars for the elevation grids are added to the maps. To create a land-water mask From e77df68cb9955ede26560f6f430cd50b5487f244 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Tue, 30 Jun 2026 15:41:25 +0200 Subject: [PATCH 39/42] Improve formulation --- examples/tutorials/advanced/create_grid_masks.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/tutorials/advanced/create_grid_masks.py b/examples/tutorials/advanced/create_grid_masks.py index 54cf62663d6..891be3d3e47 100644 --- a/examples/tutorials/advanced/create_grid_masks.py +++ b/examples/tutorials/advanced/create_grid_masks.py @@ -11,8 +11,8 @@ This value can be any number, or one of ``None``, ``"NaN"``, and ``np.nan`` for NaN. The defaults are ``0`` for ``outside``, ``0`` for ``edge``, and ``1`` for ``inside``. To treat edges as inside, use the same value as ``inside``. When setting these values, keep -in mind you are creating the grid mask which is thought to be applied to a real grid in -a second step. +in mind you are creating the mask grid first which is thought to be applied to a real +grid in a second step. As the focus of this tutorial is on creating a grid mask and a related masked grid, no colorbars for the elevation grids are added to the maps. To create a land-water mask From 9cc268c278517f8ee6393ad1edb77420934f2dfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Tue, 30 Jun 2026 15:45:01 +0200 Subject: [PATCH 40/42] Add missing word --- examples/tutorials/advanced/create_grid_masks.py | 6 +++--- pygmt/src/grdmask.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/tutorials/advanced/create_grid_masks.py b/examples/tutorials/advanced/create_grid_masks.py index 891be3d3e47..bc81e445932 100644 --- a/examples/tutorials/advanced/create_grid_masks.py +++ b/examples/tutorials/advanced/create_grid_masks.py @@ -10,9 +10,9 @@ This value can be any number, or one of ``None``, ``"NaN"``, and ``np.nan`` for NaN. The defaults are ``0`` for ``outside``, ``0`` for ``edge``, and ``1`` for ``inside``. To -treat edges as inside, use the same value as ``inside``. When setting these values, keep -in mind you are creating the mask grid first which is thought to be applied to a real -grid in a second step. +treat edges as inside, use the same value as for ``inside``. When setting these values, +keep in mind you are creating the mask grid first which is thought to be applied to a +real grid in a second step. As the focus of this tutorial is on creating a grid mask and a related masked grid, no colorbars for the elevation grids are added to the maps. To create a land-water mask diff --git a/pygmt/src/grdmask.py b/pygmt/src/grdmask.py index 4b7d109a7f3..08e7c090640 100644 --- a/pygmt/src/grdmask.py +++ b/pygmt/src/grdmask.py @@ -175,7 +175,7 @@ def grdmask( ``-Lheader``, or via ``-aZ=name``). - ``"id"``: Use a running polygon ID number. - To treat edges as inside, use the same value as ``inside``. + To treat edges as inside, use the same value as for ``inside``. id_start The starting number for polygon IDs when ``inside="id"`` [Default is ``0``]. Only valid when ``inside="id"``. From 1116e2849693bdd0553c11e94c48a881cf579b93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Tue, 30 Jun 2026 15:45:59 +0200 Subject: [PATCH 41/42] Add word --- pygmt/src/grdmask.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/grdmask.py b/pygmt/src/grdmask.py index 08e7c090640..153d7ace20d 100644 --- a/pygmt/src/grdmask.py +++ b/pygmt/src/grdmask.py @@ -167,7 +167,7 @@ def grdmask( Can be any number, or one of ``None``, ``"NaN"``, and ``np.nan`` for NaN. Defaults are ``0`` for ``outside``, ``0`` for ``edge``, and ``1`` for ``inside``. When setting these values, keep in mind you are creating a mask grid - which is thought to be applied to a real grid in a second step. + here which is thought to be applied to a real grid in a second step. ``edge`` and ``inside`` can also be set to one of the following values: From 583c5ca0a7945dd59471bc1c83e069b6b8d95aa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Tue, 30 Jun 2026 15:50:02 +0200 Subject: [PATCH 42/42] Improve intro text --- examples/tutorials/advanced/create_grid_masks.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/tutorials/advanced/create_grid_masks.py b/examples/tutorials/advanced/create_grid_masks.py index bc81e445932..3f966c47043 100644 --- a/examples/tutorials/advanced/create_grid_masks.py +++ b/examples/tutorials/advanced/create_grid_masks.py @@ -5,7 +5,7 @@ The functionn :func:`pygmt.grdmask` allows to create a grid mask based on spatial shapes given as closed polygons. These polygons can be provided as :class:`numpy.ndarray` or :class:`geopandas.GeoDataFrame`. For the nodes falling inside, outside, and on the -edges, different values can be defined, The created mask can then be applied to a +edges, different values can be defined. The created mask can then be applied to a desired grid. This value can be any number, or one of ``None``, ``"NaN"``, and ``np.nan`` for NaN. The @@ -14,11 +14,11 @@ keep in mind you are creating the mask grid first which is thought to be applied to a real grid in a second step. -As the focus of this tutorial is on creating a grid mask and a related masked grid, no -colorbars for the elevation grids are added to the maps. To create a land-water mask -based on the GMT built-in shoreline data you can directly use the function -:func:`pygmt.grdlandmask` explained in the gallery example -:doc:`Create 'wet-dry' mask grid `. +To create a land-water mask based on the GMT built-in shoreline data you can directly +use the function :func:`pygmt.grdlandmask` explained in the gallery example +:doc:`Create 'wet-dry' mask grid `. As the focus of this +tutorial is on creating a mask grid and the related masked grid, no colorbars for the +elevation grids are added to the maps. """ # %%