while elapsed_time < time_to_run: print(elapsed_time) if elapsed_time + dt < time_to_run: diffusion_component.input_timestep(dt) mg.at_node['topographic__elevation'][mg.core_nodes] += uplift * dt # mg.at_node['topographic__elevation'][mg.active_nodes[:(mg.active_nodes.shape[0]//2.)]] += uplift*dt #half block uplift # mg.at_node['topographic__elevation'][mg.active_nodes] += (numpy.arange(len(mg.active_nodes))) #nodes are tagged with their ID # pylab.figure(1) # pylab.close() #elev = mg['node']['topographic__elevation'] #elev_r = mg.node_vector_to_raster(elev) # pylab.figure(1) #im = pylab.imshow(elev_r, cmap=pylab.cm.RdBu) # pylab.show() mg = diffusion_component.diffuse(mg, elapsed_time) elapsed_time += dt #Finalize and plot elev = mg['node']['topographic__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 print(elev_r) pylab.colorbar(im)
# First, we do the nonlinear diffusion: # We're going to perform a block uplift of the interior of the grid, but # leave the boundary nodes at their original elevations. # access this function of the grid, and store the output with a local name uplifted_nodes = mg.get_core_nodes() #(Note: Node numbering runs across from the bottom left of the grid.) # nt is the number of timesteps we calculated above, i.e., loop nt times. # We never actually use i within the loop, but we could do. for i in range(nt): #("range" is a clever memory-saving way of producing consecutive integers to govern a loop) # this colon-then-tab-in arrangement is what Python uses to delineate connected blocks of text, instead of brackets or parentheses # This line performs the actual functionality of the component: # mg = lin_diffuse.diffuse(dt) #linear diffusion mg = diffuse.diffuse(mg, i * dt) # nonlinear diffusion #...swap around which line is commented out to switch between formulations of diffusion # now plot a N-S cross section from this stage in the run onto figure 1. # The sections will all be superimposed, as show() hasn't yet been called pylab.figure(1) # turn the 1-D array of elevation values into a spatially accurate 2-D # gridded format, for plotting elev_r = mg.node_vector_to_raster(mg['node']['topographic__elevation']) # square brackets denote a subset of nodes to use. im = pylab.plot(mg.dx * np.arange(nrows), elev_r[:, int(ncols // 2)]) #...this kind of data extraction from a larger data structure ("slicing", or "fancy indexing") is extremely useful and powerful, and is one of the appeals of Python #...this is plot(x, y). # x is the distance north up the grid. # y is the elevation along all the rows, but only the 50th column (more # slicing!), i.e., halfway along the grid and N-S
print('Running ...') start_time = time.time() #instantiate the component: diffusion_component = PerronNLDiffuse(mg, './drive_perron_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: diffusion_component.input_timestep(dt) mg.at_node['topographic__elevation'][mg.active_nodes[:( mg.active_nodes.shape[0] // 2.)]] += uplift * dt #half block uplift mg = diffusion_component.diffuse(mg, elapsed_time) elapsed_time += dt print('Total run time = ' + str(time.time() - start_time) + ' seconds.') # Clear previous plots pylab.figure(1) pylab.close() # Plot topography pylab.figure(1) im = imshow_node_grid(mg, 'topographic__elevation') pylab.title('Topography') elev_r = mg.node_vector_to_raster(mg.at_node['topographic__elevation']) pylab.figure(2)
print 'Running ...' #instantiate the components: fr = FlowRouter(mg) sp = SPEroder(mg, input_file) diffuse = PerronNLDiffuse(mg, input_file) lin_diffuse = DiffusionComponent(grid=mg) lin_diffuse.initialize(input_file) #perform the loops: for i in xrange(nt): mg['node']['planet_surface__elevation'][ mg.get_interior_nodes()] += uplift_per_step mg = fr.route_flow(grid=mg) mg = sp.erode(mg) mg = diffuse.diffuse(mg, i * dt) #mg = lin_diffuse.diffuse(mg, dt) ##plot long profiles along channels pylab.figure(6) profile_IDs = prf.channel_nodes(mg, mg.at_node['steepest_slope'], mg.at_node['drainage_area'], mg.at_node['upstream_ID_order'], mg.at_node['flow_receiver']) dists_upstr = prf.get_distances_upstream( mg, len(mg.at_node['steepest_slope']), profile_IDs, mg.at_node['links_to_flow_receiver']) prf.plot_profiles(dists_upstr, profile_IDs, mg.at_node['planet_surface__elevation']) print 'Completed loop ', i
print 'Running ...' #instantiate the components: fr = FlowRouter(mg) sp = SPEroder(mg, input_file) diffuse = PerronNLDiffuse(mg, input_file) lin_diffuse = DiffusionComponent(grid=mg) lin_diffuse.initialize(input_file) #perform the loops: for i in xrange(nt): mg['node']['planet_surface__elevation'][mg.get_interior_nodes()] += uplift_per_step mg = fr.route_flow(grid=mg) mg = sp.erode(mg) mg = diffuse.diffuse(mg, i*dt) #mg = lin_diffuse.diffuse(mg, dt) ##plot long profiles along channels pylab.figure(6) profile_IDs = prf.channel_nodes(mg, mg.at_node['steepest_slope'], mg.at_node['drainage_area'], mg.at_node['upstream_ID_order'], mg.at_node['flow_receiver']) dists_upstr = prf.get_distances_upstream(mg, len(mg.at_node['steepest_slope']), profile_IDs, mg.at_node['links_to_flow_receiver']) prf.plot_profiles(dists_upstr, profile_IDs, mg.at_node['planet_surface__elevation']) print 'Completed loop ', i print 'Completed the simulation. Plotting...'
#Perform the loops. #First, we do the nonlinear diffusion: #We're going to perform a block uplift of the interior of the grid, but leave the boundary nodes at their original elevations. uplifted_nodes = mg.get_core_nodes( ) #access this function of the grid, and store the output with a local name #(Note: Node numbering runs across from the bottom left of the grid.) for i in xrange( nt ): #nt is the number of timesteps we calculated above, i.e., loop nt times. We never actually use i within the loop, but we could do. #("xrange" is a clever memory-saving way of producing consecutive integers to govern a loop) #this colon-then-tab-in arrangement is what Python uses to delineate connected blocks of text, instead of brackets or parentheses #This line performs the actual functionality of the component: #mg = lin_diffuse.diffuse(mg, dt) #linear diffusion mg = diffuse.diffuse(mg, i * dt) #nonlinear diffusion #...swap around which line is commented out to switch between formulations of diffusion #now plot a N-S cross section from this stage in the run onto figure 1. The sections will all be superimposed, as show() hasn't yet been called pylab.figure(1) elev_r = mg.node_vector_to_raster( mg['node']['planet_surface__elevation'] ) #turn the 1-D array of elevation values into a spatially accurate 2-D gridded format, for plotting im = pylab.plot( mg.dx * np.arange(nrows), elev_r[:, int(ncols // 2)]) #square brackets denote a subset of nodes to use. #...this kind of data extraction from a larger data structure ("slicing", or "fancy indexing") is extremely useful and powerful, and is one of the appeals of Python #...this is plot(x, y). #x is the distance north up the grid. #y is the elevation along all the rows, but only the 50th column (more slicing!), i.e., halfway along the grid and N-S