mg = RasterModelGrid(nrows, ncols, dx) #create the fields in the grid mg.create_node_array_zeros('topographic__elevation') z = mg.create_node_array_zeros() + init_elev mg['node'][ 'topographic__elevation'] = z + numpy.random.rand(len(z))/1000. #make some K values in a field to test mg.at_node['K_values'] = 0.1+numpy.random.rand(nrows*ncols)/10. print( 'Running ...' ) time_on = time.time() #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() #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
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()
#nt needs defining uplift = inputs.read_float('uplift_rate') init_elev = inputs.read_float('init_elev') mg = RasterModelGrid(nrows, ncols, dx) #create the fields in the grid mg.create_node_array_zeros('planet_surface__elevation') z = mg.create_node_array_zeros() + init_elev mg['node'][ 'planet_surface__elevation'] = z + numpy.random.rand(len(z))/1000. print( 'Running ...' ) #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
mg = RasterModelGrid(nrows, ncols, dx) # create the fields in the grid mg.create_node_array_zeros('topographic__elevation') z = np.array([5., 5., 0., 5., 5., 5., 2., 1., 2., 5., 5., 3., 2., 3., 5., 5., 4., 4., 4., 5., 5., 5., 5., 5., 5.]) 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'])
mg = RasterModelGrid(nrows, ncols, dx) #create the fields in the grid mg.create_node_array_zeros('topographic_elevation') z = mg.create_node_array_zeros() + init_elev mg['node']['topographic_elevation'] = z + numpy.random.rand(len(z)) / 1000. #make some K values in a field to test mg.at_node['K_values'] = 0.1 + numpy.random.rand(nrows * ncols) / 10. print('Running ...') time_on = time.time() #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 = fr.route_flow(grid=mg) #print 'Area: ', numpy.max(mg.at_node['drainage_area']) #mg = fsp.erode(mg) mg, _, _ = sp.erode(mg,
# Since the discharge files were created on the WRF-Hydro topography, we use that topography as our input. The original Landlab topography and the WRF-Hydro topography are almost identical, with only slight differences created by the rotation. topo=Dataset('topography_wrf_hydro.nc') topography=topo.variables['TOPOGRAPHY'][:] topographic__elevation=np.asarray(topography, dtype=float).ravel() mg.add_field('node', 'topographic__elevation', topographic__elevation) #create the field #set boundary conditions -- these should match those used in the topography creation driver for edge in (mg.nodes_at_left_edge, mg.nodes_at_right_edge): mg.status_at_node[edge] = CLOSED_BOUNDARY for edge in (mg.nodes_at_top_edge, mg.nodes_at_bottom_edge): mg.status_at_node[edge] = FIXED_VALUE_BOUNDARY #instantiate the components fr = FlowRouter(mg) sp = StreamPowerEroder(mg, input_file) lin_diffuse = LinearDiffuser(mg, input_file) print( 'Running ...' ) time_on = time.time() #text for discharge file names streamflow = "streamflow" nc = ".nc" elapsed_time = 0. #total time in simulation #create list of all discharge files to be used, repeat as many times as necessary for run time. #Example: here we have a total of 20 discharge files -- we need one file for every time step and we have 100 timesteps. # We will repeat the discharge file namelist 5 times Run Time = 100 yrs dt = 1yr rep_num = int(5) #depends on how many discharge files/time steps you have
#nt needs defining uplift = inputs.read_float('uplift_rate') init_elev = inputs.read_float('init_elev') mg = RasterModelGrid(nrows, ncols, dx) #create the fields in the grid mg.create_node_array_zeros('topographic_elevation') z = mg.create_node_array_zeros() + init_elev mg['node']['topographic_elevation'] = z + numpy.random.rand(len(z)) / 1000. print('Running ...') #instantiate the components: fr = FlowRouter(mg) sp = StreamPowerEroder(mg, './drive_sp_params.txt') fsp = Fsc(mg, './drive_sp_params.txt') #load the Fastscape module too, to allow direct comparison fsp = Fsc(mg, './drive_sp_params.txt') vid = VideoPlotter(mg, data_centering='node', step=2.5) try: mg = copy.deepcopy(mg_mature) except NameError: #run to a steady state: #We're going to cheat by running Fastscape SP for the first part of the solution elapsed_time = 0. #total time in simulation while elapsed_time < time_to_run: print elapsed_time if elapsed_time + dt > time_to_run:
#create the field z = mg.add_zeros('topographic__elevation', at='node') z += leftmost_elev z += initial_slope*np.amax(mg.node_y) - initial_slope*mg.node_y #put these values plus roughness into that field z += np.random.rand(len(z))/100000. mg.status_at_node[mg.nodes_at_left_edge] = CLOSED_BOUNDARY 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(
#create the field z = mg.add_zeros('topographic__elevation', at='node') z += leftmost_elev z += initial_slope * np.amax(mg.node_y) - initial_slope * mg.node_y #put these values plus roughness into that field z += np.random.rand(len(z)) / 100000. mg.status_at_node[mg.nodes_at_left_edge] = CLOSED_BOUNDARY 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.create_node_array_zeros('topographic__elevation') z = mg.create_node_array_zeros() + init_elev mg['node'][ 'topographic__elevation'] = z + numpy.random.rand(len(z))/1000. mg.add_zeros('node', 'water__volume_flux_in') #make some K values in a field to test #mg.at_node['K_values'] = 0.1+numpy.random.rand(nrows*ncols)/10. mg.at_node['K_values'] = numpy.empty(nrows*ncols, dtype=float) #mg.at_node['K_values'].fill(0.1+numpy.random.rand()/10.) mg.at_node['K_values'].fill(0.001) print( 'Running ...' ) #instantiate the components: fr = FlowRouter(mg) sp = StreamPowerEroder(mg, input_file_string) #fsp = Fsc(mg, input_file_string) precip = PrecipitationDistribution(input_file=input_file_string) #load the Fastscape module too, to allow direct comparison 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
rock_stress_param = inputs.read_float('rock_density')*9.81 mg = RasterModelGrid(nrows, ncols, dx) #create the fields in the grid mg.create_node_array_zeros('topographic__elevation') z = mg.create_node_array_zeros() + init_elev mg['node'][ 'topographic__elevation'] = z + np.random.rand(len(z))/1000. #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
#create the fields in the grid mg.create_node_array_zeros('topographic_elevation') z = mg.create_node_array_zeros() + init_elev mg['node'][ 'topographic_elevation'] = z + numpy.random.rand(len(z))/1000. #make some K values in a field to test #mg.at_node['K_values'] = 0.1+numpy.random.rand(nrows*ncols)/10. mg.at_node['K_values'] = numpy.empty(nrows*ncols, dtype=float) #mg.at_node['K_values'].fill(0.1+numpy.random.rand()/10.) mg.at_node['K_values'].fill(0.001) print( 'Running ...' ) #instantiate the components: fr = FlowRouter(mg) sp = StreamPowerEroder(mg, input_file_string) #fsp = Fsc(mg, input_file_string) precip = PrecipitationDistribution(input_file=input_file_string) #load the Fastscape module too, to allow direct comparison 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
#build the grid mg = RasterModelGrid((nrows, ncols), dx) z = mg.add_zeros('node', 'topographic__elevation') # add some roughness as the initial topography, this lets "natural" channel planforms arise initial_roughness = np.random.rand(z.size) / 100000. z += initial_roughness #set the boundary conditions - here we have closed boundaries at the top/bottom and fixed boundaries at the left/right for edge in (mg.nodes_at_left_edge, mg.nodes_at_right_edge): mg.status_at_node[edge] = FIXED_VALUE_BOUNDARY for edge in (mg.nodes_at_top_edge, mg.nodes_at_bottom_edge): mg.status_at_node[edge] = CLOSED_BOUNDARY #instantiate the components fr = FlowRouter(mg, input_file) sp = StreamPowerEroder(mg, input_file) lin_diffuse = LinearDiffuser(mg, input_file) #run the model elapsed_time = 0. #total time in simulation for i in range(nt): lin_diffuse.run_one_step(dt) fr.run_one_step( ) # route_flow isn't time sensitive, so it doesn't take dt as input sp.run_one_step(dt) mg.at_node['topographic__elevation'][ mg.core_nodes] += uplift_per_step # add the uplift # if you want to see the evolution of the topogrpahy through time (say to check for steady state) you can output a topography at each time step #write_netcdf(('topography_output'+ str(elapsed_time) +'.nc'), mg, names='topographic__elevation')