def startCheckESMP(self): ''' Calls ESMP.ESMP_Initialize and registers stopESMP with atexit when called the first time. Subsequent calls only return whether or not ESMP is initialized. Registering stopESMP with atexit ensures the ESMP.ESMP_Finalize will always be called prior to exiting Python. Arguments: None Returns: True - if ESMP_Initialize has been called, either as a result of this call or from a previous call False - if stopESMP has called ESMP_Finalize ''' # Return False if attempting to re-initialize if self.__esmp_finalized: return False # Call ESMP_Initialize if not already done previously if not self.__esmp_initialized: ESMP.ESMP_Initialize() atexit.register(self.stopESMP) self.__esmp_initialized = True # Return True if ESMP_Intialize had already or has now been called return True
verbose=True, diag=diag) print cltInterp.sum() n = reduce(lambda x, y: x * y, cltInterp.shape) self.assertLess(abs(cltInterp.sum() - 696921.0) / n, 0.3) if PLOT: pylab.pcolor(ta.getLongitude()[:], ta.getLatitude()[:], cltInterp) pylab.colorbar() pylab.title('cltInterp') self.assertEqual(True, True) def test2_mkCyclic(self): import regrid2 y = numpy.array([-90.0 + i * 30.0 for i in range(7)]) x = numpy.array([(i + 0.5) * 60.0 for i in range(6)]) yy = regrid2.gsRegrid.getTensorProduct(y, 0, [len(y), len(x)]) xx = regrid2.gsRegrid.getTensorProduct(x, 1, [len(y), len(x)]) coords = [yy, xx] dims = [len(y), len(x)] newCoords, newDims = regrid2.gsRegrid.makeCoordsCyclic(coords, dims) self.assertEqual(newDims[-1], dims[-1] + 1) if __name__ == '__main__': print "" # Spacer ESMP.ESMP_Initialize() suite = unittest.TestLoader().loadTestsFromTestCase(TestTasRegrid) unittest.TextTestRunner(verbosity=1).run(suite) if PLOT: pylab.show()
from tvariable import asVariable, createVariable, isVariable from mvSphereMesh import SphereMesh from mvBaseWriter import BaseWriter from mvVsWriter import VsWriter from mvVTKSGWriter import VTKSGWriter from mvVTKUGWriter import VTKUGWriter from mvCdmsRegrid import CdmsRegrid # Gridspec is not installed by default so just pass on if it isn't installed try: from gsStaticVariable import StaticFileVariable from gsTimeVariable import TimeFileVariable except: pass from restApi import esgfConnection, esgfDataset, FacetConnection MV = MV2 ESMP_HAS_BEEN_INITIALIZED = False if not ESMP_HAS_BEEN_INITIALIZED: try: import ESMP ESMP.ESMP_Initialize(ESMP.ESMP_LOGKIND_NONE) # this turns off the PET file logs ESMP.ESMP_LogSet(False) ESMP_HAS_BEEN_INITIALIZED = True except: pass
def test_test2(self): ESMP.ESMP_Initialize() g = ESMP.ESMP_GridCreateNoPeriDim( numpy.array([3, 4], dtype=numpy.int32))
ESMP.ESMP_LogSet(True) class TestGrid(unittest.TestCase): def setUp(self): dir = cdat_info.get_prefix() + "/sample_data/" filename = dir + "so_Omon_MPI-ESM-LR_1pctCO2_r1i1p1_185001-185912_2timesteps.nc" g = cdms2.open(filename) self.so = g('so')[0,0,:,:254] gLat = cdms2.createGaussianAxis(64) deltaLon = (360/128.) gLon = cdms2.createUniformLongitudeAxis(0, 128, deltaLon) self.gaussGrid = cdms2.grid.createGenericGrid(gLat[:], gLon[:], gLat.getBounds(), gLon.getBounds()) def test1(self): soN = self.so.regrid(self.gaussGrid, rt = 'esmf', rm = 'conserve', coordSys = 'deg', periodicity = 1, fixSrcBounds=False) self.so.toVisit('MPI_so.vsh5','Vs') soN.toVisit('MPI_so_interp.vsh5', 'Vs') if __name__ == '__main__': ESMP.ESMP_Initialize(logkind = ESMP.ESMP_LOGKIND_NONE) #ESMP.ESMP_LogSet(False) print "" suite = unittest.TestLoader().loadTestsFromTestCase(TestGrid) unittest.TextTestRunner(verbosity = 2).run(suite)
def __init__(self): global INIT_REF_COUNT if INIT_REF_COUNT == 0: print 'calling ESMP.ESMP_Initialize()...' ESMP.ESMP_Initialize() INIT_REF_COUNT += 1
def test1_pairedInitializeFinalize(self): ESMP.ESMP_Initialize() ESMP.ESMP_Finalize()
def test5_noFinalize(self): ESMP.ESMP_Initialize()
def test4_multipleFinalize(self): ESMP.ESMP_Initialize() ESMP.ESMP_Finalize() ESMP.ESMP_Finalize()
def test3_multitpleInitialize(self): ESMP.ESMP_Initialize() ESMP.ESMP_Initialize() ESMP.ESMP_Finalize()