from landlab import VoronoiDelaunayGrid # , RasterModelGrid from landlab.components.flow_routing.route_flow_dn import FlowRouter from landlab.components.stream_power.stream_power import StreamPowerEroder from landlab.plot.imshow import imshow_node_grid import numpy as np from matplotlib.pyplot import figure, show nnodes = 10000 x, y = np.random.rand(nnodes), np.random.rand(nnodes) mg = VoronoiDelaunayGrid(x,y) #mg = RasterModelGrid(4,5) z = mg.add_field('node', 'topographic__elevation', np.random.rand(nnodes)/10000., copy=False) fr = FlowRouter(mg) spe = StreamPowerEroder(mg, 'drive_sp_params_voronoi.txt') for i in xrange(100): z[mg.core_nodes] += 0.01 fr.route_flow() spe.erode(mg, 1.) imshow_node_grid(mg, 'topographic__elevation') show()
mg['node']['topographic__elevation'] = z print('Running ...') # instantiate the components: fr = FlowRouter(mg) 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 xrange(1): fr.route_flow(method='D8') my_Q = mg.at_node['water__volume_flux']*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 elev = mg['node']['topographic__elevation'] elev_r = mg.node_vector_to_raster(elev) # Clear previous plots pylab.figure(1) pylab.close()
fr = FlowRouter(mg) sp = StreamPowerEroder(mg, './drive_sp_params.txt') #load the Fastscape module too, to allow direct comparison fsp = Fsc(mg, './drive_sp_params.txt') #perform the loop: elapsed_time = 0. #total time in simulation 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() #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 time_off = time.time() print('Elapsed time: ', time_off-time_on) #Finalize and plot elev = mg['node']['topographic__elevation'] elev_r = mg.node_vector_to_raster(elev) # Clear previous plots pylab.figure(1) pylab.close()
#load discharge to a new variable my_Q print (discharge_filename[num]) f=Dataset(discharge_filename[num]) discharge=f.variables['streamflow'][:] my_Q=np.asarray(discharge, dtype=float).ravel() #run diffusion component lin_diffuse.run_one_step(dt,deposit='false') #turn deposition off #run flow routing component fr.run_one_step() #add my_Q variable to landlab discharge _ = mg.add_field('node','surface_water__discharge', my_Q, noclobber=False) #run stream power component with my_Q sp.erode(mg, dt,Q_if_used=my_Q) #add uplift mg.at_node['topographic__elevation'][mg.core_nodes] +=uplift*dt #record topography through time (optional) #write_netcdf(('topography_output'+ str(elapsed_time) +'.nc'), mg, names='topographic__elevation') elapsed_time += dt time_off = time.time() #save the resultant topography as a netcdf file write_netcdf('topography_final.nc', mg, names='topographic__elevation')
#instantiate the components: fr = FlowRouter(mg) sp = StreamPowerEroder(mg, './drive_sp_params.txt') #load the Fastscape module too, to allow direct comparison fsp = Fsc(mg, './drive_sp_params.txt') #perform the loop: elapsed_time = 0. #total time in simulation 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(grid=mg) #mg = fsp.erode(mg) mg,_,_ = sp.erode(mg, dt, node_drainage_areas='drainage_area', slopes_at_nodes='steepest_slope') #add uplift mg.at_node['planet_surface__elevation'][mg.core_nodes] += uplift*dt elapsed_time += dt #Finalize and plot elev = mg['node']['planet_surface__elevation'] elev_r = mg.node_vector_to_raster(elev) # Clear previous plots pylab.figure(1) pylab.close() # Plot topography pylab.figure(1) im = pylab.imshow(elev_r, cmap=pylab.cm.RdBu) # display a colored image
mg.status_at_node[mg.nodes_at_right_edge] = CLOSED_BOUNDARY fr = FlowRouter(mg) if DL_or_TL == 'TL': tle = TransportLimitedEroder(mg, input_file) else: spe = StreamPowerEroder(mg, input_file) for i in xrange(nt): # print 'loop ', i mg.at_node['topographic__elevation'][mg.core_nodes] += uplift_per_step mg = fr.route_flow(grid=mg) if DL_or_TL == 'TL': mg, _ = tle.erode(mg, dt) else: mg, _, _ = spe.erode(mg, dt=dt) if i % init_interval == 0: print 'loop ', i print 'max_slope', np.amax(mg.at_node['topographic__steepest_slope'][ mg.core_nodes]) pylab.figure("long_profiles_init") 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']) prf.plot_profiles(dists_upstr, profile_IDs, mg.at_node['topographic__elevation']) print 'completed run to steady state...' if show_figs_in_run:
fsp = Fsc(mg, './drive_sp_params.txt') #perform the loop: elapsed_time = 0. #total time in simulation 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(grid=mg) mg = fr.route_flow(grid=mg) #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='steepest_slope', K_if_used='K_values') #add uplift mg.at_node['topographic_elevation'][mg.core_nodes] += uplift * dt elapsed_time += dt time_off = time.time() print 'Elapsed time: ', time_off - time_on #Finalize and plot elev = mg['node']['topographic_elevation'] elev_r = mg.node_vector_to_raster(elev) # Clear previous plots pylab.figure(1)
fr = FlowRouter(mg) sp = StreamPowerEroder(mg, './drive_sp_params.txt') #load the Fastscape module too, to allow direct comparison fsp = Fsc(mg, './drive_sp_params.txt') #perform the loop: elapsed_time = 0. #total time in simulation 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(grid=mg) #mg = fsp.erode(mg) mg, _, _ = sp.erode(mg, dt, node_drainage_areas='drainage_area', slopes_at_nodes='steepest_slope') #add uplift mg.at_node['planet_surface__elevation'][mg.core_nodes] += uplift * dt elapsed_time += dt #Finalize and plot elev = mg['node']['planet_surface__elevation'] elev_r = mg.node_vector_to_raster(elev) # Clear previous plots pylab.figure(1) pylab.close() # Plot topography pylab.figure(1)
mg.status_at_node[mg.nodes_at_right_edge] = CLOSED_BOUNDARY fr = FlowRouter(mg) if DL_or_TL == 'TL': tle = TransportLimitedEroder(mg, input_file) else: spe = StreamPowerEroder(mg, input_file) for i in xrange(nt): # print 'loop ', i mg.at_node['topographic__elevation'][mg.core_nodes] += uplift_per_step mg = fr.route_flow(grid=mg) if DL_or_TL == 'TL': mg, _ = tle.erode(mg, dt) else: mg, _, _ = spe.erode(mg, dt=dt) if i % init_interval == 0: print 'loop ', i print 'max_slope', np.amax( mg.at_node['topographic__steepest_slope'][mg.core_nodes]) pylab.figure("long_profiles_init") 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']) prf.plot_profiles(dists_upstr, profile_IDs, mg.at_node['topographic__elevation']) print 'completed run to steady state...'
try: #raise NameError mg = copy.deepcopy(mg_mature) except NameError: print('building a new grid...') out_interval = 50000. last_trunc = time_to_run #we use this to trigger taking an output plot #run to a steady state: #We're going to cheat by running Fastscape SP for the first part of the solution for (interval_duration, rainfall_rate) in precip.yield_storm_interstorm_duration_intensity(): if rainfall_rate != 0.: mg.at_node['water__volume_flux_in'].fill(rainfall_rate) mg = fr.route_flow() #print 'Area: ', numpy.max(mg.at_node['drainage_area']) mg,_,_ = sp.erode(mg, interval_duration, Q_if_used='water__volume_flux', K_if_used='K_values') #add uplift mg.at_node['topographic__elevation'][mg.core_nodes] += uplift*interval_duration this_trunc = precip.elapsed_time//out_interval if this_trunc != last_trunc: #a new loop round print('made it to loop ', out_interval*this_trunc) last_trunc=this_trunc mg_mature = copy.deepcopy(mg) else: #reinstantiate the components with the new grid fr = FlowRouter(mg) sp = StreamPowerEroder(mg, input_file_string) if True:
#make some surface load stresses in a field to test mg.at_node['surface_load__stress'] = np.zeros(nrows*ncols, dtype=float) #instantiate: gf = gFlex(mg, './coupled_SP_gflex_params.txt') fsp = Fsc(mg, './coupled_SP_gflex_params.txt') sp = StreamPowerEroder(mg, './coupled_SP_gflex_params.txt') fr = FlowRouter(mg) #perform the loop: elapsed_time = 0. #total time in simulation 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() #mg = fsp.erode(mg) mg,_,_ = sp.erode(mg, dt, node_drainage_areas='drainage_area', slopes_at_nodes='topographic__steepest_slope') mg.at_node['surface_load__stress'] = (mg.at_node['topographic__elevation']+1000)*rock_stress_param gf.flex_lithosphere() mg.at_node['topographic__elevation'][mg.number_of_nodes//4:3.*mg.number_of_nodes//4] += uplift_perstep elapsed_time += dt pylab.figure(1) im = imshow_node_grid(mg, 'topographic__elevation') # display a colored image pylab.figure(2) im = imshow_node_grid(mg, 'lithosphere__vertical_displacement')
fsp = Fsc(mg, input_file_string) try: #raise NameError mg = copy.deepcopy(mg_mature) except NameError: print 'building a new grid...' out_interval = 50000. last_trunc = time_to_run #we use this to trigger taking an output plot #run to a steady state: #We're going to cheat by running Fastscape SP for the first part of the solution for (interval_duration, rainfall_rate) in precip.yield_storm_interstorm_duration_intensity(): if rainfall_rate != 0.: mg = fr.route_flow(grid=mg, runoff_rate=rainfall_rate) #print 'Area: ', numpy.max(mg.at_node['drainage_area']) mg,_,_ = sp.erode(mg, interval_duration, Q_if_used='water_discharges', K_if_used='K_values') #add uplift mg.at_node['topographic_elevation'][mg.core_nodes] += uplift*interval_duration this_trunc = precip.elapsed_time//out_interval if this_trunc != last_trunc: #a new loop round print 'made it to loop ', out_interval*this_trunc last_trunc=this_trunc mg_mature = copy.deepcopy(mg) else: #reinstantiate the components with the new grid fr = FlowRouter(mg) sp = StreamPowerEroder(mg, input_file_string) if True: