# Path: topoflow/utils/rtg_files.py
# def unit_test(nx=4, ny=5, VERBOSE=False,
#               file_name="TEST_FILE.rtg"):
#     def __init__(self):
#     def open_file(self, file_name=None, UPDATE=False):
#     def check_and_store_info(self, file_name, info=None,
#                              var_name='UNKNOWN',
#                              dtype='float32',
#                              MAKE_RTI=True, MAKE_BOV=False):
#     def add_index_to_file_name(self, file_name): 
#     def open_new_file(self, file_name, info=None,
#                       var_name='UNKNOWN', dtype='float32',
#                       VERBOSE=False, ADD_INDEX=False,
#                       MAKE_RTI=True, MAKE_BOV=False):
#     def write_grid(self, grid, VERBOSE=False):
#     def add_grid(self, grid):
#     def read_grid(self, dtype='float32', rtg_type=None,
#                   REPORT=False, VERBOSE=False):
#     def get_grid(self, grid):
#     def close_file(self):
#     def close(self):
#     def byte_swap_needed(self):
# def read_grid( RTG_file, rti, RTG_type='FLOAT',
#                REPORT=False, SILENT=True ):
# def write_grid( grid, RTG_file, rti, RTG_type='FLOAT',
#                 REPORT=False, SILENT=True ):
# def read_xyz_as_grid(XYZ_file, RTG_file):
#     OK   = rtg.open_new_file( file_name, info, ADD_INDEX=True )
#     OK = rtg.open_file()
#     OK = rtg.open_new_file( file_name, info, ADD_INDEX=True)
#         NEW_INFO = True
#                 NEW_INFO = False
#         SWAP =  (machine_byte_order != self.info.byte_order)
#     SWAP_ENDIAN = tf_utils.Not_Same_Byte_Order(byte_order)
# class rtg_file():


import numpy as np
import os.path
import time
import d8_global   ### (9/19/14.  Attempt to fix issue.)
import erode_base
from topoflow.utils import rtg_files

        #------------------------------------------------
        pIDs  = self.d8.parent_ID_grid
        del_z = (self.DEM - self.DEM.flat[ pIDs ])

        #------------------------------
        # Compute stable dt, in years
        #---------------------------------------------
        # NOTE: CFL_factor is set in set_constants()
        #       function within erode_base.py.
        #--------------------------------------------------
        # See the Wikipedia article for Courant number;
        # it differs between 1D and 2D models.
        # CFL condition is necessary, but not sufficient.
        # Also, this is actually something different.
        #--------------------------------------------------
        self.dt_grid = np.zeros( [self.ny, self.nx], dtype='float64' )
 
        w1 = np.where( self.Qs > 0 )
        if (w1[0].size > 0):
            if (self.da.size == 1):
                da = self.da
            else:
                da = self.da[ w1 ]
            ## da = (self.rti.xres * self.rti.yres)
            dt_equal = (da / 2) * del_z[w1] / self.Qs[w1]
            self.dt_grid[ w1 ] = self.CFL_factor * dt_equal

        #--------------------------------------
        # This should never happen. (11/1/10)
        #--------------------------------------

# Path: topoflow/utils/rtg_files.py
# def unit_test(nx=4, ny=5, VERBOSE=False,
#               file_name="TEST_FILE.rtg"):
#     def __init__(self):
#     def open_file(self, file_name=None, UPDATE=False):
#     def check_and_store_info(self, file_name, info=None,
#                              var_name='UNKNOWN',
#                              dtype='float32',
#                              MAKE_RTI=True, MAKE_BOV=False):
#     def add_index_to_file_name(self, file_name): 
#     def open_new_file(self, file_name, info=None,
#                       var_name='UNKNOWN', dtype='float32',
#                       VERBOSE=False, ADD_INDEX=False,
#                       MAKE_RTI=True, MAKE_BOV=False):
#     def write_grid(self, grid, VERBOSE=False):
#     def add_grid(self, grid):
#     def read_grid(self, dtype='float32', rtg_type=None,
#                   REPORT=False, VERBOSE=False):
#     def get_grid(self, grid):
#     def close_file(self):
#     def close(self):
#     def byte_swap_needed(self):
# def read_grid( RTG_file, rti, RTG_type='FLOAT',
#                REPORT=False, SILENT=True ):
# def write_grid( grid, RTG_file, rti, RTG_type='FLOAT',
#                 REPORT=False, SILENT=True ):
# def read_xyz_as_grid(XYZ_file, RTG_file):
#     OK   = rtg.open_new_file( file_name, info, ADD_INDEX=True )
#     OK = rtg.open_file()
#     OK = rtg.open_new_file( file_name, info, ADD_INDEX=True)
#         NEW_INFO = True
#                 NEW_INFO = False
#         SWAP =  (machine_byte_order != self.info.byte_order)
#     SWAP_ENDIAN = tf_utils.Not_Same_Byte_Order(byte_order)
# class rtg_file():


# Path: topoflow/components/erode_d8_global.py
import numpy as np
import os.path
import time
import d8_global   ### (9/19/14.  Attempt to fix issue.)
import erode_base
from topoflow.utils import rtg_files

        #------------------------------------------------
        pIDs  = self.d8.parent_ID_grid
        del_z = (self.DEM - self.DEM.flat[ pIDs ])

        #------------------------------
        # Compute stable dt, in years
        #---------------------------------------------
        # NOTE: CFL_factor is set in set_constants()
        #       function within erode_base.py.
        #--------------------------------------------------
        # See the Wikipedia article for Courant number;
        # it differs between 1D and 2D models.
        # CFL condition is necessary, but not sufficient.
        # Also, this is actually something different.
        #--------------------------------------------------
        self.dt_grid = np.zeros( [self.ny, self.nx], dtype='float64' )
 
        w1 = np.where( self.Qs > 0 )
        if (w1[0].size > 0):
            if (self.da.size == 1):
                da = self.da
            else:
                da = self.da[ w1 ]
            ## da = (self.rti.xres * self.rti.yres)
            dt_equal = (da / 2) * del_z[w1] / self.Qs[w1]
            self.dt_grid[ w1 ] = self.CFL_factor * dt_equal

        #--------------------------------------
        # This should never happen. (11/1/10)
        #--------------------------------------

        w2 = np.where( del_z < 0)
