Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Figure.grdcontour: Adjust processing of arguments passed to the "annotation" and "interval" parameters, deprecate "sequence_plus" #3116

Merged
merged 54 commits into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
a3fa214
Use list instead of tuple
yvonnefroehlich Mar 16, 2024
ee143e6
Merge branch 'main' into fix-typos-63-grdcontour
yvonnefroehlich Mar 17, 2024
e59f077
Merge branch 'main' into fix-typos-63-grdcontour
yvonnefroehlich Mar 18, 2024
05b5abb
Remove list input option for annotation parameter
yvonnefroehlich Mar 19, 2024
99dc353
Merge branch 'main' into fix-typos-63-grdcontour
yvonnefroehlich Mar 19, 2024
731d014
Fix line length
yvonnefroehlich Mar 19, 2024
c8b805b
Update syntax to GMT 6.5
yvonnefroehlich Mar 19, 2024
584956e
Update allowed input data type
yvonnefroehlich Mar 19, 2024
4a7a143
Merge branch 'main' into fix-typos-63-grdcontour
yvonnefroehlich Mar 20, 2024
13360d4
Fix typo
yvonnefroehlich Mar 20, 2024
57837fb
Update docstring
yvonnefroehlich Mar 21, 2024
4f06fe4
Use sequence instead of sequence_comma
yvonnefroehlich Mar 21, 2024
311015e
Extend allow input formats
yvonnefroehlich Mar 21, 2024
560622d
Merge branch 'main' into fix-typos-63-grdcontour
yvonnefroehlich Mar 21, 2024
4ae5073
[format-command] fixes
actions-bot Mar 21, 2024
6925eca
Fix typo
yvonnefroehlich Mar 21, 2024
bbeb83c
Shorten documentation
yvonnefroehlich Mar 23, 2024
078553c
Shorten documentation
yvonnefroehlich Mar 23, 2024
1e114cf
Clearify documentation
yvonnefroehlich Mar 23, 2024
c67fcf8
Merge branch 'main' into fix-typos-63-grdcontour
yvonnefroehlich Mar 23, 2024
0cd2f0b
Update docs, Add code for list input
yvonnefroehlich Mar 25, 2024
ccd6b01
Merge branch 'main' into fix-typos-63-grdcontour
yvonnefroehlich Mar 25, 2024
581eef4
Process argument passt to "A" manually
yvonnefroehlich Mar 26, 2024
a86305c
Fix line length
yvonnefroehlich Mar 26, 2024
4c52daa
Merge branch 'main' into fix-typos-63-grdcontour
yvonnefroehlich Mar 26, 2024
c646b51
Merge branch 'main' into fix-typos-63-grdcontour
yvonnefroehlich Apr 5, 2024
6a6df2c
Merge branch 'main' into fix-typos-63-grdcontour
yvonnefroehlich Apr 11, 2024
7c3f012
Merge branch 'main' into fix-typos-63-grdcontour
yvonnefroehlich Apr 18, 2024
f2805bb
Merge branch 'main' into fix-typos-63-grdcontour
yvonnefroehlich Apr 22, 2024
d442adf
Merge branch 'main' into fix-typos-63-grdcontour
yvonnefroehlich Apr 24, 2024
11b2dac
Add tests
yvonnefroehlich Apr 24, 2024
4708483
Update pygmt/src/grdcontour.py
yvonnefroehlich Apr 25, 2024
56afbe8
Update pygmt/src/grdcontour.py
yvonnefroehlich Apr 25, 2024
c8772bf
Use for loop for A and C
yvonnefroehlich Apr 25, 2024
9a9ae49
Fix typo
yvonnefroehlich Apr 25, 2024
ad5c33e
Merge branch 'main' into fix-typos-63-grdcontour
yvonnefroehlich Apr 25, 2024
32c4f90
Update pygmt/tests/test_grdcontour.py
yvonnefroehlich Apr 25, 2024
d9c734b
Update pygmt/tests/test_grdcontour.py
yvonnefroehlich Apr 25, 2024
9f394f7
Explain code block for 'A' and 'C'
yvonnefroehlich Apr 25, 2024
557af15
Update tests
yvonnefroehlich Apr 25, 2024
e964dda
Add test_grdcontour_one_level.png into DVC
Apr 25, 2024
4501bab
Add test_grdcontour_multiple_levels.png into DVC
yvonnefroehlich Apr 25, 2024
5fa02fb
[format-command] fixes
actions-bot Apr 25, 2024
988d77e
Add period
yvonnefroehlich Apr 26, 2024
7ade301
Add periods
yvonnefroehlich Apr 26, 2024
cb6871b
Add code for backward-compatibility regarding 'sequence_plus'
yvonnefroehlich Apr 27, 2024
a4c9216
Merge branch 'main' into fix-typos-63-grdcontour
yvonnefroehlich Apr 27, 2024
e25e9ed
[format-command] fixes
actions-bot Apr 27, 2024
7fee937
Import warinings
yvonnefroehlich Apr 27, 2024
be21572
Use square instead of round brakets
yvonnefroehlich Apr 27, 2024
a05ec74
Add test for old syntax of 'annotations' parameter
yvonnefroehlich Apr 27, 2024
fedf60d
Fix keyword of 'warnings.warn' from 'catalog' to 'category'
yvonnefroehlich Apr 27, 2024
6c53454
Adjust test to reuse baseline image
yvonnefroehlich Apr 27, 2024
574c4a7
Fix typos
yvonnefroehlich Apr 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 45 additions & 29 deletions pygmt/src/grdcontour.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

__doctest_skip__ = ["grdcontour"]

Expand All @@ -27,9 +33,7 @@
p="perspective",
t="transparency",
)
@kwargs_to_strings(
R="sequence", L="sequence", A="sequence_plus", c="sequence_comma", p="sequence"
)
@kwargs_to_strings(R="sequence", L="sequence", c="sequence_comma", p="sequence")
yvonnefroehlich marked this conversation as resolved.
Show resolved Hide resolved
def grdcontour(self, grid, **kwargs):
r"""
Convert grids or images to contours and plot them on maps.
Expand All @@ -43,26 +47,26 @@ def grdcontour(self, grid, **kwargs):
Parameters
----------
{grid}
interval : str or int
interval : 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*.
annotation : str, int, or list
- 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.
annotation : float, list, or str
Specify or disable annotated contour levels, modifies annotated
contours specified in ``interval``.

- Specify a fixed annotation interval *annot_int* or a
single annotation level +\ *annot_int*.
- Disable all annotation with **-**.
- Optional label modifiers can be specified as a single string
``"[annot_int]+e"`` or with a list of arguments
``([annot_int], "e", "f10p", "gred")``.
- 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:`grdcontour.html#a`.
limit : str or list of 2 ints
*low*/*high*.
Do no draw contours below `low` or above `high`, specify as string
Expand Down Expand Up @@ -96,32 +100,44 @@ def grdcontour(self, grid, **kwargs):
Example
-------
>>> import pygmt
>>> # load the 15 arc-minutes grid with "gridline" registration
>>> # in a specified region
>>> # Load the 15 arc-minutes grid with "gridline" registration in the
>>> # specified region
>>> grid = pygmt.datasets.load_earth_relief(
... resolution="15m",
... region=[-92.5, -82.5, -3, 7],
... registration="gridline",
... )
>>> # create a new plot with pygmt.Figure()
>>> # Create a new plot with pygmt.Figure()
>>> fig = pygmt.Figure()
>>> # create the contour plot
>>> # Create the contour plot
>>> fig.grdcontour(
... # pass in the grid downloaded above
... # Pass in the grid downloaded above
... grid=grid,
... # set the interval for contour lines at 250 meters
... # Set the interval for contour lines at 250 meters
... interval=250,
... # set the interval for annotated contour lines at 1,000 meters
... # Set the interval for annotated contour lines at 1,000 meters
... annotation=1000,
... # add a frame for the plot
... # Add a frame for the plot
... frame="a",
... # set the projection to Mercator for the 10 cm figure
... # Set the projection to Mercator for the 10 cm figure
... projection="M10c",
... )
>>> # show the plot
>>> # Show the plot
>>> fig.show()
"""
kwargs = self._preprocess(**kwargs)
yvonnefroehlich marked this conversation as resolved.
Show resolved Hide resolved

seisman marked this conversation as resolved.
Show resolved Hide resolved
# 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="raster", data=grid) as vingrd:
lib.call_module(
Expand Down
6 changes: 6 additions & 0 deletions pygmt/tests/baseline/test_grdcontour_multiple_levels.png.dvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
outs:
- md5: 4d20cdb71af2e6568f64f0246ec860ea
size: 64008
isexec: true
hash: md5
path: test_grdcontour_multiple_levels.png
6 changes: 6 additions & 0 deletions pygmt/tests/baseline/test_grdcontour_one_level.png.dvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
outs:
- md5: fc624766f0b8eac8206735a05c7c9662
size: 45023
isexec: true
hash: md5
path: test_grdcontour_one_level.png
33 changes: 32 additions & 1 deletion pygmt/tests/test_grdcontour.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def fixture_grid():
@pytest.mark.mpl_image_compare
def test_grdcontour(grid):
"""
Plot a contour image using an xarray grid with fixed contour interval.
Plot a contour image using an xarray grid with fixed (different) contour and
annotation intervals.
"""
fig = Figure()
fig.grdcontour(
Expand All @@ -33,6 +34,36 @@ def test_grdcontour(grid):
return fig


@pytest.mark.mpl_image_compare
def test_grdcontour_one_level(grid):
"""
Plot a contour image using an xarray grid with one contour level and one
(different) annotation level.
"""
fig = Figure()
fig.grdcontour(
grid=grid, interval=[400], annotation=[570], projection="M10c", frame=True
)
return fig


@pytest.mark.mpl_image_compare
def test_grdcontour_multiple_levels(grid):
"""
Plot a contour image using an xarray grid with multiple (different) contour
and annotation levels.
"""
fig = Figure()
fig.grdcontour(
grid=grid,
interval=[400, 450, 500],
annotation=[400, 570],
projection="M10c",
frame=True,
)
return fig


@pytest.mark.benchmark
@pytest.mark.mpl_image_compare
def test_grdcontour_labels(grid):
Expand Down
Loading