forked from NCAS-CMS/cf-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_RegridOperator.py
More file actions
64 lines (53 loc) · 2.26 KB
/
Copy pathtest_RegridOperator.py
File metadata and controls
64 lines (53 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import datetime
import faulthandler
from importlib.util import find_spec
import unittest
faulthandler.enable() # to debug seg faults and timeouts
import cf
# ESMF renamed its Python module to `esmpy` at ESMF version 8.4.0. Allow
# either for now for backwards compatibility.
esmpy_imported = False
# Note: here only need esmpy for cf under-the-hood code, not in test
# directly, so no need to actually import esmpy, just test it is there.
if find_spec("esmpy") or find_spec("ESMF"):
esmpy_imported = True
class RegridOperatorTest(unittest.TestCase):
def setUp(self):
src = cf.example_field(0)
dst = cf.example_field(1)
self.r = src.regrids(dst, "linear", return_operator=True)
@unittest.skipUnless(esmpy_imported, "Requires esmpy/ESMF package.")
def test_RegridOperator_attributes(self):
self.assertEqual(self.r.coord_sys, "spherical")
self.assertEqual(self.r.method, "linear")
self.assertEqual(self.r.dimensionality, 2)
self.assertEqual(self.r.start_index, 1)
self.assertTrue(self.r.src_cyclic)
self.assertFalse(self.r.dst_cyclic)
self.assertEqual(len(self.r.src_shape), 2)
self.assertEqual(len(self.r.dst_shape), 2)
self.assertEqual(len(self.r.src_coords), 2)
self.assertEqual(len(self.r.src_bounds), 0)
self.assertIsNone(self.r.src_axes)
self.assertIsNone(self.r.dst_axes)
self.assertIsNone(self.r.src_mask)
self.assertIsNone(self.r.dst_mask)
self.assertEqual(self.r.weights.ndim, 2)
self.assertIsNone(self.r.row)
self.assertIsNone(self.r.col)
self.assertIsNone(self.r.weights_file)
self.assertFalse(self.r.src_mesh_location)
self.assertFalse(self.r.dst_mesh_location)
self.assertFalse(self.r.src_featureType)
self.assertFalse(self.r.dst_featureType)
self.assertIsNone(self.r.src_z)
self.assertIsNone(self.r.dst_z)
self.assertFalse(self.r.ln_z)
@unittest.skipUnless(esmpy_imported, "Requires esmpy/ESMF package.")
def test_RegridOperator_copy(self):
self.assertIsInstance(self.r.copy(), self.r.__class__)
if __name__ == "__main__":
print("Run date:", datetime.datetime.now())
cf.environment()
print()
unittest.main(verbosity=2)