Skip to content

Commit b5fa029

Browse files
Merge branch 'master' into speedier-tutorials
2 parents a617b80 + 805f533 commit b5fa029

File tree

6 files changed

+43
-30
lines changed

6 files changed

+43
-30
lines changed

.github/workflows/ci_tests_dev.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ jobs:
118118
python setup.py sdist --formats=zip
119119
pip install dist/*
120120
121+
- name: Add GMT's bin to PATH (Linux/macOS)
122+
run: echo ${GITHUB_WORKSPACE}/gmt-install-dir/bin >> $GITHUB_PATH
123+
if: runner.os != 'Windows'
124+
121125
# Run the tests
122126
- name: Test with pytest (Linux/macOS)
123127
run: make test PYTEST_EXTRA="-r P"

doc/install.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ PyGMT requires the following libraries:
8989
The following are optional (but recommended) dependencies:
9090

9191
* `IPython <https://ipython.org/>`__: For embedding the figures in Jupyter
92-
notebooks.
92+
notebooks.
9393

9494

9595
Installing GMT and other dependencies

pygmt/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def _get_ghostscript_version():
9595
Get ghostscript version.
9696
"""
9797
os_name = sys.platform
98-
if os_name.startswith("linux") or os_name == "darwin":
98+
if os_name.startswith(("linux", "freebsd", "darwin")):
9999
cmds = ["gs"]
100100
elif os_name == "win32":
101101
cmds = ["gswin64c.exe", "gswin32c.exe"]

pygmt/datasets/earth_relief.py

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
Function to download the Earth relief datasets from the GMT data server, and
3-
load as DataArray.
3+
load as :class:`xarray.DataArray`.
44
55
The grids are available in various resolutions.
66
"""
@@ -12,7 +12,7 @@
1212

1313
@kwargs_to_strings(region="sequence")
1414
def load_earth_relief(resolution="01d", region=None, registration=None):
15-
"""
15+
r"""
1616
Load Earth relief grids (topography and bathymetry) in various resolutions.
1717
1818
The grids are downloaded to a user data directory
@@ -21,8 +21,11 @@ def load_earth_relief(resolution="01d", region=None, registration=None):
2121
So you'll need an internet connection the first time around.
2222
2323
These grids can also be accessed by passing in the file name
24-
``'@earth_relief_rru[_reg]'`` to any grid plotting/processing function.
25-
Refer to :gmt-docs:`datasets/remote-data.html` for more details.
24+
**@earth_relief**\_\ *res*\[_\ *reg*] to any grid plotting/processing
25+
function. *res* is the grid resolution (see below), and *reg* is grid
26+
registration type (**p** for pixel registration or *g* for gridline
27+
registration). Refer to :gmt-docs:`datasets/remote-data.html` for more
28+
details.
2629
2730
Parameters
2831
----------
@@ -35,7 +38,7 @@ def load_earth_relief(resolution="01d", region=None, registration=None):
3538
3639
region : str or list
3740
The subregion of the grid to load. Required for Earth relief grids with
38-
resolutions <= 05m.
41+
resolutions higher than 5 arc-minute (i.e., ``05m``).
3942
4043
registration : str
4144
Grid registration type. Either ``pixel`` for pixel registration or
@@ -45,14 +48,15 @@ def load_earth_relief(resolution="01d", region=None, registration=None):
4548
4649
Returns
4750
-------
48-
grid : xarray.DataArray
51+
grid : :class:`xarray.DataArray`
4952
The Earth relief grid. Coordinates are latitude and longitude in
5053
degrees. Relief is in meters.
5154
5255
Notes
5356
-----
54-
The DataArray doesn's support slice operation, for Earth relief data with
55-
resolutions higher than "05m", which are stored as smaller tiles.
57+
The :class:`xarray.DataArray` grid doesn't support slice operation, for
58+
Earth relief data with resolutions higher than "05m", which are stored as
59+
smaller tiles.
5660
5761
Examples
5862
--------
@@ -83,26 +87,24 @@ def load_earth_relief(resolution="01d", region=None, registration=None):
8387
"gridline-registered grid is available."
8488
)
8589

90+
if resolution not in non_tiled_resolutions + tiled_resolutions:
91+
raise GMTInvalidInput(f"Invalid Earth relief resolution '{resolution}'.")
92+
8693
# different ways to load tiled and non-tiled earth relief data
87-
if resolution in non_tiled_resolutions:
88-
if region is not None:
89-
raise NotImplementedError(
90-
f"'region' is not supported for Earth relief resolution '{resolution}'"
91-
)
92-
fname = which(f"@earth_relief_{resolution}{reg}", download="a")
93-
with xr.open_dataarray(fname) as dataarray:
94-
grid = dataarray.load()
95-
_ = grid.gmt # load GMTDataArray accessor information
96-
elif resolution in tiled_resolutions:
97-
# Titled grid can't be sliced.
98-
# See https://github.com/GenericMappingTools/pygmt/issues/524
99-
if region is None:
94+
# Known issue: tiled grids don't support slice operation
95+
# See https://github.com/GenericMappingTools/pygmt/issues/524
96+
if region is None:
97+
if resolution in non_tiled_resolutions:
98+
fname = which(f"@earth_relief_{resolution}{reg}", download="a")
99+
with xr.open_dataarray(fname) as dataarray:
100+
grid = dataarray.load()
101+
_ = grid.gmt # load GMTDataArray accessor information
102+
else:
100103
raise GMTInvalidInput(
101-
f"'region' is required for Earth relief resolution '{resolution}'"
104+
f"'region' is required for Earth relief resolution '{resolution}'."
102105
)
103-
grid = grdcut(f"@earth_relief_{resolution}{reg}", region=region)
104106
else:
105-
raise GMTInvalidInput(f'Invalid Earth relief resolution "{resolution}"')
107+
grid = grdcut(f"@earth_relief_{resolution}{reg}", region=region)
106108

107109
# Add some metadata to the grid
108110
grid.name = "elevation"

pygmt/helpers/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,10 @@ def launch_external_viewer(fname):
209209

210210
# Open the file with the default viewer.
211211
# Fall back to the browser if can't recognize the operating system.
212-
if sys.platform.startswith("linux") and shutil.which("xdg-open"):
212+
os_name = sys.platform
213+
if os_name.startswith(("linux", "freebsd")) and shutil.which("xdg-open"):
213214
subprocess.run(["xdg-open", fname], check=False, **run_args)
214-
elif sys.platform == "darwin": # Darwin is macOS
215+
elif os_name == "darwin": # Darwin is macOS
215216
subprocess.run(["open", fname], check=False, **run_args)
216217
else:
217218
webbrowser.open_new_tab("file://{}".format(fname))

pygmt/tests/test_datasets.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,14 @@ def test_earth_relief_01d_with_region():
9393
"""
9494
Test loading low-resolution earth relief with 'region'.
9595
"""
96-
with pytest.raises(NotImplementedError):
97-
load_earth_relief("01d", region=[0, 180, 0, 90])
96+
data = load_earth_relief(
97+
resolution="01d", region=[-10, 10, -5, 5], registration="gridline"
98+
)
99+
assert data.shape == (11, 21)
100+
npt.assert_allclose(data.lat, np.arange(-5, 6, 1))
101+
npt.assert_allclose(data.lon, np.arange(-10, 11, 1))
102+
npt.assert_allclose(data.min(), -5145)
103+
npt.assert_allclose(data.max(), 805.5)
98104

99105

100106
def test_earth_relief_30m():

0 commit comments

Comments
 (0)