Ejemplo n.º 1
0
 def adddim(self, dimvalue, dimtype=None, index=None):
     '''
     Add a dimension.
     
     :param dimvalue: (*array_like*) Dimension value.
     :param dimtype: (*string*) Dimension type.
     :param index: (*int*) Index to be inserted.
     '''
     if isinstance(dimvalue, Dimension):
         dim = dimvalue
     else:
         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)
Ejemplo n.º 2
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)
Ejemplo n.º 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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
 def addtdim(self, t):
     '''
     Add a time dimension as first dimension.
     '''
     if self.tdim() is None:
         dim = Dimension(DimensionType.T)
         t = miutil.date2num(t)
         dim.setDimValues([t])
         self.dims.insert(0, dim)
         self.ndim = len(self.dims)
         ss = list(self.shape)
         ss.insert(0, 1)
         ss = tuple(ss)
         self.array = self.array.reshape(ss)
         self.shape = self.array.shape
Ejemplo n.º 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.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)
Ejemplo n.º 7
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)
Ejemplo n.º 8
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)
Ejemplo n.º 9
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)
Ejemplo n.º 10
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)
Ejemplo n.º 11
0
 def join(self, b, dimidx):
     r = ArrayMath.join(self.array, b.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)
Ejemplo n.º 12
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)
Ejemplo n.º 13
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
Ejemplo n.º 14
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