Description
Description of the problem
PyGMT provides the load_earth_relief()
function to load GMT's earth_relief data as a xarray.DataArray
object, so that users can plot it or directly manipulate the data. The function won't work in GMT 6.1.0.
Currently, the load_earth_relief()
function first calls the which()
function to get the full path of the data (which
will download the data if it's not available locally), and then read the netCDF file in by grid = xr.open_dataarray(fname)
. It works well with GMT 6.0.0 because each resolution is stored as a single grid.
In GMT 6.1.0, we will have many problems:
- earth relief data with resolutions >= 06m are stored as a single grid, e.g.,
earth_relief_06m_p.grd
. The function still works - earth relief data with resolutions <= 05m are stored as several smaller tiles. If you want to plot an earth relief map in a 3°x3° region using the 03s data, you don't have to download the ~6.8 GB large file anymore, i.e., the command
gmt grdimage @earth_relief_03s -R120/123/30/33 -pdf map
will only need to download 8 tiles (~3 MB) instead of the old 6.8 GB single grid. However,gmt which @earth_relief_03s -Ga
(-Ga
means automatically putting the data in the appropriate directory, which is new in GMT 6.1.) will download all tiles (hundreds or thousands of tiles, ~6.8 GB in total). That's definitely what we want to avoid.
Solutions
AFAIK, there are no easy solutions.
-
We can do
gmt grdinfo @earth_relief_03s -R120/123/30/33
to download the tiles (ignore the output fromgrdinfo
) and usegmt which
to return the full paths that exist locally (it will return all existing tiles, including tiles outside our target region). However, since the data are stored as tiles, we have to read several files and merge them. It's more complicated for 03s and 01s data. The original 03s and 01s data don't have data in oceans and GMT fills the ocean with the 15s data. Thus we have to resample the data and merge them. -
GMT provides a C API function (perhaps also new in GMT 6.1.0)
GMT_Get_FilePath()
to return the full path of a file. As per the documentation, it can also download remote files (e.g., earth relief data) if it's not available locally. However, (1) the API is not tested by us yet; (2) it's not clear if it can accept a region argument to download tiles in a specified region; (3) even though the tiles in the specified region are correctly downloaded with full paths returned, we still have to manually resample and merge them.
We need a better and working solution here, or we have to seek support from the upstream GMT, and ask them to provide a new API function which returns the final grid (resampled and merged).