本文整理汇总了Python中landlab.components.flow_routing.FlowRouter.route_flow方法的典型用法代码示例。如果您正苦于以下问题:Python FlowRouter.route_flow方法的具体用法?Python FlowRouter.route_flow怎么用?Python FlowRouter.route_flow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类landlab.components.flow_routing.FlowRouter
的用法示例。
在下文中一共展示了FlowRouter.route_flow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sed_dep_new
# 需要导入模块: from landlab.components.flow_routing import FlowRouter [as 别名]
# 或者: from landlab.components.flow_routing.FlowRouter import route_flow [as 别名]
def test_sed_dep_new():
"""
This tests only the power_law version of the SDE.
It uses a landscape run to 5000 100y iterations, then having experienced
a 20-fold uplift acceleration for a further 30000 y. It tests the outcome
of the next 1000 y of erosion.
"""
mg = RasterModelGrid((25, 50), 200.)
for edge in (mg.nodes_at_left_edge, mg.nodes_at_top_edge,
mg.nodes_at_right_edge):
mg.status_at_node[edge] = CLOSED_BOUNDARY
z = mg.add_zeros('node', 'topographic__elevation')
fr = FlowRouter(mg)
sde = SedDepEroder(mg, K_sp=1.e-4, sed_dependency_type='almost_parabolic',
Qc='power_law', K_t=1.e-4)
initconds = os.path.join(os.path.dirname(__file__),
'perturbedcondst300.txt')
finalconds = os.path.join(os.path.dirname(__file__),
'tenmorestepsfrom300.txt')
z[:] = np.loadtxt(initconds)
dt = 100.
up = 0.05
for i in range(10):
fr.route_flow()
sde.run_one_step(dt)
z[mg.core_nodes] += 20.*up
assert_array_almost_equal(z, np.loadtxt(finalconds))
示例2: test_sp_discharges_new
# 需要导入模块: from landlab.components.flow_routing import FlowRouter [as 别名]
# 或者: from landlab.components.flow_routing.FlowRouter import route_flow [as 别名]
def test_sp_discharges_new():
input_str = os.path.join(_THIS_DIR, 'test_sp_params_discharge_new.txt')
inputs = ModelParameterDictionary(input_str, auto_type=True)
nrows = 5
ncols = 5
dx = inputs.read_float('dx')
dt = inputs.read_float('dt')
mg = RasterModelGrid(nrows, ncols, dx)
mg.add_zeros('topographic__elevation', at='node')
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
fr = FlowRouter(mg)
sp = StreamPowerEroder(mg, **inputs)
# perform the loop (once!)
for i in range(1):
fr.route_flow()
sp.run_one_step(dt)
z_tg = np.array([5. , 5. , 0. , 5. ,
5. , 5. , 1.47759225, 0.43050087,
1.47759225, 5. , 5. , 2.32883687,
1.21525044, 2.32883687, 5. , 5. ,
3.27261262, 3.07175015, 3.27261262, 5. ,
5. , 5. , 5. , 5. ,
5. ])
assert_array_almost_equal(mg.at_node['topographic__elevation'], z_tg)
示例3: test_stupid_shaped_hole
# 需要导入模块: from landlab.components.flow_routing import FlowRouter [as 别名]
# 或者: from landlab.components.flow_routing.FlowRouter import route_flow [as 别名]
def test_stupid_shaped_hole(sink_grid4):
"""Tests inclined fill into a surface with a deliberately awkward shape."""
fr = FlowRouter(sink_grid4)
hf = SinkFiller(sink_grid4, apply_slope=True)
hf.fill_pits()
hole1 = np.array(
[
4.00007692,
4.00015385,
4.00023077,
4.00030769,
4.00038462,
4.00046154,
4.00053846,
4.00061538,
4.00069231,
4.00076923,
4.00084615,
]
)
hole2 = np.array([7.4, 7.2, 7.6])
assert_array_almost_equal(
sink_grid4.at_node["topographic__elevation"][sink_grid4.lake1], hole1
)
assert_array_almost_equal(
sink_grid4.at_node["topographic__elevation"][sink_grid4.lake2], hole2
)
fr.route_flow()
assert sink_grid4.at_node["flow__sink_flag"][sink_grid4.core_nodes].sum() == 0
示例4: test_voronoi_closedinternal
# 需要导入模块: from landlab.components.flow_routing import FlowRouter [as 别名]
# 或者: from landlab.components.flow_routing.FlowRouter import route_flow [as 别名]
def test_voronoi_closedinternal():
"""Test routing on a (radial) voronoi, but with a closed interior node."""
vmg = RadialModelGrid(2, dr=2.)
z = np.full(20, 10., dtype=float)
all_bounds_but_one = np.array((0, 1, 2, 3, 4, 7, 11, 15, 16, 17, 18, 19))
vmg.status_at_node[all_bounds_but_one] = CLOSED_BOUNDARY
vmg.status_at_node[8] = CLOSED_BOUNDARY # new internal closed
z[12] = 0. # outlet
inner_elevs = (8., 7., 1., 6., 4., 5.)
z[vmg.core_nodes] = np.array(inner_elevs)
vmg.add_field("node", "topographic__elevation", z, units="-")
fr = FlowRouter(vmg)
cells_contributing = [
np.array([0]),
np.array([1]),
np.array([0, 1, 3, 4, 5, 6]),
np.array([1, 4]),
np.array([1, 4, 5, 6]),
np.array([1, 4, 6]),
]
A_target_internal = np.zeros(vmg.number_of_core_nodes, dtype=float)
for i in range(6):
A_target_internal[i] = vmg.area_of_cell[cells_contributing[i]].sum()
A_target_outlet = vmg.area_of_cell[vmg.cell_at_node[vmg.core_nodes]].sum()
fr.route_flow()
assert vmg.at_node["drainage_area"][vmg.core_nodes] == approx(A_target_internal)
assert vmg.at_node["drainage_area"][12] == approx(A_target_outlet)
示例5: test_filler_inclined2
# 需要导入模块: from landlab.components.flow_routing import FlowRouter [as 别名]
# 或者: from landlab.components.flow_routing.FlowRouter import route_flow [as 别名]
def test_filler_inclined2(sink_grid3):
"""
Tests an inclined fill into an inclined surface, with two holes.
"""
z_init = sink_grid3.at_node["topographic__elevation"].copy()
fr = FlowRouter(sink_grid3)
hf = SinkFiller(sink_grid3, apply_slope=True)
hf.fill_pits()
hole1 = np.array(
[
4.00009091,
4.00018182,
4.00027273,
4.00036364,
4.00045455,
4.00054545,
4.00063636,
4.00072727,
4.00081818,
]
)
hole2 = np.array([7.16666667, 7.33333333, 7.5, 7.66666667])
assert_array_almost_equal(
sink_grid3.at_node["topographic__elevation"][sink_grid3.lake1], hole1
)
assert_array_almost_equal(
sink_grid3.at_node["topographic__elevation"][sink_grid3.lake2], hole2
)
fr.route_flow()
assert sink_grid3.at_node["flow__sink_flag"][sink_grid3.core_nodes].sum() == 0
示例6: test_degenerate_drainage
# 需要导入模块: from landlab.components.flow_routing import FlowRouter [as 别名]
# 或者: from landlab.components.flow_routing.FlowRouter import route_flow [as 别名]
def test_degenerate_drainage():
"""
This "hourglass" configuration should be one of the hardest to correctly
re-route.
"""
mg = RasterModelGrid(9, 5)
z_init = mg.node_x.copy()*0.0001 + 1.
lake_pits = np.array([7, 11, 12, 13, 17, 27, 31, 32, 33, 37])
z_init[lake_pits] = -1.
z_init[22] = 0. # the common spill pt for both lakes
z_init[21] = 0.1 # an adverse bump in the spillway
z_init[20] = -0.2 # the spillway
z = mg.add_field('node', 'topographic__elevation', z_init)
fr = FlowRouter(mg)
lf = DepressionFinderAndRouter(mg)
fr.route_flow()
lf.map_depressions()
correct_A = np.array([ 0., 0., 0., 0., 0.,
0., 1., 3., 1., 0.,
0., 5., 1., 2., 0.,
0., 1., 10., 1., 0.,
21., 21., 1., 1., 0.,
0., 1., 9., 1., 0.,
0., 3., 1., 2., 0.,
0., 1., 1., 1., 0.,
0., 0., 0., 0., 0.])
thelake = np.concatenate((lake_pits, [22])).sort()
assert_array_almost_equal(mg.at_node['drainage_area'], correct_A)
示例7: test_sp_voronoi
# 需要导入模块: from landlab.components.flow_routing import FlowRouter [as 别名]
# 或者: from landlab.components.flow_routing.FlowRouter import route_flow [as 别名]
def test_sp_voronoi():
nnodes = 100
np.random.seed(0)
x = np.random.rand(nnodes)
np.random.seed(1)
y = np.random.rand(nnodes)
mg = VoronoiDelaunayGrid(x, y)
np.random.seed(2)
z = mg.add_field('node', 'topographic__elevation',
np.random.rand(nnodes) / 10000., copy=False)
fr = FlowRouter(mg)
spe = StreamPowerEroder(mg, os.path.join(_THIS_DIR,
'drive_sp_params_voronoi.txt'))
for i in range(10):
z[mg.core_nodes] += 0.01
fr.route_flow()
spe.erode(mg, 1.)
z_tg = np.array([4.35994902e-05, 2.59262318e-06, 5.49662478e-05,
4.36094902e-05, 4.20367802e-05, 2.16664196e-03,
1.23484520e-02, 4.07654109e-02, 5.69974645e-02,
4.71086393e-02, 5.55056467e-02, 5.53655860e-02,
4.87984556e-02, 6.62132007e-02, 7.33132951e-02,
6.10003971e-02, 8.53975293e-05, 4.90709812e-02,
7.84728490e-02, 8.26091298e-02, 5.05246090e-05,
3.69289510e-02, 7.56743264e-02, 2.52850671e-02,
6.80517443e-02, 5.96745309e-05, 3.86335644e-02,
4.12526935e-02, 7.78476139e-02, 7.18165632e-02,
7.62359762e-02, 6.65702961e-02, 9.04684278e-02,
7.37203974e-02, 9.16862054e-02, 4.11168411e-02,
4.36498947e-02, 9.04430763e-02, 1.42123575e-02,
8.02734138e-02, 8.34895711e-02, 4.51564589e-02,
6.47124169e-02, 9.52317640e-02, 6.01917122e-05,
7.11667309e-02, 8.00463179e-02, 9.40668605e-02,
9.33247720e-02, 7.34011920e-02, 7.30924467e-02,
6.21387674e-02, 9.66278589e-02, 8.64266637e-02,
9.06100497e-02, 7.19991365e-02, 1.07162442e-02,
8.68685360e-02, 7.40515066e-02, 2.73264483e-02,
9.55406046e-02, 6.01817121e-05, 3.28663723e-02,
8.60706344e-02, 9.56285286e-02, 4.24741937e-02,
5.64139004e-03, 8.72373392e-02, 9.04304841e-02,
8.83708170e-02, 5.04000439e-05, 6.47845229e-02,
8.77304766e-02, 4.40894724e-02, 8.08029139e-02,
4.52732792e-02, 6.35806712e-02, 6.71004941e-02,
7.32682350e-02, 4.88067087e-02, 2.14920377e-02,
2.55509418e-06, 8.25346959e-02, 8.12610977e-02,
3.75778123e-02, 2.20818912e-02, 2.45940192e-02,
4.43365163e-02, 4.93255141e-02, 6.23517572e-02,
5.99594648e-02, 4.17977098e-06, 4.96450779e-02,
3.72952724e-02, 2.26332108e-03, 1.69925430e-02,
1.99835635e-02, 6.61481327e-05, 1.70477133e-05,
8.81652236e-05] )
assert_array_almost_equal(mg.at_node['topographic__elevation'], z_tg)
示例8: test_sp_voronoi
# 需要导入模块: from landlab.components.flow_routing import FlowRouter [as 别名]
# 或者: from landlab.components.flow_routing.FlowRouter import route_flow [as 别名]
def test_sp_voronoi():
nnodes = 100
np.random.seed(0)
x = np.random.rand(nnodes)
np.random.seed(1)
y = np.random.rand(nnodes)
mg = VoronoiDelaunayGrid(x, y)
np.random.seed(2)
z = mg.add_field('node', 'topographic__elevation',
np.random.rand(nnodes) / 10000., copy=False)
fr = FlowRouter(mg)
spe = StreamPowerEroder(mg, os.path.join(_THIS_DIR,
'drive_sp_params_voronoi.txt'))
for i in range(10):
z[mg.core_nodes] += 0.01
fr.route_flow()
spe.erode(mg, 1.)
z_tg = np.array([4.35994902e-05, 2.59262318e-06, 5.49662478e-05,
6.56738615e-03, 4.20367802e-05, 1.21371424e-02,
2.16596169e-02, 4.73320898e-02, 6.00389761e-02,
5.22007356e-02, 5.37507115e-02, 5.95794752e-02,
5.29862904e-02, 6.76465914e-02, 7.31720024e-02,
6.18730861e-02, 8.53975293e-05, 5.32189275e-02,
7.34302556e-02, 8.07385044e-02, 5.05246090e-05,
4.08940657e-02, 7.39971005e-02, 3.31915602e-02,
6.72650419e-02, 5.96745309e-05, 4.72752445e-02,
3.60359567e-02, 7.59432065e-02, 7.24461985e-02,
7.80305760e-02, 4.93866869e-02, 8.69642467e-02,
7.21627626e-02, 8.96368291e-02, 4.65142080e-02,
6.07720217e-02, 8.83372939e-02, 2.35887558e-02,
7.97616193e-02, 8.35615355e-02, 4.61809032e-02,
6.34634214e-02, 9.25711770e-02, 4.11717225e-03,
7.24493623e-02, 7.97908053e-02, 9.10375623e-02,
9.13155023e-02, 7.10567915e-02, 7.35271752e-02,
6.13091341e-02, 9.45498463e-02, 8.48532386e-02,
8.82702021e-02, 7.14969941e-02, 2.22640943e-02,
8.53311932e-02, 7.49161159e-02, 3.48837223e-02,
9.30132692e-02, 6.01817121e-05, 3.87455443e-02,
8.44673586e-02, 9.35213577e-02, 6.76075824e-02,
1.58614508e-02, 8.51346837e-02, 8.83645680e-02,
8.69944117e-02, 5.04000439e-05, 5.02319084e-02,
8.63882765e-02, 5.00991880e-02, 7.65156630e-02,
5.07591983e-02, 6.54909962e-02, 6.91505342e-02,
7.33358371e-02, 5.30109890e-02, 2.99074601e-02,
2.55509418e-06, 8.21523907e-02, 8.09368483e-02,
4.35073025e-02, 3.04096109e-02, 3.26298627e-02,
4.92259177e-02, 5.48690358e-02, 6.44732130e-02,
6.28133567e-02, 4.17977098e-06, 5.37149677e-02,
4.32828136e-02, 1.30559903e-02, 2.62405261e-02,
2.86079272e-02, 6.61481327e-05, 1.70477133e-05,
8.81652236e-05])
assert_array_almost_equal(mg.at_node['topographic__elevation'], z_tg)
示例9: test_irreg_topo_new
# 需要导入模块: from landlab.components.flow_routing import FlowRouter [as 别名]
# 或者: from landlab.components.flow_routing.FlowRouter import route_flow [as 别名]
def test_irreg_topo_new():
"""Test D4 routing on a toy irregular topo. 'method' passed to init."""
fr = FlowRouter(mg, method="D4")
fr.route_flow()
assert_array_equal(A_target_D4, mg.at_node["drainage_area"])
assert_array_equal(frcvr_target_D4, mg.at_node["flow__receiver_node"])
assert_array_equal(upids_target_D4, mg.at_node["flow__upstream_node_order"])
assert_array_equal(links2rcvr_target_D4, mg.at_node["flow__link_to_receiver_node"])
assert_array_almost_equal(steepest_target_D4, mg.at_node["topographic__steepest_slope"])
示例10: test_internal_closed
# 需要导入模块: from landlab.components.flow_routing import FlowRouter [as 别名]
# 或者: from landlab.components.flow_routing.FlowRouter import route_flow [as 别名]
def test_internal_closed():
"""Test closed nodes in the core of the grid."""
fr = FlowRouter(mg)
fr.route_flow()
assert_array_almost_equal(A_target, mg.at_node["drainage_area"])
assert_array_equal(frcvr_target, mg.at_node["flow__receiver_node"])
assert_array_equal(links2rcvr_target, mg.at_node["flow__link_to_receiver_node"])
assert_array_almost_equal(A_target, mg.at_node["water__discharge"])
assert_array_almost_equal(steepest_target, mg.at_node["topographic__steepest_slope"])
示例11: test_accumulate_D8
# 需要导入模块: from landlab.components.flow_routing import FlowRouter [as 别名]
# 或者: from landlab.components.flow_routing.FlowRouter import route_flow [as 别名]
def test_accumulate_D8():
"""Test accumulation works for D8 in a simple scenario."""
fr = FlowRouter(mg)
fr.route_flow()
assert_array_equal(A_target, mg.at_node["drainage_area"])
assert_array_equal(frcvr_target, mg.at_node["flow__receiver_node"])
assert_array_equal(upids_target, mg.at_node["flow__upstream_node_order"])
assert_array_equal(links2rcvr_target, mg.at_node["flow__link_to_receiver_node"])
assert_array_equal(A_target, mg.at_node["water__discharge"])
assert_array_equal(steepest_target, mg.at_node["topographic__steepest_slope"])
示例12: test_internal_closed
# 需要导入模块: from landlab.components.flow_routing import FlowRouter [as 别名]
# 或者: from landlab.components.flow_routing.FlowRouter import route_flow [as 别名]
def test_internal_closed():
"""Test closed nodes in the core of the grid."""
fr = FlowRouter(mg)
fr.route_flow()
assert_array_almost_equal(A_target, mg.at_node['drainage_area'])
assert_array_equal(frcvr_target, mg.at_node['flow_receiver'])
assert_array_equal(links2rcvr_target, mg.at_node['links_to_flow_receiver'])
assert_array_almost_equal(A_target, mg.at_node['water__volume_flux'])
assert_array_almost_equal(steepest_target,
mg.at_node['topographic__steepest_slope'])
示例13: test_three_pits
# 需要导入模块: from landlab.components.flow_routing import FlowRouter [as 别名]
# 或者: from landlab.components.flow_routing.FlowRouter import route_flow [as 别名]
def test_three_pits():
"""
A test to ensure the component correctly handles cases where there are
multiple pits.
"""
mg = RasterModelGrid(10,10,1.)
z = mg.add_field('node', 'topographic__elevation', mg.node_x.copy())
# a sloping plane
#np.random.seed(seed=0)
#z += np.random.rand(100)/10000.
# punch some holes
z[33] = 1.
z[43] = 1.
z[37] = 4.
z[74:76] = 1.
fr = FlowRouter(mg)
lf = DepressionFinderAndRouter(mg)
fr.route_flow()
lf.map_depressions()
flow_sinks_target = np.zeros(100, dtype=bool)
flow_sinks_target[mg.boundary_nodes] = True
# no internal sinks now:
assert_array_equal(mg.at_node['flow__sink_flag'], flow_sinks_target)
# test conservation of mass:
assert_almost_equal(mg.at_node['drainage_area'
].reshape((10,10))[1:-1,1].sum(), 8.**2)
# ^all the core nodes
# test the actual flow field:
nA = np.array([ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
8., 8., 7., 6., 5., 4., 3., 2., 1., 0.,
2., 2., 1., 1., 2., 1., 1., 1., 1., 0.,
26., 26., 25., 15., 11., 10., 9., 8., 1., 0.,
2., 2., 1., 9., 2., 1., 1., 1., 1., 0.,
2., 2., 1., 1., 5., 4., 3., 2., 1., 0.,
2., 2., 1., 1., 1., 1., 3., 2., 1., 0.,
20., 20., 19., 18., 17., 12., 3., 2., 1., 0.,
2., 2., 1., 1., 1., 1., 3., 2., 1., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])
assert_array_equal(mg.at_node['drainage_area'], nA)
#test a couple more properties:
lc = np.empty(100, dtype=int)
lc.fill(XX)
lc[33] = 33
lc[43] = 33
lc[37] = 37
lc[74:76] = 74
assert_array_equal(lf.lake_map, lc)
assert_array_equal(lf.lake_codes, [33, 37, 74])
assert_equal(lf.number_of_lakes, 3)
assert_array_almost_equal(lf.lake_areas, [2., 1., 2.])
assert_array_almost_equal(lf.lake_volumes, [2., 2., 4.])
示例14: test_variable_Qin
# 需要导入模块: from landlab.components.flow_routing import FlowRouter [as 别名]
# 或者: from landlab.components.flow_routing.FlowRouter import route_flow [as 别名]
def test_variable_Qin(dans_grid1):
"""Test variable Qin field."""
Qin_local = np.zeros(25, dtype=float)
Qin_local[13] = 2.
dans_grid1.mg.add_field("node", "water__unit_flux_in", Qin_local, units="m**3/s")
fr = FlowRouter(dans_grid1.mg)
fr.route_flow()
Qout_local = np.zeros_like(Qin_local)
Qout_local[10:14] = 200.
assert_array_equal(Qout_local, dans_grid1.mg.at_node["surface_water__discharge"])
assert_array_equal(dans_grid1.A_target, dans_grid1.mg.at_node["drainage_area"])
示例15: test_irreg_topo
# 需要导入模块: from landlab.components.flow_routing import FlowRouter [as 别名]
# 或者: from landlab.components.flow_routing.FlowRouter import route_flow [as 别名]
def test_irreg_topo():
"""Test D8 routing on a toy irregular topo."""
fr = FlowRouter(mg)
fr.route_flow()
assert_array_equal(A_target_D8, mg.at_node['drainage_area'])
assert_array_equal(frcvr_target_D8, mg.at_node['flow__receiver_node'])
assert_array_equal(upids_target_D8, mg.at_node['flow__upstream_node_order'])
assert_array_equal(links2rcvr_target_D8,
mg.at_node['flow__link_to_receiver_node'])
assert_array_almost_equal(steepest_target_D8,
mg.at_node['topographic__steepest_slope'])