Skip to content

Commit 78dce35

Browse files
committed
Merge branch 'main' into alias-system
2 parents 2e7db46 + 528cf2a commit 78dce35

35 files changed

+151
-84
lines changed

.github/workflows/check-links.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040

4141
- name: Link Checker
4242
id: lychee
43-
uses: lycheeverse/[email protected].0
43+
uses: lycheeverse/[email protected].1
4444
with:
4545
fail: false # Don't fail action on broken links
4646
output: /tmp/lychee-out.md
@@ -66,6 +66,7 @@ jobs:
6666
--exclude "^https://www.pygmt.org/%7B%7Bpath%7D%7D"
6767
--exclude "^https://www.researchgate.net/"
6868
--exclude "^https://zenodo.org/badge/DOI/"
69+
--exclude "^https://stackoverflow.com/a/69170441"
6970
--verbose
7071
"repository/*.md"
7172
"repository/**/*.py"

pygmt/datasets/load_remote_dataset.py

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
from typing import Any, Literal, NamedTuple
88

99
import xarray as xr
10-
from pygmt.clib import Session
1110
from pygmt.exceptions import GMTInvalidInput
12-
from pygmt.helpers import build_arg_list, kwargs_to_strings
13-
from pygmt.src import which
1411

1512
with contextlib.suppress(ImportError):
1613
# rioxarray is needed to register the rio accessor
@@ -502,7 +499,6 @@ class GMTRemoteDataset(NamedTuple):
502499
}
503500

504501

505-
@kwargs_to_strings(region="sequence")
506502
def _load_remote_dataset(
507503
name: str,
508504
prefix: str,
@@ -581,22 +577,9 @@ def _load_remote_dataset(
581577
raise GMTInvalidInput(msg)
582578

583579
fname = f"@{prefix}_{resolution}_{reg}"
584-
kwdict = {"R": region, "T": {"grid": "g", "image": "i"}[dataset.kind]}
585-
with Session() as lib:
586-
with lib.virtualfile_out(kind=dataset.kind) as voutgrd:
587-
lib.call_module(
588-
module="read",
589-
args=[fname, voutgrd, *build_arg_list(kwdict)],
590-
)
591-
grid = lib.virtualfile_to_raster(
592-
kind=dataset.kind, outgrid=None, vfname=voutgrd
593-
)
594-
595-
# Full path to the grid if not tiled grids.
596-
source = which(fname, download="a") if not resinfo.tiled else None
597-
# Manually add source to xarray.DataArray encoding to make the GMT accessors work.
598-
if source:
599-
grid.encoding["source"] = source
580+
grid = xr.load_dataarray(
581+
fname, engine="gmt", raster_kind=dataset.kind, region=region
582+
)
600583

601584
# Add some metadata to the grid
602585
grid.attrs["description"] = dataset.description

pygmt/figure.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import base64
66
import os
7+
import warnings
78
from pathlib import Path
89
from tempfile import TemporaryDirectory
910
from typing import Literal, overload
@@ -119,12 +120,19 @@ def _activate_figure(self) -> None:
119120
with Session() as lib:
120121
lib.call_module(module="figure", args=[self._name, fmt])
121122

123+
# TODO(PyGMT>=v0.18.0): Remove the _preprocess method.
122124
def _preprocess(self, **kwargs):
123125
"""
124126
Call the ``figure`` module before each plotting command to ensure we're plotting
125127
to this particular figure.
126128
"""
127129
self._activate_figure()
130+
warnings.warn(
131+
"The Figure._preprocess() method is deprecated since v0.16.0 and will be "
132+
"removed in v0.18.0. Use Figure._activate_figure() instead.",
133+
FutureWarning,
134+
stacklevel=2,
135+
)
128136
return kwargs
129137

130138
@property

pygmt/helpers/testing.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import xarray as xr
1111
from pygmt.exceptions import GMTImageComparisonFailure
12-
from pygmt.src import which
1312

1413

1514
def check_figures_equal(*, extensions=("png",), tol=0.0, result_dir="result_images"):
@@ -144,17 +143,18 @@ def wrapper(*args, ext="png", request=None, **kwargs):
144143
return decorator
145144

146145

147-
def load_static_earth_relief():
146+
def load_static_earth_relief() -> xr.DataArray:
148147
"""
149-
Load the static_earth_relief file for internal testing.
148+
Load the static_earth_relief.nc file for internal testing.
150149
151150
Returns
152151
-------
153-
data : xarray.DataArray
152+
data
154153
A grid of Earth relief for internal tests.
155154
"""
156-
fname = which("@static_earth_relief.nc", download="c")
157-
return xr.load_dataarray(fname, engine="gmt", raster_kind="grid")
155+
return xr.load_dataarray(
156+
"@static_earth_relief.nc", engine="gmt", raster_kind="grid"
157+
)
158158

159159

160160
def skip_if_no(package):

pygmt/src/basemap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def basemap(self, frame=None, **kwargs):
8282
{perspective}
8383
{transparency}
8484
"""
85-
kwargs = self._preprocess(**kwargs)
85+
self._activate_figure()
8686

8787
alias = AliasSystem(
8888
B=Alias(frame),

pygmt/src/coast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def coast(
210210
>>> # Show the plot
211211
>>> fig.show()
212212
"""
213-
kwargs = self._preprocess(**kwargs)
213+
self._activate_figure()
214214
if not args_in_kwargs(args=["C", "G", "S", "I", "N", "E", "Q", "W"], kwargs=kwargs):
215215
msg = (
216216
"At least one of the following parameters must be specified: "

pygmt/src/colorbar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,6 @@ def colorbar(self, **kwargs):
144144
>>> # Show the plot
145145
>>> fig.show()
146146
"""
147-
kwargs = self._preprocess(**kwargs)
147+
self._activate_figure()
148148
with Session() as lib:
149149
lib.call_module(module="colorbar", args=build_arg_list(kwargs))

pygmt/src/contour.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def contour(
133133
{perspective}
134134
{transparency}
135135
"""
136-
kwargs = self._preprocess(**kwargs)
136+
self._activate_figure()
137137

138138
# Specify levels for contours or annotations.
139139
# One level is converted to a string with a trailing comma to separate it from

pygmt/src/grdcontour.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def grdcontour(self, grid: PathLike | xr.DataArray, **kwargs):
138138
>>> # Show the plot
139139
>>> fig.show()
140140
"""
141-
kwargs = self._preprocess(**kwargs)
141+
self._activate_figure()
142142

143143
# Specify levels for the annotation and levels parameters.
144144
# One level is converted to a string with a trailing comma to separate it from

pygmt/src/grdimage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def grdimage(self, grid: PathLike | xr.DataArray, **kwargs):
156156
>>> # show the plot
157157
>>> fig.show()
158158
"""
159-
kwargs = self._preprocess(**kwargs)
159+
self._activate_figure()
160160

161161
# Do not support -A option
162162
if any(kwargs.get(arg) is not None for arg in ["A", "img_out"]):

0 commit comments

Comments
 (0)