Pygmt.datasets.load_earth_relief("05m", region=[116.5, 117.5, 22.8, 23.5]) return indexerror

Dear all:

This is my code:

import pygmt
grid = pygmt.datasets.load_earth_relief(resolution="05m", region=[-92.5, -82.5, -3, 7])

but it returned the error:

[Session pygmt-session (27)]: Error returned from GMT API: GMT_FILE_NOT_FOUND (16)
[Session pygmt-session (27)]: Error returned from GMT API: GMT_GRID_READ_ERROR (18)
[Session pygmt-session (27)]: Error returned from GMT API: GMT_GRID_READ_ERROR (18)

IndexError                                Traceback (most recent call last)
Cell In[10], line 4
      1 import pygmt
      3 # Load sample earth relief data
----> 4 grid = pygmt.datasets.load_earth_relief(resolution="05m", region=[-92.5, -82.5, -3, 7])

File D:\anaconda\envs\pygmt\Lib\site-packages\pygmt\helpers\decorators.py:773, in kwargs_to_strings.<locals>.converter.<locals>.new_module(*args, **kwargs)
    770             bound.arguments["kwargs"][arg] = newvalue
    772 # Execute the original function and return its output
--> 773 return module_func(*bound.args, **bound.kwargs)

File D:\anaconda\envs\pygmt\Lib\site-packages\pygmt\datasets\earth_relief.py:168, in load_earth_relief(resolution, region, registration, data_source, use_srtm)
    166     case "gebco" | "gebcosi":
    167         name = "earth_gebco"
--> 168 grid = _load_remote_dataset(
    169     name=name,
    170     prefix=prefix,
    171     resolution=resolution,
    172     region=region,
    173     registration=registration,
    174 )
    175 return grid

File D:\anaconda\envs\pygmt\Lib\site-packages\pygmt\helpers\decorators.py:773, in kwargs_to_strings.<locals>.converter.<locals>.new_module(*args, **kwargs)
    770             bound.arguments["kwargs"][arg] = newvalue
    772 # Execute the original function and return its output
--> 773 return module_func(*bound.args, **bound.kwargs)

File D:\anaconda\envs\pygmt\Lib\site-packages\pygmt\datasets\load_remote_dataset.py:418, in _load_remote_dataset(name, prefix, resolution, region, registration)
    413     with lib.virtualfile_out(kind="grid") as voutgrd:
    414         lib.call_module(
    415             module="read",
    416             args=[fname, voutgrd, *build_arg_list(kwdict)],
    417         )
--> 418         grid = lib.virtualfile_to_raster(outgrid=None, vfname=voutgrd)
    420 # Full path to the grid if not tiled grids.
    421 source = which(fname, download="a") if not resinfo.tiled else None

File D:\anaconda\envs\pygmt\Lib\site-packages\pygmt\clib\session.py:2021, in Session.virtualfile_to_raster(self, vfname, kind, outgrid)
   2015     family = self.inquire_virtualfile(vfname)
   2016     kind = {  # type: ignore[assignment]
   2017         self["GMT_IS_GRID"]: "grid",
   2018         self["GMT_IS_IMAGE"]: "image",
   2019         self["GMT_IS_CUBE"]: "cube",
   2020     }[family]
-> 2021 return self.read_virtualfile(vfname, kind=kind).contents.to_dataarray()

File D:\anaconda\envs\pygmt\Lib\site-packages\pygmt\datatypes\grid.py:192, in _GMT_GRID.to_dataarray(self)
    188 # Flip the coordinates and data if necessary so that coordinates are ascending.
    189 # `grid.sortby(list(grid.dims))` sometimes causes crashes.
    190 # The solution comes from https://github.com/pydata/xarray/discussions/6695.
    191 for dim in grid.dims:
--> 192     if grid[dim][0] > grid[dim][1]:
    193         grid = grid.isel({dim: slice(None, None, -1)})
    195 # Set GMT accessors.
    196 # Must put at the end, otherwise info gets lost after certain grid operations.

File D:\anaconda\envs\pygmt\Lib\site-packages\xarray\core\dataarray.py:901, in DataArray.__getitem__(self, key)
    898     return self._getitem_coord(key)
    899 else:
    900     # xarray-style array indexing
--> 901     return self.isel(indexers=self._item_key_to_dict(key))

File D:\anaconda\envs\pygmt\Lib\site-packages\xarray\core\dataarray.py:1540, in DataArray.isel(self, indexers, drop, missing_dims, **indexers_kwargs)
   1535     return self._from_temp_dataset(ds)
   1537 # Much faster algorithm for when all indexers are ints, slices, one-dimensional
   1538 # lists, or zero or one-dimensional np.ndarray's
-> 1540 variable = self._variable.isel(indexers, missing_dims=missing_dims)
   1541 indexes, index_variables = isel_indexes(self.xindexes, indexers)
   1543 coords = {}

File D:\anaconda\envs\pygmt\Lib\site-packages\xarray\core\variable.py:1049, in Variable.isel(self, indexers, missing_dims, **indexers_kwargs)
   1046 indexers = drop_dims_from_indexers(indexers, self.dims, missing_dims)
   1048 key = tuple(indexers.get(dim, slice(None)) for dim in self.dims)
-> 1049 return self[key]

File D:\anaconda\envs\pygmt\Lib\site-packages\xarray\core\variable.py:816, in Variable.__getitem__(self, key)
    813 dims, indexer, new_order = self._broadcast_indexes(key)
    814 indexable = as_indexable(self._data)
--> 816 data = indexing.apply_indexer(indexable, indexer)
    818 if new_order:
    819     data = np.moveaxis(data, range(len(new_order)), new_order)

File D:\anaconda\envs\pygmt\Lib\site-packages\xarray\core\indexing.py:1033, in apply_indexer(indexable, indexer)
   1031     return indexable.oindex[indexer]
   1032 else:
-> 1033     return indexable[indexer]

File D:\anaconda\envs\pygmt\Lib\site-packages\xarray\core\indexing.py:1798, in PandasIndexingAdapter.__getitem__(self, indexer)
   1795     indexable = NumpyIndexingAdapter(np.asarray(self))
   1796     return indexable[indexer]
-> 1798 result = self.array[key]
   1800 return self._handle_result(result)

File D:\anaconda\envs\pygmt\Lib\site-packages\pandas\core\indexes\base.py:5389, in Index.__getitem__(self, key)
   5386 if is_integer(key) or is_float(key):
   5387     # GH#44051 exclude bool, which would return a 2d ndarray
   5388     key = com.cast_scalar_indexer(key)
-> 5389     return getitem(key)
   5391 if isinstance(key, slice):
   5392     # This case is separated from the conditional above to avoid
   5393     # pessimization com.is_bool_indexer and ndim checks.
   5394     return self._getitem_slice(key)

IndexError: index 0 is out of bounds for axis 0 with size 0

How can I deal with it?

Hello @guofenxiwu,

Welcome to the GMT forum :slightly_smiling_face:!

Hm. Can you please post the output of pygmt.show_versions().
Did you try other resolutions, e.g,"01d" or "30m" as well as other datasets, e.g., pygmt.datasets.load_earth_age? Does this also not work?


here is my version

'‘06m’, ‘01d’ and ‘30m’ datasets work but the ‘05m’ or higher dimensions does not work.

It’s likely internet connection issues and GMT fails to download the grid tiles.

Thank you sir! you’re right.