|
25 | 25 | except ImportError:
|
26 | 26 | pass
|
27 | 27 |
|
28 |
| -disallowed_methods = ( |
29 |
| - "conservative", |
30 |
| - "conservative_2nd", |
31 |
| - "nearest_dtos", |
32 |
| -) |
33 |
| - |
34 | 28 | methods = (
|
35 | 29 | "linear",
|
36 | 30 | "nearest_stod",
|
@@ -169,6 +163,78 @@ def test_Field_regrid_grid_to_featureType_3d(self):
|
169 | 163 | else:
|
170 | 164 | self.assertFalse(y.mask.any())
|
171 | 165 |
|
| 166 | + @unittest.skipUnless(esmpy_imported, "Requires esmpy/ESMF package.") |
| 167 | + def test_Field_regrid_featureType_to_grid_2d(self): |
| 168 | + self.assertFalse(cf.regrid_logging()) |
| 169 | + |
| 170 | + # Create some nice data |
| 171 | + src = self.dst_featureType |
| 172 | + src.del_construct("cellmethod0") |
| 173 | + src = src[:12] |
| 174 | + src[...] = 273 + np.arange(12) |
| 175 | + x = src.coord("X") |
| 176 | + x[...] = [4, 6, 9, 11, 14, 16, 4, 6, 9, 11, 14, 16] |
| 177 | + y = src.coord("Y") |
| 178 | + y[...] = [41, 41, 31, 31, 21, 21, 39, 39, 29, 29, 19, 19] |
| 179 | + |
| 180 | + dst = self.src_grid.copy() |
| 181 | + x = dst.coord("X") |
| 182 | + x[...] = [5, 10, 15, 20] |
| 183 | + y = dst.coord("Y") |
| 184 | + y[...] = [10, 20, 30, 40] |
| 185 | + |
| 186 | + # Mask some destination grid points |
| 187 | + dst[0, 0, 1, 2] = cf.masked |
| 188 | + |
| 189 | + # Expected destination regridded values |
| 190 | + y0 = np.ma.array( |
| 191 | + [[0, 0, 0, 0], [0, 0, 1122, 0], [0, 1114, 0, 0], [1106, 0, 0, 0]], |
| 192 | + mask=[ |
| 193 | + [True, True, True, True], |
| 194 | + [True, True, False, True], |
| 195 | + [True, False, True, True], |
| 196 | + [False, True, True, True], |
| 197 | + ], |
| 198 | + ) |
| 199 | + |
| 200 | + for src_masked in (False, True): |
| 201 | + y = y0.copy() |
| 202 | + if src_masked: |
| 203 | + src = src.copy() |
| 204 | + src[6:8] = cf.masked |
| 205 | + # This following element should be smaller, because it |
| 206 | + # now only has two source cells contributing to it, |
| 207 | + # rather than four. |
| 208 | + y[3, 0] = 547 |
| 209 | + |
| 210 | + # Loop over whether or not to use the destination grid |
| 211 | + # masked points |
| 212 | + for use_dst_mask in (False, True): |
| 213 | + if use_dst_mask: |
| 214 | + y = y.copy() |
| 215 | + y[1, 2] = np.ma.masked |
| 216 | + |
| 217 | + kwargs = {"use_dst_mask": use_dst_mask} |
| 218 | + method = "nearest_dtos" |
| 219 | + for return_operator in (False, True): |
| 220 | + if return_operator: |
| 221 | + r = src.regrids( |
| 222 | + dst, method=method, return_operator=True, **kwargs |
| 223 | + ) |
| 224 | + x = src.regrids(r) |
| 225 | + else: |
| 226 | + x = src.regrids(dst, method=method, **kwargs) |
| 227 | + |
| 228 | + a = x.array |
| 229 | + |
| 230 | + self.assertEqual(y.size, a.size) |
| 231 | + self.assertTrue(np.allclose(y, a, atol=atol, rtol=rtol)) |
| 232 | + |
| 233 | + if isinstance(a, np.ma.MaskedArray): |
| 234 | + self.assertTrue((y.mask == a.mask).all()) |
| 235 | + else: |
| 236 | + self.assertFalse(y.mask.any()) |
| 237 | + |
172 | 238 | @unittest.skipUnless(esmpy_imported, "Requires esmpy/ESMF package.")
|
173 | 239 | def test_Field_regrid_grid_to_featureType_2d(self):
|
174 | 240 | self.assertFalse(cf.regrid_logging())
|
@@ -196,7 +262,6 @@ def test_Field_regrid_grid_to_featureType_2d(self):
|
196 | 262 | a = x.array
|
197 | 263 |
|
198 | 264 | y = esmpy_regrid(coord_sys, method, src, dst, **kwargs)
|
199 |
| - |
200 | 265 | self.assertEqual(y.size, a.size)
|
201 | 266 | self.assertTrue(np.allclose(y, a, atol=atol, rtol=rtol))
|
202 | 267 |
|
@@ -259,7 +324,7 @@ def test_Field_regrid_featureType_bad_methods(self):
|
259 | 324 | dst = self.dst_featureType.copy()
|
260 | 325 | src = self.src_grid.copy()
|
261 | 326 |
|
262 |
| - for method in disallowed_methods: |
| 327 | + for method in ("conservative", "conservative_2nd"): |
263 | 328 | with self.assertRaises(ValueError):
|
264 | 329 | src.regrids(dst, method=method)
|
265 | 330 |
|
|
0 commit comments