Skip to content

Commit a8f5705

Browse files
committed
Merge branch 'main' into fix/arg_is_not_None
2 parents c7725e0 + 61781e4 commit a8f5705

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+157
-139
lines changed

doc/contributing.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,9 @@ When editing documentation, use the following standards to demonstrate the examp
405405

406406
The API reference is manually assembled in `doc/api/index.rst`.
407407
The *autodoc* sphinx extension will automatically create pages for each
408-
function/class/module listed there.
408+
function/class/module/method listed there.
409409

410-
You can reference functions, classes, methods, and modules from anywhere
410+
You can reference functions, classes, modules, and methods from anywhere
411411
(including docstrings) using:
412412

413413
- <code>:func:\`package.module.function\`</code>
@@ -435,7 +435,7 @@ For GMT configuration parameters, an example is
435435
{gmt-term}`https://docs.generic-mapping-tools.org/latest/gmt.conf#term-COLOR_FOREGROUND <COLOR_FOREGROUND>`.
436436

437437
Sphinx will create a link to the automatically generated page for that
438-
function/class/module.
438+
function/class/module/method.
439439

440440
## Contributing Code
441441

@@ -500,7 +500,7 @@ Tests also help us be confident that we won't break your code in the future.
500500

501501
When writing tests, don't test everything that the GMT function already tests, such as
502502
the every unique combination arguments. An exception to this would be the most popular
503-
modules, such as `plot` and `basemap`. The highest priority for tests should be the
503+
methods, such as `plot` and `basemap`. The highest priority for tests should be the
504504
Python-specific code, such as numpy, pandas, and xarray objects and the virtualfile
505505
mechanism.
506506

doc/maintenance.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ publishing the actual release notes at https://www.pygmt.org/latest/changes.html
254254
typo fixes, CI configuration, test updates due to GMT releases, etc).
255255
5. Sort the items within each section (i.e., New Features, Enhancements, etc.)
256256
such that similar items are located near each other (e.g., new wrapped
257-
modules, gallery examples, API docs changes) and entries within each group
257+
modules and methods, gallery examples, API docs changes) and entries within each group
258258
are alphabetical.
259259
6. Move a few important items from the main sections to the highlights section.
260260
7. Edit the list of people who contributed to the release, linking to their

examples/gallery/lines/vector_heads_tails.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Vector heads and tails
33
----------------------
44
5-
Many modules in PyGMT allow plotting vectors with individual
5+
Many methods in PyGMT allow plotting vectors with individual
66
heads and tails. For this purpose, several modifiers may be appended to
77
the corresponding vector-producing parameters for specifying the placement
88
of vector heads and tails, their shapes, and the justification of the vector.
@@ -21,7 +21,7 @@
2121
**+h**\ *shape* (e.g. ``+h0.5``).
2222
2323
For further modifiers see the *Vector Attributes* subsection of the
24-
corresponding module.
24+
corresponding method.
2525
2626
In the following we use the :meth:`pygmt.Figure.plot` method to plot vectors
2727
with individual heads and tails. We must specify the modifiers (together with

examples/get-started/README.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ This tutorial assumes that PyGMT has been successfully
1313

1414
This tutorial will progressively cover PyGMT plotting concepts, and later
1515
examples will use concepts explained in previous examples. It will not
16-
cover all PyGMT modules.
16+
cover all PyGMT methods.
1717

examples/get-started/first_figure.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
55
This tutorial page covers the basics of creating a figure using PyGMT - a
66
Python wrapper for the Generic Mapping Tools (GMT). It will only use
7-
the ``coast`` module for plotting. Later examples will address other PyGMT
8-
modules.
7+
the ``coast`` method for plotting. Later examples will address other PyGMT
8+
methods.
99
"""
1010

1111
###############################################################################
@@ -21,7 +21,7 @@
2121
# Loading the library
2222
# -------------------
2323
#
24-
# The first step is to import ``pygmt``. All modules and figure generation is
24+
# The first step is to import ``pygmt``. All methods and figure generation is
2525
# accessible from the :mod:`pygmt` top level package.
2626

2727
# sphinx_gallery_thumbnail_number = 4
@@ -38,14 +38,14 @@
3838

3939
###############################################################################
4040
# To add to a plot object (``fig`` in this example), the PyGMT module is used
41-
# as a method on the class. This example will use the module ``coast``, which
42-
# can be used to create a map without any other modules or external data. The
43-
# ``coast`` module plots the coastlines, borders, and bodies of water using a
44-
# database that is included in GMT.
41+
# as a method on the class. This example will use the ``coast`` method, which
42+
# can be used to create a map without any other methods, modules or external
43+
# data. The ``coast`` method plots the coastlines, borders, and bodies of water
44+
# using a database that is included in GMT.
4545
#
4646
# First, a region for the figure must be selected. This example will plot some
4747
# of the coast of Maine in the northeastern US. A Python list can be passed to
48-
# the ``region`` argument with the minimum and maximum X-values (longitude)
48+
# the ``region`` parameter with the minimum and maximum X-values (longitude)
4949
# and the minimum and maximum Y-values (latitude). For this example, the
5050
# minimum (bottom left) coordinates are (N43.75, W69) and the maximum (top
5151
# right) coordinates are (N44.75, W68). Negative values can be passed for

examples/projections/README.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Projections
22
===========
33

44
PyGMT support many map projections. Use the ``projection`` parameter to specify which
5-
one you want to use in all plotting modules. The projection is specified by a one
5+
one you want to use in all plotting methods. The projection is specified by a one
66
letter code along with (sometimes optional) reference longitude and latitude and the
77
width of the map (for example, **A**\ *lon0/lat0*\ [*/horizon*\ ]\ */width*). The map
88
height is determined based on the region and projection.

examples/tutorials/basics/frames.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
###############################################################################
2424
# To add the default GMT frame to the plot, use ``frame="f"`` in
25-
# :meth:`pygmt.Figure.basemap` or any other plotting module:
25+
# :meth:`pygmt.Figure.basemap` or any other plotting method:
2626

2727
fig = pygmt.Figure()
2828
fig.coast(shorelines="1/0.5p", region=[-180, 180, -60, 60], projection="M25c")

pygmt/helpers/utils.py

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,12 @@ def dummy_context(arg):
119119
yield arg
120120

121121

122-
def build_arg_string(kwargs):
122+
def build_arg_string(kwdict, infile=None, outfile=None):
123123
r"""
124-
Transform keyword arguments into a GMT argument string.
124+
Convert a dict and optional input/output files into a GMT argument string.
125125
126-
Make sure all arguments have been previously converted to a string
127-
representation using the ``kwargs_to_strings`` decorator. The only
126+
Make sure all values in ``kwdict`` have been previously converted to a
127+
string representation using the ``kwargs_to_strings`` decorator. The only
128128
exceptions are True, False and None.
129129
130130
Any lists or tuples left will be interpreted as multiple entries for the
@@ -138,14 +138,19 @@ def build_arg_string(kwargs):
138138
139139
Parameters
140140
----------
141-
kwargs : dict
142-
Parsed keyword arguments.
141+
kwdict : dict
142+
A dict containing parsed keyword arguments.
143+
infile : str or pathlib.Path
144+
The input file.
145+
outfile : str or pathlib.Path
146+
The output file.
143147
144148
Returns
145149
-------
146150
args : str
147151
The space-delimited argument string with '-' inserted before each
148-
keyword. The arguments are sorted alphabetically.
152+
keyword. The arguments are sorted alphabetically, with optional input
153+
file at the begining and optioanl output file at the end.
149154
150155
Examples
151156
--------
@@ -191,29 +196,42 @@ def build_arg_string(kwargs):
191196
... )
192197
... )
193198
-BWSne+tBlank\040Space -Baf -F+t"Empty\040\040Spaces" -l'Void\040Space'
199+
>>> print(
200+
... build_arg_string(
201+
... dict(A="0", B=True, C="rainbow"),
202+
... infile="input.txt",
203+
... outfile="output.txt",
204+
... )
205+
... )
206+
input.txt -A0 -B -Crainbow ->output.txt
194207
"""
195208
gmt_args = []
196209

197-
for key in kwargs:
210+
for key in kwdict:
198211
if len(key) > 2: # raise an exception for unrecognized options
199212
raise GMTInvalidInput(f"Unrecognized parameter '{key}'.")
200-
if kwargs[key] is None or kwargs[key] is False:
213+
if kwdict[key] is None or kwdict[key] is False:
201214
pass # Exclude arguments that are None and False
202-
elif is_nonstr_iter(kwargs[key]):
203-
for value in kwargs[key]:
215+
elif is_nonstr_iter(kwdict[key]):
216+
for value in kwdict[key]:
204217
_value = str(value).replace(" ", r"\040")
205218
gmt_args.append(rf"-{key}{_value}")
206-
elif kwargs[key] is True:
219+
elif kwdict[key] is True:
207220
gmt_args.append(f"-{key}")
208221
else:
209222
if key != "J": # non-projection parameters
210-
_value = str(kwargs[key]).replace(" ", r"\040")
223+
_value = str(kwdict[key]).replace(" ", r"\040")
211224
else:
212225
# special handling if key == "J" (projection)
213226
# remove any spaces in PROJ4 string
214-
_value = str(kwargs[key]).replace(" ", "")
227+
_value = str(kwdict[key]).replace(" ", "")
215228
gmt_args.append(rf"-{key}{_value}")
216-
return " ".join(sorted(gmt_args))
229+
gmt_args = sorted(gmt_args)
230+
if infile:
231+
gmt_args = [str(infile)] + gmt_args
232+
if outfile:
233+
gmt_args.append("->" + str(outfile))
234+
return " ".join(gmt_args)
217235

218236

219237
def is_nonstr_iter(value):
@@ -306,5 +324,23 @@ def args_in_kwargs(args, kwargs):
306324
--------
307325
bool
308326
If one of the required arguments is in ``kwargs``.
327+
328+
Examples
329+
--------
330+
331+
>>> args_in_kwargs(args=["A", "B"], kwargs={"C": "xyz"})
332+
False
333+
>>> args_in_kwargs(args=["A", "B"], kwargs={"B": "af"})
334+
True
335+
>>> args_in_kwargs(args=["A", "B"], kwargs={"B": None})
336+
False
337+
>>> args_in_kwargs(args=["A", "B"], kwargs={"B": True})
338+
True
339+
>>> args_in_kwargs(args=["A", "B"], kwargs={"B": False})
340+
False
341+
>>> args_in_kwargs(args=["A", "B"], kwargs={"B": 0})
342+
True
309343
"""
310-
return any(arg in kwargs for arg in args)
344+
return any(
345+
kwargs.get(arg) is not None and kwargs.get(arg) is not False for arg in args
346+
)

pygmt/src/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Source code for PyGMT modules.
2+
Source code for PyGMT methods.
33
"""
44
# pylint: disable=import-outside-toplevel
55

pygmt/src/blockm.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ def _blockm(block_method, data, x, y, z, outfile, **kwargs):
5151
with table_context as infile:
5252
if outfile is None:
5353
outfile = tmpfile.name
54-
arg_str = " ".join([infile, build_arg_string(kwargs), "->" + outfile])
55-
lib.call_module(module=block_method, args=arg_str)
54+
lib.call_module(
55+
module=block_method,
56+
args=build_arg_string(kwargs, infile=infile, outfile=outfile),
57+
)
5658

5759
# Read temporary csv output to a pandas table
5860
if outfile == tmpfile.name: # if user did not set outfile, return pd.DataFrame

0 commit comments

Comments
 (0)