From 0a3e77d38d70178706fae3ff3f949b2e19cede5f Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sat, 30 Sep 2023 19:32:03 +0200 Subject: [PATCH 01/15] Fix input types for A and C --- pygmt/src/contour.py | 4 ++-- pygmt/src/grdcontour.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pygmt/src/contour.py b/pygmt/src/contour.py index eb5def52940..5125a57ddfa 100644 --- a/pygmt/src/contour.py +++ b/pygmt/src/contour.py @@ -54,14 +54,14 @@ def contour(self, data=None, x=None, y=None, z=None, **kwargs): Arrays of x and y coordinates and values z of the data points. {projection} {region} - annotation : str or int + annotation : str, int, or float Specify or disable annotated contour levels, modifies annotated contours specified in ``levels``. - Specify a fixed annotation interval *annot_int* or a single annotation level +\ *annot_int*. {frame} - levels : str or int + levels : bool, str, int, or float Specify the contour lines to generate. - The file name of a CPT file where the color boundaries will diff --git a/pygmt/src/grdcontour.py b/pygmt/src/grdcontour.py index 6d43c794a44..52299d82318 100644 --- a/pygmt/src/grdcontour.py +++ b/pygmt/src/grdcontour.py @@ -43,7 +43,7 @@ def grdcontour(self, grid, **kwargs): ---------- grid : str or xarray.DataArray The file name of the input grid or the grid loaded as a DataArray. - interval : str or int + interval : bool, str, int, or float Specify the contour lines to generate. - The file name of a CPT file where the color boundaries will @@ -53,7 +53,7 @@ def grdcontour(self, grid, **kwargs): angle (col 3). - A fixed contour interval *cont_int* or a single contour with +\ *cont_int*. - annotation : str, int, or list + annotation : str, int, float, or list Specify or disable annotated contour levels, modifies annotated contours specified in ``interval``. From 066ab45d3cb8975f8fa13a50cf16e816a9c65366 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sat, 30 Sep 2023 20:39:31 +0200 Subject: [PATCH 02/15] Use always 'or' --- pygmt/src/contour.py | 4 ++-- pygmt/src/grdcontour.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pygmt/src/contour.py b/pygmt/src/contour.py index 5125a57ddfa..528baae82c5 100644 --- a/pygmt/src/contour.py +++ b/pygmt/src/contour.py @@ -54,14 +54,14 @@ def contour(self, data=None, x=None, y=None, z=None, **kwargs): Arrays of x and y coordinates and values z of the data points. {projection} {region} - annotation : str, int, or float + annotation : str or int or float Specify or disable annotated contour levels, modifies annotated contours specified in ``levels``. - Specify a fixed annotation interval *annot_int* or a single annotation level +\ *annot_int*. {frame} - levels : bool, str, int, or float + levels : bool or str or int or float Specify the contour lines to generate. - The file name of a CPT file where the color boundaries will diff --git a/pygmt/src/grdcontour.py b/pygmt/src/grdcontour.py index 52299d82318..8e5c1bdb12c 100644 --- a/pygmt/src/grdcontour.py +++ b/pygmt/src/grdcontour.py @@ -43,7 +43,7 @@ def grdcontour(self, grid, **kwargs): ---------- grid : str or xarray.DataArray The file name of the input grid or the grid loaded as a DataArray. - interval : bool, str, int, or float + interval : bool or str or int or float Specify the contour lines to generate. - The file name of a CPT file where the color boundaries will @@ -53,7 +53,7 @@ def grdcontour(self, grid, **kwargs): angle (col 3). - A fixed contour interval *cont_int* or a single contour with +\ *cont_int*. - annotation : str, int, float, or list + annotation : str or int or float or list Specify or disable annotated contour levels, modifies annotated contours specified in ``interval``. From a5f8a81da5d0489a9397e73ba94fbd6a245ddbf2 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Wed, 4 Oct 2023 20:11:01 +0200 Subject: [PATCH 03/15] Remove second tilemap example --- examples/gallery/maps/tilemaps.py | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/examples/gallery/maps/tilemaps.py b/examples/gallery/maps/tilemaps.py index 3eb8fc0055a..996c28ddb4f 100644 --- a/examples/gallery/maps/tilemaps.py +++ b/examples/gallery/maps/tilemaps.py @@ -26,20 +26,3 @@ ) fig.show() - -# %% -# It's also possible to use tiles provided via the -# `contextily `__ -# library. See :doc:`Contextily providers ` -# for a list of possible tilemap options. - -fig = pygmt.Figure() -fig.tilemap( - region=[-157.84, -157.8, 21.255, 21.285], - projection="M12c", - # Use the Stamen.Watercolor option from contextily - source=contextily.providers.Stamen.Watercolor, - frame="afg", -) - -fig.show() From aa7180ee6d4e39d544f81ad4c80d135cecbb6c97 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Wed, 4 Oct 2023 20:43:08 +0200 Subject: [PATCH 04/15] Add second code example back with zoom=13 --- examples/gallery/maps/tilemaps.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/examples/gallery/maps/tilemaps.py b/examples/gallery/maps/tilemaps.py index 996c28ddb4f..710b598f4a4 100644 --- a/examples/gallery/maps/tilemaps.py +++ b/examples/gallery/maps/tilemaps.py @@ -26,3 +26,21 @@ ) fig.show() + +# %% +# It's also possible to use tiles provided via the +# `contextily `__ +# library. See :doc:`Contextily providers ` +# for a list of possible tilemap options. + +fig = pygmt.Figure() +fig.tilemap( + region=[-157.84, -157.8, 21.255, 21.285], + projection="M12c", + zoom=13, + # Use the Stamen.Watercolor option from contextily + source=contextily.providers.Stamen.Watercolor, + frame="afg", +) + +fig.show() From 03f1599bb48372bb58539d29e5442fdea3bd0905 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Wed, 4 Oct 2023 21:18:29 +0200 Subject: [PATCH 05/15] Run second code example with zoom=15 --- examples/gallery/maps/tilemaps.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/maps/tilemaps.py b/examples/gallery/maps/tilemaps.py index 710b598f4a4..3e442deb5f4 100644 --- a/examples/gallery/maps/tilemaps.py +++ b/examples/gallery/maps/tilemaps.py @@ -37,7 +37,7 @@ fig.tilemap( region=[-157.84, -157.8, 21.255, 21.285], projection="M12c", - zoom=13, + zoom=15, # Use the Stamen.Watercolor option from contextily source=contextily.providers.Stamen.Watercolor, frame="afg", From ea3e74c54c85a09f67cc97affd97c38dbb5213cb Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Thu, 5 Oct 2023 20:27:55 +0200 Subject: [PATCH 06/15] Revert changes for tilemap gallery example --- examples/gallery/maps/tilemaps.py | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/gallery/maps/tilemaps.py b/examples/gallery/maps/tilemaps.py index 3e442deb5f4..3eb8fc0055a 100644 --- a/examples/gallery/maps/tilemaps.py +++ b/examples/gallery/maps/tilemaps.py @@ -37,7 +37,6 @@ fig.tilemap( region=[-157.84, -157.8, 21.255, 21.285], projection="M12c", - zoom=15, # Use the Stamen.Watercolor option from contextily source=contextily.providers.Stamen.Watercolor, frame="afg", From 5788d6b86eec6709dbbf827d19eb070830df6a8c Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Fri, 26 Apr 2024 13:57:33 +0200 Subject: [PATCH 07/15] Add docs and code for 'A' and 'C' processing --- pygmt/src/contour.py | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/pygmt/src/contour.py b/pygmt/src/contour.py index ec287ef6828..b6bc3c3bf35 100644 --- a/pygmt/src/contour.py +++ b/pygmt/src/contour.py @@ -54,23 +54,26 @@ def contour(self, data=None, x=None, y=None, z=None, **kwargs): Arrays of x and y coordinates and values z of the data points. {projection} {region} - annotation : str or int or float + annotation : float, list, or str Specify or disable annotated contour levels, modifies annotated contours specified in ``levels``. - - Specify a fixed annotation interval *annot_int* or a - single annotation level +\ *annot_int*. + - Specify a fixed annotation interval. + - Specify a list of annotation levels. + - Disable all annotations by setting ``annotation="n"``. + - Adjust the appearance by appending different modifiers, e.g., + ``"annot_int+f10p+gred"`` gives annotations with a font size of 10 points and + a red filled box. For all available modifiers see :gmt-docs:`contour.html#a`. {frame} - levels : bool or str or int or float + levels : float, list, or str Specify the contour lines to generate. - - The file name of a CPT file where the color boundaries will - be used as contour levels. - - The file name of a 2 (or 3) column file containing the contour - levels (col 1), (**C**)ontour or (**A**)nnotate (col 2), and optional - angle (col 3). - - A fixed contour interval *cont_int* or a single contour with - +\ *cont_int*. + - The file name of a CPT file where the color boundaries will be used as + contour levels. + - The file name of a 2 (or 3) column file containing the contour levels (col 0), + (**C**)ontour or (**A**)nnotate (col 1), and optional angle (col 2). + - A fixed contour interval. + - A list of contour levels. D : str Dump contour coordinates. E : str @@ -114,6 +117,17 @@ def contour(self, data=None, x=None, y=None, z=None, **kwargs): """ kwargs = self._preprocess(**kwargs) + # Specify levels for contours or annotations. + # One level is converted to a string with a trailing comma to separate it from + # specifying an interval. + # Multiple levels are concatenated to a comma-separated string. + for arg in ["A", "C"]: + if is_nonstr_iter(kwargs.get(arg)): + if len(kwargs[arg]) == 1: # One level + kwargs[arg] = str(kwargs[arg][0]) + "," + else: # Multiple levels + kwargs[arg] = ",".join(f"{item}" for item in kwargs[arg]) + with Session() as lib: with lib.virtualfile_in( check_kind="vector", data=data, x=x, y=y, z=z, required_z=True From 4e749847326e8aefc4e83941064b853675312c15 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Fri, 26 Apr 2024 14:07:21 +0200 Subject: [PATCH 08/15] Add 'is_nonstr_iter' from helpers --- pygmt/src/contour.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pygmt/src/contour.py b/pygmt/src/contour.py index b6bc3c3bf35..7c6dc8a3904 100644 --- a/pygmt/src/contour.py +++ b/pygmt/src/contour.py @@ -3,7 +3,13 @@ """ from pygmt.clib import Session -from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias +from pygmt.helpers import ( + build_arg_list, + fmt_docstring, + is_nonstr_iter, + kwargs_to_strings, + use_alias, +) @fmt_docstring From 640b274ef5fd67f6f58f39ecb1fe81ebad6978fd Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Fri, 26 Apr 2024 17:00:11 +0200 Subject: [PATCH 09/15] Add tests --- pygmt/tests/test_contour.py | 54 +++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/pygmt/tests/test_contour.py b/pygmt/tests/test_contour.py index 6cca6ecbf7c..c359c1d124c 100644 --- a/pygmt/tests/test_contour.py +++ b/pygmt/tests/test_contour.py @@ -75,6 +75,60 @@ def test_contour_from_file(region): return fig +@pytest.mark.mpl_image_compare +def test_contour_interval(region): + """ + Plot data with fixed (different) contour and annotation intervals. + """ + fig = Figure() + fig.contour( + data=POINTS_DATA, + projection="X10c", + region=region, + frame="af", + levels=0.1, + annotation=0.2, + pen=True, + ) + return fig + + +@pytest.mark.mpl_image_compare +def test_contour_one_level(region): + """ + Plot data with one contour level and one (different) annotation level. + """ + fig = Figure() + fig.contour( + data=POINTS_DATA, + projection="X10c", + region=region, + frame="af", + levels=[0.4], + annotation=[0.5], + pen=True, + ) + return fig + + +@pytest.mark.mpl_image_compare +def test_contour_multiple_levels(region): + """ + Plot data with multiple (different) contour and annotation levels. + """ + fig = Figure() + fig.contour( + data=POINTS_DATA, + projection="X10c", + region=region, + frame="af", + levels=[0.2, 0.3], + annotation=[0.4, 0.45], + pen=True, + ) + return fig + + @pytest.mark.mpl_image_compare(filename="test_contour_vec.png") def test_contour_incols_transposed_data(region): """ From 76a6031515f34cebeca9477c0388e8179fef2cc4 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Fri, 26 Apr 2024 17:14:06 +0200 Subject: [PATCH 10/15] Add test_contour_interval.png into DVC --- pygmt/tests/baseline/test_contour_interval.png.dvc | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100755 pygmt/tests/baseline/test_contour_interval.png.dvc diff --git a/pygmt/tests/baseline/test_contour_interval.png.dvc b/pygmt/tests/baseline/test_contour_interval.png.dvc new file mode 100755 index 00000000000..32b57f89111 --- /dev/null +++ b/pygmt/tests/baseline/test_contour_interval.png.dvc @@ -0,0 +1,6 @@ +outs: +- md5: 44d70a0b17bc7c7939462184bf06e4da + size: 50998 + isexec: true + hash: md5 + path: test_contour_interval.png From 3741d820f29c95c16e7dd5f1738f6a752ede9846 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Fri, 26 Apr 2024 17:14:37 +0200 Subject: [PATCH 11/15] Add test_contour_one_level.png into DVC --- pygmt/tests/baseline/test_contour_one_level.png.dvc | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100755 pygmt/tests/baseline/test_contour_one_level.png.dvc diff --git a/pygmt/tests/baseline/test_contour_one_level.png.dvc b/pygmt/tests/baseline/test_contour_one_level.png.dvc new file mode 100755 index 00000000000..02234514e0c --- /dev/null +++ b/pygmt/tests/baseline/test_contour_one_level.png.dvc @@ -0,0 +1,6 @@ +outs: +- md5: 8c1ed221788e3af76279a7765640ea43 + size: 28882 + isexec: true + hash: md5 + path: test_contour_one_level.png From 65708ebff61de0c36cd5cc6dc873c1690f84926c Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Fri, 26 Apr 2024 17:15:05 +0200 Subject: [PATCH 12/15] Add test_contour_multiple_levels.png into DVC --- pygmt/tests/baseline/test_contour_multiple_levels.png.dvc | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100755 pygmt/tests/baseline/test_contour_multiple_levels.png.dvc diff --git a/pygmt/tests/baseline/test_contour_multiple_levels.png.dvc b/pygmt/tests/baseline/test_contour_multiple_levels.png.dvc new file mode 100755 index 00000000000..1e5012d7460 --- /dev/null +++ b/pygmt/tests/baseline/test_contour_multiple_levels.png.dvc @@ -0,0 +1,6 @@ +outs: +- md5: 7bef85a616c46b9f05f4dbed07bd703d + size: 29247 + isexec: true + hash: md5 + path: test_contour_multiple_levels.png From cb4dc4d9648c656709a4bc6d027565e182a885ca Mon Sep 17 00:00:00 2001 From: actions-bot <58130806+actions-bot@users.noreply.github.com> Date: Fri, 26 Apr 2024 15:20:21 +0000 Subject: [PATCH 13/15] [format-command] fixes --- pygmt/tests/baseline/test_contour_interval.png.dvc | 0 pygmt/tests/baseline/test_contour_multiple_levels.png.dvc | 0 pygmt/tests/baseline/test_contour_one_level.png.dvc | 0 3 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 pygmt/tests/baseline/test_contour_interval.png.dvc mode change 100755 => 100644 pygmt/tests/baseline/test_contour_multiple_levels.png.dvc mode change 100755 => 100644 pygmt/tests/baseline/test_contour_one_level.png.dvc diff --git a/pygmt/tests/baseline/test_contour_interval.png.dvc b/pygmt/tests/baseline/test_contour_interval.png.dvc old mode 100755 new mode 100644 diff --git a/pygmt/tests/baseline/test_contour_multiple_levels.png.dvc b/pygmt/tests/baseline/test_contour_multiple_levels.png.dvc old mode 100755 new mode 100644 diff --git a/pygmt/tests/baseline/test_contour_one_level.png.dvc b/pygmt/tests/baseline/test_contour_one_level.png.dvc old mode 100755 new mode 100644 From 490ee658af12c910fd32af0a9380778356ae47fe Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Fri, 26 Apr 2024 17:32:58 +0200 Subject: [PATCH 14/15] Revert change in 'grdcontour' --- pygmt/src/grdcontour.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/grdcontour.py b/pygmt/src/grdcontour.py index b9dda413149..53e6b32ced8 100644 --- a/pygmt/src/grdcontour.py +++ b/pygmt/src/grdcontour.py @@ -43,7 +43,7 @@ def grdcontour(self, grid, **kwargs): Parameters ---------- {grid} - interval : bool, str, or float + interval : str or int Specify the contour lines to generate. - The file name of a CPT file where the color boundaries will From 6c24c49a311600d260e68542852b704c14f82841 Mon Sep 17 00:00:00 2001 From: actions-bot <58130806+actions-bot@users.noreply.github.com> Date: Sun, 28 Apr 2024 04:27:12 +0000 Subject: [PATCH 15/15] [format-command] fixes --- pygmt/datasets/earth_relief.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/datasets/earth_relief.py b/pygmt/datasets/earth_relief.py index 5ba34a24c4d..38461137e7c 100644 --- a/pygmt/datasets/earth_relief.py +++ b/pygmt/datasets/earth_relief.py @@ -140,7 +140,7 @@ def load_earth_relief( land_only_srtm_resolutions = ["03s", "01s"] # Map data source to prefix - prefix = { + prefix = { "igpp": "earth_relief", "gebco": "earth_gebco", "gebcosi": "earth_gebcosi",