def main():
    """
    This driver takes in a DEM of a subwatershed from
    the Chiricahua Mountains, Arizona and routes a storm across it using
    the default input file (overland_flow_input.txt).

    This has two ways to look at the data: at one point (generating
    a hydrograph and looking for temporal changes in water depth, etc...)
    and across the grid for spatial patterns. 
    
    """
    
    # This provides us with an initial time. At the end, it gives us total
    # model run time in seconds.
    start_time = time.time()
    
    # This is the DEM of the subwatershed from the Chiricahua Mountains, Arizona
    dem_name = 'chiri.asc'
    
    # Now we can create and initialize a raster model grid by reading a DEM
    
    # First, this looks for the DEM in the overland_flow folder in Landlab
    DATA_FILE = os.path.join(os.path.dirname(__file__), dem_name)

    # This print statement verifies that we are opening the data file.
    print('Reading data from "'+str(DATA_FILE)+'"')
    
    # Now the ASCII is read, assuming that it it standard ESRI format.
    (rg, z) = read_esri_ascii(DATA_FILE)
    
    # Whatever the NODATA value is in the DEM is needed here to set bounary condition.
    nodata_val=-9999
    
    # Modify the grid DEM to set all NODATA nodes to inactive boundaries
    rg.set_nodata_nodes_to_inactive(z, nodata_val) 
    
    # This prints standard grid characteristics (rows, columns and cell size)

    print('DEM has ' +
          str(rg.number_of_node_rows) + ' rows, ' +
          str(rg.number_of_node_columns) + ' columns, and cell size ' +
          str(rg.dx))
    


    # Right now, the outlet must be explicitly set for boundary conditions
    # using the row and column from the DEM.
    the_outlet_row = 152
    the_outlet_column = 230
    
    # This converts the grid row and column into coordinates that the raster grid will recognize
    the_outlet_node = rg.grid_coords_to_node_id(the_outlet_row, the_outlet_column)

    # The outlet node is set as a fixed value boundary
    rg.set_fixed_value_boundaries(the_outlet_node)
                                                                                                       
    # To plot the grid, we can call the plot_topography() function
    plot_topography(rg, z)
    
    # Now we will initialize the Overland Flow component.
    of=OverlandFlow(rg)   

    # First, the flow_at_one_node() method will be covered here.
    
    # When using the flow_at_one_node() method, a study node is needed to sample at.
    # This should not be a boundary node!        

    study_row = 122
    study_column = 140
    
    # This takes the study row and study column grid coordinates and converts it 
    # to a node ID that the raster grid will recognize. 
    study_node = rg.grid_coords_to_node_id(study_row, study_column)

    # Because this function reads in data using the Model Parameter Dictionary
    # from the default input file, the only arguments needed to run the flow_at_one_node()
    # method is the RasterModelGrid instance, the initial elevations and the study node
    # coordinates.
    
    # This is the standard way to call the flow_at_one_node method using the input file.
    of.flow_at_one_node(rg, z, study_node)

   # Once run, we can plot the output
    of.plot_at_one_node()
    
    # If you did not want to use the input file and instead define the total model run time of 
    # rainfall intensity and storm duration, the commented function call below demonstrates this with
    # the following parameters:
        # Total model run time: 6000 seconds
        # Storm intensity: (9.2177*(10**-6)) meters per second.
        # Storm duration: 5868 seconds
    #of.flow_at_one_node(rg, z, study_node, 6000, (9.2177*(10**-6)),5868)

    # Now the flow_across_grid() method will be discussed. The commands needed to
    # run this method are triple-commented ('###') for convenience. All flow_at_one_node()
    # methods calls *should* be commented out to run this driver quicker.
    
    # Again, this function reads in data using the ModelParameterDictionary and the default
    # input file. The only required arguments for this method are the  RasterModelGrid instance
    # and the the initial elevations.
    
    # This is the standard call to the flow_across_grid() method
    ###of.flow_across_grid(rg,z)
    
    # And these are the calls to plot the rasters
    ###of.plot_water_depths(rg)
    ###of.plot_discharge(rg)
    ###of.plot_shear_stress_grid(rg)
    ###of.plot_slopes(rg)
    
    # To forgo the call to the input file and define model run time, rainfall
    # intensity and storm duration in the function call itself, the following command 
    # can be used with the following parameters:
        # Total model run time: 6000 seconds
        # Storm intensity: (9.2177*(10**-6)) meters per second.
        # Storm duration: 5868 seconds
    ###of.flow_across_grid(rg, z, 6000, (9.2177*(10**-6)), 5868)

    endtime = time.time()
    print endtime - start_time, "seconds"
    
    #If you call the plot_topography method...
    plt.show()
        str(rg.number_of_node_columns) + ' columns, and cell size ' +
        str(rg.dx)))

# Right now, the outlet must be explicitly set for boundary conditions
# using the row and column from the DEM.
the_outlet_row = 1
the_outlet_column = 29

# This converts the grid row and column into coordinates that the raster grid will recognize
the_outlet_node = rg.grid_coords_to_node_id(the_outlet_row, the_outlet_column)

# The outlet node is set as a fixed value boundary
rg.set_fixed_value_boundaries(the_outlet_node)
                                                                                                
# Now we will initialize the Overland Flow component.
of=OverlandFlow(rg)   

# First, the flow_at_one_node() method will be covered here.
# When using the flow_at_one_node() method, a study node is needed to sample at.
# This should not be a boundary node!        

# To use the flow_at_one_node() method, uncomment out every line with ('##')

##study_row = 5
##study_column = 26

# This takes the study row and study column grid coordinates and converts it 
# to a node ID that the raster grid will recognize. 

##study_node = rg.grid_coords_to_node_id(study_row, study_column)
Example #3
0
print('DEM has ' + str(rg.number_of_node_rows) + ' rows, ' +
      str(rg.number_of_node_columns) + ' columns, and cell size ' + str(rg.dx))

# Right now, the outlet must be explicitly set for boundary conditions
# using the row and column from the DEM.
the_outlet_row = 1
the_outlet_column = 29

# This converts the grid row and column into coordinates that the raster grid will recognize
the_outlet_node = rg.grid_coords_to_node_id(the_outlet_row, the_outlet_column)

# The outlet node is set as a fixed value boundary
rg.set_fixed_value_boundaries(the_outlet_node)

# Now we will initialize the Overland Flow component.
of = OverlandFlow(rg)

# First, the flow_at_one_node() method will be covered here.
# When using the flow_at_one_node() method, a study node is needed to sample at.
# This should not be a boundary node!

# To use the flow_at_one_node() method, uncomment out every line with ('##')

##study_row = 5
##study_column = 26

# This takes the study row and study column grid coordinates and converts it
# to a node ID that the raster grid will recognize.

##study_node = rg.grid_coords_to_node_id(study_row, study_column)
def main():
    """
    This driver takes in a DEM of a subwatershed from
    the Chiricahua Mountains, Arizona and routes a storm across it using
    the default input file (overland_flow_input.txt).

    This has two ways to look at the data: at one point (generating
    a hydrograph and looking for temporal changes in water depth, etc...)
    and across the grid for spatial patterns. 
    
    """

    # This provides us with an initial time. At the end, it gives us total
    # model run time in seconds.
    start_time = time.time()

    # This is the DEM of the subwatershed from the Chiricahua Mountains, Arizona
    dem_name = 'chiri.asc'

    # Now we can create and initialize a raster model grid by reading a DEM

    # First, this looks for the DEM in the overland_flow folder in Landlab
    DATA_FILE = os.path.join(os.path.dirname(__file__), dem_name)

    # This print statement verifies that we are opening the data file.
    print('Reading data from "' + str(DATA_FILE) + '"')

    # Now the ASCII is read, assuming that it it standard ESRI format.
    (rg, z) = read_esri_ascii(DATA_FILE)

    # Whatever the NODATA value is in the DEM is needed here to set bounary condition.
    nodata_val = -9999

    # Modify the grid DEM to set all NODATA nodes to inactive boundaries
    rg.set_nodata_nodes_to_inactive(z, nodata_val)

    # This prints standard grid characteristics (rows, columns and cell size)

    print('DEM has ' + str(rg.number_of_node_rows) + ' rows, ' +
          str(rg.number_of_node_columns) + ' columns, and cell size ' +
          str(rg.dx))

    # Right now, the outlet must be explicitly set for boundary conditions
    # using the row and column from the DEM.
    the_outlet_row = 152
    the_outlet_column = 230

    # This converts the grid row and column into coordinates that the raster grid will recognize
    the_outlet_node = rg.grid_coords_to_node_id(the_outlet_row,
                                                the_outlet_column)

    # The outlet node is set as a fixed value boundary
    rg.set_fixed_value_boundaries(the_outlet_node)

    # To plot the grid, we can call the plot_topography() function
    plot_topography(rg, z)

    # Now we will initialize the Overland Flow component.
    of = OverlandFlow(rg)

    # First, the flow_at_one_node() method will be covered here.

    # When using the flow_at_one_node() method, a study node is needed to sample at.
    # This should not be a boundary node!

    study_row = 122
    study_column = 140

    # This takes the study row and study column grid coordinates and converts it
    # to a node ID that the raster grid will recognize.
    study_node = rg.grid_coords_to_node_id(study_row, study_column)

    # Because this function reads in data using the Model Parameter Dictionary
    # from the default input file, the only arguments needed to run the flow_at_one_node()
    # method is the RasterModelGrid instance, the initial elevations and the study node
    # coordinates.

    # This is the standard way to call the flow_at_one_node method using the input file.
    of.flow_at_one_node(rg, z, study_node)

    # Once run, we can plot the output
    of.plot_at_one_node()

    # If you did not want to use the input file and instead define the total model run time of
    # rainfall intensity and storm duration, the commented function call below demonstrates this with
    # the following parameters:
    # Total model run time: 6000 seconds
    # Storm intensity: (9.2177*(10**-6)) meters per second.
    # Storm duration: 5868 seconds
    #of.flow_at_one_node(rg, z, study_node, 6000, (9.2177*(10**-6)),5868)

    # Now the flow_across_grid() method will be discussed. The commands needed to
    # run this method are triple-commented ('###') for convenience. All flow_at_one_node()
    # methods calls *should* be commented out to run this driver quicker.

    # Again, this function reads in data using the ModelParameterDictionary and the default
    # input file. The only required arguments for this method are the  RasterModelGrid instance
    # and the the initial elevations.

    # This is the standard call to the flow_across_grid() method
    ###of.flow_across_grid(rg,z)

    # And these are the calls to plot the rasters
    ###of.plot_water_depths(rg)
    ###of.plot_discharge(rg)
    ###of.plot_shear_stress_grid(rg)
    ###of.plot_slopes(rg)

    # To forgo the call to the input file and define model run time, rainfall
    # intensity and storm duration in the function call itself, the following command
    # can be used with the following parameters:
    # Total model run time: 6000 seconds
    # Storm intensity: (9.2177*(10**-6)) meters per second.
    # Storm duration: 5868 seconds
    ###of.flow_across_grid(rg, z, 6000, (9.2177*(10**-6)), 5868)

    endtime = time.time()
    print endtime - start_time, "seconds"

    #If you call the plot_topography method...
    plt.show()
def main():
    """
    initialize DEM
    Get storm info
    Generate hydrograph
    """

    start_time = time.time()

    dem_name = 'HalfFork.asc'
    input_file = 'input_data.txt'
    IT_FILE = os.path.join(os.path.dirname(__file__), input_file)

    # Create and initialize a raster model grid by reading a DEM
    DATA_FILE = os.path.join(os.path.dirname(__file__), dem_name)
    print('Reading data from "' + str(DATA_FILE) + '"')
    (rg, z) = read_esri_ascii(DATA_FILE)
    nodata_val = -9999
    # Modify the grid DEM to set all nodata nodes to inactive boundaries
    rg.set_nodata_nodes_to_inactive(
        z, nodata_val)  # set nodata nodes to inactive bounds

    print('DEM has ' + str(rg.number_of_node_rows) + ' rows, ' +
          str(rg.number_of_node_columns) + ' columns, and cell size ' +
          str(rg.dx))

    # Select point to sample at.

    #study_row = 110
    #study_column = 150
    #
    #study_node = rg.grid_coords_to_node_id(study_row, study_column)

    ## Set outlet point to set boundary conditions.
    the_outlet_row = 240
    the_outlet_column = 215
    the_outlet_node = rg.grid_coords_to_node_id(the_outlet_row,
                                                the_outlet_column)

    rg.set_fixed_value_boundaries(the_outlet_node)

    # Get a 2D array version of the elevations for plotting purposes
    elev_raster = rg.node_vector_to_raster(z, True)

    # Everything below plots the topography and sampling points

    #    levels = []
    #    x_up = 1990
    #    while x_up !=2200:
    #        levels.append(x_up)
    #        x_up+=1
    #    plt.figure('Topography')
    #    plt.contourf(elev_raster, levels, colors='k')#('r','g','b'))
    #    plt.set_cmap('bone')
    #    plt.colorbar()
    #
    #    plt.plot([150],[109],'cs', label= 'Study Node')
    #    plt.plot([215],[9], 'wo', label= 'Outlet')
    #    plt.legend(loc=3)

    pd = PrecipitationDistribution()
    pd.initialize()
    duration_hrs = pd.storm_duration
    intensity_mmhr = pd.intensity

    duration_secs = duration_hrs * 60.0 * 60.0
    intensity_ms = ((intensity_mmhr / 1000.0) / 3600.0)
    total_duration_secs = 1.25 * duration_secs

    #print 'total_duration_secs: ', total_duration_secs

    of = OverlandFlow()  #IT_FILE,rg,0)
    of.initialize(rg)

    ## (-,-,-,-,how long we route overland flow, intensity in m/s, duration of storm) ##

    ## Trial 1, 10 year storm ##
    #of.flow_at_one_node(rg,z,study_node,900,(7.167*(10**-6)), 2916)
    #of.flow_at_one_node(rg, z, study_node,9000, (1.384*(10**-5)), 2916)
    #of.flow_at_one_node(rg, z, study_node,900, (7.06*(10**-6)), 900)

    #of.plot_at_one_node()
    of.flow_across_grid(rg, z, 5800, (9.2177 * (10**-6)), 5868)
    #of.flow_at_one_node(rg,z,study_node,150,(9.2177*(10**-6)),5868)
    of.plot_water_depths(rg)
    of.plot_discharge(rg)
    of.plot_shear_stress_grid(rg)
    of.plot_slopes(rg)
    #rg.display_grid()

    endtime = time.time()
    print endtime - start_time, "seconds"
    plt.show()
    plt.show()
    plt.show()
def main():
    """
    initialize DEM
    Get storm info
    Generate hydrograph
    """
    
    start_time = time.time()
    
    dem_name = 'HalfFork.asc'
    input_file = 'input_data.txt'
    IT_FILE = os.path.join(os.path.dirname(__file__), input_file)

    # Create and initialize a raster model grid by reading a DEM
    DATA_FILE = os.path.join(os.path.dirname(__file__), dem_name)
    print('Reading data from "'+str(DATA_FILE)+'"')
    (rg, z) = read_esri_ascii(DATA_FILE)
    nodata_val=-9999
    # Modify the grid DEM to set all nodata nodes to inactive boundaries
    rg.set_nodata_nodes_to_inactive(z, nodata_val) # set nodata nodes to inactive bounds
    
    print('DEM has ' +
          str(rg.number_of_node_rows) + ' rows, ' +
          str(rg.number_of_node_columns) + ' columns, and cell size ' +
          str(rg.dx))
    

    # Select point to sample at.
    
    study_row = 110
    study_column = 150
      
    study_node = rg.grid_coords_to_node_id(study_row, study_column)


    ## Set outlet point to set boundary conditions.
    the_outlet_row = 240
    the_outlet_column = 215
    the_outlet_node = rg.grid_coords_to_node_id(the_outlet_row, the_outlet_column)

    rg.set_fixed_value_boundaries(the_outlet_node)
                                                                                                       
    # Get a 2D array version of the elevations for plotting purposes
    elev_raster = rg.node_vector_to_raster(z,True)
    
    # Everything below plots the topography and sampling points
    
    levels = []
    x_up = 1990
    while x_up !=2200:
        levels.append(x_up)
        x_up+=1
    s = plt.contourf(elev_raster, levels, colors='k')#('r','g','b'))
    plt.set_cmap('bone')
    cb = plt.colorbar()

    plt.plot([150],[109],'cs', label= 'Study Node')
    plt.plot([215],[9], 'wo', label= 'Outlet')
    plt.legend(loc=3)


    of=OverlandFlow()#IT_FILE,rg,0)
    of.initialize(rg)

    ## (-,-,-,-,how long we route overland flow, intensity in m/s, duration of storm) ##

    ## Trial 1, 10 year storm ##
    of.calculate_flow_at_one_point(rg,z,study_node,90,(7.167*(10**-6)), 2916)


    plt.show()
def main():
    """
    initialize DEM
    Get storm info
    Generate hydrograph
    """

    start_time = time.time()

    dem_name = 'HalfFork.asc'
    input_file = 'input_data.txt'
    IT_FILE = os.path.join(os.path.dirname(__file__), input_file)

    # Create and initialize a raster model grid by reading a DEM
    DATA_FILE = os.path.join(os.path.dirname(__file__), dem_name)
    print('Reading data from "' + str(DATA_FILE) + '"')
    (rg, z) = read_esri_ascii(DATA_FILE)
    nodata_val = -9999
    # Modify the grid DEM to set all nodata nodes to inactive boundaries
    rg.set_nodata_nodes_to_inactive(
        z, nodata_val)  # set nodata nodes to inactive bounds

    print('DEM has ' + str(rg.number_of_node_rows) + ' rows, ' +
          str(rg.number_of_node_columns) + ' columns, and cell size ' +
          str(rg.dx))

    # Select point to sample at.

    study_row = 110
    study_column = 150

    study_node = rg.grid_coords_to_node_id(study_row, study_column)

    ## Set outlet point to set boundary conditions.
    the_outlet_row = 240
    the_outlet_column = 215
    the_outlet_node = rg.grid_coords_to_node_id(the_outlet_row,
                                                the_outlet_column)

    rg.set_fixed_value_boundaries(the_outlet_node)

    # Get a 2D array version of the elevations for plotting purposes
    elev_raster = rg.node_vector_to_raster(z, True)

    # Everything below plots the topography and sampling points

    levels = []
    x_up = 1990
    while x_up != 2200:
        levels.append(x_up)
        x_up += 1
    s = plt.contourf(elev_raster, levels, colors='k')  #('r','g','b'))
    plt.set_cmap('bone')
    cb = plt.colorbar()

    plt.plot([150], [109], 'cs', label='Study Node')
    plt.plot([215], [9], 'wo', label='Outlet')
    plt.legend(loc=3)

    of = OverlandFlow()  #IT_FILE,rg,0)
    of.initialize(rg)

    ## (-,-,-,-,how long we route overland flow, intensity in m/s, duration of storm) ##

    ## Trial 1, 10 year storm ##
    of.calculate_flow_at_one_point(rg, z, study_node, 90, (7.167 * (10**-6)),
                                   2916)

    plt.show()
def main():
    """
    initialize DEM
    Get storm info
    Generate hydrograph
    """
    
    start_time = time.time()
    
    dem_name = 'HalfFork.asc'
    input_file = 'input_data.txt'
    IT_FILE = os.path.join(os.path.dirname(__file__), input_file)

    # Create and initialize a raster model grid by reading a DEM
    DATA_FILE = os.path.join(os.path.dirname(__file__), dem_name)
    print('Reading data from "'+str(DATA_FILE)+'"')
    (rg, z) = read_esri_ascii(DATA_FILE)
    nodata_val=-9999
    # Modify the grid DEM to set all nodata nodes to inactive boundaries
    rg.set_nodata_nodes_to_inactive(z, nodata_val) # set nodata nodes to inactive bounds
    
    print('DEM has ' +
          str(rg.number_of_node_rows) + ' rows, ' +
          str(rg.number_of_node_columns) + ' columns, and cell size ' +
          str(rg.dx))
    

    # Select point to sample at.
    
    #study_row = 110
    #study_column = 150
    #  
    #study_node = rg.grid_coords_to_node_id(study_row, study_column)


    ## Set outlet point to set boundary conditions.
    the_outlet_row = 240
    the_outlet_column = 215
    the_outlet_node = rg.grid_coords_to_node_id(the_outlet_row, the_outlet_column)

    rg.set_fixed_value_boundaries(the_outlet_node)
                                                                                                       
    # Get a 2D array version of the elevations for plotting purposes
    elev_raster = rg.node_vector_to_raster(z,True)
    
    # Everything below plots the topography and sampling points
    
#    levels = []
#    x_up = 1990
#    while x_up !=2200:
#        levels.append(x_up)
#        x_up+=1
#    plt.figure('Topography')
#    plt.contourf(elev_raster, levels, colors='k')#('r','g','b'))
#    plt.set_cmap('bone')
#    plt.colorbar()
#
#    plt.plot([150],[109],'cs', label= 'Study Node')
#    plt.plot([215],[9], 'wo', label= 'Outlet')
#    plt.legend(loc=3)
    
    pd = PrecipitationDistribution()
    pd.initialize()
    duration_hrs = pd.storm_duration
    intensity_mmhr = pd.intensity

    duration_secs = duration_hrs*60.0*60.0
    intensity_ms = ((intensity_mmhr/1000.0)/3600.0)
    total_duration_secs = 1.25 * duration_secs
    
    #print 'total_duration_secs: ', total_duration_secs


    of=OverlandFlow()#IT_FILE,rg,0)
    of.initialize(rg)

    ## (-,-,-,-,how long we route overland flow, intensity in m/s, duration of storm) ##

    ## Trial 1, 10 year storm ##
    #of.flow_at_one_node(rg,z,study_node,900,(7.167*(10**-6)), 2916)
    #of.flow_at_one_node(rg, z, study_node,9000, (1.384*(10**-5)), 2916)
    #of.flow_at_one_node(rg, z, study_node,900, (7.06*(10**-6)), 900)

    #of.plot_at_one_node()
    of.flow_across_grid(rg, z, 5800, (9.2177*(10**-6)), 5868)
    #of.flow_at_one_node(rg,z,study_node,150,(9.2177*(10**-6)),5868) 
    of.plot_water_depths(rg)
    of.plot_discharge(rg)
    of.plot_shear_stress_grid(rg)
    of.plot_slopes(rg)
    #rg.display_grid()

    endtime = time.time()
    print endtime - start_time, "seconds"
    plt.show()
    plt.show()
    plt.show()