def read_flow_grid(self):

        #----------------------------------------------------
        # Read a grid of D8 flow codes, same size as DEM.
        #----------------------------------------------------
        TF_Print('Reading D8 flow grid...')
        code_file = (self.in_directory + self.site_prefix + '_flow.rtg')
        self.flow_grid = rtg_files.read_grid(code_file,
                                             self.rti,
                                             RTG_type='BYTE')
示例#2
0
    def read_flow_grid(self):

        #----------------------------------------------------
        # Read a grid of D8 flow codes, same size as DEM.
        #----------------------------------------------------
        TF_Print('Reading D8 flow grid...')
        code_file = (self.in_directory +
                     self.site_prefix + '_flow.rtg')
        self.flow_grid = rtg_files.read_grid(code_file, self.rti,
                                             RTG_type='BYTE')
示例#3
0
def unit_test(SILENT=False):

    import CSDMS_base
    import rtg_files
    import tf_utils

    #------------------------------------------------------------
    # For some reason, the number of pixels that differ between
    # KY_Sub_rawDEM.rtg and KY_Sub_DEM.rtg is 4901, while the
    # number that get raised by this function is 4902.
    #------------------------------------------------------------
    directory   = '/Applications/Erode/Data/KY_Sub2/'
    data_prefix = 'KY_Sub'
    case_prefix = 'Test1'

    #---------------------------------------------
    # Resulting DEM is identical to a DEM with
    # pits filled by RT. Number of pixels raised
    # = 52353, with MacPro time of 79.6 seconds.
    # Beaver_rawDEM.rtg has 1 nodata or NaN.
    #---------------------------------------------
##    directory   = '/Applications/Erode/Data/Beaver2/'
##    data_prefix = 'Beaver'
##    case_prefix = 'Test1'

    #-------------------------------------------------
    # NOTE: The Treynor_Iowa DEM has no depressions!
    #-------------------------------------------------
##    directory   = tf_utils.TF_Test_Directory()
##    data_prefix = tf_utils.TF_Test_Data_Prefix()
##    case_prefix = tf_utils.TF_Test_Case_Prefix()

    cc = CSDMS_base.CSDMS_component()
    cc.CCA = False

    cc.initialize(directory, data_prefix, case_prefix)
    
    #-------------------
    # Read the raw DEM
    #-------------------
    DEM_file = (directory + data_prefix + '_rawDEM.rtg')
    DEM = rtg_files.read_grid(DEM_file, cc.rti, SILENT=SILENT)

    print '(nx, ny) =', cc.rti.ncols, cc.rti.nrows
    
    DEM2 = DEM.copy()
    fill_pits(DEM2, cc.rti.data_type, cc.nx, cc.ny, SILENT=SILENT)

    w1 = where(DEM != DEM2)
    n1 = size(w1[0])
    print 'Number of DEM values changed by fill_pits() =', n1
    print ' '
    
    #---------------------------------------------------
    # Compare saved DEM with no depressions to the one
    # that we just processed to fill depressions.
    #---------------------------------------------------
    DEM_file = (directory + data_prefix + '_DEM.rtg')
    filled_DEM = rtg_files.read_grid( DEM_file, cc.rti )
    w = where( filled_DEM != DEM2 )
    print '########################################'
    if (size(w[0]) == 0):
        print ' SUCCESS! Filled DEMs are identical.'
    else:
        print '  WARNING. Filled DEMs differ at:'
        print '     number of pixels =', size(w[0])
    print '########################################'
    print ' '
    print 'filled_DEM ='
    print filled_DEM
    print ' '
    print 'DEM2 ='
    print DEM2
    print ' '
def unit_test(SILENT=False):

    import CSDMS_base
    import rtg_files
    import tf_utils

    #------------------------------------------------------------
    # For some reason, the number of pixels that differ between
    # KY_Sub_rawDEM.rtg and KY_Sub_DEM.rtg is 4901, while the
    # number that get raised by this function is 4902.
    #------------------------------------------------------------
    directory = '/Applications/Erode/Data/KY_Sub2/'
    data_prefix = 'KY_Sub'
    case_prefix = 'Test1'

    #---------------------------------------------
    # Resulting DEM is identical to a DEM with
    # pits filled by RT. Number of pixels raised
    # = 52353, with MacPro time of 79.6 seconds.
    # Beaver_rawDEM.rtg has 1 nodata or NaN.
    #---------------------------------------------
    ##    directory   = '/Applications/Erode/Data/Beaver2/'
    ##    data_prefix = 'Beaver'
    ##    case_prefix = 'Test1'

    #-------------------------------------------------
    # NOTE: The Treynor_Iowa DEM has no depressions!
    #-------------------------------------------------
    ##    directory   = tf_utils.TF_Test_Directory()
    ##    data_prefix = tf_utils.TF_Test_Data_Prefix()
    ##    case_prefix = tf_utils.TF_Test_Case_Prefix()

    cc = CSDMS_base.CSDMS_component()
    cc.CCA = False

    cc.initialize(directory, data_prefix, case_prefix)

    #-------------------
    # Read the raw DEM
    #-------------------
    DEM_file = (directory + data_prefix + '_rawDEM.rtg')
    DEM = rtg_files.read_grid(DEM_file, cc.rti, SILENT=SILENT)

    print '(nx, ny) =', cc.rti.ncols, cc.rti.nrows

    DEM2 = DEM.copy()
    fill_pits(DEM2, cc.rti.data_type, cc.nx, cc.ny, SILENT=SILENT)

    w1 = where(DEM != DEM2)
    n1 = size(w1[0])
    print 'Number of DEM values changed by fill_pits() =', n1
    print ' '

    #---------------------------------------------------
    # Compare saved DEM with no depressions to the one
    # that we just processed to fill depressions.
    #---------------------------------------------------
    DEM_file = (directory + data_prefix + '_DEM.rtg')
    filled_DEM = rtg_files.read_grid(DEM_file, cc.rti)
    w = where(filled_DEM != DEM2)
    print '########################################'
    if (size(w[0]) == 0):
        print ' SUCCESS! Filled DEMs are identical.'
    else:
        print '  WARNING. Filled DEMs differ at:'
        print '     number of pixels =', size(w[0])
    print '########################################'
    print ' '
    print 'filled_DEM ='
    print filled_DEM
    print ' '
    print 'DEM2 ='
    print DEM2
    print ' '