def get_flow_length_grid(self, DOUBLE=False):

        #-------------------------------------------------------------
        # NOTES: This routine returns the flow lengths for each
        #        pixel in the DEM.  The extra length of flowing to a
        #        diagonal pixel is taken into account, as well as the
        #        latitude-dependence for DEMs with fixed-angle pixels
        #        (Geographic lat/lon).

        #        The only difference between this and the Flow_Widths
        #        function is that roles of dx and dy are switched.

        #        Flow lengths are set to dx[0] for the pixels where
        #       (flow grid eq 0), such as on the edges of the DEM.
        #-------------------------------------------------------------
        TF_Print('Computing flow length grid...')

        #-----------------------
        # Get pixel dimensions
        #-----------------------
        dx, dy, dd = pixels.get_sizes_by_row(self.rti, METERS=True)

        #-------------------------
        # Double or Float type ?
        #-------------------------
        if (DOUBLE):
            ds = zeros([self.ny, self.nx], dtype='Float64')
        else:
            ds = zeros([self.ny, self.nx], dtype='Float32')
            dx = float32(dx)
            dy = float32(dy)
            dd = float32(dd)

        #----------------------------------------------
        # Initialize to default value that is used
        # for pixels with flow code of zero.  This is
        # done to avoid "divide by zero" errors.
        #----------------------------------------------
        ds += dx[0]
        ## ds += dx.min()

        for row in xrange(self.ny):
            g = self.flow_grid[row, :]

            #----------------
            # Diagonal flow
            #----------------
            wd  = where(logical_or(logical_or(logical_or((g == 1), (g == 4)), \
                                              (g == 16)), (g == 64)))
            nwd = size(wd[0])
            if (nwd != 0):
                ds[row, wd] = dd[row]

            #---------------------
            # East and west flow
            #---------------------
            wh = where(logical_or((g == 2), (g == 32)))
            nwh = size(wh[0])
            if (nwh != 0):
                ds[row, wh] = dx[row]

            #-----------------------
            # North and south flow
            #-----------------------
            wv = where(logical_or((g == 8), (g == 128)))
            nwv = size(wv[0])
            if (nwv != 0):
                ds[row, wv] = dy[row]

        #----------
        # Report
        #----------
        ds_min = ds.min()
        ds_max = ds.max()
        TF_Print('    min(ds) = ' + str(ds_min) + '  [m]')
        TF_Print('    max(ds) = ' + str(ds_max) + '  [m]')

        self.ds = ds
Exemplo n.º 2
0
    def get_flow_length_grid(self, DOUBLE=False):

        #-------------------------------------------------------------
        # NOTES: This routine returns the flow lengths for each
        #        pixel in the DEM.  The extra length of flowing to a
        #        diagonal pixel is taken into account, as well as the
        #        latitude-dependence for DEMs with fixed-angle pixels
        #        (Geographic lat/lon).

        #        The only difference between this and the Flow_Widths
        #        function is that roles of dx and dy are switched.

        #        Flow lengths are set to dx[0] for the pixels where
        #       (flow grid eq 0), such as on the edges of the DEM.
        #-------------------------------------------------------------
        TF_Print('Computing flow length grid...')

        #-----------------------
        # Get pixel dimensions
        #-----------------------
        dx, dy, dd = pixels.get_sizes_by_row(self.rti, METERS=True)
            
        #-------------------------
        # Double or Float type ?
        #-------------------------
        if (DOUBLE):    
            ds = zeros([self.ny, self.nx], dtype='Float64')
        else:    
            ds = zeros([self.ny, self.nx], dtype='Float32')
            dx = float32(dx)
            dy = float32(dy)
            dd = float32(dd)
        
        #----------------------------------------------
        # Initialize to default value that is used
        # for pixels with flow code of zero.  This is
        # done to avoid "divide by zero" errors.
        #----------------------------------------------
        ds += dx[0]
        ## ds += dx.min()
        
        for row in xrange(self.ny):
            g = self.flow_grid[row,:]
            
            #----------------
            # Diagonal flow
            #----------------
            wd  = where(logical_or(logical_or(logical_or((g == 1), (g == 4)), \
                                              (g == 16)), (g == 64)))
            nwd = size(wd[0])
            if (nwd != 0):    
                ds[row, wd] = dd[row]
            
            #---------------------
            # East and west flow
            #---------------------
            wh  = where(logical_or((g == 2), (g == 32)))
            nwh = size(wh[0])
            if (nwh != 0):    
                ds[row, wh] = dx[row]
            
            #-----------------------
            # North and south flow
            #-----------------------
            wv  = where(logical_or((g == 8), (g == 128)))
            nwv = size(wv[0])
            if (nwv != 0):    
                ds[row, wv] = dy[row]
            
        #----------
        # Report
        #----------
        ds_min = ds.min()
        ds_max = ds.max()
        TF_Print('    min(ds) = ' + str(ds_min) + '  [m]')
        TF_Print('    max(ds) = ' + str(ds_max) + '  [m]')

        self.ds = ds
    def get_flow_width_grid(self, DOUBLE=False, METHOD2=False):

        #-------------------------------------------------------------
        # NOTES: This routine returns the flow widths for each
        #        pixel in the DEM.  The extra width of flowing to a
        #        diagonal pixel is taken into account, as well as the
        #        lat/lon-dependence for DEMs with fixed-angle pixels
        #        (Geographic lat/lon).

        #        METHOD2 version ensures that the sum of all flow
        #        widths around a pixel is equal to 2*(dx + dy), but
        #        is incorrect for case of a plane and others.

        #        Flow widths are zero where (flow grid eq 0).

        #        Flow widths are for entire pixel and are appropriate
        #        for overland or subsurface flow.
        #-------------------------------------------------------------
        #        Is this only used by Seepage function now ???
        #-------------------------------------------------------------
        # NB!    numpy.where returns a 2-tuple, but with "empty"
        #        second part when applied to a 1D array.  This means
        #        that nw = size(w[0]) still works.
        #-------------------------------------------------------------
        print 'Computing flow width grid...'

        #-----------------------
        # Get pixel dimensions
        #-----------------------
        dx, dy, dd = pixels.get_sizes_by_row(self.rti, METERS=True)

        #-------------------------
        # Double or Float type ?
        #-------------------------
        if (DOUBLE):
            dw = zeros([self.ny, self.nx], dtype='Float64')
        else:
            dw = zeros([self.ny, self.nx], dtype='Float32')
            dx = float32(dx)
            dy = float32(dy)
            dd = float32(dd)

        #----------------------------------------------
        # Initialize to default value that is used
        # for pixels with flow code of zero.  This is
        # done to avoid "divide by zero" errors.
        #----------------------------------------------
        dw += dx[0]
        ## dw = dw + dx.min()

        for row in xrange(self.ny):
            g = self.flow_grid[row, :]

            #----------------
            # Diagonal flow
            #----------------
            wd  = where(logical_or(logical_or(logical_or((g == 1), (g == 4)), \
                                              (g == 16)), (g == 64)))
            nwd = size(wd[0])
            if (nwd != 0):
                if not (METHOD2):
                    dw[row, wd] = dd[row]
                else:
                    dw[row, wd] = (dx[row] + dy[row]) / 4

            #---------------------
            # East and west flow
            #---------------------
            wh = where(logical_or((g == 2), (g == 32)))
            nwh = size(wh[0])
            if (nwh != 0):
                dw[row, wh] = dy[row]
                if (METHOD2):
                    dw[row, wh] = dw[row, wh] / 2

            #-----------------------
            # North and south flow
            #-----------------------
            wv = where(logical_or((g == 8), (g == 128)))
            nwv = size(wv[0])
            if (nwv != 0):
                dw[row, wv] = dx[row]
                if (METHOD2):
                    dw[row, wv] = dw[row, wv] / 2

        #----------
        # Report
        #----------
        dw_min = dw.min()
        dw_max = dw.max()
        TF_Print('    min(dw) = ' + str(dw_min) + '  [m]')
        TF_Print('    max(dw) = ' + str(dw_max) + '  [m]')

        self.dw = dw
Exemplo n.º 4
0
    def get_flow_width_grid(self, DOUBLE=False, METHOD2=False):

        #-------------------------------------------------------------
        # NOTES: This routine returns the flow widths for each
        #        pixel in the DEM.  The extra width of flowing to a
        #        diagonal pixel is taken into account, as well as the
        #        lat/lon-dependence for DEMs with fixed-angle pixels
        #        (Geographic lat/lon).

        #        METHOD2 version ensures that the sum of all flow
        #        widths around a pixel is equal to 2*(dx + dy), but
        #        is incorrect for case of a plane and others.

        #        Flow widths are zero where (flow grid eq 0).
        
        #        Flow widths are for entire pixel and are appropriate
        #        for overland or subsurface flow.
        #------------------------------------------------------------- 
        #        Is this only used by Seepage function now ???
        #-------------------------------------------------------------
        # NB!    numpy.where returns a 2-tuple, but with "empty"
        #        second part when applied to a 1D array.  This means
        #        that nw = size(w[0]) still works.
        #-------------------------------------------------------------        
        print 'Computing flow width grid...'

        #-----------------------
        # Get pixel dimensions
        #-----------------------
        dx, dy, dd = pixels.get_sizes_by_row(self.rti, METERS=True)

        #-------------------------
        # Double or Float type ?
        #-------------------------
        if (DOUBLE):    
            dw = zeros([self.ny, self.nx], dtype='Float64')
        else:    
            dw = zeros([self.ny, self.nx], dtype='Float32')
            dx = float32(dx)
            dy = float32(dy)
            dd = float32(dd)

        #----------------------------------------------
        # Initialize to default value that is used
        # for pixels with flow code of zero.  This is
        # done to avoid "divide by zero" errors.
        #----------------------------------------------
        dw += dx[0]
        ## dw = dw + dx.min()
        
        for row in xrange(self.ny):
            g = self.flow_grid[row,:]
            
            #----------------
            # Diagonal flow
            #----------------
            wd  = where(logical_or(logical_or(logical_or((g == 1), (g == 4)), \
                                              (g == 16)), (g == 64)))
            nwd = size(wd[0])
            if (nwd != 0):    
                if not(METHOD2):    
                    dw[row, wd] = dd[row]
                else:    
                    dw[row, wd] = (dx[row] + dy[row]) / 4
            
            #---------------------
            # East and west flow
            #---------------------
            wh  = where(logical_or((g == 2), (g == 32)))
            nwh = size(wh[0])
            if (nwh != 0):    
                dw[row, wh] = dy[row]
                if (METHOD2):    
                    dw[row, wh] = dw[row,wh] / 2
            
            #-----------------------
            # North and south flow
            #-----------------------
            wv  = where(logical_or((g == 8), (g == 128)))
            nwv = size(wv[0])
            if (nwv != 0):    
                dw[row, wv] = dx[row]
                if (METHOD2):    
                    dw[row, wv] = dw[row, wv] / 2

        #----------
        # Report
        #----------
        dw_min = dw.min()
        dw_max = dw.max()
        TF_Print('    min(dw) = ' + str(dw_min) + '  [m]')
        TF_Print('    max(dw) = ' + str(dw_max) + '  [m]')

        self.dw = dw