|
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 |
13 | 12 |
|
14 | 13 | if TYPE_CHECKING:
|
15 | 14 | import xarray as xr
|
@@ -406,18 +405,24 @@ def _load_remote_dataset(
|
406 | 405 | )
|
407 | 406 | reg = f"_{registration[0]}"
|
408 | 407 |
|
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: |
414 |
| - raise GMTInvalidInput( |
415 |
| - f"'region' is required for {dataset.title} resolution '{resolution}'." |
| 408 | + if region is None and dataset.resolutions[resolution].tiled: |
| 409 | + raise GMTInvalidInput( |
| 410 | + f"'region' is required for {dataset.title} resolution '{resolution}'." |
| 411 | + ) |
| 412 | + |
| 413 | + # Currently, only grids are supported. Should support images in the future. |
| 414 | + kwdict = {"T": "g", "R": region} # region can be None |
| 415 | + with Session() as lib: |
| 416 | + with lib.virtualfile_out(kind="grid") as voutgrd: |
| 417 | + lib.call_module( |
| 418 | + module="read", |
| 419 | + args=[ |
| 420 | + f"@{dataset_prefix}{resolution}{reg}", |
| 421 | + voutgrd, |
| 422 | + *build_arg_list(kwdict), |
| 423 | + ], |
416 | 424 | )
|
417 |
| - fname = which(f"@{dataset_prefix}{resolution}{reg}", download="a") |
418 |
| - grid = load_dataarray(fname, engine="netcdf4") |
419 |
| - else: |
420 |
| - grid = grdcut(f"@{dataset_prefix}{resolution}{reg}", region=region) |
| 425 | + grid = lib.virtualfile_to_raster(outgrid=None, vfname=voutgrd) |
421 | 426 |
|
422 | 427 | # Add some metadata to the grid
|
423 | 428 | grid.name = dataset.name
|
|
0 commit comments