Skip to content

grdimage does not plot subsets of data correctly on a global map #732

Closed
@MarkWieczorek

Description

@MarkWieczorek

Problem

I have a subset of data that I would like to plot on a global projection (such as mollweide). This works with GMT, but pygmt provides incorrect output.

Example

Let's create a global dataset of random numbers on a grid with 1 degree spacing in latitude and longitude:

lats = np.arange(90., -91., -1.)
lons = np.arange(0., 361., 1.)
data = np.random.rand(181, 361)
da = xr.DataArray(data, coords=[('latitude', lats), ('longitude', lons)])

Now let's plot only the region from 90N-30S and 0E-220E with a Mollweide projection centered on 180 E

figure = pygmt.Figure()
pygmt.makecpt(series=[0., 1., 0.1], cmap='vik', continuous=True)
figure.grdimage(da[0:121, 0:221], region='g', projection='W180/8i', frame=True)
figure.show(method='external')

ex1

This is as expected, but now do the same, but centered on 0 E

figure = pygmt.Figure()
pygmt.makecpt(series=[0., 1., 0.1], cmap='vik', continuous=True)
figure.grdimage(da[0:121, 0:221], region='g', projection='W0/8i', frame=True)
figure.show(method='external')

ex2

And as a second example, here I want to plot the global data, but using a dataset the doesn't contain the redundant data at 360 E

figure = pygmt.Figure()
pygmt.makecpt(series=[0., 1., 0.1], cmap='vik', continuous=True)
figure.grdimage(da[0:181, 0:360], region='g', projection='W0/8i', frame=True)
figure.show(method='external')

ex3
This is a complete failure, but changing the central meridian to 180 degrees works!

figure = pygmt.Figure()
pygmt.makecpt(series=[0., 1., 0.1], cmap='vik', continuous=True)
figure.grdimage(da[0:181, 0:360], region='g', projection='W180/8i', frame=True)
figure.show(method='external')

ex4

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingupstreamBug or missing feature of upstream core GMT

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions