Repository navigation
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 mapwill only need to download 8 tiles (~3 MB) instead of the old 6.8 GB single grid. However,gmt which @earth_relief_03s -Ga(-Gameans 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/33to download the tiles (ignore the output fromgrdinfo) and usegmt whichto 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).
Activity
seisman commentedon Jun 23, 2020
Ping @PaulWessel @joa-quim @leouieda @weiji14 for thoughts.
PaulWessel commentedon Jun 23, 2020
First, just some minor corrections. 6.1 does not affect how 01s and 03s are handled which were always tiled and only tiles in the region were downloaded. Presumably, you never called load_earth_relief () on those SRTM datasets. However, it is true for 15s through 05m that these are now also tiled.
Second, could you make load_earth_relief (which I assume has an implicit region of -180/80/-90/90) call
gmt grdcut -Rdon the resolution remtoe data you want, and then it will assemble the global grid for you, including the resampling of 15s if 03s or 01s is used. First time it will download all tiles (if tiled), the next time it is local. I don't know how pyGMT handles grid internally so you could either have grdcut write to a netCDF file and then you read that as you did before, else you set up a virtual grid and that is what grdcut should return directly.seisman commentedon Jun 23, 2020
Yes, 03s and 01s are never implemented or supported in PyGMT.
It sounds a great solution!
lhoupert commentedon Jul 9, 2020
Hi guys,
Just a comment from a new user.
It works fine for me when I run
However for a resolution of '05m', pygmt cannot find the files. I got this error message
I am wondering if it is because pygmt is looking for files named
@***********while my local files don't have the same exact name (they dont start with a@. See what awhichcommand return for me:I will just use the 6m files right now, but I thought I would flag this up
weiji14 commentedon Jul 9, 2020
Thanks for the detailed writeup! As @seisman mentioned above, the problem with the "earth_relief_05m" grid (and higher resolution ones) is that it's actually tiled (specifically into two tiles, S90W180 and S90E000 as you've discovered), but we're trying to read it using
xr.open_dataarraythat only expects one NetCDF file. We'll definitely have to fix this in the redesign.