def test2_3x4_to_5x7_cart(self): # Test non-periodic grid returning double grid resolution roESMP = CdmsRegrid(self.fromGrid3x4, self.toGrid5x7, dtype=self.data3x4.dtype, srcGridMask=self.data3x4.mask, regridTool='ESMP', periodicity=0, regridMethod='Conserve', coordSys='cart') diag = { 'srcAreas': 0, 'dstAreas': 0, 'srcAreaFractions': 0, 'dstAreaFractions': 0 } ESMP5x7 = roESMP(self.data3x4, diag=diag) dstMass = (ESMP5x7 * diag['dstAreas']).sum() srcMass = (self.data3x4 * diag['srcAreas'] \ * diag['srcAreaFractions']).sum() if PLOT: pylab.figure(1) pylab.pcolor(self.data3x4) pylab.colorbar() pylab.title('original self.data3x4') pylab.figure(2) pylab.pcolor(ESMP5x7) pylab.colorbar() pylab.title('interpolated ESMP5x7') self.assertLess(abs(srcMass - dstMass), self.eps) self.assertEqual(self.data3x4[0, 0], ESMP5x7[0, 0]) self.assertEqual(1.0, ESMP5x7[0, 0]) self.assertEqual(0.25, ESMP5x7[1, 1]) self.assertEqual(0.0, ESMP5x7[2, 2])
def test1_3x4_to_3x4(self): # Test non-periodic grid returning same grid roESMF = CdmsRegrid(self.fromGrid3x4, self.toGrid3x4, dtype='float64', srcGridMask=self.data3x4.mask, periodicity=0, regridTool='ESMF', regridMethod='Conserve', coordSys='cart') diag = { 'srcAreas': 0, 'dstAreas': 0, 'srcAreaFractions': 0, 'dstAreaFractions': 0 } ESMF3x4 = roESMF(self.data3x4, diag=diag) dstResult = (ESMF3x4 * diag['dstAreas']).sum() srcResult = (self.data3x4 * diag['srcAreas'] * diag['srcAreaFractions']).sum() self.assertLess(abs(srcResult - dstResult), self.eps) self.assertEqual(self.data3x4[0, 0], ESMF3x4[0, 0]) self.assertEqual(1.0, ESMF3x4[0, 0])
def test4_5x7_to_3x4_4Corner_Cells_equal_1(self): # Test double grid resolution original grid resolution. # Reset the data in 0:2, 0:2 to 1 self.data5x7[:2, :2] = 1 self.data5x7.mask[1, 1] = True roESMP = CdmsRegrid(self.fromGrid5x7, self.toGrid3x4, dtype=self.data5x7.dtype, srcGridMask=self.data5x7.mask, regridTool='ESMP', periodicity=0, regridMethod='Conserve', coordSys='cart') diag = { 'srcAreas': 0, 'dstAreas': 0, 'srcAreaFractions': 0, 'dstAreaFractions': 0 } ESMP3x4 = roESMP(self.data5x7, diag=diag) dstResult = (ESMP3x4 * diag['dstAreas']).sum() srcResult = (self.data5x7 * diag['srcAreas'] * \ diag['srcAreaFractions']).sum() self.assertLess(abs(srcResult - dstResult), self.eps) self.assertNotEqual(self.data5x7[0, 0], ESMP3x4[0, 0]) self.assertEqual(self.data5x7[0, 0], 1.0) self.assertEqual(ESMP3x4[0, 0], 0.5)
def test2_3x4_to_5x7_degr(self): # Test NonPeriodic grid Returning double grid resolution roESMF = CdmsRegrid(self.fromGrid3x4, self.toGrid5x7, dtype='float64', regridTool='ESMF', regridMethod='cOnserve', periodicity=0, coordSys='cart') diag = {'srcAreas': 0, 'dstAreas': 0, 'srcAreaFractions': 0, 'dstAreaFractions': 0} ESMF5x7 = roESMF(self.data3x4, diag=diag) dstResult = (ESMF5x7 * diag['dstAreas']).sum() srcResult = (self.data3x4 * diag['srcAreas'] * diag['srcAreaFractions']).sum() self.assertLess(abs(srcResult - dstResult), self.eps)
def test2_3x4_to_5x7_degr(self): # Test non-periodic grid returning double grid resolution roESMF = CdmsRegrid(self.fromGrid3x4, self.toGrid5x7, dtype='float64', srcGridMask=self.data3x4.mask, regridTool='ESMF', periodicity=0, regridMethod='Conserve', coordSys='degrees') diag = {'srcAreas': 0, 'dstAreas': 0, 'srcAreaFractions': 0, 'dstAreaFractions': 0} ESMF5x7 = roESMF(self.data3x4, diag=diag) dstMass = (ESMF5x7 * diag['dstAreas']).sum() srcMass = (self.data3x4 * diag['srcAreas'] * diag['srcAreaFractions']).sum() # self.assertLess(abs(srcMass - dstMass), self.eps) self.assertEqual(self.data3x4[0, 0], ESMF5x7[0, 0])
def test3_5x7_to_3x4(self): # Test double grid resolution original grid resolution # Just the corner is one valued roESMF = CdmsRegrid(self.fromGrid5x7, self.toGrid3x4, dtype='float64', regridTool='esmf', regridMethod='Conserve', periodicity=0, coordSys='degr') diag = { 'srcAreas': 0, 'dstAreas': 0, 'srcAreaFractions': 0, 'dstAreaFractions': 0} ESMF3x4 = roESMF(self.data5x7, diag=diag) dstResult = (ESMF3x4 * diag['dstAreas']).sum() srcResult = (self.data5x7 * diag['srcAreas'] * diag['srcAreaFractions']).sum() self.assertLess(abs(srcResult - dstResult), self.eps)
def test4_5x7_to_3x4_4Corner_Cells_equal_1(self): # Test double grid resolution original grid resolution. # Reset the data in 0:2, 0:2 to 1 self.data5x7[:2, :2] = 1 roESMF = CdmsRegrid(self.fromGrid5x7, self.toGrid3x4, dtype='float64', regridTool='esmp', regridMethod='Conserve', periodicity=0, coordSys='cart') diag = { 'srcAreas': 0, 'dstAreas': 0, 'srcAreaFractions': 0, 'dstAreaFractions': 0} ESMF3x4 = roESMF(self.data5x7, diag=diag) dstResult = (ESMF3x4 * diag['dstAreas']).sum() srcResult = (self.data5x7 * diag['srcAreas'] * diag['srcAreaFractions']).sum() self.assertLess(abs(srcResult - dstResult), self.eps)
def test1_3x4_to_3x4(self): for d in dir(unittest): if re.search('assert', d): print(d) # Test NonPeriodic grid Returning same grid roESMF = CdmsRegrid(self.fromGrid3x4, self.toGrid3x4, dtype='float64', regridTool='ESMF', regridMethod='Conserve', coordSys='degr') diag = { 'srcAreas': 0, 'dstAreas': 0, 'srcAreaFractions': 0, 'dstAreaFractions': 0} ESMF3x4 = roESMF(self.data3x4, diag=diag) dstResult = (ESMF3x4 * diag['dstAreas']).sum() srcResult = (self.data3x4 * diag['srcAreas'] * diag['srcAreaFractions']).sum() self.assertLess(abs(srcResult - dstResult), self.eps) self.assertEqual(self.data3x4[0, 0], ESMF3x4.data[0, 0]) self.assertEqual(1.0, ESMF3x4.data[0, 0])
def test3_5x7_to_3x4(self): # Test double grid resolution original grid resolution # Just the corner is one valued roESMP = CdmsRegrid(self.fromGrid5x7, self.toGrid3x4, dtype=self.data5x7.dtype, srcGridMask=self.data5x7.mask, regridTool='ESMP', periodicity=0, regridMethod='Conserve', coordSys='cart') diag = { 'srcAreas': 0, 'dstAreas': 0, 'srcAreaFractions': 0, 'dstAreaFractions': 0 } ESMP3x4 = roESMP(self.data5x7, diag=diag) dstResult = (ESMP3x4 * diag['dstAreas']).sum() srcResult = (self.data5x7 * diag['srcAreas'] * \ diag['srcAreaFractions']).sum() self.assertLess(abs(srcResult - dstResult), self.eps) self.assertNotEqual(self.data5x7[0, 0], ESMP3x4[0, 0]) self.assertLess(0.25 - ESMP3x4[0, 0], self.eps)
def test2_3x4_to_5x7_cart(self): # Test NonPeriodic grid Returning double grid resolution roESMP = CdmsRegrid(self.fromGrid3x4, self.toGrid5x7, dtype=self.data3x4.dtype, regridTool='ESMP', regridMethod='cOnserve', periodicity=0, coordSys='cart') diag = { 'srcAreas': 0, 'dstAreas': 0, 'srcAreaFractions': 0, 'dstAreaFractions': 0 } ESMP5x7 = roESMP(self.data3x4, diag=diag) dstResult = (ESMP5x7 * diag['dstAreas']).sum() srcResult = (self.data3x4 * diag['srcAreas'] * \ diag['srcAreaFractions']).sum() self.assertLess(abs(srcResult - dstResult), self.eps) self.assertEqual(self.data3x4[0, 0], ESMP5x7[0, 0]) self.assertEqual(1.0, ESMP5x7[0, 0]) self.assertLess(0.249, ESMP5x7[1, 1]) self.assertGreater(0.251, ESMP5x7[1, 1])