# instantiate the components: fr = FlowAccumulator(mg, flow_director='D8') sde = SedDepEroder(mg, input_file) # don't allow overwriting of these, just in case try: x_profiles except NameError: x_profiles = [] z_profiles = [] S_profiles = [] A_profiles = [] # plot init conds if make_output_plots: mg = fr.route_flow(grid=mg) pylab.figure('long_profile_anim') ylim([0, y_max]) prf.analyze_channel_network_and_plot(mg) savefig('0profile_anim_init.png') close('long_profile_anim') (profile_IDs, dists_upstr) = prf.analyze_channel_network_and_plot(mg) start_node = [profile_IDs[0]] time_on = time() #perform the loops: for i in range(nt): #print 'loop ', i mg.at_node['topographic__elevation'][mg.core_nodes] += uplift_per_step mg = fr.run_one_step()
from landlab.io import read_esri_ascii from landlab.plot.imshow import imshow_node_grid dem_name = "../../../io/tests/data/west_bijou_gully.asc" outlet_row = 82 outlet_column = 38 # Read in a DEM and set its boundaries DATA_FILE = os.path.join(os.path.dirname(__file__), dem_name) (grid, z) = read_esri_ascii(DATA_FILE) grid.set_nodata_nodes_to_inactive(z, 0) # set nodata nodes to inactive bounds outlet_node = grid.grid_coords_to_node_id(outlet_row, outlet_column) # Route flow flow_router = FlowAccumulator(grid, flow_director="D8") flow_router.route_flow() # Get a 2D array version of the elevations ar = grid.node_vector_to_raster(grid["node"]["drainage_area"]) numcols = grid.number_of_node_columns numrows = grid.number_of_node_rows dx = grid.dx # Create a shaded image pylab.close() # clear any pre-existing plot im = pylab.imshow(ar, cmap=pylab.cm.RdBu, extent=[0, numcols * dx, 0, numrows * dx]) # add contour lines with labels cset = pylab.contour(ar, extent=[0, numcols * dx, numrows * dx, 0])
from landlab.components import FlowAccumulator from landlab.io import read_esri_ascii dem_name = "../../../io/tests/data/west_bijou_gully.asc" outlet_row = 82 outlet_column = 38 # Read in a DEM and set its boundaries DATA_FILE = os.path.join(os.path.dirname(__file__), dem_name) (grid, z) = read_esri_ascii(DATA_FILE) grid.set_nodata_nodes_to_inactive(z, 0) # set nodata nodes to inactive bounds outlet_node = grid.grid_coords_to_node_id(outlet_row, outlet_column) # Route flow flow_router = FlowAccumulator(grid, flow_director="D8") flow_router.route_flow() # Get a 2D array version of the elevations ar = grid.node_vector_to_raster(grid["node"]["drainage_area"]) numcols = grid.number_of_node_columns numrows = grid.number_of_node_rows dx = grid.dx # Create a shaded image pylab.close() # clear any pre-existing plot im = pylab.imshow(ar, cmap=pylab.cm.RdBu, extent=[0, numcols * dx, 0, numrows * dx]) # add contour lines with labels cset = pylab.contour(ar, extent=[0, numcols * dx, numrows * dx, 0]) pylab.clabel(cset, inline=True, fmt="%1.1f", fontsize=10)
grid = RasterModelGrid(4, 5, 1.0) grid.set_inactive_boundaries(False, True, True, True) z = grid.add_zeros("node", "Land_Surface__Elevation") z[6] = 4.5 z[7] = 3. z[8] = 1. z[11] = 4. z[12] = 2.8 z[13] = 2. # Get array of interior (active) node IDs interior_nodes = np.where(grid.status_at_node != CLOSED_BOUNDARY)[0] # Route flow flow_router = FlowAccumulator(grid, flow_director="D8") grid = flow_router.route_flow() for i in range(grid.number_of_nodes): print( i, grid.node_x[i], grid.node_y[i], z[i], grid.status_at_node[i], r[i], a[i], q[i], ss[i], rl[i], )
5., ] ) mg["node"]["topographic__elevation"] = z print("Running ...") # instantiate the components: fr = FlowAccumulator(mg, flow_director="D8") sp = StreamPowerEroder(mg, "./drive_sp_params_discharge.txt") # load the Fastscape module too, to allow direct comparison fsp = Fsc(mg, "./drive_sp_params_discharge.txt") # perform the loop (once!) for i in range(1): fr.route_flow(method="D8") my_Q = mg.at_node["surface_water__discharge"] * 1. sp.erode( mg, dt, node_drainage_areas="drainage_area", slopes_at_nodes="topographic__steepest_slope", Q_if_used=my_Q, ) # no uplift # print the stream power that was calculated: print("stream power values:") print(mg.at_node["stream_power_erosion"]) # Finalize and plot
#instantiate the components: fr = FlowAccumulator(mg, flow_director='D8') sp = StreamPowerEroder(mg, './drive_sp_params.txt') #load the Fastscape module too, to allow direct comparison fsp = FastscapeEroder(mg, './drive_sp_params.txt') #perform the loop: elapsed_time = 0. #total time in simulation counter = 0. while elapsed_time < time_to_run: print(elapsed_time) if elapsed_time + dt > time_to_run: print("Short step!") dt = time_to_run - elapsed_time mg = fr.route_flow(method='D8') #print 'Area: ', numpy.max(mg.at_node['drainage_area']) #mg = fsp.erode(mg) mg, _, _ = sp.erode(mg, dt, node_drainage_areas='drainage_area', slopes_at_nodes='topographic__steepest_slope', K_if_used='K_values') #add uplift mg.at_node['topographic__elevation'][mg.core_nodes] += uplift * dt elapsed_time += dt if counter % 20 == 0: pylab.figure('profiles') profiles = prf.analyze_channel_network_and_plot(mg) counter += 1
#instantiate the components: fr = FlowAccumulator(mg, flow_director='D8') sp = StreamPowerEroder(mg, './drive_sp_params.txt') #load the Fastscape module too, to allow direct comparison fsp = FastscapeEroder(mg, './drive_sp_params.txt') #perform the loop: elapsed_time = 0. #total time in simulation counter = 0. while elapsed_time < time_to_run: print(elapsed_time) if elapsed_time+dt>time_to_run: print("Short step!") dt = time_to_run - elapsed_time mg = fr.route_flow(method='D8') #print 'Area: ', numpy.max(mg.at_node['drainage_area']) #mg = fsp.erode(mg) mg,_,_ = sp.erode(mg, dt, node_drainage_areas='drainage_area', slopes_at_nodes='topographic__steepest_slope', K_if_used='K_values') #add uplift mg.at_node['topographic__elevation'][mg.core_nodes] += uplift*dt elapsed_time += dt if counter%20 == 0: pylab.figure('profiles') profiles = prf.analyze_channel_network_and_plot(mg) counter += 1 time_off = time.time() print('Elapsed time: ', time_off-time_on) time_off = time.time()
grid.set_inactive_boundaries(False, True, True, True) z = grid.add_zeros('node', 'Land_Surface__Elevation') z[6] = 4.5 z[7] = 3. z[8] = 1. z[11] = 4. z[12] = 2.8 z[13] = 2. # Get array of interior (active) node IDs interior_nodes = np.where(grid.status_at_node != CLOSED_BOUNDARY)[0] # Route flow flow_router = FlowAccumulator(grid, flow_director='D8') grid = flow_router.route_flow() for i in range(grid.number_of_nodes): print(i, grid.node_x[i], grid.node_y[i], z[i], grid.status_at_node[i], \ r[i], a[i], q[i], ss[i], rl[i]) # Let's take a look for debugging #print 'node receiver flow_link' #for i in interior_nodes: # print i, r[i], rl[i] # Calculate lengths of flow links flow_link_length = np.ones(np.size(z)) # DEJH suspects a node ordering bug here - rl is not in ID order, # but interior_nodes is
total_t = 250. for edge in (mg.nodes_at_top_edge, mg.nodes_at_left_edge, mg.nodes_at_right_edge): mg.status_at_node[edge] = CLOSED_BOUNDARY for edge in ( mg.nodes_at_bottom_edge): mg.status_at_node[edge] = FIXED_VALUE_BOUNDARY fr = FlowRouter(mg, **inputs) sp = FastscapeEroder(mg, **inputs) lin_diffuse = LinearDiffuser(mg, **inputs) out_interval = 10. last_trunc = total_t # we use this to trigger taking an output plot for (interval_duration, rainfall_rate) in precip.yield_storm_interstorm_duration_intensity(): if rainfall_rate > 0.: # note diffusion also only happens when it's raining... fr.route_flow() sp.run_one_step(interval_duration) lin_diffuse.run_one_step(interval_duration) z[mg.core_nodes] += uplift_rate * interval_duration this_trunc = precip.elapsed_time // out_interval if this_trunc != last_trunc: # time to plot a new profile! print ('made it to time %d' % (out_interval * this_trunc)) last_trunc = this_trunc figure("long_profiles-storm_model") profile_IDs = prf.channel_nodes(mg, mg.at_node['topographic__steepest_slope'], mg.at_node['drainage_area'], mg.at_node['flow__receiver_node']) dists_upstr = prf.get_distances_upstream( mg, len(mg.at_node['topographic__steepest_slope']), profile_IDs, mg.at_node['flow__link_to_receiver_node']) plot(dists_upstr[0], z[profile_IDs[0]], label=out_interval * this_trunc)