Skip to content

Commit 80f8bf6

Browse files
committed
Merge remote-tracking branch 'origin/master' into gmt-master-gh-actions
2 parents 65ec7ce + eb93372 commit 80f8bf6

File tree

11 files changed

+65
-44
lines changed

11 files changed

+65
-44
lines changed

.github/workflows/ci_tests.yaml

+4-5
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ jobs:
4343
fail-fast: false
4444
matrix:
4545
python-version: [3.6, 3.7, 3.8]
46-
#os: [ubuntu-latest, macOS-latest, windows-latest]
47-
os: [ubuntu-latest, macOS-latest]
46+
os: [ubuntu-latest, macOS-latest, windows-latest]
4847
# environmental variables used in coverage
4948
env:
5049
OS: ${{ matrix.os }}
@@ -112,9 +111,9 @@ jobs:
112111
run: make test PYTEST_EXTRA="-r P"
113112

114113
# Build the documentation
115-
#- name: Build the documentation
116-
# shell: bash -l {0}
117-
# run: make -C doc clean all
114+
- name: Build the documentation
115+
shell: bash -l {0}
116+
run: make -C doc clean all
118117

119118
# Upload coverage to Codecov
120119
- name: Upload coverage to Codecov

.stickler.yml

-12
This file was deleted.

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ Guidelines for a good tutorial:
156156
* Explain the options and features in as much detail as possible. The gallery has
157157
concise examples while the tutorials are detailed and full of text.
158158

159-
Note that the `Figure.plot` function needs to be called for a plot to be inserted into
159+
Note that the `Figure.show()` function needs to be called for a plot to be inserted into
160160
the documentation.
161161

162162

examples/gallery/grid/track_sampling.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
fig = pygmt.Figure()
2626
# Plot the earth relief grid on Cylindrical Stereographic projection, masking land areas
27-
fig.basemap(region="g", frame=True, projection="Cyl_stere/150/-20/8i")
27+
fig.basemap(region="d", frame=True, projection="Cyl_stere/8i")
2828
fig.grdimage(grid=grid, cmap="gray")
2929
fig.coast(land="#666666")
3030
# Plot using circles (c) of 0.15cm, the sampled bathymetry points

pygmt/figure.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def shift_origin(self, xshift=None, yshift=None):
298298
Shift plot origin in x and/or y directions.
299299
300300
This method shifts plot origin relative to the current origin by
301-
(*xshift*,*yshift*) and optionally append the length unit (**c**,
301+
(*xshift*, *yshift*) and optionally append the length unit (**c**,
302302
**i**, or **p**).
303303
304304
Prepend **a** to shift the origin back to the original position after
@@ -308,14 +308,22 @@ def shift_origin(self, xshift=None, yshift=None):
308308
move the origin relative to its current location.
309309
310310
Detailed usage at
311-
:gmt-docs:`GMT_Docs.html#plot-positioning-and-layout-the-x-y-options`
311+
:gmt-docs:`cookbook/options.html#plot-positioning-and-layout-the-x-y-options`
312312
313313
Parameters
314314
----------
315315
xshift : str
316316
Shift plot origin in x direction.
317317
yshift : str
318318
Shift plot origin in y direction.
319+
320+
Notes
321+
-----
322+
For GMT 6.1.0, this function can't be used as the first plotting
323+
function of :meth:`pygmt.Figure`, since it relies the *region* and
324+
*projection* settings from previous commands.
325+
326+
.. TODO: Remove the notes when PyGMT bumps to GMT>=6.1.1.
319327
"""
320328
self._preprocess()
321329
args = ["-T"]

pygmt/gridding.py

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def surface(x=None, y=None, z=None, data=None, **kwargs):
9090
if outfile == tmpfile.name: # if user did not set outfile, return DataArray
9191
with xr.open_dataarray(outfile) as dataarray:
9292
result = dataarray.load()
93+
_ = result.gmt # load GMTDataArray accessor information
9394
elif outfile != tmpfile.name: # if user sets an outfile, return None
9495
result = None
9596

pygmt/gridops.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ def grdcut(grid, **kwargs):
4747
4848
Parameters
4949
----------
50-
grid : str
51-
The name of the input grid file.
50+
grid : str or xarray.DataArray
51+
The file name of the input grid or the grid loaded as a DataArray.
5252
outgrid : str or None
5353
The name of the output netCDF file with extension .nc to store the grid
5454
in.
@@ -94,12 +94,7 @@ def grdcut(grid, **kwargs):
9494
if kind == "file":
9595
file_context = dummy_context(grid)
9696
elif kind == "grid":
97-
raise NotImplementedError(
98-
"xarray.DataArray is not supported as the input grid yet!"
99-
)
100-
# file_context = lib.virtualfile_from_grid(grid)
101-
# See https://github.com/GenericMappingTools/gmt/pull/3532
102-
# for a feature request.
97+
file_context = lib.virtualfile_from_grid(grid)
10398
else:
10499
raise GMTInvalidInput("Unrecognized data type: {}".format(type(grid)))
105100

@@ -113,6 +108,7 @@ def grdcut(grid, **kwargs):
113108
if outgrid == tmpfile.name: # if user did not set outgrid, return DataArray
114109
with xr.open_dataarray(outgrid) as dataarray:
115110
result = dataarray.load()
111+
_ = result.gmt # load GMTDataArray accessor information
116112
else:
117113
result = None # if user sets an outgrid, return None
118114

pygmt/helpers/decorators.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,13 @@ def use_alias(**aliases):
180180
R = bla J = meh
181181
>>> my_module(region='bla', projection='meh')
182182
R = bla J = meh
183-
183+
>>> my_module(
184+
... region='bla', projection='meh', J="bla"
185+
... ) # doctest: +NORMALIZE_WHITESPACE
186+
Traceback (most recent call last):
187+
...
188+
pygmt.exceptions.GMTInvalidInput:
189+
Arguments in short-form (J) and long-form (projection) can't coexist
184190
"""
185191

186192
def alias_decorator(module_func):
@@ -194,6 +200,10 @@ def new_module(*args, **kwargs):
194200
New module that parses and replaces the registered aliases.
195201
"""
196202
for arg, alias in aliases.items():
203+
if alias in kwargs and arg in kwargs:
204+
raise GMTInvalidInput(
205+
f"Arguments in short-form ({arg}) and long-form ({alias}) can't coexist"
206+
)
197207
if alias in kwargs:
198208
kwargs[arg] = kwargs.pop(alias)
199209
return module_func(*args, **kwargs)

pygmt/tests/test_grdcut.py

+29-14
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
from ..helpers import GMTTempFile
1313

1414

15+
@pytest.fixture(scope="module", name="grid")
16+
def fixture_grid():
17+
"Load the grid data from the sample earth_relief file"
18+
return load_earth_relief(registration="pixel")
19+
20+
1521
def test_grdcut_file_in_file_out():
1622
"grduct an input grid file, and output to a grid file"
1723
with GMTTempFile(suffix=".nc") as tmpfile:
@@ -26,6 +32,8 @@ def test_grdcut_file_in_dataarray_out():
2632
"grdcut an input grid file, and output as DataArray"
2733
outgrid = grdcut("@earth_relief_01d", region="0/180/0/90")
2834
assert isinstance(outgrid, xr.DataArray)
35+
assert outgrid.gmt.registration == 1 # Pixel registration
36+
assert outgrid.gmt.gtype == 1 # Geographic type
2937
# check information of the output grid
3038
# the '@earth_relief_01d' is in pixel registration, so the grid range is
3139
# not exactly 0/180/0/90
@@ -39,23 +47,30 @@ def test_grdcut_file_in_dataarray_out():
3947
assert outgrid.sizes["lon"] == 180
4048

4149

42-
def test_grdcut_dataarray_in_file_out():
43-
"grdcut an input DataArray, and output to a grid file"
44-
# Not supported yet.
45-
# See https://github.com/GenericMappingTools/gmt/pull/3532
46-
47-
48-
def test_grdcut_dataarray_in_dataarray_out():
50+
def test_grdcut_dataarray_in_file_out(grid):
4951
"grdcut an input DataArray, and output to a grid file"
50-
# Not supported yet.
51-
# See https://github.com/GenericMappingTools/gmt/pull/3532
52+
with GMTTempFile(suffix=".nc") as tmpfile:
53+
result = grdcut(grid, outgrid=tmpfile.name, region="0/180/0/90")
54+
assert result is None # grdcut returns None if output to a file
55+
result = grdinfo(tmpfile.name, C=True)
56+
assert result == "0 180 0 90 -8182 5651.5 1 1 180 90 1 1\n"
5257

5358

54-
def test_grdcut_dataarray_in_fail():
55-
"Make sure that grdcut fails correctly if DataArray is the input grid"
56-
with pytest.raises(NotImplementedError):
57-
grid = load_earth_relief()
58-
grdcut(grid, region="0/180/0/90")
59+
def test_grdcut_dataarray_in_dataarray_out(grid):
60+
"grdcut an input DataArray, and output as DataArray"
61+
outgrid = grdcut(grid, region="0/180/0/90")
62+
assert isinstance(outgrid, xr.DataArray)
63+
# check information of the output grid
64+
# the '@earth_relief_01d' is in pixel registration, so the grid range is
65+
# not exactly 0/180/0/90
66+
assert outgrid.coords["lat"].data.min() == 0.5
67+
assert outgrid.coords["lat"].data.max() == 89.5
68+
assert outgrid.coords["lon"].data.min() == 0.5
69+
assert outgrid.coords["lon"].data.max() == 179.5
70+
assert outgrid.data.min() == -8182.0
71+
assert outgrid.data.max() == 5651.5
72+
assert outgrid.sizes["lat"] == 90
73+
assert outgrid.sizes["lon"] == 180
5974

6075

6176
def test_grdcut_fails():

pygmt/tests/test_image.py

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Tests image.
33
"""
44
import os
5+
import sys
56

67
import pytest
78

@@ -11,6 +12,7 @@
1112
TEST_IMG = os.path.join(os.path.dirname(__file__), "baseline", "test_logo.png")
1213

1314

15+
@pytest.mark.skipif(sys.platform == "win32", reason="crashes on Windows")
1416
@pytest.mark.mpl_image_compare
1517
def test_image():
1618
"Place images on map"

pygmt/tests/test_surface.py

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ def test_surface_input_file():
2323
fname = which("@tut_ship.xyz", download="c")
2424
output = surface(data=fname, spacing="5m", region=[245, 255, 20, 30])
2525
assert isinstance(output, xr.DataArray)
26+
assert output.gmt.registration == 0 # Gridline registration
27+
assert output.gmt.gtype == 0 # Cartesian type
2628
return output
2729

2830

0 commit comments

Comments
 (0)