示例#1
0
    def __call__(self, _var, region):
        var = _var.clone()
        if not region in self.regions.keys():
            return None
        
        val = self.regions[region]
        # reading mask data
        regions_data = self.file['mask']
        regions_var  = cdms2.createVariable(
                         ones(regions_data.shape),
                         grid = cdms2.createUniformGrid(89.75, 360, -0.5, -180, 720, 0.5),
                         mask = where(equal(regions_data, val), 0, 1))
        lats = cdms2.createUniformLatitudeAxis(89.75, 360, -0.5)
        lons = cdms2.createUniformLongitudeAxis(-180, 720, 0.5)
        regions_var.setAxisList((lats,lons))
        
        new_mask_var = regions_var.regrid(var.getGrid(), regridTool='regrid2', regridMethod='linear')
        new_mask = getmask(new_mask_var)
 
        if var.mask <> None:
            var.mask = logical_or(var.mask, new_mask)
        else:
            var.mask = new_mask;
            
        return var
示例#2
0
 def setUp(self):
     dir = "../cdat_data/"
     filename = dir + "so_Omon_NorESM1-M_historicalNat_r1i1p1_185001-185312_2timesteps.nc"
     g = cdms2.open(filename)
     self.so = g("so")[0, 0, ...]
     gLat = cdms2.createGaussianAxis(64)
     deltaLon = 360 / 128.0
     gLon = cdms2.createUniformLongitudeAxis(0, 128, deltaLon)
     self.gaussGrid = cdms2.grid.createGenericGrid(gLat[:], gLon[:], gLat.getBounds(), gLon.getBounds())
示例#3
0
 def setUp(self):
     dir = "../cdat_data/"
     filename = dir + "so_Omon_HadGEM2-ES_esmFixClim1_r1i1p1_185912-186911_2timesteps.nc"
     g = cdms2.open(filename)
     self.so = g('so')[0, 0, ...]
     gLat = cdms2.createGaussianAxis(64)
     deltaLon = (360 / 128.)
     gLon = cdms2.createUniformLongitudeAxis(0, 128, deltaLon)
     self.gaussGrid = cdms2.grid.createGenericGrid(gLat[:], gLon[:],
                                                   gLat.getBounds(),
                                                   gLon.getBounds())
示例#4
0
 def setUp(self):
   dir = cdat_info.get_sampledata_path() + "/"
   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())
示例#5
0
 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())
示例#6
0
 def setUp(self):
     dir = "../cdat_data/"
     filename = dir + "so_Omon_NorESM1-M_historicalNat_r1i1p1_185001-185312_2timesteps.nc"
     g = cdms2.open(filename)
     self.so = g('so')[0, 0, ...]
     gLat = cdms2.createGaussianAxis(64)
     deltaLon = (360 / 128.)
     gLon = cdms2.createUniformLongitudeAxis(0, 128, deltaLon)
     self.gaussGrid = cdms2.grid.createGenericGrid(gLat[:], gLon[:],
                                                   gLat.getBounds(),
                                                   gLon.getBounds())
示例#7
0
 def setUp(self):
   dir = "../cdat_data/"
   filename = dir + "so_Omon_IPSL-CM5A-LR_1pctCO2_r1i1p1_185001-189912_2timesteps.nc"
   g = cdms2.open(filename)
   self.so = g('so')[0,0,...]
   gLat = cdms2.createGaussianAxis(64)
   deltaLon = (360/128.)
   gLon = cdms2.createUniformLongitudeAxis(0, 128, deltaLon)
   self.gaussGrid = cdms2.grid.createGenericGrid(gLat[:], gLon[:], 
                                        gLat.getBounds(),
                                        gLon.getBounds())
示例#8
0
 def setUp(self):
   dir = "../cdat_data/"
   filename = dir + "so_Omon_HadGEM2-ES_esmFixClim1_r1i1p1_185912-186911_2timesteps.nc"
   g = cdms2.open(filename)
   self.so = g('so')[0,0,...]
   gLat = cdms2.createGaussianAxis(64)
   deltaLon = (360/128.)
   gLon = cdms2.createUniformLongitudeAxis(0, 128, deltaLon)
   self.gaussGrid = cdms2.grid.createGenericGrid(gLat[:], gLon[:], 
                                        gLat.getBounds(),
                                        gLon.getBounds())
示例#9
0
 def setUp(self):
   filename = sys.prefix + \
       "/sample_data/so_Omon_CNRM-CM5_decadal2004_r9i1p1_200501-201412_2timesteps.nc"
   g = cdms2.open(filename)
   self.so = g('so')[0,0,...]
   self.so.toVisit('soCNRM.vsh5', 'Vs')
   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 createEqualIntervalLongitude(self,longitude, delta):
		''' calling cdms2.createUniformLongitudeAxis to genrate its bounds and axis '''
		
		lon_start = longitude[0]
		lon_end =longitude[-1]
		length = len(np.asarray(np.arange(lon_start,lon_end+delta,delta))) # we cant call xrange here, since xrange takes only int arg not float. delta may have float. so we are calling here numpy arange
		
		eq_interval_long = cdms2.createUniformLongitudeAxis(startLon = lon_start, nlon = length, deltaLon = delta) 
		
		#print 	eq_interval_long[:]
		#print 	eq_interval_long.getBounds()
		return 	eq_interval_long
示例#11
0
 def setUp(self):
     filename = cdat_info.get_prefix() + \
         "/sample_data/so_Omon_CNRM-CM5_decadal2004_r9i1p1_200501-201412_2timesteps.nc"
     g = cdms2.open(filename)
     self.so = g('so')[0, 0, ...]
     self.so.toVisit('soCNRM.vsh5', 'Vs')
     gLat = cdms2.createGaussianAxis(64)
     deltaLon = (360 / 128.)
     gLon = cdms2.createUniformLongitudeAxis(0, 128, deltaLon)
     self.gaussGrid = cdms2.grid.createGenericGrid(gLat[:], gLon[:],
                                                   gLat.getBounds(),
                                                   gLon.getBounds())
示例#12
0
    def buildOutlineMap(self):
        # This function load a binary image (black and white)
        # and create a default grid for it. Then it uses re-gridding algorithms
        # to scale in the correct domain.
        from pylab import imread
        import vtk.util.vtkImageImportFromArray as vtkUtil

        # read outline image and convert to gray scale
        try:
            data = imread(defaultOutlineMapFile)
            data = data.mean(axis=2)

            #        # create a variable using the data loaded in the image and an uniform grid
            dims = data.shape
            reso = [180.0 / dims[0], 360.0 / dims[1]]
            var = cdms2.createVariable(data)
            lat = cdms2.createUniformLatitudeAxis(90, dims[0], -reso[0])
            lon = cdms2.createUniformLongitudeAxis(-180, dims[1], reso[1])
            var.setAxis(0, lat)
            var.setAxis(1, lon)

            # create the final map using the ROI
            ROI = self.roi[:]
            if ROI[2] < -90.0: ROI[2] = -90.0
            if ROI[3] > 90.0: ROI[3] = 90.0
            odims = [(ROI[3] - ROI[2]) / reso[0], (ROI[1] - ROI[0]) / reso[1]]
            ogrid = cdms2.createUniformGrid(ROI[2], odims[0], reso[0], ROI[0],
                                            odims[1], reso[1])
            ovar = var.regrid(ogrid, regridTool='regrid2')

            # replace outlier numbers
            d = ovar.data
            d[d == 1e+20] = d[d <> 1e+20].max()

            img = vtkUtil.vtkImageImportFromArray()
            img.SetArray(ovar.data)
            img.Update()

        except Exception:
            print >> sys.stderr, "Error building Outline Map"
            traceback.print_exc()
            return None

        # convert to vtkImageData
        return img.GetOutput()
示例#13
0
    def buildOutlineMap(self):
        # This function load a binary image (black and white)
        # and create a default grid for it. Then it uses re-gridding algorithms 
        # to scale in the correct domain.
        from pylab import imread
        import vtk.util.vtkImageImportFromArray as vtkUtil

        # read outline image and convert to gray scale
        try:
            data = imread(defaultOutlineMapFile)
            data = data.mean(axis=2)
    
    #        # create a variable using the data loaded in the image and an uniform grid
            dims = data.shape
            reso = [180.0/dims[0], 360.0/dims[1]]
            var = cdms2.createVariable(data)
            lat = cdms2.createUniformLatitudeAxis(90, dims[0], -reso[0])
            lon = cdms2.createUniformLongitudeAxis(-180, dims[1], reso[1])
            var.setAxis(0, lat)
            var.setAxis(1, lon)
    
            # create the final map using the ROI
            ROI = self.roi[:]
            if ROI[2] < -90.0: ROI[2] = -90.0
            if ROI[3] >  90.0: ROI[3] =  90.0
            odims = [ (ROI[3]-ROI[2])/reso[0] , (ROI[1]-ROI[0])/reso[1] ]
            ogrid = cdms2.createUniformGrid( ROI[2], odims[0], reso[0], ROI[0], odims[1], reso[1] )
            ovar = var.regrid(ogrid, regridTool='regrid2')
            
            # replace outlier numbers
            d = ovar.data
            d[d==1e+20] = d[d<>1e+20].max()
            
            img = vtkUtil.vtkImageImportFromArray()
            img.SetArray(ovar.data)
            img.Update()
            
        except Exception:
            print>>sys.stderr, "Error building Outline Map"
            traceback.print_exc()
            return None
        
        # convert to vtkImageData       
        return img.GetOutput()
示例#14
0
import cdms2
import numpy as np
from OpenSSL import crypto
from OpenSSL import SSL
from socket import gethostname


def random_str(count):
    return ''.join(
        random.choice(string.ascii_letters + string.digits)
        for _ in xrange(count))


random.seed(1987)

longitude = cdms2.createUniformLongitudeAxis(-180.0, 360.0, 1.0)

latitude = cdms2.createUniformLatitudeAxis(-90.0, 180.0, 1.0)


def write_file(file_path, axes, var_name):
    with cdms2.open(file_path, 'w') as outfile:
        outfile.write(np.array(
            [[[random.random() for _ in xrange(len(axes[2]))]
              for _ in xrange(len(axes[1]))] for _ in xrange(len(axes[0]))]),
                      axes=axes,
                      id=var_name)


def generate_variable(axes, var_name):
    data = np.array([[[random.random() for _ in xrange(len(axes[2]))]