I’m starting a transition from regular GMT to pygmt and and I’m having problems to plot data fields in grib format due to wrong georeferentiation.
I’m working a simple grib file with a single “message”. Note that the grid is irregular, in particular it is Lambert conformal. Now, I open it with xarray (which I assume is the format preferred by pygmt???).
import pygmt
import xarray as xr
import numpy as np
grb = xr.open_dataset('class_thun_m_000_0112.grb')
The result looks more or less good. There is some metadata a bit funny with unnecessary coordinates and some attributes not well digested by GMT when I try to plot it (probably because the file itself is not perfectly formed). But anyway, I’m just interested in the metadata related to georeferentiation. Therefore, and to make sure I control de values of the field, I have made up random data and taken just the coordinates from the original grib file to create a fresh new DataArray
.
coords = grb['unknown'].coords
values = np.random.randn(*grb.shape)
grid = xarray.DataArray(values, coords=coords)
grid.name = 'random'
Now, when I try to plot this with the following code:
fig = pygmt.Figure()
fig.basemap(region=[-20, 20, -10, 60], projection="M15c", frame=True)
fig.coast(shorelines=["1/1p,black"], land='green', water='skyblue')
fig.grdcontour(grid=grid)
fig.show()
I get this image, which clearly shows that gmt is not aware of the actual coordinates (the data covers the Iberian Peninsula). Instead, it is erroneously interpreting the array index as degrees.
How can I make GMT correctly understand the georeferentiation? Can I work with non-regular grids anyway? In the old good times of regular GMT, to cope with this type of grids I had to make an overlay, plotting the coasts with the actual projection, and then overlaying the grid using X projection. Something like this classical example. Is it possible to translate this approach to pygmt?