Skip to content

Commit

Permalink
Merge branch 'main' into ci/pin-actions
Browse files Browse the repository at this point in the history
  • Loading branch information
seisman authored Sep 9, 2024
2 parents 65921af + 1ccdcce commit 7eeaa14
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 168 deletions.
1 change: 0 additions & 1 deletion pygmt/helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
_validate_data_input,
args_in_kwargs,
build_arg_list,
build_arg_string,
data_kind,
is_nonstr_iter,
launch_external_viewer,
Expand Down
134 changes: 0 additions & 134 deletions pygmt/helpers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import subprocess
import sys
import time
import warnings
import webbrowser
from collections.abc import Iterable, Sequence
from typing import Any, Literal
Expand Down Expand Up @@ -461,139 +460,6 @@ def build_arg_list( # noqa: PLR0912
return gmt_args


def build_arg_string(kwdict, confdict=None, infile=None, outfile=None):
r"""
Convert keyword dictionaries and input/output files into a GMT argument string.
Make sure all values in ``kwdict`` have been previously converted to a
string representation using the ``kwargs_to_strings`` decorator. The only
exceptions are True, False and None.
Any lists or tuples left will be interpreted as multiple entries for the
same command line option. For example, the kwargs entry ``'B': ['xa',
'yaf']`` will be converted to ``-Bxa -Byaf`` in the argument string.
Note that spaces `` `` in arguments are converted to the equivalent octal
code ``\040``, except in the case of -J (projection) arguments where PROJ4
strings (e.g. "+proj=longlat +datum=WGS84") will have their spaces removed.
See https://github.com/GenericMappingTools/pygmt/pull/1487 for more info.
.. deprecated:: 0.12.0
Use :func:`build_arg_list` instead.
Parameters
----------
kwdict : dict
A dictionary containing parsed keyword arguments.
confdict : dict
A dictionary containing configurable GMT parameters.
infile : str or pathlib.Path
The input file.
outfile : str or pathlib.Path
The output file.
Returns
-------
args : str
The space-delimited argument string with '-' inserted before each
keyword, or '--' inserted before GMT configuration key-value pairs.
The keyword arguments are sorted alphabetically, followed by GMT
configuration key-value pairs, with optional input file at the
beginning and optional output file at the end.
Examples
--------
>>> print(
... build_arg_string(
... dict(
... A=True,
... B=False,
... E=200,
... J="+proj=longlat +datum=WGS84",
... P="",
... R="1/2/3/4",
... X=None,
... Y=None,
... Z=0,
... )
... )
... )
-A -E200 -J+proj=longlat+datum=WGS84 -P -R1/2/3/4 -Z0
>>> print(
... build_arg_string(
... dict(
... R="1/2/3/4",
... J="X4i",
... B=["xaf", "yaf", "WSen"],
... I=("1/1p,blue", "2/0.25p,blue"),
... )
... )
... )
-BWSen -Bxaf -Byaf -I1/1p,blue -I2/0.25p,blue -JX4i -R1/2/3/4
>>> print(build_arg_string(dict(R="1/2/3/4", J="X4i", watre=True)))
Traceback (most recent call last):
...
pygmt.exceptions.GMTInvalidInput: Unrecognized parameter 'watre'.
>>> print(
... build_arg_string(
... dict(
... B=["af", "WSne+tBlank Space"],
... F='+t"Empty Spaces"',
... l="'Void Space'",
... ),
... )
... )
-BWSne+tBlank\040Space -Baf -F+t"Empty\040\040Spaces" -l'Void\040Space'
>>> print(
... build_arg_string(
... dict(A="0", B=True, C="rainbow"),
... confdict=dict(FORMAT_DATE_MAP="o dd"),
... infile="input.txt",
... outfile="output.txt",
... )
... )
input.txt -A0 -B -Crainbow --FORMAT_DATE_MAP="o dd" ->output.txt
"""
msg = (
"Utility function 'build_arg_string()' is deprecated in v0.12.0 and will be "
"removed in v0.14.0. Use 'build_arg_list()' instead."
)
warnings.warn(msg, category=FutureWarning, stacklevel=2)

gmt_args = []
for key in kwdict:
if len(key) > 2: # raise an exception for unrecognized options
raise GMTInvalidInput(f"Unrecognized parameter '{key}'.")
if kwdict[key] is None or kwdict[key] is False:
pass # Exclude arguments that are None and False
elif is_nonstr_iter(kwdict[key]):
for value in kwdict[key]:
_value = str(value).replace(" ", r"\040")
gmt_args.append(rf"-{key}{_value}")
elif kwdict[key] is True:
gmt_args.append(f"-{key}")
else:
if key != "J": # non-projection parameters
_value = str(kwdict[key]).replace(" ", r"\040")
else:
# special handling if key == "J" (projection)
# remove any spaces in PROJ4 string
_value = str(kwdict[key]).replace(" ", "")
gmt_args.append(rf"-{key}{_value}")
gmt_args = sorted(gmt_args)

if confdict:
gmt_args.extend(f'--{key}="{value}"' for key, value in confdict.items())

if infile:
gmt_args = [str(infile), *gmt_args]
if outfile:
gmt_args.append("->" + str(outfile))
return non_ascii_to_octal(" ".join(gmt_args))


def is_nonstr_iter(value):
"""
Check if the value is not a string but is iterable (list, tuple, array)
Expand Down
16 changes: 0 additions & 16 deletions pygmt/src/grdcontour.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
grdcontour - Plot a contour figure.
"""

import warnings

from pygmt.clib import Session
from pygmt.helpers import (
build_arg_list,
Expand Down Expand Up @@ -140,20 +138,6 @@ def grdcontour(self, grid, **kwargs):
"""
kwargs = self._preprocess(**kwargs)

# Backward compatibility with the old syntax for the annotation parameter, e.g.,
# [100, "e", "f10p", "gred"].
if is_nonstr_iter(kwargs.get("A")) and any(
i[0] in "acdefgijlLnoprtuvwx=" for i in kwargs["A"] if isinstance(i, str)
):
msg = (
"Argument of the parameter 'annotation'/'A' is using the old, deprecated "
"syntax. Please refer to the PyGMT documentation for the new syntax. "
"The warning will be removed in v0.14.0 and the old syntax will no longer "
"be supported. "
)
warnings.warn(msg, category=FutureWarning, stacklevel=2)
kwargs["A"] = "+".join(f"{item}" for item in kwargs["A"])

# Specify levels for the annotation and levels parameters.
# One level is converted to a string with a trailing comma to separate it from
# specifying an interval.
Expand Down
17 changes: 0 additions & 17 deletions pygmt/tests/test_grdcontour.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,6 @@ def test_grdcontour_one_level(grid):
return fig


@pytest.mark.mpl_image_compare(filename="test_grdcontour_one_level.png")
def test_grdcontour_old_annotations(grid):
"""
Test the old syntax for the annotation parameter using "sequence_plus".
Modified from the "test_grdcontour_one_level()" test. Can be removed in v0.14.0.
"""
fig = Figure()
fig.grdcontour(
grid=grid,
levels=[400],
annotation=["570,", "gwhite"],
projection="M10c",
frame=True,
)
return fig


@pytest.mark.mpl_image_compare
def test_grdcontour_multiple_levels(grid):
"""
Expand Down

0 comments on commit 7eeaa14

Please sign in to comment.