Ejemplo n.º 1
0
Archivo: hgrid.py Proyecto: cjh1/uvcdat
    def intersect(self, spec):
        """Intersect with the region specification.

        'spec' is a region specification of the form defined in the grid module.

        Returns (mask, indexspecs) where
        'mask' is the mask of the result grid AFTER self and region spec are interested.
        'indexspecs' is a list of index specifications suitable for slicing a
          variable with the given grid.
        """

        ni, nj = self.shape
        index = self.getIndex()
        latspec = spec[CoordTypeToLoc[LatitudeType]]
        lonspec = spec[CoordTypeToLoc[LongitudeType]]
        latlin = numpy.ravel(numpy.ma.filled(self._lataxis_))
        lonlin = numpy.ravel(numpy.ma.filled(self._lonaxis_))
        points = bindex.intersectHorizontalGrid(latspec, lonspec, latlin, lonlin, index)
        if len(points)==0:
            raise CDMSError, 'No data in the specified region, longitude=%s, latitude=%s'%(`lonspec`, `latspec`)

        fullmask = numpy.ones(ni*nj)
        numpy.put(fullmask, points, 0)
        fullmask = numpy.reshape(fullmask, (ni,nj))
        
        iind = points/nj
        jind = points - iind*nj
        imin, imax, jmin, jmax = (min(iind), max(iind)+1, min(jind), max(jind)+1)
        submask = fullmask[imin:imax, jmin:jmax]

        yid = self.getAxis(0).id
        xid = self.getAxis(1).id
        indexspecs = {yid:slice(imin,imax), xid:slice(jmin,jmax)}

        return submask, indexspecs
Ejemplo n.º 2
0
    def intersect(self, spec):
        """Intersect with the region specification.

        'spec' is a region specification of the form defined in the grid module.

        Returns (mask, indexspecs) where
        'mask' is the mask of the result grid AFTER self and region spec are interested.
        'indexspecs' is a dictionary of index specifications suitable for slicing a
          variable with the given grid.
        """

        ncell = self.shape
        index = self.getIndex()
        latspec = spec[CoordTypeToLoc[LatitudeType]]
        lonspec = spec[CoordTypeToLoc[LongitudeType]]
        latlin = numpy.ma.filled(self._lataxis_)
        lonlin = numpy.ma.filled(self._lonaxis_)
        lonlin = numpy.ma.where(numpy.ma.greater_equal(lonlin,360.0), lonlin-360.0, lonlin)
        points = bindex.intersectHorizontalGrid(latspec, lonspec, latlin, lonlin, index)
        if len(points)==0:
            raise CDMSError, 'No data in the specified region, longitude=%s, latitude=%s'%(`lonspec`, `latspec`)

        fullmask = numpy.ones(ncell)
        numpy.put(fullmask, points, 0)
        
        imin, imax  = (min(points), max(points)+1)
        submask = fullmask[imin:imax]

        cellid = self.getAxis(0).id
        indexspecs = {cellid:slice(imin,imax)}

        return submask, indexspecs
Ejemplo n.º 3
0
    def intersect(self, spec):
        """Intersect with the region specification.

        'spec' is a region specification of the form defined in the grid module.

        Returns (mask, indexspecs) where
        'mask' is the mask of the result grid AFTER self and region spec are interested.
        'indexspecs' is a list of index specifications suitable for slicing a
          variable with the given grid.
        """

        ni, nj = self.shape
        index = self.getIndex()
        latspec = spec[CoordTypeToLoc[LatitudeType]]
        lonspec = spec[CoordTypeToLoc[LongitudeType]]
        latlin = numpy.ravel(numpy.ma.filled(self._lataxis_))
        lonlin = numpy.ravel(numpy.ma.filled(self._lonaxis_))
        points = bindex.intersectHorizontalGrid(latspec, lonspec, latlin, lonlin, index)
        if len(points)==0:
            raise CDMSError, 'No data in the specified region, longitude=%s, latitude=%s'%(`lonspec`, `latspec`)

        fullmask = numpy.ones(ni*nj)
        numpy.put(fullmask, points, 0)
        fullmask = numpy.reshape(fullmask, (ni,nj))
        
        iind = points/nj
        jind = points - iind*nj
        imin, imax, jmin, jmax = (min(iind), max(iind)+1, min(jind), max(jind)+1)
        submask = fullmask[imin:imax, jmin:jmax]

        yid = self.getAxis(0).id
        xid = self.getAxis(1).id
        indexspecs = {yid:slice(imin,imax), xid:slice(jmin,jmax)}

        return submask, indexspecs