Skip to content

Conversation

@Chuan1937
Copy link
Contributor

@Chuan1937 Chuan1937 commented Oct 31, 2025

Unify grdsample for filenames and DataArray: load filenames via xarray GMT engine (fallback to path) and, when -T/-r aren’t set, infer registration with grdinfo to align -R/-I.
Don’t mutate DataArray registration, ensure -T isn’t combined with -r, and add a regression test confirming identical outputs for file vs DataArray.

Issues : #3337

Right example:

(base) chuan@DESKTOP-QF9C9FL:~/Code/pygmt$ python - << 'PY'
> import pygmt
> from pygmt.helpers.testing import load_static_earth_relief
> print('--- file input @static_earth_relief.nc ---')
> print(pygmt.grdsample("@static_earth_relief.nc", region=[-53,-47,-20, -15], spacing=[2, 1]))
> print('--- dataarray input (static) ---')
> grid = load_static_earth_relief()
> print(pygmt.grdsample(grid, region=[-53,-47,-20, -15], spacing=[2, 1]))
> PY
--- file input @static_earth_relief.nc ---
grdsample [WARNING]: Output sampling interval in x exceeds input interval and may lead to aliasing.
<xarray.DataArray 'z' (lat: 5, lon: 3)> Size: 60B
array([[460.84375, 482.78125, 891.09375],
       [680.46875, 519.09375, 764.9375 ],
       [867.75   , 579.03125, 852.53125],
       [551.75   , 666.6875 , 958.21875],
       [411.3125 , 518.4375 , 931.28125]], dtype=float32)
Coordinates:
  * lat      (lat) float64 40B -19.5 -18.5 -17.5 -16.5 -15.5
  * lon      (lon) float64 24B -52.0 -50.0 -48.0
Attributes:
    Conventions:   CF-1.7
    title:         
    history:       gmt grdsample @GMTAPI@-S-I-G-M-G-N-000000 -G@GMTAPI@-S-O-G...
    description:   
    actual_range:  [411.3125  958.21875]
    long_name:     z
--- dataarray input (static) ---
grdsample [WARNING]: Output sampling interval in x exceeds input interval and may lead to aliasing.
<xarray.DataArray 'z' (lat: 5, lon: 3)> Size: 60B
array([[460.84375, 482.78125, 891.09375],
       [680.46875, 519.09375, 764.9375 ],
       [867.75   , 579.03125, 852.53125],
       [551.75   , 666.6875 , 958.21875],
       [411.3125 , 518.4375 , 931.28125]], dtype=float32)
Coordinates:
  * lat      (lat) float64 40B -19.5 -18.5 -17.5 -16.5 -15.5
  * lon      (lon) float64 24B -52.0 -50.0 -48.0
Attributes:
    Conventions:   CF-1.7
    title:         
    history:       gmt grdsample @GMTAPI@-S-I-G-M-G-N-000000 -G@GMTAPI@-S-O-G...
    description:   
    actual_range:  [411.3125  958.21875]
    long_name:     z

@seisman
Copy link
Member

seisman commented Oct 31, 2025

@Chuan1937 First of all, thank you for contributing to the PyGMT project.

Before anyone spends time investigating the cause of issue #3337, could you please open a separate PR to add the translate and registration parameters? This will allow us to have a dedicated PR for the new parameters and keep this PR focused on fixing PR #3337.

@seisman seisman added the bug Something isn't working label Oct 31, 2025
@seisman
Copy link
Member

seisman commented Nov 1, 2025

This will allow us to have a dedicated PR for the new parameters and keep this PR focused on fixing PR #3337.

Sorry, I just realized that the grdsample method already has the translate/registration parameters, but they're still using the old alias system. Since translate and registration can't be used together, maybe we should just raise an error if both are used. This would be simplify the code logic a little bit. Again, I think it could be done in a separate PR to make this PR easier for review.

@Chuan1937
Copy link
Contributor Author

@seisman

@seisman seisman marked this pull request as draft November 6, 2025 03:29
@Chuan1937 Chuan1937 closed this Nov 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants