def test_Field_regridc(self): self.assertFalse(cf.regrid_logging()) with cf.atol(1e-11): for chunksize in self.chunk_sizes: self.assertFalse(cf.regrid_logging()) with cf.chunksize(chunksize): f1 = cf.read(self.filename7)[0] f2 = cf.read(self.filename8)[0] f3 = cf.read(self.filename9)[0] self.assertTrue( f3.equals(f1.regridc(f2, axes="T", method="linear")), "destination=time series, CHUNKSIZE={}".format( chunksize ), ) f4 = cf.read(self.filename1)[0] f5 = cf.read(self.filename2)[0] f6 = cf.read(self.filename10)[0] self.assertTrue( f6.equals( f4.regridc( f5, axes=("X", "Y"), method="conservative" ) ), "destination=global Field, CHUNKSIZE={}".format( chunksize ), ) self.assertTrue( f6.equals( f4.regridc( f5, axes=("X", "Y"), method="conservative" ) ), "destination=global Field, CHUNKSIZE={}".format( chunksize ), ) dst = {"X": f5.dim("X"), "Y": f5.dim("Y")} self.assertTrue( f6.equals( f4.regridc( dst, axes=("X", "Y"), method="conservative" ) ), "destination=global dict, CHUNKSIZE={}".format( chunksize ), ) self.assertTrue( f6.equals( f4.regridc( dst, axes=("X", "Y"), method="conservative" ) ), "destination=global dict, CHUNKSIZE={}".format( chunksize ), )
def test_Field_regridc_operator(self): self.assertFalse(cf.regrid_logging()) with cf.atol(1e-12): f1 = cf.read(self.filename7)[0] f2 = cf.read(self.filename8)[0] f3 = cf.read(self.filename9)[0] f4 = cf.read(self.filename1)[0] f5 = cf.read(self.filename2)[0] f6 = cf.read(self.filename10)[0] op = f1.regridc(f2, axes="T", method="linear", return_operator=True) self.assertTrue(f3.equals(f1.regridc(op))) op = f4.regridc( f5, axes=("X", "Y"), method="conservative", return_operator=True, ) self.assertTrue(f6.equals(f4.regridc(op))) op = f4.regridc( f5, axes=("X", "Y"), method="conservative", return_operator=True, ) self.assertTrue(f6.equals(f4.regridc(op))) dst = { "X": f5.dimension_coordinate("X"), "Y": f5.dimension_coordinate("Y"), } op = f4.regridc( dst, axes=("X", "Y"), method="conservative", return_operator=True, ) self.assertTrue(f6.equals(f4.regridc(op))) self.assertTrue(f6.equals(f4.regridc(op))) # Raise exception when the source grid does not match that of # the regrid operator op = f1.regridc(f2, axes="T", method="linear", return_operator=True) with self.assertRaises(ValueError): f2.regrids(op)
def test_aliases(self): self.assertEqual(cf.log_level(), cf.LOG_LEVEL()) self.assertEqual(cf.free_memory(), cf.FREE_MEMORY()) self.assertEqual(cf.free_memory_factor(), cf.FREE_MEMORY_FACTOR()) self.assertEqual(cf.fm_threshold(), cf.FM_THRESHOLD()) self.assertEqual(cf.total_memory(), cf.TOTAL_MEMORY()) self.assertEqual(cf.regrid_logging(), cf.REGRID_LOGGING()) self.assertEqual(cf.relaxed_identities(), cf.RELAXED_IDENTITIES()) self.assertEqual(cf.tempdir(), cf.TEMPDIR()) self.assertEqual(cf.chunksize(), cf.CHUNKSIZE()) self.assertEqual(cf.set_performance(), cf.SET_PERFORMANCE()) self.assertEqual(cf.of_fraction(), cf.OF_FRACTION()) self.assertEqual(cf.collapse_parallel_mode(), cf.COLLAPSE_PARALLEL_MODE())
def test_Field_regrids(self): self.assertFalse(cf.regrid_logging()) with cf.atol(1e-12): for chunksize in self.chunk_sizes: with cf.chunksize(chunksize): f1 = cf.read(self.filename1)[0] f2 = cf.read(self.filename2)[0] f3 = cf.read(self.filename3)[0] f4 = cf.read(self.filename4)[0] f5 = cf.read(self.filename5)[0] r = f1.regrids(f2, "conservative") self.assertTrue( f3.equals(r), "destination=global Field, CHUNKSIZE={}".format( chunksize ), ) dst = {"longitude": f2.dim("X"), "latitude": f2.dim("Y")} r = f1.regrids(dst, "conservative", dst_cyclic=True) self.assertTrue( f3.equals(r), "destination=global dict, CHUNKSIZE={}".format( chunksize ), ) r = f1.regrids(dst, method="conservative", dst_cyclic=True) self.assertTrue( f3.equals(r), "destination=global dict, CHUNKSIZE={}".format( chunksize ), ) # Regrid global to regional roated pole r = f1.regrids(f5, method="linear") self.assertTrue( f4.equals(r, verbose=3), "destination=regional Field, CHUNKSIZE={}".format( chunksize ), ) f6 = cf.read(self.filename6)[0] with self.assertRaises(Exception): f1.regridc(f6, axes="T", method="linear")
def test_Field_regrids_operator(self): self.assertFalse(cf.regrid_logging()) with cf.atol(1e-12): f1 = cf.read(self.filename1)[0] f2 = cf.read(self.filename2)[0] f3 = cf.read(self.filename3)[0] f4 = cf.read(self.filename4)[0] f5 = cf.read(self.filename5)[0] op = f1.regrids(f2, "conservative", return_operator=True) r = f1.regrids(op) self.assertTrue(f3.equals(r)) # Repeat r = f1.regrids(op) self.assertTrue(f3.equals(r)) dst = {"longitude": f2.dim("X"), "latitude": f2.dim("Y")} op = f1.regrids(dst, "conservative", dst_cyclic=True, return_operator=True) r = f1.regrids(op) self.assertTrue(f3.equals(r)) op = f1.regrids( dst, method="conservative", dst_cyclic=True, return_operator=True, ) r = f1.regrids(op) self.assertTrue(f3.equals(r)) # Regrid global to regional rotated pole op = f1.regrids(f5, method="linear", return_operator=True) r = f1.regrids(op) self.assertTrue(f4.equals(r)) # Raise exception when the source grid does not match that of # the regrid operator op = f1.regrids(f2, "conservative", return_operator=True) with self.assertRaises(ValueError): f2.regrids(op)
def test_Field_regrid_size1_dimensions(self): # Check that non-regridded size 1 axes are handled OK self.assertFalse(cf.regrid_logging()) f = cf.example_field(0) shape = f.shape g = f.regrids(f, method="linear") self.assertEqual(g.shape, (shape)) g = f.regridc(f, method="linear", axes="X") self.assertEqual(g.shape, (shape)) f.insert_dimension("T", position=0, inplace=True) shape = f.shape g = f.regrids(f, method="linear") self.assertEqual(g.shape, shape) g = f.regridc(f, method="linear", axes="X") self.assertEqual(g.shape, shape)
def test_Field_regrids(self): if self.test_only and inspect.stack()[0][3] not in self.test_only: return self.assertFalse(cf.regrid_logging()) with cf.atol(1e-12): for chunksize in self.chunk_sizes: with cf.chunksize(chunksize): f1 = cf.read(self.filename1)[0] f2 = cf.read(self.filename2)[0] f3 = cf.read(self.filename3)[0] r = f1.regrids(f2, "conservative") self.assertTrue( f3.equals(r), "destination=global Field, CHUNKSIZE={}".format( chunksize), ) r = f1.regrids(f2, method="conservative") self.assertTrue( f3.equals(r), "destination=global Field, CHUNKSIZE={}".format( chunksize), ) dst = {"longitude": f2.dim("X"), "latitude": f2.dim("Y")} r = f1.regrids(dst, "conservative", dst_cyclic=True) self.assertTrue( f3.equals(r), "destination=global dict, CHUNKSIZE={}".format( chunksize), ) r = f1.regrids(dst, method="conservative", dst_cyclic=True) self.assertTrue( f3.equals(r), "destination=global dict, CHUNKSIZE={}".format( chunksize), ) f4 = cf.read(self.filename4)[0] f5 = cf.read(self.filename5)[0] r = f1.regrids(f5, "linear") self.assertTrue( f4.equals(r), "destination=regional Field, CHUNKSIZE={}".format( chunksize), ) r = f1.regrids(f5, method="linear") self.assertTrue( f4.equals(r), "destination=regional Field, CHUNKSIZE={}".format( chunksize), ) # --- End: for f6 = cf.read(self.filename6)[0] with self.assertRaises(Exception): f1.regridc(f6, axes="T", method="linear")