Beispiel #1
0
 def __init__(self, latobj, lonobj, order, gridtype, maskarray=None):
     AbstractRectGrid.__init__(self, None)
     if latobj.__class__ != TransientAxis:
         latobj = TransientAxis(latobj[:], latobj.getBounds())
     if lonobj.__class__ != TransientAxis:
         lonobj = TransientAxis(lonobj[:], lonobj.getBounds())
     self._lataxis_ = latobj
     self._lataxis_.designateLatitude()
     self._lonaxis_ = lonobj
     self._lonaxis_.designateLongitude()
     if not order in ["yx", "xy"]:
         raise CDMSError, 'Grid order must be "yx" or "xy"'
     self._order_ = order
     self.setType(gridtype)
     self.setMask(maskarray)  # numpy mask array
Beispiel #2
0
def sort (a, axis=-1):
    ta = _makeMaskedArg(a)
    maresult = numpy.ma.sort(a.asma(), axis)
    axes, attributes, id, grid = _extractMetadata(a)
    sortaxis = axes[axis]
    if (grid is not None) and (sortaxis in grid.getAxisList()):
        grid = None
    axes[axis] = TransientAxis(numpy.arange(len(sortaxis)))
    F=getattr(a,"fill_value",1.e20)
    return TransientVariable(maresult, axes=axes, attributes=attributes, grid=grid, id=id, fill_value=F)
Beispiel #3
0
def commonAxes(a,bdom,omit=None):
    """Helper function for commonDomain. 'a' is a variable or array,
    'b' is an axislist or None.
    """
    if isinstance(a, AbstractVariable) and bdom is not None:
        adom = a.getAxisList()
        arank = len(adom)
        brank = len(bdom)
        if arank>brank:
            maxrank = arank
            minrank = brank
        else:
            maxrank = brank
            minrank = arank
        diffrank = maxrank-minrank
        if maxrank==arank:
            maxdom = adom
        else:
            maxdom = bdom
        common = [None]*maxrank
        if omit is None:
            iomit = None
        else:
            iomit = omit-minrank

        # Check shared dimensions, last to first
        for i in range(minrank):
            j = -i-1
            if j==iomit:
                continue
            aj = adom[j]
            bj = bdom[j]
            if len(aj)!=len(bj):
                return None
            elif axisAllclose(aj,bj):
                common[j] = aj
            else:
                common[j] = TransientAxis(numpy.arange(len(aj)))

        # Copy leading (non-shared) axes
        for i in range(diffrank):
            common[i]=maxdom[i]

        return common
    elif isinstance(a, AbstractVariable):
        common = a.getAxisList()
        if omit is not None:
            common[omit] = None
        return common
    else:
        if omit is not None:
            bdom[omit] = None
        return bdom