# += 0.05 #half block uplift # 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() # Display a message 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.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)
mg.create_node_array_zeros('topographic_elevation') z = mg.create_node_array_zeros() + leftmost_elev z += initial_slope * np.amax(mg.node_y) - initial_slope * mg.node_y #put these values plus roughness into that field mg.at_node['topographic_elevation'] = z + np.random.rand(len(z)) / 100000. #set up grid's boundary conditions (bottom, right, top, left is inactive) mg.set_closed_boundaries_at_grid_edges(False, True, False, True) # Display a message print 'Running ...' #instantiate the components: fr = FlowRouter(mg) sp = SPEroder(mg, input_file) diffuse = PerronNLDiffuse(mg, input_file) lin_diffuse = DiffusionComponent(grid=mg, input_stream=input_file) #perform the loops: for i in xrange(nt): #note the input arguments here are not totally standardized between modules #mg = diffuse.diffuse(mg, i*dt) mg = lin_diffuse.diffuse(mg, dt) mg = fr.route_flow(grid=mg) mg = sp.erode(mg) ##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'],
# create the field mg.add_zeros('topographic__elevation', at='node') # in our case, slope is zero, so the leftmost_elev is the mean elev z = mg.zeros(at='node') + leftmost_elev # put these values plus roughness into that field mg['node']['topographic__elevation'] = z + np.random.rand(len(z)) / 100000. # set up its boundary conditions (bottom, left, top, right) # The mechanisms for this are all automated within the grid object mg.set_fixed_value_boundaries_at_grid_edges(True, True, True, True) # Display a message print('Running ...') # instantiate the components: diffuse = PerronNLDiffuse(mg, input_file) lin_diffuse = LinearDiffuser(grid=mg, input_stream=input_file) # lin_diffuse.initialize(input_file) # 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. # 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):
mg = RasterModelGrid(nrows, ncols, dx) # mg.set_looped_boundaries(True, True) mg.set_closed_boundaries_at_grid_edges(True, True, True, True) #create the fields in the grid mg.create_node_array_zeros('topographic__elevation') z = mg.create_node_array_zeros() + init_elev mg.at_node['topographic__elevation'] = z + numpy.random.rand(len(z)) / 1000. # Display a message 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.')
##create the elevation field in the grid: #create the field mg.create_node_array_zeros('planet_surface__elevation') z = mg.create_node_array_zeros() + leftmost_elev z += initial_slope * np.amax(mg.node_y) - initial_slope * mg.node_y #put these values plus roughness into that field mg['node']['planet_surface__elevation'] = z + np.random.rand(len(z)) / 100000. # Display a message 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'],
##create the elevation field in the grid: #create the field mg.create_node_array_zeros('planet_surface__elevation') z = mg.create_node_array_zeros() + leftmost_elev z += initial_slope*np.amax(mg.node_y) - initial_slope*mg.node_y #put these values plus roughness into that field mg['node'][ 'planet_surface__elevation'] = z + np.random.rand(len(z))/100000. # Display a message 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'],
#The mechanisms for this are all automated within the grid object mg.set_inactive_boundaries(False, False, False, False) ##create the elevation field in the grid: #create the field mg.create_node_array_zeros('planet_surface__elevation') z = mg.create_node_array_zeros( ) + leftmost_elev #in our case, slope is zero, so the leftmost_elev is the mean elev #put these values plus roughness into that field mg['node']['planet_surface__elevation'] = z + np.random.rand(len(z)) / 100000. # Display a message print 'Running ...' #instantiate the components: diffuse = PerronNLDiffuse(mg, input_file) lin_diffuse = DiffusionComponent(grid=mg, input_stream=input_file) #lin_diffuse.initialize(input_file) #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)