#rep_num = int(2) #depends on how many discharge files/ time steps you have #discharge_filename=[streamflow + repr(j) + nc for k in range(rep_num) for j in range(1,7302)] #run the model: load a new discharge file at each time step, use this discharge file in the stream power erosion component while elapsed_time < run_time: num = int(elapsed_time/dt) #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')
# View the initial grid figure() imshow_grid(mg, 'topographic__elevation', cmap='viridis', grid_units=['m', 'm']) show() linear_diffusivity = 0.01 #in m2 per year ld = LinearDiffuser(grid=mg, linear_diffusivity=linear_diffusivity) dt = 100. #Evolve landscape for i in range(25): ld.run_one_step(dt) #Plot new landscape figure() imshow_grid(mg, 'topographic__elevation', cmap='viridis', grid_units=['m', 'm']) show() #%% Create an uplifted block in the center of model domain and continue to uplift this block - use only linear diffusion modeling #Create a raster grid with 100 rows, 100 columns, and cell spacing of 1 m n = 100 mg = RasterModelGrid((n, n), 1.0) z = mg.add_zeros('node', 'topographic__elevation') mg.set_closed_boundaries_at_grid_edges(right_is_closed=False, top_is_closed=False, \
#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') elapsed_time += dt if i % 100 == 0: print('completed loop %d' % i) #save the resultant topography as a netcdf file