def test4_cdmsRegrid(self): srcF = cdms2.open(cdat_info.get_prefix() + \ '/sample_data/so_Omon_ACCESS1-0_historical_r1i1p1_185001-185412_2timesteps.nc') so = srcF('so')[0, 0, ...] srcGridMask = numpy.array((so == so.missing_value), numpy.int32) clt = cdms2.open(cdat_info.get_prefix() + '/sample_data/clt.nc')('clt') # create regrid object r = cdms2.CdmsRegrid(so.getGrid(), clt.getGrid(), dtype=so.dtype, regridMethod='conserve', regridTool='esmf', srcGridMask=srcGridMask, srcGridAreas=None, dstGridMask=None, dstGridAreas=None) dstData = r(so) # checks if self.pe == 0: dstDataMask = (dstData == so.missing_value) print 'number of masked values = ', dstDataMask.sum() self.assertTrue(str(type(dstData)), str(type(clt))) dstData.mask = (dstData == so.missing_value) dstDataMin = dstData.min() dstDataMax = dstData.max() zeroValCnt = (dstData == 0).sum() print 'Number of zero valued cells', zeroValCnt print 'min/max value of dstData: %f %f' % (dstDataMin, dstDataMax) self.assertLess(dstDataMax, so.max())
def test4_cdmsRegrid(self): srcF = cdms2.open(sys.prefix + \ '/sample_data/so_Omon_ACCESS1-0_historical_r1i1p1_185001-185412_2timesteps.nc') so = srcF('so')[0, 0, ...] clt = cdms2.open(sys.prefix + '/sample_data/clt.nc')('clt') # create regrid object r = cdms2.CdmsRegrid(so.getGrid(), clt.getGrid(), so.dtype, regridMethod='linear', regridTool='libcf', srcGridMask=(so == so.missing_value), srcGridAreas=None, dstGridMask=None, dstGridAreas=None, mkCyclic=False, handleCut=False) dstData = r(so) # checks dstDataMask = (dstData == so.missing_value) dstDataFltd = dstData * (1 - dstDataMask) if so.missing_value > 0: dstDataMin = dstData.min() dstDataMax = dstDataFltd.max() else: dstDataMin = dstDataFltd.min() dstDataMax = dstData.max() print 'min/max value of dstData: %f %f' % (dstDataMin, dstDataMax) self.assertGreater(dstDataMin, so.min()) self.assertLess(dstDataMax, so.max())
def test3_5x7_to_3x4(self): # Test double grid resolution original grid resolution # Just the corner is one valued roESMP = cdms2.CdmsRegrid(self.fromGrid5x7, self.toGrid3x4, dtype = self.data5x7.dtype, srcMask = self.data5x7.mask, periodicity = 0, regridTool = 'ESMP', coordSys = 'carT') ESMP3x4 = roESMP(self.data5x7) self.assertEqual(self.data5x7[0,0], ESMP3x4[0,0]) self.assertEqual(0.,ESMP3x4[1,1])
def test2_3x4_to_5x7(self): # Test NonPeriodic grid Returning double grid resolution roESMP = cdms2.CdmsRegrid(self.fromGrid3x4, self.toGrid5x7, dtype = self.data3x4.dtype, srcMask = self.data3x4.mask, periodicity = 0, regridTool = 'ESMP', coordSys = 'cart') ESMP5x7 = roESMP(self.data3x4) self.assertEqual(self.data3x4[0,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 roESMP = cdms2.CdmsRegrid(self.fromGrid3x4, self.toGrid3x4, dtype = self.data3x4.dtype, srcGridMask = self.data3x4.mask, regridTool = 'ESMP', coordSys = 'CART') ESMP3x4 = roESMP(self.data3x4) self.assertEqual(self.data3x4[0,0], ESMP3x4[0,0]) self.assertEqual(1.0, ESMP3x4[0,0]) self.assertEqual(0.0, self.data3x4[1,1])
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 roESMP = cdms2.CdmsRegrid(self.fromGrid5x7, self.toGrid3x4, dtype = self.data5x7.dtype, srcMask = self.data5x7.mask, periodicity = 0, regridTool = 'ESMP') ESMP3x4 = roESMP(self.data5x7) self.assertEqual(self.data5x7[0,0], ESMP3x4[0,0]) self.assertEqual(self.data5x7[0,0], 1.0) self.assertEqual(ESMP3x4[0,0] ,1.0)