|
6 | 6 |
|
7 | 7 | from typing import TYPE_CHECKING, ClassVar, NamedTuple
|
8 | 8 |
|
| 9 | +from pygmt.clib import Session |
9 | 10 | from pygmt.exceptions import GMTInvalidInput
|
10 |
| -from pygmt.helpers import kwargs_to_strings |
11 |
| -from pygmt.io import load_dataarray |
12 |
| -from pygmt.src import grdcut, which |
| 11 | +from pygmt.helpers import build_arg_list, kwargs_to_strings |
| 12 | +from pygmt.src import which |
13 | 13 |
|
14 | 14 | if TYPE_CHECKING:
|
15 | 15 | import xarray as xr
|
@@ -406,18 +406,27 @@ def _load_remote_dataset(
|
406 | 406 | )
|
407 | 407 | reg = f"_{registration[0]}"
|
408 | 408 |
|
409 |
| - # different ways to load tiled and non-tiled grids. |
410 |
| - # Known issue: tiled grids don't support slice operation |
411 |
| - # See https://github.com/GenericMappingTools/pygmt/issues/524 |
412 |
| - if region is None: |
413 |
| - if dataset.resolutions[resolution].tiled: |
| 409 | + fname = f"@{dataset_prefix}{resolution}{reg}" |
| 410 | + if dataset.resolutions[resolution].tiled: |
| 411 | + if region is None: |
414 | 412 | raise GMTInvalidInput(
|
415 | 413 | f"'region' is required for {dataset.title} resolution '{resolution}'."
|
416 | 414 | )
|
417 |
| - fname = which(f"@{dataset_prefix}{resolution}{reg}", download="a") |
418 |
| - grid = load_dataarray(fname, engine="netcdf4") |
| 415 | + fullname = None |
419 | 416 | else:
|
420 |
| - grid = grdcut(f"@{dataset_prefix}{resolution}{reg}", region=region) |
| 417 | + fullname = which(fname, download="a") |
| 418 | + |
| 419 | + # Currently, only grids are supported. Should support images in the future. |
| 420 | + kwdict = {"T": "g", "R": region} # region can be None |
| 421 | + with Session() as lib: |
| 422 | + with lib.virtualfile_out(kind="grid") as voutgrd: |
| 423 | + lib.call_module( |
| 424 | + module="read", |
| 425 | + args=[fname, voutgrd, *build_arg_list(kwdict)], |
| 426 | + ) |
| 427 | + grid = lib.virtualfile_to_raster(outgrid=None, vfname=voutgrd) |
| 428 | + if fullname is not None: |
| 429 | + grid.encoding["source"] = fullname |
421 | 430 |
|
422 | 431 | # Add some metadata to the grid
|
423 | 432 | grid.name = dataset.name
|
|
0 commit comments