|
1 | 1 | """Unit tests for :mod:`esmf_regrid.experimental.partition`.""" |
2 | 2 |
|
3 | 3 | import dask.array as da |
| 4 | +import esmpy |
4 | 5 | import numpy as np |
5 | 6 | import pytest |
6 | 7 |
|
7 | | -from esmf_regrid import ESMFAreaWeighted, ESMFNearest |
| 8 | +from esmf_regrid import ESMFAreaWeighted, ESMFBilinear, ESMFNearest |
8 | 9 | from esmf_regrid.experimental.partition import Partition |
9 | 10 | from esmf_regrid.tests.unit.schemes.test__cube_to_GridInfo import ( |
10 | 11 | _curvilinear_cube, |
@@ -155,6 +156,32 @@ def test_Partition_curv_src(tmp_path): |
155 | 156 | assert result == expected |
156 | 157 |
|
157 | 158 |
|
| 159 | +def test_Partition_bilinear(tmp_path): |
| 160 | + """Test Partition class for bilinear regridding.""" |
| 161 | + src = _grid_cube(150, 500, (-180, 180), (-90, 90), circular=True) |
| 162 | + src.data = np.arange(150 * 500).reshape([500, 150]) |
| 163 | + tgt = _grid_cube(16, 36, (-180, 180), (-90, 90), circular=True) |
| 164 | + |
| 165 | + files = [tmp_path / f"partial_{x}.nc" for x in range(5)] |
| 166 | + src_chunks = (100, 150) |
| 167 | + |
| 168 | + bad_scheme = ESMFBilinear() |
| 169 | + with pytest.raises(ValueError): |
| 170 | + _ = Partition(src, tgt, bad_scheme, files, src_chunks=src_chunks) |
| 171 | + |
| 172 | + # The pole_method must be NONE for bilinear regridding partitions to work. |
| 173 | + scheme = ESMFBilinear(esmf_args={"pole_method": esmpy.PoleMethod.NONE}) |
| 174 | + |
| 175 | + partition = Partition(src, tgt, scheme, files, src_chunks=src_chunks) |
| 176 | + |
| 177 | + partition.generate_files() |
| 178 | + |
| 179 | + result = partition.apply_regridders(src) |
| 180 | + expected = src.regrid(tgt, scheme) |
| 181 | + assert np.allclose(result.data, expected.data) |
| 182 | + assert result == expected |
| 183 | + |
| 184 | + |
158 | 185 | def test_Partition_mesh_tgt(tmp_path): |
159 | 186 | """Test Partition class when the target has a mesh.""" |
160 | 187 | src = _grid_cube(150, 500, (-180, 180), (-90, 90), circular=True) |
|
0 commit comments