本文整理汇总了Python中landlab.HexModelGrid.set_closed_nodes方法的典型用法代码示例。如果您正苦于以下问题:Python HexModelGrid.set_closed_nodes方法的具体用法?Python HexModelGrid.set_closed_nodes怎么用?Python HexModelGrid.set_closed_nodes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类landlab.HexModelGrid
的用法示例。
在下文中一共展示了HexModelGrid.set_closed_nodes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_flow__distance_irregular_grid_d4
# 需要导入模块: from landlab import HexModelGrid [as 别名]
# 或者: from landlab.HexModelGrid import set_closed_nodes [as 别名]
def test_flow__distance_irregular_grid_d4():
"""Test to demonstrate that flow__distance utility works as expected with irregular grids"""
# instantiate a model grid
dx = 1.0
hmg = HexModelGrid(5, 3, dx)
# instantiate and add the elevation field
hmg.add_field(
"topographic__elevation", hmg.node_x + np.round(hmg.node_y), at="node"
)
# instantiate the expected flow__distance array
flow__distance_expected = np.array(
[
0.0,
0.0,
0.0,
0.0,
0.0,
dx,
0.0,
0.0,
dx,
dx,
2.0 * dx,
0.0,
0.0,
2.0 * dx,
2.0 * dx,
0.0,
0.0,
0.0,
0.0,
]
)
# setting boundary conditions
hmg.set_closed_nodes(hmg.boundary_nodes)
# calculating flow directions with FlowAccumulator component: D4 algorithm
fr = FlowAccumulator(hmg, flow_director="D4")
fr.run_one_step()
# calculating flow distance map
flow__distance = calculate_flow__distance(hmg, add_to_grid=True, noclobber=False)
# test that the flow__distance utility works as expected
assert_almost_equal(flow__distance_expected, flow__distance, decimal=10)
示例2: main
# 需要导入模块: from landlab import HexModelGrid [as 别名]
# 或者: from landlab.HexModelGrid import set_closed_nodes [as 别名]
def main():
# INITIALIZE
# User-defined parameters
nr = 21
nc = 21
plot_interval = 0.5
run_duration = 25.0
report_interval = 5.0 # report interval, in real-time seconds
# Remember the clock time, and calculate when we next want to report
# progress.
current_real_time = time.time()
next_report = current_real_time + report_interval
# Create a grid
hmg = HexModelGrid(nr, nc, 1.0, orientation='vertical', reorient_links=True)
# Close the grid boundaries
hmg.set_closed_nodes(hmg.open_boundary_nodes)
# Set up the states and pair transitions.
# Transition data here represent the disease status of a population.
ns_dict = { 0 : 'fluid', 1 : 'grain' }
xn_list = setup_transition_list()
# Create data and initialize values. We start with the 3 middle columns full
# of grains, and the others empty.
node_state_grid = hmg.add_zeros('node', 'node_state_grid')
middle = 0.25*(nc-1)*sqrt(3)
is_middle_cols = logical_and(hmg.node_x<middle+1., hmg.node_x>middle-1.)
node_state_grid[where(is_middle_cols)[0]] = 1
# Create the CA model
ca = OrientedHexCTS(hmg, ns_dict, xn_list, node_state_grid)
# Create a CAPlotter object for handling screen display
ca_plotter = CAPlotter(ca)
# Plot the initial grid
ca_plotter.update_plot()
# RUN
current_time = 0.0
while current_time < run_duration:
# Once in a while, print out simulation and real time to let the user
# know that the sim is running ok
current_real_time = time.time()
if current_real_time >= next_report:
print('Current sim time',current_time,'(',100*current_time/run_duration,'%)')
next_report = current_real_time + report_interval
# Run the model forward in time until the next output step
ca.run(current_time+plot_interval, ca.node_state,
plot_each_transition=False)
current_time += plot_interval
# Plot the current grid
ca_plotter.update_plot()
# FINALIZE
# Plot
ca_plotter.finalize()