Skip to content

Commit 6eabbf4

Browse files
committed
Handle image kind in _load_remote_dataset function
Special case `earth_day` to be loaded as GMT_IMAGE rather than GMT_GRID. Need to use `GMT_OUT|GMT_IS_REFERENCE` in virtualfile_out to avoid segfault, xref #3115.
1 parent 971ec11 commit 6eabbf4

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

pygmt/clib/session.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,7 +1697,9 @@ def virtualfile_from_data(
16971697

16981698
@contextlib.contextmanager
16991699
def virtualfile_out(
1700-
self, kind: Literal["dataset", "grid"] = "dataset", fname: str | None = None
1700+
self,
1701+
kind: Literal["dataset", "grid", "image"] = "dataset",
1702+
fname: str | None = None,
17011703
):
17021704
r"""
17031705
Create a virtual file or an actual file for storing output data.
@@ -1754,8 +1756,11 @@ def virtualfile_out(
17541756
family, geometry = {
17551757
"dataset": ("GMT_IS_DATASET", "GMT_IS_PLP"),
17561758
"grid": ("GMT_IS_GRID", "GMT_IS_SURFACE"),
1759+
"image": ("GMT_IS_IMAGE", "GMT_IS_SURFACE"),
17571760
}[kind]
1758-
with self.open_virtualfile(family, geometry, "GMT_OUT", None) as vfile:
1761+
with self.open_virtualfile(
1762+
family, geometry, "GMT_OUT|GMT_IS_REFERENCE", None
1763+
) as vfile:
17591764
yield vfile
17601765

17611766
def inquire_virtualfile(self, vfname: str) -> int:

pygmt/datasets/load_remote_dataset.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,14 +427,20 @@ def _load_remote_dataset(
427427
)
428428

429429
# Currently, only grids are supported. Will support images in the future.
430-
kwdict = {"T": "g", "R": region} # region can be None
430+
kwdict = {"R": region} # region can be None
431+
if name in ("earth_day",):
432+
kind = "image"
433+
kwdict.update({"T": "i"})
434+
else:
435+
kind = "grid"
436+
kwdict.update({"T": "g"})
431437
with Session() as lib:
432-
with lib.virtualfile_out(kind="grid") as voutgrd:
438+
with lib.virtualfile_out(kind=kind) as voutgrd:
433439
lib.call_module(
434440
module="read",
435441
args=[fname, voutgrd, *build_arg_list(kwdict)],
436442
)
437-
grid = lib.virtualfile_to_raster(outgrid=None, vfname=voutgrd)
443+
grid = lib.virtualfile_to_raster(kind=kind, outgrid=None, vfname=voutgrd)
438444

439445
# Full path to the grid if not tiled grids.
440446
source = which(fname, download="a") if not resinfo.tiled else None

0 commit comments

Comments
 (0)