Skip to content

Commit 9c9ff98

Browse files
authored
Merge branch 'master' into double-yaxis
2 parents 39080f7 + ac51c2e commit 9c9ff98

File tree

9 files changed

+69
-65
lines changed

9 files changed

+69
-65
lines changed

.github/workflows/check-links.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ jobs:
3131
# 429: Too many requests
3232
args: >
3333
--accept 429
34+
--exclude "^https://doi.org/10.5281/zenodo$"
3435
--exclude "^https://zenodo.org/badge/DOI/$"
36+
--exclude "^https://zenodo.org/badge/DOI/10.5281/zenodo$"
3537
--exclude "^https://github.com/GenericMappingTools/pygmt/pull/[0-9]*$"
3638
--exclude "^https://github.com/GenericMappingTools/pygmt/issues/[0-9]*$"
3739
--exclude "^https://www.generic-mapping-tools.org/_static/gmt-logo.png/$"
@@ -40,6 +42,7 @@ jobs:
4042
--exclude "^git"
4143
--exclude "^file://"
4244
--exclude "^https://docs.generic-mapping-tools.org/latest/%s$"
45+
--exclude "https://hackmd.io/@pygmt"
4346
--verbose
4447
"repository/**/*.rst"
4548
"repository/**/*.md"

.github/workflows/ci_tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ jobs:
8686

8787
# Download cached remote files (artifacts) from GitHub
8888
- name: Download remote data from GitHub
89-
uses: dawidd6/action-download-artifact@v2.11.1
89+
uses: dawidd6/action-download-artifact@v2.12.0
9090
with:
9191
workflow: cache_data.yaml
9292
workflow_conclusion: success

.github/workflows/ci_tests_dev.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ jobs:
9797

9898
# Download cached remote files (artifacts) from GitHub
9999
- name: Download remote data from GitHub
100-
uses: dawidd6/action-download-artifact@v2.11.1
100+
uses: dawidd6/action-download-artifact@v2.12.0
101101
with:
102102
workflow: cache_data.yaml
103103
workflow_conclusion: success

doc/Makefile

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,31 @@
11
# Makefile for Sphinx documentation
22

33
# You can set these variables from the command line.
4-
SPHINXOPTS =
4+
SPHINXOPTS = -j auto
55
SPHINXBUILD = sphinx-build
66
SPHINXAUTOGEN = sphinx-autogen
77
BUILDDIR = _build
88

99
# Internal variables.
10-
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(SPHINXOPTS) .
10+
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(SPHINXOPTS) .
1111

12-
.PHONY: help clean html linkcheck doctest api
13-
14-
all: html
12+
.PHONY: help all api html server clean
1513

1614
help:
17-
@echo "Please use \`make <target>' where <target> is one of"
18-
@echo " all generate the complete webpage"
19-
@echo " html make only the HTML files from the existing rst sources"
20-
@echo " linkcheck check all external links for integrity"
21-
@echo " doctest run all doctests embedded in the documentation (if enabled)"
15+
@echo "Please use 'make <target>' where <target> is one of"
16+
@echo " all build the HTML files from the existing rst sources"
17+
@echo " api generate rst source files of API documentation"
18+
@echo " html build the HTML files from the existing rst sources"
19+
@echo " server make a local HTTP server for previewing the built documentation"
20+
@echo " clean clean up built and generated files"
2221

23-
clean:
24-
rm -rf $(BUILDDIR)/html
25-
rm -rf $(BUILDDIR)/doctrees
26-
rm -rf $(BUILDDIR)/linkcheck
27-
rm -rf modules
28-
rm -rf api/generated
29-
rm -rf gallery
30-
rm -rf tutorials
31-
rm -rf projections
32-
rm -rf .ipynb_checkpoints
22+
all: html
23+
24+
api:
25+
@echo
26+
@echo "Generating rst source files of API documentation."
27+
@echo
28+
$(SPHINXAUTOGEN) -i -t _templates -o api/generated api/*.rst
3329

3430
html: api
3531
@echo
@@ -39,23 +35,16 @@ html: api
3935
@echo
4036
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
4137

42-
api:
38+
server:
4339
@echo
44-
@echo "Building API docs."
40+
@echo "Running a server on port 8009."
41+
@echo "Open http://localhost:8009 in a web browser to preview the documentation."
4542
@echo
46-
$(SPHINXAUTOGEN) -i -t _templates -o api/generated api/*.rst
47-
48-
49-
linkcheck:
50-
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
51-
@echo
52-
@echo "Link check complete; look for any errors in the above output " \
53-
"or in $(BUILDDIR)/linkcheck/output.txt."
54-
55-
doctest:
56-
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
57-
@echo "Testing of doctests in the sources finished, look at the " \
58-
"results in $(BUILDDIR)/doctest/output.txt."
59-
60-
serve:
6143
cd $(BUILDDIR)/html && python -m http.server 8009
44+
45+
clean:
46+
rm -rf $(BUILDDIR)
47+
rm -rf api/generated
48+
rm -rf gallery
49+
rm -rf tutorials
50+
rm -rf projections

pygmt/clib/session.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,9 @@ def virtualfile_from_grid(self, grid):
13601360
with self.open_virtual_file(*args) as vfile:
13611361
yield vfile
13621362

1363-
def virtualfile_from_data(self, check_kind=None, data=None, x=None, y=None, z=None):
1363+
def virtualfile_from_data(
1364+
self, check_kind=None, data=None, x=None, y=None, z=None, extra_arrays=None
1365+
):
13641366
"""
13651367
Store any data inside a virtual file.
13661368
@@ -1378,6 +1380,9 @@ def virtualfile_from_data(self, check_kind=None, data=None, x=None, y=None, z=No
13781380
raster grid, a vector matrix/arrays, or other supported data input.
13791381
x/y/z : 1d arrays or None
13801382
x, y and z columns as numpy arrays.
1383+
extra_arrays : list of 1d arrays
1384+
Optional. A list of numpy arrays in addition to x, y and z. All
1385+
of these arrays must be of the same size as the x/y/z arrays.
13811386
13821387
Returns
13831388
-------
@@ -1430,14 +1435,26 @@ def virtualfile_from_data(self, check_kind=None, data=None, x=None, y=None, z=No
14301435
if kind in ("file", "grid"):
14311436
_data = (data,)
14321437
elif kind == "vectors":
1433-
_data = (x, y, z)
1438+
_data = [np.atleast_1d(x), np.atleast_1d(y)]
1439+
if z is not None:
1440+
_data.append(np.atleast_1d(z))
1441+
if extra_arrays:
1442+
_data.extend(extra_arrays)
14341443
elif kind == "matrix": # turn 2D arrays into list of vectors
14351444
try:
14361445
# pandas.DataFrame and xarray.Dataset types
14371446
_data = [array for _, array in data.items()]
14381447
except AttributeError:
1439-
# Python lists, tuples, and numpy ndarray types
1440-
_data = np.atleast_2d(np.asanyarray(data).T)
1448+
try:
1449+
# Just use virtualfile_from_matrix for 2D numpy.ndarray
1450+
# which are signed integer (i), unsigned integer (u) or
1451+
# floating point (f) types
1452+
assert data.ndim == 2 and data.dtype.kind in "iuf"
1453+
_virtualfile_from = self.virtualfile_from_matrix
1454+
_data = (data,)
1455+
except (AssertionError, AttributeError):
1456+
# Python lists, tuples, and numpy ndarray types
1457+
_data = np.atleast_2d(np.asanyarray(data).T)
14411458

14421459
# Finally create the virtualfile from the data, to be passed into GMT
14431460
file_context = _virtualfile_from(*_data)

pygmt/src/plot.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
"""
22
plot - Plot in two dimensions.
33
"""
4-
import numpy as np
54
from pygmt.clib import Session
65
from pygmt.exceptions import GMTInvalidInput
76
from pygmt.helpers import (
87
build_arg_string,
98
data_kind,
10-
dummy_context,
119
fmt_docstring,
1210
is_nonstr_iter,
1311
kwargs_to_strings,
@@ -226,14 +224,9 @@ def plot(self, x=None, y=None, data=None, sizes=None, direction=None, **kwargs):
226224

227225
with Session() as lib:
228226
# Choose how data will be passed in to the module
229-
if kind == "file":
230-
file_context = dummy_context(data)
231-
elif kind == "matrix":
232-
file_context = lib.virtualfile_from_matrix(data)
233-
elif kind == "vectors":
234-
file_context = lib.virtualfile_from_vectors(
235-
np.atleast_1d(x), np.atleast_1d(y), *extra_arrays
236-
)
227+
file_context = lib.virtualfile_from_data(
228+
check_kind="vector", data=data, x=x, y=y, extra_arrays=extra_arrays
229+
)
237230

238231
with file_context as fname:
239232
arg_str = " ".join([fname, build_arg_string(kwargs)])

pygmt/src/plot3d.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
"""
22
plot3d - Plot in three dimensions.
33
"""
4-
import numpy as np
54
from pygmt.clib import Session
65
from pygmt.exceptions import GMTInvalidInput
76
from pygmt.helpers import (
87
build_arg_string,
98
data_kind,
10-
dummy_context,
119
fmt_docstring,
1210
is_nonstr_iter,
1311
kwargs_to_strings,
@@ -189,14 +187,9 @@ def plot3d(
189187

190188
with Session() as lib:
191189
# Choose how data will be passed in to the module
192-
if kind == "file":
193-
file_context = dummy_context(data)
194-
elif kind == "matrix":
195-
file_context = lib.virtualfile_from_matrix(data)
196-
elif kind == "vectors":
197-
file_context = lib.virtualfile_from_vectors(
198-
np.atleast_1d(x), np.atleast_1d(y), np.atleast_1d(z), *extra_arrays
199-
)
190+
file_context = lib.virtualfile_from_data(
191+
check_kind="vector", data=data, x=x, y=y, z=z, extra_arrays=extra_arrays
192+
)
200193

201194
with file_context as fname:
202195
arg_str = " ".join([fname, build_arg_string(kwargs)])

pygmt/tests/test_grdinfo.py

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

1111
def test_grdinfo():
1212
"""
13-
Make sure grd info works as expected.
13+
Make sure grdinfo works as expected.
1414
"""
1515
grid = load_earth_relief(registration="gridline")
1616
result = grdinfo(grid=grid, force_scan=0, per_column="n")

pygmt/tests/test_info.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ def test_info():
2929
assert output == expected_output
3030

3131

32+
def test_info_2d_list():
33+
"""
34+
Make sure info works on a 2d list.
35+
"""
36+
output = info(table=[[0, 8], [3, 5], [6, 2]])
37+
expected_output = "<vector memory>: N = 3 <0/6> <2/8>\n"
38+
assert output == expected_output
39+
40+
3241
def test_info_dataframe():
3342
"""
3443
Make sure info works on pandas.DataFrame inputs.
@@ -105,7 +114,7 @@ def test_info_2d_array():
105114
table = np.loadtxt(POINTS_DATA)
106115
output = info(table=table)
107116
expected_output = (
108-
"<vector memory>: N = 20 <11.5309/61.7074> <-2.9289/7.8648> <0.1412/0.9338>\n"
117+
"<matrix memory>: N = 20 <11.5309/61.7074> <-2.9289/7.8648> <0.1412/0.9338>\n"
109118
)
110119
assert output == expected_output
111120

0 commit comments

Comments
 (0)