From a56a2816063879654d2c85b03f22c639a9f77d7e Mon Sep 17 00:00:00 2001 From: Michael Grund <23025878+michaelgrund@users.noreply.github.com> Date: Fri, 27 Aug 2021 19:00:44 +0200 Subject: [PATCH 1/9] Add gallery example for grdlandmask According to #1421 here's now the gallery example showcasing the use of ``grdlandmask``. --- examples/gallery/images/grdlandmask.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 examples/gallery/images/grdlandmask.py diff --git a/examples/gallery/images/grdlandmask.py b/examples/gallery/images/grdlandmask.py new file mode 100644 index 00000000000..414f21f3786 --- /dev/null +++ b/examples/gallery/images/grdlandmask.py @@ -0,0 +1,24 @@ +""" +Create 'wet-dry' mask grid +-------------------- +The :meth:`pygmt.grdlandmash` method allows to set +all nodes on land or water to a specified value using +the ``maskvalues`` parameter. +""" + +import pygmt + +fig = pygmt.Figure() + +# Assign a value of 0 for all water masses and a value of 1 for all land masses +grid = pygmt.grdlandmask(region=[-65, -40, -40, -20], spacing = "5m", maskvalues = "0/1", resolution = "l") + +# Plot clipped grid +fig.basemap( + region=region, projection="M12c", frame=True +) + +fig.grdimage(grid=grid, cmap="lajolla") +fig.colorbar(position="JMR+o0.5c/0c+w8c") + +fig.show() From 5fb489a222be58e3e69f786639dce2d35a382bbe Mon Sep 17 00:00:00 2001 From: actions-bot <58130806+actions-bot@users.noreply.github.com> Date: Fri, 27 Aug 2021 17:03:30 +0000 Subject: [PATCH 2/9] [format-command] fixes --- examples/gallery/images/grdlandmask.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/gallery/images/grdlandmask.py b/examples/gallery/images/grdlandmask.py index 414f21f3786..4d25dd9ecdc 100644 --- a/examples/gallery/images/grdlandmask.py +++ b/examples/gallery/images/grdlandmask.py @@ -11,12 +11,12 @@ fig = pygmt.Figure() # Assign a value of 0 for all water masses and a value of 1 for all land masses -grid = pygmt.grdlandmask(region=[-65, -40, -40, -20], spacing = "5m", maskvalues = "0/1", resolution = "l") +grid = pygmt.grdlandmask( + region=[-65, -40, -40, -20], spacing="5m", maskvalues="0/1", resolution="l" +) # Plot clipped grid -fig.basemap( - region=region, projection="M12c", frame=True -) +fig.basemap(region=region, projection="M12c", frame=True) fig.grdimage(grid=grid, cmap="lajolla") fig.colorbar(position="JMR+o0.5c/0c+w8c") From c01a30573a8e5e785886a40b5cfacc8a313ae92c Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Fri, 27 Aug 2021 19:19:07 +0200 Subject: [PATCH 3/9] adjustments --- examples/gallery/images/grdlandmask.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/gallery/images/grdlandmask.py b/examples/gallery/images/grdlandmask.py index 4d25dd9ecdc..5b0bda77568 100644 --- a/examples/gallery/images/grdlandmask.py +++ b/examples/gallery/images/grdlandmask.py @@ -10,9 +10,12 @@ fig = pygmt.Figure() +# Define region of interest +region=[-65, -40, -40, -20] + # Assign a value of 0 for all water masses and a value of 1 for all land masses grid = pygmt.grdlandmask( - region=[-65, -40, -40, -20], spacing="5m", maskvalues="0/1", resolution="l" + region=region, spacing="5m", maskvalues="0/1", resolution="l" ) # Plot clipped grid From 9ef73c9d600ea83e9bb74c086ca0731ebfef3e46 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Fri, 27 Aug 2021 19:22:34 +0200 Subject: [PATCH 4/9] formatting --- examples/gallery/images/grdlandmask.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/examples/gallery/images/grdlandmask.py b/examples/gallery/images/grdlandmask.py index 5b0bda77568..be852084541 100644 --- a/examples/gallery/images/grdlandmask.py +++ b/examples/gallery/images/grdlandmask.py @@ -11,12 +11,10 @@ fig = pygmt.Figure() # Define region of interest -region=[-65, -40, -40, -20] +region = [-65, -40, -40, -20] # Assign a value of 0 for all water masses and a value of 1 for all land masses -grid = pygmt.grdlandmask( - region=region, spacing="5m", maskvalues="0/1", resolution="l" -) +grid = pygmt.grdlandmask(region=region, spacing="5m", maskvalues="0/1", resolution="l") # Plot clipped grid fig.basemap(region=region, projection="M12c", frame=True) From 961c891ee53d89cddb5d6b7f8e41ababe3d11a2b Mon Sep 17 00:00:00 2001 From: actions-bot <58130806+actions-bot@users.noreply.github.com> Date: Fri, 27 Aug 2021 17:27:16 +0000 Subject: [PATCH 5/9] [format-command] fixes --- examples/gallery/images/grdlandmask.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/examples/gallery/images/grdlandmask.py b/examples/gallery/images/grdlandmask.py index 5b0bda77568..be852084541 100644 --- a/examples/gallery/images/grdlandmask.py +++ b/examples/gallery/images/grdlandmask.py @@ -11,12 +11,10 @@ fig = pygmt.Figure() # Define region of interest -region=[-65, -40, -40, -20] +region = [-65, -40, -40, -20] # Assign a value of 0 for all water masses and a value of 1 for all land masses -grid = pygmt.grdlandmask( - region=region, spacing="5m", maskvalues="0/1", resolution="l" -) +grid = pygmt.grdlandmask(region=region, spacing="5m", maskvalues="0/1", resolution="l") # Plot clipped grid fig.basemap(region=region, projection="M12c", frame=True) From ffbcdfe5640a498bd1bf45a0b7b112fd0f1f630f Mon Sep 17 00:00:00 2001 From: Michael Grund <23025878+michaelgrund@users.noreply.github.com> Date: Sat, 28 Aug 2021 13:17:14 +0200 Subject: [PATCH 6/9] Apply suggestions from code review Co-authored-by: Dongdong Tian --- examples/gallery/images/grdlandmask.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/gallery/images/grdlandmask.py b/examples/gallery/images/grdlandmask.py index be852084541..af2bdbeb1c8 100644 --- a/examples/gallery/images/grdlandmask.py +++ b/examples/gallery/images/grdlandmask.py @@ -1,7 +1,7 @@ """ Create 'wet-dry' mask grid --------------------- -The :meth:`pygmt.grdlandmash` method allows to set +-------------------------- +The :meth:`pygmt.grdlandmask` method allows setting all nodes on land or water to a specified value using the ``maskvalues`` parameter. """ @@ -14,7 +14,7 @@ region = [-65, -40, -40, -20] # Assign a value of 0 for all water masses and a value of 1 for all land masses -grid = pygmt.grdlandmask(region=region, spacing="5m", maskvalues="0/1", resolution="l") +grid = pygmt.grdlandmask(region=region, spacing="5m", maskvalues=[0, 1], resolution="l") # Plot clipped grid fig.basemap(region=region, projection="M12c", frame=True) From 2cdd4fd52735cee346d49d2d046a07f6ab448bbd Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Mon, 30 Aug 2021 18:23:18 +0200 Subject: [PATCH 7/9] updates based on code review --- examples/gallery/images/grdlandmask.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/examples/gallery/images/grdlandmask.py b/examples/gallery/images/grdlandmask.py index af2bdbeb1c8..95ec40db5fc 100644 --- a/examples/gallery/images/grdlandmask.py +++ b/examples/gallery/images/grdlandmask.py @@ -1,9 +1,9 @@ """ Create 'wet-dry' mask grid -------------------------- -The :meth:`pygmt.grdlandmask` method allows setting +The :meth:`pygmt.grdlandmask` method allows setting all nodes on land or water to a specified value using -the ``maskvalues`` parameter. +the ``maskvalues`` parameter. """ import pygmt @@ -13,13 +13,22 @@ # Define region of interest region = [-65, -40, -40, -20] -# Assign a value of 0 for all water masses and a value of 1 for all land masses +# Assign a value of 0 for all water masses and a value of 1 for all land masses. +# Use shoreline data with (l)ow resolution and set the grid spacing to 5 m in x +# and y direction. grid = pygmt.grdlandmask(region=region, spacing="5m", maskvalues=[0, 1], resolution="l") # Plot clipped grid fig.basemap(region=region, projection="M12c", frame=True) -fig.grdimage(grid=grid, cmap="lajolla") +# Define a colormap to be used for two categories, define the range of the +# new discrete CPT using series=(lowest_value, highest_value, interval), +# use color_model="+cwater,land" to write the discrete color palette +# "batlow" in categorical format and add water/land as annotations for the +# colorbar. +pygmt.makecpt(cmap="batlow", series=(0, 1, 1), color_model="+cwater,land") + +fig.grdimage(grid=grid, cmap=True) fig.colorbar(position="JMR+o0.5c/0c+w8c") fig.show() From 66dc1ce504a67f6907c98a84fb105995c9fb3211 Mon Sep 17 00:00:00 2001 From: Michael Grund <23025878+michaelgrund@users.noreply.github.com> Date: Tue, 31 Aug 2021 09:04:36 +0200 Subject: [PATCH 8/9] Apply suggestions from code review Co-authored-by: Dongdong Tian --- examples/gallery/images/grdlandmask.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/gallery/images/grdlandmask.py b/examples/gallery/images/grdlandmask.py index 95ec40db5fc..62cdaf40c37 100644 --- a/examples/gallery/images/grdlandmask.py +++ b/examples/gallery/images/grdlandmask.py @@ -14,8 +14,8 @@ region = [-65, -40, -40, -20] # Assign a value of 0 for all water masses and a value of 1 for all land masses. -# Use shoreline data with (l)ow resolution and set the grid spacing to 5 m in x -# and y direction. +# Use shoreline data with (l)ow resolution and set the grid spacing to +# 5 arc minute in x and y direction. grid = pygmt.grdlandmask(region=region, spacing="5m", maskvalues=[0, 1], resolution="l") # Plot clipped grid From 8ed5b091b8dc8f5099a1d1d98d29f91c596a4b3c Mon Sep 17 00:00:00 2001 From: actions-bot <58130806+actions-bot@users.noreply.github.com> Date: Tue, 31 Aug 2021 16:18:02 +0000 Subject: [PATCH 9/9] [format-command] fixes --- examples/gallery/images/grdlandmask.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/images/grdlandmask.py b/examples/gallery/images/grdlandmask.py index 62cdaf40c37..de4e833e7f4 100644 --- a/examples/gallery/images/grdlandmask.py +++ b/examples/gallery/images/grdlandmask.py @@ -14,7 +14,7 @@ region = [-65, -40, -40, -20] # Assign a value of 0 for all water masses and a value of 1 for all land masses. -# Use shoreline data with (l)ow resolution and set the grid spacing to +# Use shoreline data with (l)ow resolution and set the grid spacing to # 5 arc minute in x and y direction. grid = pygmt.grdlandmask(region=region, spacing="5m", maskvalues=[0, 1], resolution="l")