From a2a2bc51d8ba055e48986232ace21b9a211d1a00 Mon Sep 17 00:00:00 2001 From: Michael Grund <23025878+michaelgrund@users.noreply.github.com> Date: Mon, 17 Jan 2022 08:53:49 +0100 Subject: [PATCH 01/24] Add missing Q alias to pygmt.Figure.coast This PR adds an alias for the ``-Q`` flag which I need to set up a new gallery example. --- pygmt/src/coast.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pygmt/src/coast.py b/pygmt/src/coast.py index 7111f3d6f5a..df76417fb0e 100644 --- a/pygmt/src/coast.py +++ b/pygmt/src/coast.py @@ -27,6 +27,7 @@ N="borders", W="shorelines", G="land", + Q="end_path", S="water", U="timestamp", V="verbose", @@ -145,7 +146,11 @@ def coast(self, **kwargs): 3 = Marine boundaries - a = All boundaries (1-3) + a = All boundaries (1-3) + end_path : bool + Mark end of existing clip path. No projection information is needed. + Also supply ``xshift`` and ``yshift`` settings if you have moved + since the clip started. water : str Select filling or clipping of "wet" areas. {U} From 5fb85907e50d757a7db684b39147f0481fce1ddb Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Mon, 17 Jan 2022 09:00:02 +0100 Subject: [PATCH 02/24] format --- pygmt/src/coast.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pygmt/src/coast.py b/pygmt/src/coast.py index df76417fb0e..5a3e8d5bb91 100644 --- a/pygmt/src/coast.py +++ b/pygmt/src/coast.py @@ -146,11 +146,11 @@ def coast(self, **kwargs): 3 = Marine boundaries - a = All boundaries (1-3) + a = All boundaries (1-3) end_path : bool - Mark end of existing clip path. No projection information is needed. - Also supply ``xshift`` and ``yshift`` settings if you have moved - since the clip started. + Mark end of existing clip path. No projection information is needed. + Also supply ``xshift`` and ``yshift`` settings if you have moved + since the clip started. water : str Select filling or clipping of "wet" areas. {U} From 7d1342dd23d6018d317c9e9432e544ec78ca6d07 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Sun, 13 Feb 2022 18:23:07 +0100 Subject: [PATCH 03/24] add clip parameter and different selection choices --- pygmt/src/coast.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/pygmt/src/coast.py b/pygmt/src/coast.py index 5a3e8d5bb91..66a53410074 100644 --- a/pygmt/src/coast.py +++ b/pygmt/src/coast.py @@ -27,7 +27,6 @@ N="borders", W="shorelines", G="land", - Q="end_path", S="water", U="timestamp", V="verbose", @@ -82,7 +81,7 @@ def coast(self, **kwargs): (**h**\ )igh, (**i**\ )ntermediate, (**l**\ )ow, and (**c**\ )rude. land : str - Select filling or clipping of "dry" areas. + Select filling of "dry" areas. rivers : int or str or list *river*\ [/*pen*]. Draw rivers. Specify the type of rivers and [optionally] append @@ -152,7 +151,7 @@ def coast(self, **kwargs): Also supply ``xshift`` and ``yshift`` settings if you have moved since the clip started. water : str - Select filling or clipping of "wet" areas. + Select filling of "wet" areas. {U} shorelines : int or str or list [*level*\ /]\ *pen*. @@ -164,6 +163,10 @@ def coast(self, **kwargs): lake-in-island-in-lake shore. Pass a list of *level*\ /*pen* strings to ``shorelines`` to set multiple levels. When specific level pens are set, those not listed will not be drawn. + clip : str + To clip land do ``clip=land``, ``clip=water`` clips water. Use + ``clip=end`` to mark end of existing clip path. No projection + information is needed. dcw : str or list *code1,code2,…*\ [**+l**\|\ **L**\ ][**+g**\ *fill*\ ] [**+p**\ *pen*\ ][**+z**]. @@ -188,10 +191,22 @@ def coast(self, **kwargs): {V} """ kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access + + if "clip" in kwargs and kwargs["clip"][0] in "land": + kwargs["G"] = True + kwargs.pop("clip") + elif "clip" in kwargs and kwargs["clip"][0] in "water": + kwargs["S"] = True + kwargs.pop("clip") + elif "clip" in kwargs and kwargs["clip"][0] in "end": + kwargs["Q"] = True + kwargs.pop("clip") + if not args_in_kwargs(args=["C", "G", "S", "I", "N", "E", "Q", "W"], kwargs=kwargs): raise GMTInvalidInput( """At least one of the following parameters must be specified: - lakes, land, water, rivers, borders, dcw, Q, or shorelines""" + lakes, land, water, rivers, borders, dcw, clip, or shorelines""" ) + with Session() as lib: lib.call_module("coast", build_arg_string(kwargs)) From 63da1aeed599117d2d6e8baea3092e7b4fdca672 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Sun, 13 Feb 2022 18:24:39 +0100 Subject: [PATCH 04/24] remove old end_path parameter --- pygmt/src/coast.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pygmt/src/coast.py b/pygmt/src/coast.py index 66a53410074..c9c59b28c31 100644 --- a/pygmt/src/coast.py +++ b/pygmt/src/coast.py @@ -146,10 +146,6 @@ def coast(self, **kwargs): 3 = Marine boundaries a = All boundaries (1-3) - end_path : bool - Mark end of existing clip path. No projection information is needed. - Also supply ``xshift`` and ``yshift`` settings if you have moved - since the clip started. water : str Select filling of "wet" areas. {U} @@ -166,7 +162,8 @@ def coast(self, **kwargs): clip : str To clip land do ``clip=land``, ``clip=water`` clips water. Use ``clip=end`` to mark end of existing clip path. No projection - information is needed. + information is needed. Also supply ``xshift`` and ``yshift`` settings + if you have moved since the clip started. dcw : str or list *code1,code2,…*\ [**+l**\|\ **L**\ ][**+g**\ *fill*\ ] [**+p**\ *pen*\ ][**+z**]. From cd800d333f8cdebfe82a003aa8477d2fd9efbbb6 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Tue, 15 Feb 2022 18:58:29 +0100 Subject: [PATCH 05/24] updates based on code review --- pygmt/src/coast.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pygmt/src/coast.py b/pygmt/src/coast.py index c9c59b28c31..cd4dd101831 100644 --- a/pygmt/src/coast.py +++ b/pygmt/src/coast.py @@ -189,13 +189,13 @@ def coast(self, **kwargs): """ kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access - if "clip" in kwargs and kwargs["clip"][0] in "land": + if "clip" in kwargs and kwargs["clip"] == "land": kwargs["G"] = True kwargs.pop("clip") - elif "clip" in kwargs and kwargs["clip"][0] in "water": + elif "clip" in kwargs and kwargs["clip"] == "water": kwargs["S"] = True kwargs.pop("clip") - elif "clip" in kwargs and kwargs["clip"][0] in "end": + elif "clip" in kwargs and kwargs["clip"] == "end": kwargs["Q"] = True kwargs.pop("clip") From f44aa2ee8019496f708c37b3906b3ade5948e456 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Tue, 15 Feb 2022 23:20:13 +0100 Subject: [PATCH 06/24] Add plot into DVC --- .../baseline/test_coast_clip_land.png.dvc | 4 +++ .../baseline/test_coast_clip_water.png.dvc | 4 +++ pygmt/tests/test_coast.py | 34 +++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 pygmt/tests/baseline/test_coast_clip_land.png.dvc create mode 100644 pygmt/tests/baseline/test_coast_clip_water.png.dvc diff --git a/pygmt/tests/baseline/test_coast_clip_land.png.dvc b/pygmt/tests/baseline/test_coast_clip_land.png.dvc new file mode 100644 index 00000000000..2b07575261c --- /dev/null +++ b/pygmt/tests/baseline/test_coast_clip_land.png.dvc @@ -0,0 +1,4 @@ +outs: +- md5: 018789fd8a60f7122cd8593e88e9a821 + size: 29104 + path: test_coast_clip_land.png diff --git a/pygmt/tests/baseline/test_coast_clip_water.png.dvc b/pygmt/tests/baseline/test_coast_clip_water.png.dvc new file mode 100644 index 00000000000..d91875c397d --- /dev/null +++ b/pygmt/tests/baseline/test_coast_clip_water.png.dvc @@ -0,0 +1,4 @@ +outs: +- md5: 5dcea737212679746b741e9ebaf437b4 + size: 42421 + path: test_coast_clip_water.png diff --git a/pygmt/tests/test_coast.py b/pygmt/tests/test_coast.py index 1fc66a0ae9b..ec7d52b286b 100644 --- a/pygmt/tests/test_coast.py +++ b/pygmt/tests/test_coast.py @@ -4,6 +4,7 @@ import pytest from pygmt import Figure from pygmt.exceptions import GMTInvalidInput +from pygmt.datasets import load_earth_relief @pytest.mark.mpl_image_compare @@ -72,3 +73,36 @@ def test_coast_dcw_list(): dcw=["ES+gbisque+pgreen", "IT+gcyan+pblue"], ) return fig + + + +@pytest.mark.mpl_image_compare +def test_coast_clip_land(): + """ + Test to clip dry areas + """ + region = [-28, -10, 62, 68] + grid = load_earth_relief(resolution="10m", region=region) + + fig = Figure() + fig.basemap(region=region, projection="M12c", frame=True) + fig.coast(resolution="l", clip = "land") + fig.grdimage(grid=grid, shading = True, cmap="batlow") + fig.coast(clip="end", frame=True) + return fig + + +@pytest.mark.mpl_image_compare +def test_coast_clip_water(): + """ + Test to clip wet areas + """ + region = [-28, -10, 62, 68] + grid = load_earth_relief(resolution="10m", region=region) + + fig = Figure() + fig.basemap(region=region, projection="M12c", frame=True) + fig.coast(resolution="l", clip = "water") + fig.grdimage(grid=grid, shading = True, cmap="batlow") + fig.coast(clip="end", frame=True) + return fig \ No newline at end of file From 8fd9b59fdb441b654225d082f23c43aa392a63e0 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Tue, 15 Feb 2022 23:26:27 +0100 Subject: [PATCH 07/24] format --- pygmt/tests/test_coast.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/pygmt/tests/test_coast.py b/pygmt/tests/test_coast.py index ec7d52b286b..182ff33717e 100644 --- a/pygmt/tests/test_coast.py +++ b/pygmt/tests/test_coast.py @@ -3,8 +3,8 @@ """ import pytest from pygmt import Figure -from pygmt.exceptions import GMTInvalidInput from pygmt.datasets import load_earth_relief +from pygmt.exceptions import GMTInvalidInput @pytest.mark.mpl_image_compare @@ -75,19 +75,18 @@ def test_coast_dcw_list(): return fig - @pytest.mark.mpl_image_compare def test_coast_clip_land(): """ - Test to clip dry areas + Test to clip dry areas. """ region = [-28, -10, 62, 68] grid = load_earth_relief(resolution="10m", region=region) fig = Figure() fig.basemap(region=region, projection="M12c", frame=True) - fig.coast(resolution="l", clip = "land") - fig.grdimage(grid=grid, shading = True, cmap="batlow") + fig.coast(resolution="l", clip="land") + fig.grdimage(grid=grid, shading=True, cmap="batlow") fig.coast(clip="end", frame=True) return fig @@ -95,14 +94,14 @@ def test_coast_clip_land(): @pytest.mark.mpl_image_compare def test_coast_clip_water(): """ - Test to clip wet areas + Test to clip wet areas. """ region = [-28, -10, 62, 68] grid = load_earth_relief(resolution="10m", region=region) fig = Figure() fig.basemap(region=region, projection="M12c", frame=True) - fig.coast(resolution="l", clip = "water") - fig.grdimage(grid=grid, shading = True, cmap="batlow") + fig.coast(resolution="l", clip="water") + fig.grdimage(grid=grid, shading=True, cmap="batlow") fig.coast(clip="end", frame=True) - return fig \ No newline at end of file + return fig From 1cd776f9d7820f1c02f42538d5d23bdc55370423 Mon Sep 17 00:00:00 2001 From: Michael Grund <23025878+michaelgrund@users.noreply.github.com> Date: Wed, 16 Feb 2022 09:08:22 +0100 Subject: [PATCH 08/24] Apply suggestions from code review Btw, should we also use the static_earth_relief here? Co-authored-by: Dongdong Tian --- pygmt/src/coast.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/pygmt/src/coast.py b/pygmt/src/coast.py index cd4dd101831..7c35d7a30bb 100644 --- a/pygmt/src/coast.py +++ b/pygmt/src/coast.py @@ -160,8 +160,8 @@ def coast(self, **kwargs): strings to ``shorelines`` to set multiple levels. When specific level pens are set, those not listed will not be drawn. clip : str - To clip land do ``clip=land``, ``clip=water`` clips water. Use - ``clip=end`` to mark end of existing clip path. No projection + To clip land do ``clip="land"``, ``clip="water"`` clips water. Use + ``clip="end"`` to mark end of existing clip path. No projection information is needed. Also supply ``xshift`` and ``yshift`` settings if you have moved since the clip started. dcw : str or list @@ -189,15 +189,16 @@ def coast(self, **kwargs): """ kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access - if "clip" in kwargs and kwargs["clip"] == "land": - kwargs["G"] = True - kwargs.pop("clip") - elif "clip" in kwargs and kwargs["clip"] == "water": - kwargs["S"] = True - kwargs.pop("clip") - elif "clip" in kwargs and kwargs["clip"] == "end": - kwargs["Q"] = True - kwargs.pop("clip") + if "clip" in kwargs: + if kwargs["clip"] == "land": + kwargs["G"] = True + kwargs.pop("clip") + elif kwargs["clip"] == "water": + kwargs["S"] = True + kwargs.pop("clip") + elif kwargs["clip"] == "end": + kwargs["Q"] = True + kwargs.pop("clip") if not args_in_kwargs(args=["C", "G", "S", "I", "N", "E", "Q", "W"], kwargs=kwargs): raise GMTInvalidInput( From 9a158e3c1d1297c6ad3ca77dfd0ba8bc390c11a3 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Wed, 16 Feb 2022 12:19:33 +0100 Subject: [PATCH 09/24] updates based on code review --- pygmt/src/coast.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/pygmt/src/coast.py b/pygmt/src/coast.py index 7c35d7a30bb..eb839b4a76f 100644 --- a/pygmt/src/coast.py +++ b/pygmt/src/coast.py @@ -190,15 +190,18 @@ def coast(self, **kwargs): kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access if "clip" in kwargs: - if kwargs["clip"] == "land": - kwargs["G"] = True - kwargs.pop("clip") - elif kwargs["clip"] == "water": - kwargs["S"] = True - kwargs.pop("clip") - elif kwargs["clip"] == "end": - kwargs["Q"] = True + if kwargs["clip"] in ["land", "water", "end"]: + if kwargs["clip"] == "land": + kwargs["G"] = True + elif kwargs["clip"] == "water": + kwargs["S"] = True + elif kwargs["clip"] == "end": + kwargs["Q"] = True kwargs.pop("clip") + else: + raise GMTInvalidInput( + "Invalid clip parameter. Must be one of 'land', 'water', and 'end'." + ) if not args_in_kwargs(args=["C", "G", "S", "I", "N", "E", "Q", "W"], kwargs=kwargs): raise GMTInvalidInput( From 082dadb98043607259f216d3221d6e412cab5a9c Mon Sep 17 00:00:00 2001 From: Michael Grund <23025878+michaelgrund@users.noreply.github.com> Date: Wed, 16 Feb 2022 12:20:20 +0100 Subject: [PATCH 10/24] Apply suggestions from code review Co-authored-by: Dongdong Tian --- pygmt/tests/test_coast.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/tests/test_coast.py b/pygmt/tests/test_coast.py index 182ff33717e..645a8e800aa 100644 --- a/pygmt/tests/test_coast.py +++ b/pygmt/tests/test_coast.py @@ -87,7 +87,7 @@ def test_coast_clip_land(): fig.basemap(region=region, projection="M12c", frame=True) fig.coast(resolution="l", clip="land") fig.grdimage(grid=grid, shading=True, cmap="batlow") - fig.coast(clip="end", frame=True) + fig.coast(clip="end") return fig @@ -103,5 +103,5 @@ def test_coast_clip_water(): fig.basemap(region=region, projection="M12c", frame=True) fig.coast(resolution="l", clip="water") fig.grdimage(grid=grid, shading=True, cmap="batlow") - fig.coast(clip="end", frame=True) + fig.coast(clip="end") return fig From 2246ab5fef1ff831e84ac64da08c186bb4b8190e Mon Sep 17 00:00:00 2001 From: Michael Grund <23025878+michaelgrund@users.noreply.github.com> Date: Thu, 17 Feb 2022 09:13:21 +0100 Subject: [PATCH 11/24] Apply suggestions from code review Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> Co-authored-by: Dongdong Tian --- pygmt/src/coast.py | 16 +++++++--------- pygmt/tests/test_coast.py | 6 +++--- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/pygmt/src/coast.py b/pygmt/src/coast.py index eb839b4a76f..8bb0197e9bf 100644 --- a/pygmt/src/coast.py +++ b/pygmt/src/coast.py @@ -189,15 +189,13 @@ def coast(self, **kwargs): """ kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access - if "clip" in kwargs: - if kwargs["clip"] in ["land", "water", "end"]: - if kwargs["clip"] == "land": - kwargs["G"] = True - elif kwargs["clip"] == "water": - kwargs["S"] = True - elif kwargs["clip"] == "end": - kwargs["Q"] = True - kwargs.pop("clip") + if clip: + if clip == "land": + kwargs["G"] = True + elif clip == "water": + kwargs["S"] = True + elif clip == "end": + kwargs["Q"] = True else: raise GMTInvalidInput( "Invalid clip parameter. Must be one of 'land', 'water', and 'end'." diff --git a/pygmt/tests/test_coast.py b/pygmt/tests/test_coast.py index 645a8e800aa..a2d26c85b78 100644 --- a/pygmt/tests/test_coast.py +++ b/pygmt/tests/test_coast.py @@ -3,8 +3,8 @@ """ import pytest from pygmt import Figure -from pygmt.datasets import load_earth_relief from pygmt.exceptions import GMTInvalidInput +from pygmt.helpers.testing import load_static_earth_relief @pytest.mark.mpl_image_compare @@ -86,7 +86,7 @@ def test_coast_clip_land(): fig = Figure() fig.basemap(region=region, projection="M12c", frame=True) fig.coast(resolution="l", clip="land") - fig.grdimage(grid=grid, shading=True, cmap="batlow") + fig.grdimage(grid=grid, cmap="batlow") fig.coast(clip="end") return fig @@ -102,6 +102,6 @@ def test_coast_clip_water(): fig = Figure() fig.basemap(region=region, projection="M12c", frame=True) fig.coast(resolution="l", clip="water") - fig.grdimage(grid=grid, shading=True, cmap="batlow") + fig.grdimage(grid=grid, cmap="batlow") fig.coast(clip="end") return fig From f750d10b384b29bac2a74d60060d7834248df32e Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Thu, 17 Feb 2022 09:17:08 +0100 Subject: [PATCH 12/24] change cmap in tests to relief --- pygmt/tests/test_coast.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/tests/test_coast.py b/pygmt/tests/test_coast.py index a2d26c85b78..8a4ae8ff5a3 100644 --- a/pygmt/tests/test_coast.py +++ b/pygmt/tests/test_coast.py @@ -86,7 +86,7 @@ def test_coast_clip_land(): fig = Figure() fig.basemap(region=region, projection="M12c", frame=True) fig.coast(resolution="l", clip="land") - fig.grdimage(grid=grid, cmap="batlow") + fig.grdimage(grid=grid, cmap="relief") fig.coast(clip="end") return fig @@ -102,6 +102,6 @@ def test_coast_clip_water(): fig = Figure() fig.basemap(region=region, projection="M12c", frame=True) fig.coast(resolution="l", clip="water") - fig.grdimage(grid=grid, cmap="batlow") + fig.grdimage(grid=grid, cmap="relief") fig.coast(clip="end") return fig From 5c21707c214ed9321261e6723e3146b6d556d734 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Thu, 17 Feb 2022 17:41:00 +0100 Subject: [PATCH 13/24] use earth_age dataset for tests --- pygmt/tests/test_coast.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pygmt/tests/test_coast.py b/pygmt/tests/test_coast.py index 8a4ae8ff5a3..e22dd224580 100644 --- a/pygmt/tests/test_coast.py +++ b/pygmt/tests/test_coast.py @@ -4,7 +4,7 @@ import pytest from pygmt import Figure from pygmt.exceptions import GMTInvalidInput -from pygmt.helpers.testing import load_static_earth_relief +from pygmt.datasets import load_earth_age @pytest.mark.mpl_image_compare @@ -81,12 +81,12 @@ def test_coast_clip_land(): Test to clip dry areas. """ region = [-28, -10, 62, 68] - grid = load_earth_relief(resolution="10m", region=region) + grid = load_earth_age() fig = Figure() fig.basemap(region=region, projection="M12c", frame=True) fig.coast(resolution="l", clip="land") - fig.grdimage(grid=grid, cmap="relief") + fig.grdimage(grid=grid, cmap="magma") fig.coast(clip="end") return fig @@ -97,11 +97,11 @@ def test_coast_clip_water(): Test to clip wet areas. """ region = [-28, -10, 62, 68] - grid = load_earth_relief(resolution="10m", region=region) + grid = load_earth_age() fig = Figure() fig.basemap(region=region, projection="M12c", frame=True) fig.coast(resolution="l", clip="water") - fig.grdimage(grid=grid, cmap="relief") + fig.grdimage(grid=grid, cmap="magma") fig.coast(clip="end") return fig From e30d1e062a2746548f2b00e663788766d2c7e18c Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Thu, 17 Feb 2022 18:01:59 +0100 Subject: [PATCH 14/24] update baseline images in dvc --- pygmt/tests/baseline/test_coast_clip_land.png.dvc | 4 ++-- pygmt/tests/baseline/test_coast_clip_water.png.dvc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pygmt/tests/baseline/test_coast_clip_land.png.dvc b/pygmt/tests/baseline/test_coast_clip_land.png.dvc index 2b07575261c..bde8c0eeb0d 100644 --- a/pygmt/tests/baseline/test_coast_clip_land.png.dvc +++ b/pygmt/tests/baseline/test_coast_clip_land.png.dvc @@ -1,4 +1,4 @@ outs: -- md5: 018789fd8a60f7122cd8593e88e9a821 - size: 29104 +- md5: ce898a07ab10461f8da35278c14de7b9 + size: 21384 path: test_coast_clip_land.png diff --git a/pygmt/tests/baseline/test_coast_clip_water.png.dvc b/pygmt/tests/baseline/test_coast_clip_water.png.dvc index d91875c397d..00632bc622e 100644 --- a/pygmt/tests/baseline/test_coast_clip_water.png.dvc +++ b/pygmt/tests/baseline/test_coast_clip_water.png.dvc @@ -1,4 +1,4 @@ outs: -- md5: 5dcea737212679746b741e9ebaf437b4 - size: 42421 +- md5: eaddf4bdd672f7a2c094899e315cf786 + size: 23420 path: test_coast_clip_water.png From d7a34dcefd81340e73bb1ae6d2eb3aa8b8222e26 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Thu, 17 Feb 2022 18:04:32 +0100 Subject: [PATCH 15/24] format --- pygmt/src/coast.py | 2 +- pygmt/tests/test_coast.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/src/coast.py b/pygmt/src/coast.py index 8bb0197e9bf..8e05c796d31 100644 --- a/pygmt/src/coast.py +++ b/pygmt/src/coast.py @@ -37,7 +37,7 @@ t="transparency", ) @kwargs_to_strings(R="sequence", c="sequence_comma", p="sequence") -def coast(self, **kwargs): +def coast(self, clip=None, **kwargs): r""" Plot continents, shorelines, rivers, and borders on maps diff --git a/pygmt/tests/test_coast.py b/pygmt/tests/test_coast.py index e22dd224580..ec8a80394b1 100644 --- a/pygmt/tests/test_coast.py +++ b/pygmt/tests/test_coast.py @@ -3,8 +3,8 @@ """ import pytest from pygmt import Figure -from pygmt.exceptions import GMTInvalidInput from pygmt.datasets import load_earth_age +from pygmt.exceptions import GMTInvalidInput @pytest.mark.mpl_image_compare From bec668b6406cc3014b67ff20614695c539d62b31 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Thu, 17 Feb 2022 18:14:39 +0100 Subject: [PATCH 16/24] add test --- pygmt/tests/test_coast.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pygmt/tests/test_coast.py b/pygmt/tests/test_coast.py index ec8a80394b1..5a4571864d1 100644 --- a/pygmt/tests/test_coast.py +++ b/pygmt/tests/test_coast.py @@ -105,3 +105,16 @@ def test_coast_clip_water(): fig.grdimage(grid=grid, cmap="magma") fig.coast(clip="end") return fig + + +@pytest.mark.mpl_image_compare +def test_coast_fail_invalid_parameter(data): + """ + Coast should raise an exception if an invalid parameter is given as input. + """ + region = [-28, -10, 62, 68] + + fig = Figure() + + with pytest.raises(GMTInvalidInput): + fig.coast(region=region, resolution="l", clip="invalid") From c55e4dcc5d7d70e80da832b2b88f96febfde1647 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Thu, 17 Feb 2022 18:16:39 +0100 Subject: [PATCH 17/24] update --- pygmt/tests/test_coast.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pygmt/tests/test_coast.py b/pygmt/tests/test_coast.py index 5a4571864d1..3d9df9836eb 100644 --- a/pygmt/tests/test_coast.py +++ b/pygmt/tests/test_coast.py @@ -107,7 +107,6 @@ def test_coast_clip_water(): return fig -@pytest.mark.mpl_image_compare def test_coast_fail_invalid_parameter(data): """ Coast should raise an exception if an invalid parameter is given as input. From 03625a80adead0395edc0933e204f76566301cb4 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Thu, 17 Feb 2022 18:21:08 +0100 Subject: [PATCH 18/24] remove unused data argument in test --- pygmt/tests/test_coast.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/tests/test_coast.py b/pygmt/tests/test_coast.py index 3d9df9836eb..657e9d5bb2c 100644 --- a/pygmt/tests/test_coast.py +++ b/pygmt/tests/test_coast.py @@ -107,7 +107,7 @@ def test_coast_clip_water(): return fig -def test_coast_fail_invalid_parameter(data): +def test_coast_fail_invalid_parameter(): """ Coast should raise an exception if an invalid parameter is given as input. """ From 05c384ac5f298c928b5e9e6a2c6b5fe2addb7c07 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Fri, 18 Feb 2022 09:14:40 +0100 Subject: [PATCH 19/24] add inline example for clip --- pygmt/src/coast.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pygmt/src/coast.py b/pygmt/src/coast.py index 8e05c796d31..8d66535ca8c 100644 --- a/pygmt/src/coast.py +++ b/pygmt/src/coast.py @@ -186,6 +186,25 @@ def coast(self, clip=None, **kwargs): {p} {t} {V} + + Example + ------- + >>> # Initiate a clip path for Africa so that the subsequent colorimage of + >>> # gridded topography is only seen over land + >>> import pygmt # doctest: +SKIP + >>> # Load a grid of @earth_relief_05m data, with an x-range of -30 to 30, + >>> # and a y-range of -40 to 40 + >>> grid = pygmt.datasets.load_earth_relief( + ... resolution="30m", region=[-30, 30, -40, 40] + ... ) # doctest: +SKIP + >>> # Initiate clip path for land areas + >>> fig.coast( + ... projection="M12c", resolution="l", clip="land", frame=True + ... ) # doctest: +SKIP + >>> # Plot the clipped grid + >>> fig.grdimage(grid="@earth_relief_05m", cmap="relief") # doctest: +SKIP + >>> # End clip path + >>> fig.coast(clip="end") # doctest: +SKIP """ kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access From 482751391b7e8790bb01027c9938ec97e8930839 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Sat, 19 Feb 2022 10:58:13 +0100 Subject: [PATCH 20/24] update tests and dvc figures --- pygmt/tests/baseline/test_coast_clip_land.png.dvc | 4 ++-- pygmt/tests/baseline/test_coast_clip_water.png.dvc | 4 ++-- pygmt/tests/test_coast.py | 11 ++++------- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/pygmt/tests/baseline/test_coast_clip_land.png.dvc b/pygmt/tests/baseline/test_coast_clip_land.png.dvc index bde8c0eeb0d..2ab18888f9d 100644 --- a/pygmt/tests/baseline/test_coast_clip_land.png.dvc +++ b/pygmt/tests/baseline/test_coast_clip_land.png.dvc @@ -1,4 +1,4 @@ outs: -- md5: ce898a07ab10461f8da35278c14de7b9 - size: 21384 +- md5: 12f5586967f870a7e70e012a5dadf76c + size: 14597 path: test_coast_clip_land.png diff --git a/pygmt/tests/baseline/test_coast_clip_water.png.dvc b/pygmt/tests/baseline/test_coast_clip_water.png.dvc index 00632bc622e..0712f34faa9 100644 --- a/pygmt/tests/baseline/test_coast_clip_water.png.dvc +++ b/pygmt/tests/baseline/test_coast_clip_water.png.dvc @@ -1,4 +1,4 @@ outs: -- md5: eaddf4bdd672f7a2c094899e315cf786 - size: 23420 +- md5: dcae0e21783cd153f6daaae927e3a771 + size: 23423 path: test_coast_clip_water.png diff --git a/pygmt/tests/test_coast.py b/pygmt/tests/test_coast.py index 657e9d5bb2c..21310c11baa 100644 --- a/pygmt/tests/test_coast.py +++ b/pygmt/tests/test_coast.py @@ -3,7 +3,6 @@ """ import pytest from pygmt import Figure -from pygmt.datasets import load_earth_age from pygmt.exceptions import GMTInvalidInput @@ -81,12 +80,11 @@ def test_coast_clip_land(): Test to clip dry areas. """ region = [-28, -10, 62, 68] - grid = load_earth_age() fig = Figure() - fig.basemap(region=region, projection="M12c", frame=True) + fig.basemap(region=region, projection="M8c", frame=True) fig.coast(resolution="l", clip="land") - fig.grdimage(grid=grid, cmap="magma") + fig.plot(x = [-22.5, -22.5, -15, -15 ], y = [66, 64, 66, 64], style = "c4c", color = "red", pen="1.5p,black") fig.coast(clip="end") return fig @@ -97,12 +95,11 @@ def test_coast_clip_water(): Test to clip wet areas. """ region = [-28, -10, 62, 68] - grid = load_earth_age() fig = Figure() - fig.basemap(region=region, projection="M12c", frame=True) + fig.basemap(region=region, projection="M8c", frame=True) fig.coast(resolution="l", clip="water") - fig.grdimage(grid=grid, cmap="magma") + fig.plot(x = [-22.5, -22.5, -15, -15 ], y = [66, 64, 66, 64], style = "c4c", color = "red", pen="1.5p,black") fig.coast(clip="end") return fig From 0c8fe0c9fd850e3db9c29fcce0ec9bfc04905b60 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Sat, 19 Feb 2022 11:04:25 +0100 Subject: [PATCH 21/24] update docstring and format --- pygmt/src/coast.py | 8 +++++--- pygmt/tests/test_coast.py | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/pygmt/src/coast.py b/pygmt/src/coast.py index 8d66535ca8c..f9193c6e87e 100644 --- a/pygmt/src/coast.py +++ b/pygmt/src/coast.py @@ -161,9 +161,11 @@ def coast(self, clip=None, **kwargs): level pens are set, those not listed will not be drawn. clip : str To clip land do ``clip="land"``, ``clip="water"`` clips water. Use - ``clip="end"`` to mark end of existing clip path. No projection - information is needed. Also supply ``xshift`` and ``yshift`` settings - if you have moved since the clip started. + ``clip="end"`` to mark end of existing clip path. The clip path applies + to all plotting calls between the start of the clip path and the end of + the clip path. No projection information is needed. Also supply + ``xshift`` and ``yshift`` settings if you have moved since the clip + started. dcw : str or list *code1,code2,…*\ [**+l**\|\ **L**\ ][**+g**\ *fill*\ ] [**+p**\ *pen*\ ][**+z**]. diff --git a/pygmt/tests/test_coast.py b/pygmt/tests/test_coast.py index 21310c11baa..35f28b24abe 100644 --- a/pygmt/tests/test_coast.py +++ b/pygmt/tests/test_coast.py @@ -84,7 +84,13 @@ def test_coast_clip_land(): fig = Figure() fig.basemap(region=region, projection="M8c", frame=True) fig.coast(resolution="l", clip="land") - fig.plot(x = [-22.5, -22.5, -15, -15 ], y = [66, 64, 66, 64], style = "c4c", color = "red", pen="1.5p,black") + fig.plot( + x=[-22.5, -22.5, -15, -15], + y=[66, 64, 66, 64], + style="c4c", + color="red", + pen="1.5p,black", + ) fig.coast(clip="end") return fig @@ -99,7 +105,13 @@ def test_coast_clip_water(): fig = Figure() fig.basemap(region=region, projection="M8c", frame=True) fig.coast(resolution="l", clip="water") - fig.plot(x = [-22.5, -22.5, -15, -15 ], y = [66, 64, 66, 64], style = "c4c", color = "red", pen="1.5p,black") + fig.plot( + x=[-22.5, -22.5, -15, -15], + y=[66, 64, 66, 64], + style="c4c", + color="red", + pen="1.5p,black", + ) fig.coast(clip="end") return fig From cb955a099e5cdd14886b5dded6ddf5c49246020e Mon Sep 17 00:00:00 2001 From: Michael Grund <23025878+michaelgrund@users.noreply.github.com> Date: Sat, 19 Feb 2022 11:05:36 +0100 Subject: [PATCH 22/24] Apply suggestions from code review Co-authored-by: Meghan Jones --- pygmt/src/coast.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pygmt/src/coast.py b/pygmt/src/coast.py index f9193c6e87e..805562414ab 100644 --- a/pygmt/src/coast.py +++ b/pygmt/src/coast.py @@ -199,6 +199,8 @@ def coast(self, clip=None, **kwargs): >>> grid = pygmt.datasets.load_earth_relief( ... resolution="30m", region=[-30, 30, -40, 40] ... ) # doctest: +SKIP + >>> # Create an instance of the Figure class + >>> fig = pygmt.Figure() # doctest: +SKIP >>> # Initiate clip path for land areas >>> fig.coast( ... projection="M12c", resolution="l", clip="land", frame=True From 448be5c31af97aeb0e3742c7a938e2807407dddc Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Sat, 19 Feb 2022 11:35:50 +0100 Subject: [PATCH 23/24] update inline example --- pygmt/src/coast.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pygmt/src/coast.py b/pygmt/src/coast.py index 805562414ab..0772fe3fe8c 100644 --- a/pygmt/src/coast.py +++ b/pygmt/src/coast.py @@ -194,10 +194,10 @@ def coast(self, clip=None, **kwargs): >>> # Initiate a clip path for Africa so that the subsequent colorimage of >>> # gridded topography is only seen over land >>> import pygmt # doctest: +SKIP - >>> # Load a grid of @earth_relief_05m data, with an x-range of -30 to 30, + >>> # Load a grid of earth_relief_05m data, with an x-range of -30 to 30, >>> # and a y-range of -40 to 40 >>> grid = pygmt.datasets.load_earth_relief( - ... resolution="30m", region=[-30, 30, -40, 40] + ... resolution="05m", region=[-30, 30, -40, 40] ... ) # doctest: +SKIP >>> # Create an instance of the Figure class >>> fig = pygmt.Figure() # doctest: +SKIP @@ -206,7 +206,7 @@ def coast(self, clip=None, **kwargs): ... projection="M12c", resolution="l", clip="land", frame=True ... ) # doctest: +SKIP >>> # Plot the clipped grid - >>> fig.grdimage(grid="@earth_relief_05m", cmap="relief") # doctest: +SKIP + >>> fig.grdimage(grid=grid, cmap="relief") # doctest: +SKIP >>> # End clip path >>> fig.coast(clip="end") # doctest: +SKIP """ From 053a478ff41226a7ea2ed375f0d2d637c4dd2a95 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Sat, 19 Feb 2022 11:45:08 +0100 Subject: [PATCH 24/24] update inline example --- pygmt/src/coast.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/coast.py b/pygmt/src/coast.py index 0772fe3fe8c..a89da6a43a1 100644 --- a/pygmt/src/coast.py +++ b/pygmt/src/coast.py @@ -201,7 +201,7 @@ def coast(self, clip=None, **kwargs): ... ) # doctest: +SKIP >>> # Create an instance of the Figure class >>> fig = pygmt.Figure() # doctest: +SKIP - >>> # Initiate clip path for land areas + >>> # Initiate clip path for land areas based on low-resolution coastlines >>> fig.coast( ... projection="M12c", resolution="l", clip="land", frame=True ... ) # doctest: +SKIP