|
4 | 4 |
|
5 | 5 | from pathlib import Path
|
6 | 6 |
|
| 7 | +import numpy as np |
| 8 | +import numpy.testing as npt |
7 | 9 | import pytest
|
8 | 10 | import xarray as xr
|
9 | 11 | from pygmt import grdclip, load_dataarray
|
| 12 | +from pygmt.datasets import load_earth_mask |
10 | 13 | from pygmt.enums import GridRegistration, GridType
|
11 | 14 | from pygmt.helpers import GMTTempFile
|
12 | 15 | from pygmt.helpers.testing import load_static_earth_relief
|
@@ -69,3 +72,19 @@ def test_grdclip_no_outgrid(grid, expected_grid):
|
69 | 72 | assert temp_grid.gmt.gtype == GridType.GEOGRAPHIC
|
70 | 73 | assert temp_grid.gmt.registration == GridRegistration.PIXEL
|
71 | 74 | xr.testing.assert_allclose(a=temp_grid, b=expected_grid)
|
| 75 | + |
| 76 | + |
| 77 | +def test_grdclip_replace(): |
| 78 | + """ |
| 79 | + Test the replace parameter for grdclip. |
| 80 | + """ |
| 81 | + grid = load_earth_mask(region=[0, 10, 0, 10]) |
| 82 | + npt.assert_array_equal(np.unique(grid), [0, 1]) # Only have 0 and 1 |
| 83 | + grid = grdclip(grid=grid, replace=[0, 2]) # Replace 0 with 2 |
| 84 | + npt.assert_array_equal(np.unique(grid), [1, 2]) |
| 85 | + |
| 86 | + # Test for the deprecated 'new' parameter |
| 87 | + # TODO(PyGMT>=0.19.0): Remove this test below for the 'new' parameter |
| 88 | + with pytest.warns(FutureWarning): |
| 89 | + grid = grdclip(grid=grid, new=[1, 3]) # Replace 1 with 3 |
| 90 | + npt.assert_array_equal(np.unique(grid), [2, 3]) |
0 commit comments