|
28 | 28 | disallowed_methods = (
|
29 | 29 | "conservative",
|
30 | 30 | "conservative_2nd",
|
31 |
| - "nearest_dtos", |
| 31 | + # "nearest_dtos", |
32 | 32 | )
|
33 | 33 |
|
34 | 34 | methods = (
|
@@ -161,6 +161,75 @@ def test_Field_regrid_grid_to_featureType_3d(self):
|
161 | 161 |
|
162 | 162 | y = esmpy_regrid(coord_sys, method, src, dst, **kwargs)
|
163 | 163 |
|
| 164 | + self.assertEqual(y.size, a.size) |
| 165 | + self.assertTrue(np.allclose(y, a, atol=4e-3, rtol=rtol)) |
| 166 | + |
| 167 | + if isinstance(a, np.ma.MaskedArray): |
| 168 | + self.assertTrue((y.mask == a.mask).all()) |
| 169 | + else: |
| 170 | + self.assertFalse(y.mask.any()) |
| 171 | + |
| 172 | + @unittest.skipUnless(esmpy_imported, "Requires esmpy/ESMF package.") |
| 173 | + def test_Field_regrid_featureType_to_grid_2d(self): |
| 174 | + self.assertFalse(cf.regrid_logging()) |
| 175 | + |
| 176 | + src = self.dst_featureType |
| 177 | + src.del_construct("cellmethod0") |
| 178 | + src = src[:12] |
| 179 | + src[...] = 273 + np.arange(12) |
| 180 | + x = src.coord("X") |
| 181 | + x[...] = [4, 6, 9, 11, 14, 16, 4, 6, 9, 11, 14, 16] |
| 182 | + y = src.coord("Y") |
| 183 | + y[...] = [41, 41, 31, 31, 21, 21, 39, 39, 29, 29, 19, 19] |
| 184 | + |
| 185 | + dst = self.src_grid.copy() |
| 186 | + x = dst.coord("X") |
| 187 | + x[...] = [5, 10, 15, 20] |
| 188 | + y = dst.coord("Y") |
| 189 | + y[...] = [10, 20, 30, 40] |
| 190 | + |
| 191 | + # Mask some destination grid points |
| 192 | + dst[0, 0, 1, 2] = cf.masked |
| 193 | + |
| 194 | + y0 = np.ma.array( |
| 195 | + [[0, 0, 0, 0], [0, 0, 1122, 0], [0, 1114, 0, 0], [1106, 0, 0, 0]], |
| 196 | + mask=[ |
| 197 | + [True, True, True, True], |
| 198 | + [True, True, False, True], |
| 199 | + [True, False, True, True], |
| 200 | + [False, True, True, True], |
| 201 | + ], |
| 202 | + ) |
| 203 | + |
| 204 | + coord_sys = "spherical" |
| 205 | + |
| 206 | + for src_masked in (False, True): |
| 207 | + y = y0.copy() |
| 208 | + if src_masked: |
| 209 | + src = src.copy() |
| 210 | + src[6:8] = cf.masked |
| 211 | + y[3, 0] = 547 |
| 212 | + |
| 213 | + # Loop over whether or not to use the destination grid |
| 214 | + # masked points |
| 215 | + for use_dst_mask in (False, True): |
| 216 | + if use_dst_mask: |
| 217 | + y = y.copy() |
| 218 | + y[1, 2] = np.ma.masked |
| 219 | + |
| 220 | + kwargs = {"use_dst_mask": use_dst_mask} |
| 221 | + method = "nearest_dtos" |
| 222 | + for return_operator in (False, True): |
| 223 | + if return_operator: |
| 224 | + r = src.regrids( |
| 225 | + dst, method=method, return_operator=True, **kwargs |
| 226 | + ) |
| 227 | + x = src.regrids(r) |
| 228 | + else: |
| 229 | + x = src.regrids(dst, method=method, **kwargs) |
| 230 | + |
| 231 | + a = x.array |
| 232 | + |
164 | 233 | self.assertEqual(y.size, a.size)
|
165 | 234 | self.assertTrue(np.allclose(y, a, atol=atol, rtol=rtol))
|
166 | 235 |
|
@@ -196,7 +265,6 @@ def test_Field_regrid_grid_to_featureType_2d(self):
|
196 | 265 | a = x.array
|
197 | 266 |
|
198 | 267 | y = esmpy_regrid(coord_sys, method, src, dst, **kwargs)
|
199 |
| - |
200 | 268 | self.assertEqual(y.size, a.size)
|
201 | 269 | self.assertTrue(np.allclose(y, a, atol=atol, rtol=rtol))
|
202 | 270 |
|
|
0 commit comments