def test_sed_dep(): input_file = os.path.join(_THIS_DIR, "sed_dep_params.txt") inputs = ModelParameterDictionary(input_file, auto_type=True) nrows = inputs.read_int("nrows") ncols = inputs.read_int("ncols") dx = inputs.read_float("dx") uplift_rate = inputs.read_float("uplift_rate") runtime = inputs.read_float("total_time") dt = inputs.read_float("dt") nt = int(runtime // dt) uplift_per_step = uplift_rate * dt mg = RasterModelGrid((nrows, ncols), xy_spacing=(dx, dx)) mg.add_zeros("topographic__elevation", at="node") z = np.loadtxt(os.path.join(_THIS_DIR, "seddepinit.txt")) mg["node"]["topographic__elevation"] = z mg.set_closed_boundaries_at_grid_edges(True, False, True, False) fr = FlowAccumulator(mg, flow_director="D8") sde = SedDepEroder(mg, **inputs) for i in range(nt): mg.at_node["topographic__elevation"][mg.core_nodes] += uplift_per_step mg = fr.run_one_step() mg, _ = sde.erode(dt) z_tg = np.loadtxt(os.path.join(_THIS_DIR, "seddepz_tg.txt")) assert_array_almost_equal( mg.at_node["topographic__elevation"][mg.core_nodes], z_tg[mg.core_nodes])
def test_sed_dep(): input_file = os.path.join(_THIS_DIR, "sed_dep_params.txt") inputs = ModelParameterDictionary(input_file, auto_type=True) nrows = inputs.read_int("nrows") ncols = inputs.read_int("ncols") dx = inputs.read_float("dx") uplift_rate = inputs.read_float("uplift_rate") runtime = inputs.read_float("total_time") dt = inputs.read_float("dt") nt = int(runtime // dt) uplift_per_step = uplift_rate * dt mg = RasterModelGrid((nrows, ncols), xy_spacing=(dx, dx)) mg.add_zeros("topographic__elevation", at="node") z = np.loadtxt(os.path.join(_THIS_DIR, "seddepinit.txt")) mg["node"]["topographic__elevation"] = z mg.set_closed_boundaries_at_grid_edges(True, False, True, False) fr = FlowAccumulator(mg, flow_director="D8") sde = SedDepEroder(mg, **inputs) for i in range(nt): mg.at_node["topographic__elevation"][mg.core_nodes] += uplift_per_step mg = fr.run_one_step() mg, _ = sde.erode(dt) z_tg = np.loadtxt(os.path.join(_THIS_DIR, "seddepz_tg.txt")) assert_array_almost_equal( mg.at_node["topographic__elevation"][mg.core_nodes], z_tg[mg.core_nodes] )
def test_sed_dep(): input_file = os.path.join(_THIS_DIR, 'sed_dep_params.txt') inputs = ModelParameterDictionary(input_file, auto_type=True) nrows = inputs.read_int('nrows') ncols = inputs.read_int('ncols') dx = inputs.read_float('dx') leftmost_elev = inputs.read_float('leftmost_elevation') initial_slope = inputs.read_float('initial_slope') uplift_rate = inputs.read_float('uplift_rate') runtime = inputs.read_float('total_time') dt = inputs.read_float('dt') nt = int(runtime // dt) uplift_per_step = uplift_rate * dt mg = RasterModelGrid((nrows, ncols), (dx, dx)) mg.add_zeros('topographic__elevation', at='node') z = np.loadtxt(os.path.join(_THIS_DIR, 'seddepinit.txt')) mg['node']['topographic__elevation'] = z mg.set_closed_boundaries_at_grid_edges(True, False, True, False) fr = FlowAccumulator(mg, flow_director='D8') sde = SedDepEroder(mg, **inputs) for i in range(nt): mg.at_node['topographic__elevation'][mg.core_nodes] += uplift_per_step mg = fr.run_one_step() mg, _ = sde.erode(dt) z_tg = np.loadtxt(os.path.join(_THIS_DIR, 'seddepz_tg.txt')) assert_array_almost_equal( mg.at_node['topographic__elevation'][mg.core_nodes], z_tg[mg.core_nodes])
def test_sed_dep(): input_file = os.path.join(_THIS_DIR, 'sed_dep_params.txt') inputs = ModelParameterDictionary(input_file, auto_type=True) nrows = inputs.read_int('nrows') ncols = inputs.read_int('ncols') dx = inputs.read_float('dx') leftmost_elev = inputs.read_float('leftmost_elevation') initial_slope = inputs.read_float('initial_slope') uplift_rate = inputs.read_float('uplift_rate') runtime = inputs.read_float('total_time') dt = inputs.read_float('dt') nt = int(runtime // dt) uplift_per_step = uplift_rate * dt mg = RasterModelGrid((nrows, ncols), (dx, dx)) mg.add_zeros('topographic__elevation', at='node') z = np.loadtxt(os.path.join(_THIS_DIR, 'seddepinit.txt')) mg['node']['topographic__elevation'] = z mg.set_closed_boundaries_at_grid_edges(True, False, True, False) fr = FlowAccumulator(mg, flow_director='D8') sde = SedDepEroder(mg, **inputs) for i in range(nt): mg.at_node['topographic__elevation'][mg.core_nodes] += uplift_per_step mg = fr.run_one_step() mg, _ = sde.erode(dt) z_tg = np.loadtxt(os.path.join(_THIS_DIR, 'seddepz_tg.txt')) assert_array_almost_equal(mg.at_node['topographic__elevation'][ mg.core_nodes], z_tg[mg.core_nodes])
start_node = [profile_IDs[0]] time_on = time() #perform the loops: for i in range(nt): #print 'loop ', i mg.at_node['topographic__elevation'][mg.core_nodes] += uplift_per_step mg = fr.run_one_step() #mg.calc_grad_across_cell_faces(mg.at_node['topographic__elevation']) #neighbor_slopes = mg.calc_grad_along_node_links(mg.at_node['topographic__elevation']) #mean_slope = np.mean(np.fabs(neighbor_slopes),axis=1) #max_slope = np.max(np.fabs(neighbor_slopes),axis=1) #mg,_,capacity_out = tl.erode(mg,dt,slopes_at_nodes='topographic__steepest_slope') #mg,_,capacity_out = tl.erode(mg,dt,slopes_at_nodes=max_slope) mg_copy = deepcopy(mg) mg, _ = sde.erode(mg, dt) #print sde.iterations_in_dt #print 'capacity ', np.amax(capacity_out[mg.core_nodes]) #print 'rel sed ', np.nanmax(sed_in[mg.core_nodes]/capacity_out[mg.core_nodes]) if i % out_interval == 0: print('loop ', i) print( 'max_slope', np.amax(mg.at_node['topographic__steepest_slope'][mg.core_nodes])) pylab.figure("long_profiles") 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'])
start_node = [profile_IDs[0]] time_on = time() #perform the loops: for i in range(nt): #print 'loop ', i mg.at_node['topographic__elevation'][mg.core_nodes] += uplift_per_step mg = fr.run_one_step() #mg.calc_grad_across_cell_faces(mg.at_node['topographic__elevation']) #neighbor_slopes = mg.calc_grad_along_node_links(mg.at_node['topographic__elevation']) #mean_slope = np.mean(np.fabs(neighbor_slopes),axis=1) #max_slope = np.max(np.fabs(neighbor_slopes),axis=1) #mg,_,capacity_out = tl.erode(mg,dt,slopes_at_nodes='topographic__steepest_slope') #mg,_,capacity_out = tl.erode(mg,dt,slopes_at_nodes=max_slope) mg_copy = deepcopy(mg) mg,_ = sde.erode(mg,dt) #print sde.iterations_in_dt #print 'capacity ', np.amax(capacity_out[mg.core_nodes]) #print 'rel sed ', np.nanmax(sed_in[mg.core_nodes]/capacity_out[mg.core_nodes]) if i%out_interval == 0: print('loop ', i) print('max_slope', np.amax(mg.at_node['topographic__steepest_slope'][mg.core_nodes])) pylab.figure("long_profiles") 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']) if i%out_interval == 0: x_profiles.append(dists_upstr) z_profiles.append(mg.at_node['topographic__elevation'][profile_IDs])