def test_atol_rtol(self): """Test the atol and rtol functions.""" org = cfdm.RTOL() self.assertEqual(cfdm.RTOL(1e-5), org) self.assertEqual(cfdm.RTOL(), 1e-5) self.assertEqual(cfdm.RTOL(org), 1e-5) self.assertEqual(cfdm.RTOL(), org) org = cfdm.ATOL() self.assertEqual(cfdm.ATOL(1e-5), org) self.assertEqual(cfdm.ATOL(), 1e-5) self.assertEqual(cfdm.ATOL(org), 1e-5) self.assertEqual(cfdm.ATOL(), org) org = cfdm.atol() self.assertTrue(org == cfdm.ATOL()) # check alias self.assertTrue(cfdm.atol(1e-5) == org) self.assertTrue(cfdm.atol() == 1e-5) self.assertTrue(cfdm.atol(org) == 1e-5) self.assertTrue(cfdm.atol() == org)
def test_atol_rtol(self): """TODO DOCS.""" org = cfdm.RTOL() self.assertEqual(cfdm.RTOL(1e-5), org) self.assertEqual(cfdm.RTOL(), 1e-5) self.assertEqual(cfdm.RTOL(org), 1e-5) self.assertEqual(cfdm.RTOL(), org) org = cfdm.ATOL() self.assertEqual(cfdm.ATOL(1e-5), org) self.assertEqual(cfdm.ATOL(), 1e-5) self.assertEqual(cfdm.ATOL(org), 1e-5) self.assertEqual(cfdm.ATOL(), org) org = cfdm.atol() self.assertTrue(org == cfdm.ATOL()) # check alias self.assertTrue(cfdm.atol(1e-5) == org) self.assertTrue(cfdm.atol() == 1e-5) self.assertTrue(cfdm.atol(org) == 1e-5) self.assertTrue(cfdm.atol() == org)
def test_atol_rtol(self): if self.test_only and inspect.stack()[0][3] not in self.test_only: return org = cfdm.RTOL() self.assertEqual(cfdm.RTOL(1e-5), org) self.assertEqual(cfdm.RTOL(), 1e-5) self.assertEqual(cfdm.RTOL(org), 1e-5) self.assertEqual(cfdm.RTOL(), org) org = cfdm.ATOL() self.assertEqual(cfdm.ATOL(1e-5), org) self.assertEqual(cfdm.ATOL(), 1e-5) self.assertEqual(cfdm.ATOL(org), 1e-5) self.assertEqual(cfdm.ATOL(), org) org = cfdm.atol() self.assertTrue(org == cfdm.ATOL()) # check alias self.assertTrue(cfdm.atol(1e-5) == org) self.assertTrue(cfdm.atol() == 1e-5) self.assertTrue(cfdm.atol(org) == 1e-5) self.assertTrue(cfdm.atol() == org)
def test_Constant(self): """Test the Constant class.""" c = cfdm.Constant(20) d = cfdm.Constant(10) e = cfdm.Constant(999) self.assertIsInstance(hash(c), int) self.assertIsInstance(repr(c), str) self.assertEqual(float(c), 20.0) self.assertEqual(int(c), 20) self.assertEqual(str(c), "20") # Binary operations self.assertEqual(c, 20) self.assertEqual(20, c) self.assertEqual(c, c) self.assertEqual(c, copy.deepcopy(c)) self.assertEqual(c, numpy.array(20)) self.assertNotEqual(c, 999) self.assertNotEqual(999, c) self.assertNotEqual(c, d) self.assertNotEqual(c, numpy.array(999)) self.assertNotEqual(numpy.array(999), c) self.assertLess(c, 999) self.assertLessEqual(c, 999) self.assertGreater(c, 10) self.assertGreaterEqual(c, 10) self.assertGreater(999, c) self.assertGreaterEqual(999, c) self.assertLess(10, c) self.assertLessEqual(10, c) self.assertLess(c, e) self.assertLessEqual(c, e) self.assertGreater(c, d) self.assertGreaterEqual(c, d) self.assertEqual(c + 10, 30) self.assertEqual(c - 10, 10) self.assertEqual(c / 10, 2) self.assertEqual(c * 10, 200) self.assertEqual(c // 10, 2) self.assertEqual(c + d, 30) self.assertEqual(c - d, 10) self.assertEqual(c / d, 2) self.assertEqual(c * d, 200) self.assertEqual(c // d, 2) self.assertEqual(20 + d, 30) self.assertEqual(20 - d, 10) self.assertEqual(20 / d, 2) self.assertEqual(20 * d, 200) self.assertEqual(20 // d, 2) c = cfdm.Constant(20) c -= 10 self.assertEqual(c, 10) c += 10 self.assertEqual(c, 20) c *= 10 self.assertEqual(c, 200) c /= 10 self.assertEqual(c, 20) c //= 10 self.assertEqual(c, 2) # Unary operations c = cfdm.Constant(-20) self.assertEqual(-c, 20) self.assertEqual(abs(c), 20) self.assertEqual(+c, -20) # Copy c = cfdm.atol().copy() del c._func self.assertEqual(c, c.copy()) # Bool self.assertTrue(cfdm.Constant(1)) self.assertTrue(cfdm.Constant(True)) self.assertFalse(cfdm.Constant(0)) self.assertFalse(cfdm.Constant(False))
u.data[0, 0, 0] t.data[0, 0, 0] key = u.construct_key("grid_latitude") u.del_construct(key) u.constructs("grid_latitude") t.constructs("grid_latitude") import copy u = copy.deepcopy(t) orog = t.constructs("surface_altitude").value().copy() t.equals(t) t.equals(t.copy()) t.equals(t[...]) t.equals(q) t.equals(q, verbose=True) cfdm.atol() cfdm.rtol() original = cfdm.rtol(0.00001) cfdm.rtol() cfdm.rtol(original) cfdm.rtol() orog = t.constructs("surface_altitude").value() orog.equals(orog.copy()) print("\n**NetCDF interface**\n") print(t.constructs.filter_by_ncvar("b")) t.constructs("ncvar%x").value() t.constructs("ncdim%x") q.nc_get_variable() q.nc_global_attributes()
u = t.copy() u.data[0, 0, 0] = -1e30 u.data[0, 0, 0] t.data[0, 0, 0] u.del_construct('grid_latitude') u.constructs('grid_latitude') t.constructs('grid_latitude') import copy u = copy.deepcopy(t) orog = t.constructs('surface_altitude').value().copy() t.equals(t) t.equals(t.copy()) t.equals(t[...]) t.equals(q) t.equals(q, verbose=True) print(cfdm.atol()) print(cfdm.rtol()) original = cfdm.rtol(0.00001) print(cfdm.rtol()) print(cfdm.rtol(original)) print(cfdm.rtol()) print(cfdm.atol()) with cfdm.atol(1e-5): print(cfdm.atol()) print(cfdm.atol()) orog = t.constructs('surface_altitude').value() orog.equals(orog.copy()) print(t.constructs.filter_by_ncvar('b')) t.constructs('ncvar%x').value() t.constructs('ncdim%x') q.nc_get_variable()