From dc5cf3ef8b0d9e6b35536047d513a33063640bfe Mon Sep 17 00:00:00 2001 From: Michael Grund <23025878+michaelgrund@users.noreply.github.com> Date: Mon, 26 Jul 2021 22:33:35 +0200 Subject: [PATCH 1/9] Add gallery example for grdclip Since noone worked on this issue during the scipy-sprint here's a gallery example adressing #1384. --- examples/gallery/images/grdclip.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 examples/gallery/images/grdclip.py diff --git a/examples/gallery/images/grdclip.py b/examples/gallery/images/grdclip.py new file mode 100644 index 00000000000..f0779ceec49 --- /dev/null +++ b/examples/gallery/images/grdclip.py @@ -0,0 +1,22 @@ +import pygmt + +fig = pygmt.Figure() + +# Load sample grid and use area around the Hawaiian Islands +grid = pygmt.datasets.load_earth_relief(resolution="01m", region = [-162, -153, 18, 23]) + +# Plot original grid +fig.basemap(region = [-162, -153, 18, 23], projection="M12c", frame=["f", '+t"original grid"']) +fig.grdimage(grid=grid, cmap="oleron") + +fig.shift_origin(yshift = "-9c") + +# Set all grid points < 0 to a value of -2000. +grid = pygmt.grdclip(grid, below = [0, -2000]) + +# Plot clipped grid +fig.basemap(region = [-162, -153, 18, 23], projection="M12c", frame=["f", '+t"clipped grid"']) +fig.grdimage(grid=grid) +fig.colorbar(frame=["x+lElevation", "y+lm"]) + +fig.show() From a6c4e626f204b86a3017df3a4e6ec82363d583ae Mon Sep 17 00:00:00 2001 From: actions-bot <58130806+actions-bot@users.noreply.github.com> Date: Mon, 26 Jul 2021 20:35:47 +0000 Subject: [PATCH 2/9] [format-command] fixes --- examples/gallery/images/grdclip.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/examples/gallery/images/grdclip.py b/examples/gallery/images/grdclip.py index f0779ceec49..da6578add44 100644 --- a/examples/gallery/images/grdclip.py +++ b/examples/gallery/images/grdclip.py @@ -3,19 +3,23 @@ fig = pygmt.Figure() # Load sample grid and use area around the Hawaiian Islands -grid = pygmt.datasets.load_earth_relief(resolution="01m", region = [-162, -153, 18, 23]) +grid = pygmt.datasets.load_earth_relief(resolution="01m", region=[-162, -153, 18, 23]) -# Plot original grid -fig.basemap(region = [-162, -153, 18, 23], projection="M12c", frame=["f", '+t"original grid"']) +# Plot original grid +fig.basemap( + region=[-162, -153, 18, 23], projection="M12c", frame=["f", '+t"original grid"'] +) fig.grdimage(grid=grid, cmap="oleron") -fig.shift_origin(yshift = "-9c") +fig.shift_origin(yshift="-9c") # Set all grid points < 0 to a value of -2000. -grid = pygmt.grdclip(grid, below = [0, -2000]) +grid = pygmt.grdclip(grid, below=[0, -2000]) -# Plot clipped grid -fig.basemap(region = [-162, -153, 18, 23], projection="M12c", frame=["f", '+t"clipped grid"']) +# Plot clipped grid +fig.basemap( + region=[-162, -153, 18, 23], projection="M12c", frame=["f", '+t"clipped grid"'] +) fig.grdimage(grid=grid) fig.colorbar(frame=["x+lElevation", "y+lm"]) From 03a198461360bf8ac35d144e2d4b0996eb22983f Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Tue, 27 Jul 2021 07:07:35 +0200 Subject: [PATCH 3/9] add docstring --- examples/gallery/images/grdclip.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/gallery/images/grdclip.py b/examples/gallery/images/grdclip.py index da6578add44..30fc630eb66 100644 --- a/examples/gallery/images/grdclip.py +++ b/examples/gallery/images/grdclip.py @@ -1,3 +1,9 @@ +""" +Grdclip +------- +The :meth:`pygmt.grdclip` method allows to clip defined ranges of grid values. +""" + import pygmt fig = pygmt.Figure() @@ -13,7 +19,7 @@ fig.shift_origin(yshift="-9c") -# Set all grid points < 0 to a value of -2000. +# Set all grid points < 0 m to a value of -2000 m. grid = pygmt.grdclip(grid, below=[0, -2000]) # Plot clipped grid From 6f9f84a2ffd8c91b17488c9ec4542ab2075d8161 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Tue, 27 Jul 2021 18:19:03 +0200 Subject: [PATCH 4/9] update docstring --- examples/gallery/images/grdclip.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/gallery/images/grdclip.py b/examples/gallery/images/grdclip.py index 30fc630eb66..dcec1eeed1d 100644 --- a/examples/gallery/images/grdclip.py +++ b/examples/gallery/images/grdclip.py @@ -1,14 +1,17 @@ """ -Grdclip -------- +Clip 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() -# Load sample grid and use area around the Hawaiian Islands +# Load sample grid (1 arc minute global relief) and use area around the Hawaiian Islands grid = pygmt.datasets.load_earth_relief(resolution="01m", region=[-162, -153, 18, 23]) # Plot original grid From d5c9037b6483523c6950a54a316d55715e1b7eb5 Mon Sep 17 00:00:00 2001 From: Michael Grund <23025878+michaelgrund@users.noreply.github.com> Date: Thu, 29 Jul 2021 07:33:58 +0200 Subject: [PATCH 5/9] Update examples/gallery/images/grdclip.py Co-authored-by: Dongdong Tian --- examples/gallery/images/grdclip.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/gallery/images/grdclip.py b/examples/gallery/images/grdclip.py index dcec1eeed1d..001aced7741 100644 --- a/examples/gallery/images/grdclip.py +++ b/examples/gallery/images/grdclip.py @@ -1,6 +1,6 @@ """ -Clip grid values ----------------- +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 From 6ad00e82536b6dd458dfcf3c53a8f2a4051c7441 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Thu, 29 Jul 2021 08:08:48 +0200 Subject: [PATCH 6/9] updates --- examples/gallery/images/grdclip.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/gallery/images/grdclip.py b/examples/gallery/images/grdclip.py index 001aced7741..eb571943e92 100644 --- a/examples/gallery/images/grdclip.py +++ b/examples/gallery/images/grdclip.py @@ -11,24 +11,24 @@ fig = pygmt.Figure() -# Load sample grid (1 arc minute global relief) and use area around the Hawaiian Islands -grid = pygmt.datasets.load_earth_relief(resolution="01m", region=[-162, -153, 18, 23]) +# Define region of interest around the Hawaiian Islands +region = [-162, -153, 18, 23] + +# Load sample grid (1 arc minute global relief) in target area +grid = pygmt.datasets.load_earth_relief(resolution="01m", region=region) # Plot original grid -fig.basemap( - region=[-162, -153, 18, 23], projection="M12c", frame=["f", '+t"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 -9 cm in y direction fig.shift_origin(yshift="-9c") # 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=[-162, -153, 18, 23], projection="M12c", frame=["f", '+t"clipped grid"'] -) +fig.basemap(region=region, projection="M12c", frame=["f", '+t"clipped grid"']) fig.grdimage(grid=grid) fig.colorbar(frame=["x+lElevation", "y+lm"]) From ba5c10589ad4792925616a199080b8e4d090421c Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Sat, 31 Jul 2021 11:17:23 +0200 Subject: [PATCH 7/9] updates based on code review --- examples/gallery/images/grdclip.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/gallery/images/grdclip.py b/examples/gallery/images/grdclip.py index eb571943e92..12945259880 100644 --- a/examples/gallery/images/grdclip.py +++ b/examples/gallery/images/grdclip.py @@ -11,18 +11,18 @@ fig = pygmt.Figure() -# Define region of interest around the Hawaiian Islands -region = [-162, -153, 18, 23] +# Define region of interest around Iceland +region = [-28, -10, 62, 68] -# Load sample grid (1 arc minute global relief) in target area -grid = pygmt.datasets.load_earth_relief(resolution="01m", region=region) +# 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 -9 cm in y direction -fig.shift_origin(yshift="-9c") +# Shift plot origin for second map 12.5 cm in x direction +fig.shift_origin(xshift="12.5c") # Set all grid points < 0 m to a value of -2000 m. grid = pygmt.grdclip(grid, below=[0, -2000]) @@ -30,6 +30,6 @@ # 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"]) +fig.colorbar(frame=["x+lElevation", "y+lm"], position="JMR+o0.5c/0c+w8c") fig.show() From a1401bd0b4c26b6947bc2c1a88982d5910f7b257 Mon Sep 17 00:00:00 2001 From: Michael Grund <23025878+michaelgrund@users.noreply.github.com> Date: Sun, 1 Aug 2021 11:14:15 +0200 Subject: [PATCH 8/9] Update examples/gallery/images/grdclip.py Co-authored-by: Dongdong Tian --- examples/gallery/images/grdclip.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/gallery/images/grdclip.py b/examples/gallery/images/grdclip.py index 12945259880..789c7c756e9 100644 --- a/examples/gallery/images/grdclip.py +++ b/examples/gallery/images/grdclip.py @@ -21,8 +21,8 @@ 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") +# Shift plot origin of the second map by "width of the first map + 0.5 cm" +fig.shift_origin(xshift="w+0.5c") # Set all grid points < 0 m to a value of -2000 m. grid = pygmt.grdclip(grid, below=[0, -2000]) From da13edb6e85d8ba0acddd1525b3562842ba472f4 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Sun, 1 Aug 2021 11:17:30 +0200 Subject: [PATCH 9/9] updates --- examples/gallery/images/grdclip.py | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/gallery/images/grdclip.py b/examples/gallery/images/grdclip.py index 789c7c756e9..989ce26ce3f 100644 --- a/examples/gallery/images/grdclip.py +++ b/examples/gallery/images/grdclip.py @@ -22,6 +22,7 @@ fig.grdimage(grid=grid, cmap="oleron") # Shift plot origin of the second map by "width of the first map + 0.5 cm" +# in x direction fig.shift_origin(xshift="w+0.5c") # Set all grid points < 0 m to a value of -2000 m.