Skip to content

Matrix grid doesn't always work with different central meridians #4335

Open

Description

@seisman

Description of the problem

The issue was first reported in GenericMappingTools/pygmt#390, but was thought to be fixed by GMT PRs #3813 and #3829. The GMT master branch works for some projection parameters but doesn't always work.

Full script that generated the error

import pygmt
fig = pygmt.Figure()

fig.grdimage("@earth_relief_01d_g", projection="Q123/0/15c", cmap="geo")

fig.shift_origin(yshift="8c")

dem = pygmt.datasets.load_earth_relief(resolution="01d", registration="gridline")
fig.grdimage(dem, projection="Q123/0/15c", cmap="geo")
fig.savefig("map.pdf")

Output

image

Image difference
image

In the PyGMT, we test several different projection parameters. Here are the ones that are known to fail:

  • Q123/0/15c
  • Q123/30/15c
  • Q180/0/15c
  • Q180/30/15c

Here are the ones that are known to work:

  • Q0/0/15c
  • Q0/30/15c

The same parameters work well for General Stereographic projection (i.e., changing Q to S).

Note: Those tests were originally written by @weiji14.

Activity

  1. PaulWessel commented on Oct 16, 2020

    @PaulWessel
    Contributor

    Is this a gridline registration issue only or is it the same for pixel as well?

  2. seisman commented on Oct 16, 2020

    @seisman
    MemberAuthor

    Same issue for pixel-registered grids (just tried Q123/0/15c).

  3. PaulWessel commented on Oct 16, 2020

    @PaulWessel
    Contributor

    And just to be absolutely clear, the plot on the bottom is what you expect? That rougher plot is what I get with long=0 which you said works, so just checking.

  4. seisman commented on Oct 16, 2020

    @seisman
    MemberAuthor

    And just to be absolutely clear, the plot on the bottom is what you expect?

    Yes, the bottom one uses the earth relief grid file, which gives the same plot as GMT CLI.

  5. PaulWessel commented on Oct 16, 2020

    @PaulWessel
    Contributor

    So what happens is this: We have a read-only grid and it has a certain central meridian. This kicks in:

    if (got_z_grid && (gmt_whole_earth (GMT, Grid_orig->header->wesn, wesn) == 1))
    	need_to_project = true;	/* This can only happen if reading a remote global geographic grid and the central meridian differs from that of the projection */
    

    So now we go the way of resampling the images - hence the smoother apparance. The other image is not resampled, just plotted, but handles the change in longitude. I will see if I can make it work the same. You would think that should be doable, but the big difference is that the file is read in and the matrix is rotated to fit the -R while in the xarray case the pixels are still -180/180. So not the same case.

  6. stale commented on Jan 16, 2021

    @stale

    This issue has been automatically marked as stale because it has not had activity in the last 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions.

  7. added
    stale
    on Jan 16, 2021
  8. removed
    stale
    on Jan 23, 2021
  9. stale commented on Jun 2, 2021

    @stale

    This issue has been automatically marked as stale because it has not had activity in the last 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions.

  10. added
    stale
    on Jun 2, 2021
  11. removed
    stale
    on Jun 17, 2021
  12. added
    bug
    on Jan 21, 2022
  13. added this to the milestone on Mar 23, 2022
  14. modified the milestones: , 6.5.0 on Jun 25, 2022
  15. modified the milestones: 6.5.0, 6.6.0 on Jan 7, 2024
  16. joa-quim commented on Apr 6, 2024

    @joa-quim
    Member

    What is the status of this? Mane related changes have been committed meanwhile.

  17. seisman commented on Apr 6, 2024

    @seisman
    MemberAuthor

    I'll find some time to check it.

  18. self-assigned this
    on Apr 6, 2024
  19. joa-quim commented on Jun 9, 2025

    @joa-quim
    Member

    Ping?

  20. joa-quim commented on May 8, 2026

    @joa-quim
    Member

    Another ping

  21. seisman commented on May 8, 2026

    @seisman
    MemberAuthor

    Still fail with the master branch, for Q123/0/15c and Q180/0/15c

  22. joa-quim commented on May 8, 2026

    @joa-quim
    Member

    A CLI example?

  23. seisman commented on May 9, 2026

    @seisman
    MemberAuthor

    The bug only exists when passing virtual files from wrappers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions