示例#1
0
 def __init__(self, variable, dataset):
     self.variable = variable
     self.dataset = dataset
     self.name = variable.getName()
     self.datatype = variable.getDataType()        
     self.ndim = variable.getDimNumber()
     self.fill_value = variable.getFillValue()
     self.scale_factor = variable.getScaleFactor()
     self.add_offset = variable.getAddOffset()
     dims = variable.getDimensions()
     tdim = Dimension(DimensionType.T)
     times = []
     for t in self.dataset.times:
         times.append(miutil.date2num(t))
     tdim.setDimValues(times)
     dims[0] = tdim
     self.dims = dims
     self.tnum = len(times)
示例#2
0
 def adddim(self, dimvalue, dimtype=None, index=None):
     if isinstance(dimvalue, (MIArray, DimArray)):
         dimvalue = dimvalue.aslist()
     dtype = DimensionType.Other
     if not dimtype is None:
         if dimtype.upper() == 'X':
             dtype = DimensionType.X
         elif dimtype.upper() == 'Y':
             dtype = DimensionType.Y
         elif dimtype.upper() == 'Z':
             dtype = DimensionType.Z
         elif dimtype.upper() == 'T':
             dtype = DimensionType.T
     dim = Dimension(dtype)
     dim.setDimValues(dimvalue)
     if self.dims is None:
         self.dims = [dim]
     else:
         if index is None:
             self.dims.append(dim)
         else:
             self.dims.insert(index, dim)
     self.ndim = len(self.dims)
示例#3
0
 def asdimarray(self, x, y, fill_value=-9999.0):
     dims = []
     ydim = Dimension(DimensionType.Y)
     ydim.setDimValues(y.aslist())
     dims.append(ydim)
     xdim = Dimension(DimensionType.X)
     xdim.setDimValues(x.aslist())
     dims.append(xdim)        
     return DimArray(self, dims, fill_value)
示例#4
0
 def join(self, b, dimidx):
     r = ArrayMath.join(self.array.array, b.array.array, dimidx)
     dima = self.dimvalue(dimidx)
     dimb = b.dimvalue(dimidx)
     dimr = []
     if dima[0] < dimb[0]:
         for i in range(0, len(dima)):
             dimr.append(dima[i])
         for i in range(0, len(dimb)):
             dimr.append(dimb[i])
     else:
         for i in range(0, len(dimb)):
             dimr.append(dimb[i])
         for i in range(0, len(dima)):
             dimr.append(dima[i])
     rdims = []
     for i in range(0, len(self.dims)):
         if i == dimidx:
             ndim = Dimension()
             ndim.setDimValues(dimr)
             rdims.append(ndim)
         else:
             rdims.append(self.dims[i])
     return DimArray(MIArray(r), rdims, self.fill_value, self.proj)
示例#5
0
def dimension(dimvalue, dimname='null', dimtype=None):
    """
    Create a new Dimension.
    
    :param dimvalue: (*array_like*) Dimension value.
    :param dimname: (*string*) Dimension name.
    :param dimtype: (*DimensionType*) Dimension type.
    """
    if isinstance(dimvalue, (MIArray, DimArray)):
        dimvalue = dimvalue.aslist()
    dtype = DimensionType.Other
    if not dimtype is None:
        if dimtype.upper() == 'X':
            dtype = DimensionType.X
        elif dimtype.upper() == 'Y':
            dtype = DimensionType.Y
        elif dimtype.upper() == 'Z':
            dtype = DimensionType.Z
        elif dimtype.upper() == 'T':
            dtype = DimensionType.T
    dim = Dimension(dtype)
    dim.setDimValues(dimvalue)
    dim.setShortName(dimname)
    return dim
示例#6
0
 def project(self, x=None, y=None, toproj=None, method='bilinear'):
     """
     Project array
     
     :param x: To x coordinates.
     :param y: To y coordinates.
     :param toproj: To projection.
     :param method: Interpolation method: ``bilinear`` or ``neareast`` .
     
     :returns: (*MIArray*) Projected array
     """
     yy = self.dims[self.ndim - 2].getDimValue()
     xx = self.dims[self.ndim - 1].getDimValue()
     if toproj is None:
         toproj = self.proj
     
     if x is None or y is None:
         pr = ArrayUtil.reproject(self.array, xx, yy, self.proj, toproj)
         r = pr[0]
         x = pr[1]
         y = pr[2]
         dims = self.dims
         ydim = Dimension(DimensionType.Y)
         ydim.setDimValues(MIArray(y).aslist())
         dims[-2] = ydim
         xdim = Dimension(DimensionType.X)
         xdim.setDimValues(MIArray(x).aslist())    
         dims[-1] = xdim
         rr = DimArray(MIArray(r), dims, self.fill_value, toproj)
         return rr
     
     if method == 'bilinear':
         method = ResampleMethods.Bilinear
     else:
         method = ResampleMethods.NearestNeighbor
     if isinstance(x, list):
         r = ArrayUtil.reproject(self.array, xx, yy, x, y, self.proj, toproj, self.fill_value, method)
     elif isinstance(x, MIArray):
         if x.ndim == 1:
             r = ArrayUtil.reproject(self.array, xx, yy, x.aslist(), y.aslist(), self.proj, toproj, self.fill_value, method)
         else:
             r = ArrayUtil.reproject(self.array, xx, yy, x.asarray(), y.asarray(), self.proj, toproj, self.fill_value, method)
     else:
         r = ArrayUtil.reproject(self.array, xx, yy, x.asarray(), y.asarray(), self.proj, toproj, self.fill_value, method)
     #r = ArrayUtil.reproject(self.array, xx, yy, x.asarray(), y.asarray(), self.proj, toproj, self.fill_value, method)
     return MIArray(r)
示例#7
0
 def project(self, x=None, y=None, toproj=None, method='bilinear'):
     """
     Project array
     
     :param x: To x coordinates.
     :param y: To y coordinates.
     :param toproj: To projection.
     :param method: Interpolation method: ``bilinear`` or ``neareast`` .
     
     :returns: (*MIArray*) Projected array
     """
     yy = self.dims[self.ndim - 2].getDimValue()
     xx = self.dims[self.ndim - 1].getDimValue()
     if toproj is None:
         toproj = self.proj
     
     if x is None or y is None:
         pr = ArrayUtil.reproject(self.array.array, xx, yy, self.proj, toproj)
         r = pr[0]
         x = pr[1]
         y = pr[2]
         dims = []
         ydim = Dimension()
         ydim.setDimValues(MIArray(y).aslist())
         dims.append(ydim)
         xdim = Dimension()
         xdim.setDimValues(MIArray(x).aslist())    
         dims.append(xdim)
         rr = DimArray(MIArray(r), dims, self.fill_value, toproj)
         return rr
     
     if method == 'bilinear':
         method = ResampleMethods.Bilinear
     else:
         method = ResampleMethods.NearestNeighbor
     if isinstance(x, list):
         r = ArrayUtil.reproject(self.array.array, xx, yy, x, y, self.proj, toproj, self.fill_value, method)
     elif isinstance(x, MIArray):
         if x.rank == 1:
             r = ArrayUtil.reproject(self.array.array, xx, yy, x.aslist(), y.aslist(), self.proj, toproj, self.fill_value, method)
         else:
             r = ArrayUtil.reproject(self.array.array, xx, yy, x.asarray(), y.asarray(), self.proj, toproj, self.fill_value, method)
     else:
         r = ArrayUtil.reproject(self.array.array, xx, yy, x.asarray(), y.asarray(), self.proj, toproj, self.fill_value, method)
     #r = ArrayUtil.reproject(self.array.array, xx, yy, x.asarray(), y.asarray(), self.proj, toproj, self.fill_value, method)
     return MIArray(r)
示例#8
0
def dimension(dimvalue, dimname='null', dimtype=None):
    """
    Create a new Dimension.
    
    :param dimvalue: (*array_like*) Dimension value.
    :param dimname: (*string*) Dimension name.
    :param dimtype: (*DimensionType*) Dimension type.
    """
    if isinstance(dimvalue, (MIArray, DimArray)):
        dimvalue = dimvalue.aslist()
    dtype = DimensionType.Other
    if not dimtype is None:
        if dimtype.upper() == 'X':
            dtype = DimensionType.X
        elif dimtype.upper() == 'Y':
            dtype = DimensionType.Y
        elif dimtype.upper() == 'Z':
            dtype = DimensionType.Z
        elif dimtype.upper() == 'T':
            dtype = DimensionType.T
    dim = Dimension(dtype)
    dim.setDimValues(dimvalue)
    dim.setShortName(dimname)
    return dim
示例#9
0
stIndYr = None
endIndYr = None
while spl < ts.size():
	if(ts.get(spl).getYear() + 1900 == yrWant):
		realTs += [ts.get(spl)]

		endIndYr = spl
		if stIndYr is None:
			stIndYr = spl
	spl += 1
ts = realTs
tDims = tDims.extract(stIndYr, endIndYr, 1)

mns = [x.getMonth() + 1 for x in ts[1:]]

tDim = Dimension(tDims.getDimType(), 1, 1, tDims.getDimLength())
tDim.setDimName("time")
tDim.setDimId(3)
tDim.setValues(range(1, tDims.getDimLength()+1))

tind = 1
for mn in range(1, 13):
	print mn
	fileOut = dirOut + "/" + "narccap." + month_abbr[mn].lower() + "66"
	if os.path.isfile(fileOut):
		os.remove(fileOut)


	while not mns[tind-1] == mn:
		tind += 1
	startInd = tind
示例#10
0
stIndYr = None
endIndYr = None
while spl < ts.size():
    if (ts.get(spl).getYear() + 1900 == yrWant):
        realTs += [ts.get(spl)]

        endIndYr = spl
        if stIndYr is None:
            stIndYr = spl
    spl += 1
ts = realTs
tDims = tDims.extract(stIndYr, endIndYr, 1)

mns = [x.getMonth() + 1 for x in ts[1:]]

tDim = Dimension(tDims.getDimType(), 1, 1, tDims.getDimLength())
tDim.setDimName("time")
tDim.setDimId(3)
tDim.setValues(range(1, tDims.getDimLength() + 1))

tind = 1
for mn in range(1, 13):
    print mn
    fileOut = dirOut + "/" + "narccap." + month_abbr[mn].lower() + "66"
    if os.path.isfile(fileOut):
        os.remove(fileOut)

    while not mns[tind - 1] == mn:
        tind += 1
    startInd = tind
示例#11
0
    xmin = -180.0
    ymin = -50.0
    xnum = 1440
    ynum = 400
    xdelt = 0.25
    ydelt = 0.25
    xlist = []
    ylist = []
    for i in range(0, xnum):
        xlist.append(xmin + xdelt * i)
    for i in range(0, ynum):
        ylist.append(ymin + ydelt * i)

    X = jarray.array(xlist, 'd')
    Y = jarray.array(ylist, 'd')
    xDim = Dimension(DimensionType.X)
    xDim.setValues(X)
    dataInfo.setXDimension(xDim)
    yDim = Dimension(DimensionType.Y)
    yDim.setValues(Y)
    dataInfo.setYDimension(yDim)
    var = dataInfo.getVariable('precipitation')
    print var.getName()
    dimList = [xDim, yDim]
    var.setDimensions(dimList)
    gData = mdi.getGridData(var.getName())
    aLS = LegendManage.createLegendSchemeFromGridData(
        gData, LegendType.GraduatedColor, ShapeTypes.Polygon)
    aLayer = DrawMeteoData.createRasterLayer(gData, "Test_HDF", aLS)
    mf = miapp.getMapDocument().getActiveMapFrame()
    mf.addLayer(aLayer)
示例#12
0
	xmin = -180.0
	ymin = -50.0
	xnum = 1440
	ynum = 400
	xdelt = 0.25
	ydelt = 0.25
	xlist = []
	ylist = []
	for i in range(0,xnum):
		xlist.append(xmin + xdelt * i)
	for i in range(0,ynum):
		ylist.append(ymin + ydelt * i)

	X = jarray.array(xlist, 'd')
	Y = jarray.array(ylist, 'd')
	xDim = Dimension(DimensionType.X)
	xDim.setValues(X)
	dataInfo.setXDimension(xDim)
	yDim = Dimension(DimensionType.Y)
	yDim.setValues(Y)
	dataInfo.setYDimension(yDim)
	var = dataInfo.getVariable('precipitation')
	print var.getName()
	dimList = [xDim, yDim]
	var.setDimensions(dimList)
	gData = mdi.getGridData(var.getName())	
	aLS = LegendManage.createLegendSchemeFromGridData(gData, LegendType.GraduatedColor, ShapeTypes.Polygon)
	aLayer = DrawMeteoData.createRasterLayer(gData, "Test_HDF", aLS)
	mf = miapp.getMapDocument().getActiveMapFrame()
	mf.addLayer(aLayer)
	mf.moveLayer(aLayer, 0)