当前位置: 首页>>代码示例>>Python>>正文


Python HexModelGrid.add_zeros方法代码示例

本文整理汇总了Python中landlab.HexModelGrid.add_zeros方法的典型用法代码示例。如果您正苦于以下问题:Python HexModelGrid.add_zeros方法的具体用法?Python HexModelGrid.add_zeros怎么用?Python HexModelGrid.add_zeros使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在landlab.HexModelGrid的用法示例。


在下文中一共展示了HexModelGrid.add_zeros方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_save_and_load_hex

# 需要导入模块: from landlab import HexModelGrid [as 别名]
# 或者: from landlab.HexModelGrid import add_zeros [as 别名]
def test_save_and_load_hex():
    """Test saving and loading of a HexModelGrid."""
    mg1 = HexModelGrid(3, 3, 1.0)
    mg1.add_zeros("node", "topographic__elevation")
    save_grid(mg1, "testsavedgrid.grid")
    mg2 = load_grid("testsavedgrid.grid")
    assert mg1.x_of_node[0] == mg2.x_of_node[0]
    assert_array_equal(mg1.status_at_node, mg2.status_at_node)
    for name in mg1.at_node:
        assert_array_equal(mg1.at_node[name], mg2.at_node[name])
开发者ID:landlab,项目名称:landlab,代码行数:12,代码来源:test_read_write_native.py

示例2: test_can_run_with_hex

# 需要导入模块: from landlab import HexModelGrid [as 别名]
# 或者: from landlab.HexModelGrid import add_zeros [as 别名]
def test_can_run_with_hex():
    """Test that model can run with hex model grid."""

    # Set up a 5x5 grid with open boundaries and low initial elevations.
    mg = HexModelGrid(7, 7)
    z = mg.add_zeros("node", "topographic__elevation")
    z[:] = 0.01 * mg.x_of_node

    # Create a D8 flow handler
    fa = FlowAccumulator(mg, flow_director="FlowDirectorSteepest")

    # Parameter values for test 1
    U = 0.001
    dt = 10.0

    # Create the Space component...
    sp = Space(
        mg,
        K_sed=0.00001,
        K_br=0.00000000001,
        F_f=0.5,
        phi=0.1,
        H_star=1.,
        v_s=0.001,
        m_sp=0.5,
        n_sp=1.0,
        sp_crit_sed=0,
        sp_crit_br=0,
    )

    # ... and run it to steady state.
    for i in range(2000):
        fa.run_one_step()
        sp.run_one_step(dt=dt)
        z[mg.core_nodes] += U * dt
开发者ID:cmshobe,项目名称:landlab,代码行数:37,代码来源:test_space.py

示例3: HexLatticeTectonicizer

# 需要导入模块: from landlab import HexModelGrid [as 别名]
# 或者: from landlab.HexModelGrid import add_zeros [as 别名]
class HexLatticeTectonicizer(object):
    """Base class from which classes to represent particular baselevel/fault
    geometries are derived.
    """

    def __init__(self, grid=None, node_state=None):

        # If needed, create grid
        if grid is None:
            num_rows = _DEFAULT_NUM_ROWS
            num_cols = _DEFAULT_NUM_COLS
            self.grid = HexModelGrid(num_rows, num_cols, dx=1.0,
                                     orientation='vertical',
                                     shape='rect', reorient_links=True)
        else:
            # Make sure caller passed the right type of grid
            assert (grid.orientation == 'vertical'), \
                'Grid must have vertical orientation'

            # Keep a reference to the grid
            self.grid = grid

        # If needed, create node-state grid
        if node_state is None:
            self.node_state = self.grid.add_zeros('node', 'node_state_map')
        else:
            self.node_state = node_state

        # Remember the # of rows and cols
        self.nr = self.grid.number_of_node_rows
        self.nc = self.grid.number_of_node_columns
开发者ID:Fooway,项目名称:landlab,代码行数:33,代码来源:hex_lattice_tectonicizer.py

示例4: test_non_raster

# 需要导入模块: from landlab import HexModelGrid [as 别名]
# 或者: from landlab.HexModelGrid import add_zeros [as 别名]
def test_non_raster():
    """Test a hex model grid."""
    grid = HexModelGrid(7, 3, dx=10)

    _ = grid.add_zeros('node', 'topographic__elevation')

    param_dict = {'faulted_surface': 'topographic__elevation',
                  'fault_dip_angle': 90.0,
                  'fault_throw_rate_through_time': {'time': [0, 9, 10],
                                                    'rate': [0, 0, 0.05]},
                  'fault_trace': {'y1': 30.0,
                                  'x1': 30.0,
                                  'y2': 20.0,
                                  'x2': 0.0},
                  'include_boundaries': True}

    nf = NormalFault(grid, **param_dict)

    # plotting, to test this. it works!
    #import matplotlib.pyplot as plt
    #plt.figure()
    #imshow_grid(grid, nf.faulted_nodes, color_for_background='y')
    #plt.plot(grid.x_of_node, grid.y_of_node, 'c.')
    #plt.plot([param_dict['fault_trace']['x1'], param_dict['fault_trace']['x2']],
    #         [param_dict['fault_trace']['y1'], param_dict['fault_trace']['y2']], 'r')
    #plt.show()

    out = np.array([ True,  True,  True,  True,  True,  True,  True, False,  True,
                     True,  True,  True, False, False, False, False,  True,  True,
                     False, False, False, False, False, False, False, False, False,
                     False, False, False], dtype=bool)

    assert_array_equal(nf.faulted_nodes, out)
开发者ID:awickert,项目名称:landlab,代码行数:35,代码来源:test_normal_fault.py

示例5: test_functions_with_Hex

# 需要导入模块: from landlab import HexModelGrid [as 别名]
# 或者: from landlab.HexModelGrid import add_zeros [as 别名]
def test_functions_with_Hex():
    mg = HexModelGrid(10, 10)
    z = mg.add_zeros("node", "topographic__elevation")
    z += mg.x_of_node + mg.y_of_node
    fa = FlowAccumulator(mg)
    fa.run_one_step()

    ch = ChiFinder(mg, min_drainage_area=1.0, reference_concavity=1.0)
    ch.calculate_chi()
开发者ID:landlab,项目名称:landlab,代码行数:11,代码来源:test_chi_finder.py

示例6: test_neighbor_shaping_hex

# 需要导入模块: from landlab import HexModelGrid [as 别名]
# 或者: from landlab.HexModelGrid import add_zeros [as 别名]
def test_neighbor_shaping_hex():
    hmg = HexModelGrid(6, 5, dx=1.)
    hmg.add_zeros("node", "topographic__elevation", dtype=float)
    hmg.add_zeros("node", "topographic__steepest_slope", dtype=float)
    hmg.add_zeros("node", "flow__receiver_node", dtype=int)
    hmg.add_zeros("node", "flow__link_to_receiver_node", dtype=int)
    lmb = LakeMapperBarnes(hmg, redirect_flow_steepest_descent=True)
    for arr in (lmb._neighbor_arrays, lmb._link_arrays):
        assert len(arr) == 1
        assert arr[0].shape == (hmg.number_of_nodes, 6)
    assert len(lmb._neighbor_lengths) == hmg.number_of_links
开发者ID:cmshobe,项目名称:landlab,代码行数:13,代码来源:test_lake_fill.py

示例7: test_transitions_as_ids

# 需要导入模块: from landlab import HexModelGrid [as 别名]
# 或者: from landlab.HexModelGrid import add_zeros [as 别名]
def test_transitions_as_ids():
    """Test passing from-state and to-state IDs instead of tuples """

    mg = HexModelGrid(3, 2, 1.0, orientation="vertical", reorient_links=True)
    nsd = {0: "zero", 1: "one"}
    xnlist = []
    xnlist.append(Transition(2, 3, 1.0, "transitioning"))
    nsg = mg.add_zeros("node", "node_state_grid")
    cts = HexCTS(mg, nsd, xnlist, nsg)
    assert cts.num_link_states == 4, "wrong number of transitions"
开发者ID:landlab,项目名称:landlab,代码行数:12,代码来源:test_celllab_cts.py

示例8: test_hex_cts

# 需要导入模块: from landlab import HexModelGrid [as 别名]
# 或者: from landlab.HexModelGrid import add_zeros [as 别名]
def test_hex_cts():
    """Tests instantiation of a HexCTS() object"""
    mg = HexModelGrid(3, 2, 1.0, orientation='vertical', reorient_links=True)
    nsd = {0 : 'zero', 1 : 'one'}
    xnlist = []
    xnlist.append(Transition((0,1,0), (1,1,0), 1.0, 'transitioning'))
    nsg = mg.add_zeros('node', 'node_state_grid')
    hcts = HexCTS(mg, nsd, xnlist, nsg)

    assert_equal(hcts.num_link_states, 4)
    assert_array_equal(hcts.link_orientation, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
开发者ID:evanthaler,项目名称:landlab,代码行数:13,代码来源:test_celllab_cts.py

示例9: test_oriented_hex_cts

# 需要导入模块: from landlab import HexModelGrid [as 别名]
# 或者: from landlab.HexModelGrid import add_zeros [as 别名]
def test_oriented_hex_cts():
    """Tests instantiation of an OrientedHexCTS() object"""
    mg = HexModelGrid(3, 2, 1.0, orientation="vertical", reorient_links=True)
    nsd = {0: "zero", 1: "one"}
    xnlist = []
    xnlist.append(Transition((0, 1, 0), (1, 1, 0), 1.0, "transitioning"))
    nsg = mg.add_zeros("node", "node_state_grid")
    ohcts = OrientedHexCTS(mg, nsd, xnlist, nsg)

    assert_equal(ohcts.num_link_states, 12)
    assert_array_equal(ohcts.link_orientation, [2, 1, 0, 0, 0, 2, 1, 0, 2, 1, 0])
开发者ID:emielkater,项目名称:landlab,代码行数:13,代码来源:test_celllab_cts.py

示例10: test_handle_grid_mismatch

# 需要导入模块: from landlab import HexModelGrid [as 别名]
# 或者: from landlab.HexModelGrid import add_zeros [as 别名]
def test_handle_grid_mismatch():
    """Test error handling when user passes wrong grid type."""
    mg = HexModelGrid(3, 2, 1.0, orientation="vertical", reorient_links=True)
    nsd = {0: "zero", 1: "one"}
    xnlist = []
    xnlist.append(Transition(2, 3, 1.0, "transitioning"))
    nsg = mg.add_zeros("node", "node_state_grid")
    assert_raises(TypeError, RasterCTS, mg, nsd, xnlist, nsg)
    assert_raises(TypeError, OrientedRasterCTS, mg, nsd, xnlist, nsg)

    mg = RasterModelGrid((3, 3))
    assert_raises(TypeError, HexCTS, mg, nsd, xnlist, nsg)
    assert_raises(TypeError, OrientedHexCTS, mg, nsd, xnlist, nsg)
开发者ID:landlab,项目名称:landlab,代码行数:15,代码来源:test_celllab_cts.py

示例11: test_shift_link_and_transition_data_upward

# 需要导入模块: from landlab import HexModelGrid [as 别名]
# 或者: from landlab.HexModelGrid import add_zeros [as 别名]
def test_shift_link_and_transition_data_upward():
    """Test the LatticeUplifter method that uplifts link data and tr'ns."""

    mg = HexModelGrid(4, 3, 1.0, orientation="vertical", shape="rect")
    nsd = {0: "yes", 1: "no"}
    xnlist = []
    xnlist.append(Transition((0, 0, 0), (1, 1, 0), 1.0, "frogging"))
    xnlist.append(Transition((0, 0, 1), (1, 1, 1), 1.0, "frogging"))
    xnlist.append(Transition((0, 0, 2), (1, 1, 2), 1.0, "frogging"))
    nsg = mg.add_zeros("node", "node_state_grid")
    ohcts = OrientedHexCTS(mg, nsd, xnlist, nsg)

    assert_array_equal(
        ohcts.link_state[mg.active_links], [0, 4, 8, 8, 4, 0, 4, 8, 8, 4, 0]
    )

    assert_array_equal(
        ohcts.next_trn_id[mg.active_links], [0, 1, 2, 2, 1, 0, 1, 2, 2, 1, 0]
    )

    assert_array_equal(
        np.round(ohcts.next_update[mg.active_links], 2),
        [0.8, 1.26, 0.92, 0.79, 0.55, 1.04, 0.58, 2.22, 3.31, 0.48, 1.57],
    )

    pq = ohcts.priority_queue

    assert_equal(pq._queue[0][2], 20)  # link for first event = 20, not shifted
    assert_equal(round(pq._queue[0][0], 2), 0.48)  # trn scheduled for t = 0.48
    assert_equal(pq._queue[2][2], 15)  # this event scheduled for link 15...
    assert_equal(round(pq._queue[2][0], 2), 0.58)  # ...trn sched for t = 0.58

    lu = LatticeUplifter(grid=mg)
    lu.shift_link_and_transition_data_upward(ohcts, 0.0)

    # note new events lowest 5 links
    assert_array_equal(
        np.round(ohcts.next_update[mg.active_links], 2),
        [0.75, 0.84, 2.6, 0.07, 0.09, 0.8, 0.02, 1.79, 1.51, 2.04, 3.85],
    )
    assert_equal(pq._queue[0][2], 15)  # new soonest event
    assert_equal(pq._queue[9][2], 14)  # was previously 7, now shifted up...
    assert_equal(round(pq._queue[9][0], 2), 0.8)  # ...still sched for t = 0.80
开发者ID:cmshobe,项目名称:landlab,代码行数:45,代码来源:test_hex_normal_fault.py

示例12: test_can_run_with_hex

# 需要导入模块: from landlab import HexModelGrid [as 别名]
# 或者: from landlab.HexModelGrid import add_zeros [as 别名]
def test_can_run_with_hex():
    """Test that model can run with hex model grid."""

    # Set up a 5x5 grid with open boundaries and low initial elevations.
    mg = HexModelGrid(7, 7)
    z = mg.add_zeros('node', 'topographic__elevation')
    z[:] = 0.01 * mg.x_of_node

    # Create a D8 flow handler
    fa = FlowAccumulator(mg, flow_director='FlowDirectorSteepest')

    # Parameter values for test 1
    K = 0.001
    vs = 0.0001
    U = 0.001
    dt = 10.0

    # Create the ErosionDeposition component...
    ed = ErosionDeposition(mg, K=K, phi=0.0, v_s=vs, m_sp=0.5, n_sp=1.0,
                           method='simple_stream_power',
                           discharge_method='drainage_area',
                           area_field='drainage_area',
                           solver='adaptive')

    # ... and run it to steady state.
    for i in range(2000):
        fa.run_one_step()
        ed.run_one_step(dt=dt)
        z[mg.core_nodes] += U * dt

    # Test the results
    s = mg.at_node['topographic__steepest_slope']
    sa_factor = (1.0 + vs) * U / K
    a18 = mg.at_node['drainage_area'][18]
    a28 = mg.at_node['drainage_area'][28]
    s = mg.at_node['topographic__steepest_slope']
    s18 = sa_factor * (a18 ** -0.5)
    s28 = sa_factor * (a28 ** -0.5)
    assert_equal(np.round(s[18], 3), np.round(s18, 3))
    assert_equal(np.round(s[28], 3), np.round(s28, 3))
开发者ID:awickert,项目名称:landlab,代码行数:42,代码来源:test_erodep.py

示例13: test_non_raster

# 需要导入模块: from landlab import HexModelGrid [as 别名]
# 或者: from landlab.HexModelGrid import add_zeros [as 别名]
def test_non_raster():
    """Test a hex model grid."""
    grid = HexModelGrid(7, 3, dx=10, xy_of_lower_left=(-15.0, 0.0))

    grid.add_zeros("node", "topographic__elevation")

    param_dict = {
        "faulted_surface": "topographic__elevation",
        "fault_dip_angle": 90.0,
        "fault_throw_rate_through_time": {"time": [0, 9, 10], "rate": [0, 0, 0.05]},
        "fault_trace": {"y1": 30.0, "x1": 30.0, "y2": 20.0, "x2": 0.0},
        "include_boundaries": True,
    }

    nf = NormalFault(grid, **param_dict)

    # plotting, to test this. it works!
    # import matplotlib.pyplot as plt
    # plt.figure()
    # imshow_grid(grid, nf.faulted_nodes, color_for_background='y')
    # plt.plot(grid.x_of_node, grid.y_of_node, 'c.')
    # plt.plot([param_dict['fault_trace']['x1'], param_dict['fault_trace']['x2']],
    #         [param_dict['fault_trace']['y1'], param_dict['fault_trace']['y2']], 'r')
    # plt.show()

    out = np.array(
        [
            True,
            True,
            True,
            True,
            True,
            True,
            True,
            False,
            True,
            True,
            True,
            True,
            False,
            False,
            False,
            False,
            True,
            True,
            False,
            False,
            False,
            False,
            False,
            False,
            False,
            False,
            False,
            False,
            False,
            False,
        ],
        dtype=bool,
    )

    assert_array_equal(nf.faulted_nodes, out)
开发者ID:landlab,项目名称:landlab,代码行数:64,代码来源:test_normal_fault.py

示例14: test_bad_init_gridmethod

# 需要导入模块: from landlab import HexModelGrid [as 别名]
# 或者: from landlab.HexModelGrid import add_zeros [as 别名]
def test_bad_init_gridmethod():
    hmg = HexModelGrid(30, 29, dx=3.)
    hmg.add_zeros("node", "topographic__elevation", dtype=float)
    with pytest.raises(ValueError):
        LakeMapperBarnes(hmg, method="D8")
开发者ID:cmshobe,项目名称:landlab,代码行数:7,代码来源:test_lake_fill.py

示例15: CTSModel

# 需要导入模块: from landlab import HexModelGrid [as 别名]
# 或者: from landlab.HexModelGrid import add_zeros [as 别名]
class CTSModel(object):
    """
    Implement a generic CellLab-CTS model.

    This is the base class from which models should inherit.
    """

    def __init__(self, grid_size=(5, 5), report_interval=5.0,
                 grid_orientation='vertical', grid_shape='rect',
                 show_plots=False, cts_type='oriented_hex',
                 run_duration=1.0, output_interval=1.0e99,
                 plot_every_transition=False, initial_state_grid=None,
                 prop_data=None, prop_reset_value=None,
                 closed_boundaries=(False, False, False, False), **kwds):

        self.initialize(grid_size, report_interval, grid_orientation,
                        grid_shape, show_plots, cts_type, run_duration,
                        output_interval, plot_every_transition,
                        initial_state_grid, prop_data, prop_reset_value,
                        closed_boundaries, **kwds)


    def initialize(self, grid_size=(5, 5), report_interval=5.0,
                 grid_orientation='vertical', grid_shape='rect',
                 show_plots=False, cts_type='oriented_hex',
                 run_duration=1.0, output_interval=1.0e99,
                 plot_every_transition=False, initial_state_grid=None,
                 prop_data=None, prop_reset_value=None,
                 closed_boundaries=(False, False, False, False), **kwds):
        """Initialize CTSModel."""
        # Remember the clock time, and calculate when we next want to report
        # progress.
        self.current_real_time = time.time()
        self.next_report = self.current_real_time + report_interval
        self.report_interval = report_interval

        # Interval for output
        self.output_interval = output_interval

        # Duration for run
        self.run_duration = run_duration

        # Create a grid
        self.create_grid_and_node_state_field(grid_size[0], grid_size[1],
                                              grid_orientation, grid_shape,
                                              cts_type, closed_boundaries)

        # If prop_data is a string, we assume it is a field name
        if isinstance(prop_data, string_types):
            prop_data = self.grid.add_zeros('node', prop_data)

        # Create the node-state dictionary
        ns_dict = self.node_state_dictionary()

        # Initialize values of the node-state grid
        if initial_state_grid is None:
            nsg = self.initialize_node_state_grid()
        else:
            try:
                nsg = initial_state_grid
                self.grid.at_node['node_state'][:] = nsg
            except:
                #TODO: use new Messaging capability
                print('If initial_state_grid given, must be array of int')
                raise

        # Create the transition list
        xn_list = self.transition_list()

        # Create the CA object
        if cts_type == 'raster':
            from landlab.ca.raster_cts import RasterCTS
            self.ca = RasterCTS(self.grid, ns_dict, xn_list, nsg, prop_data,
                                prop_reset_value)
        elif cts_type == 'oriented_raster':
            from landlab.ca.oriented_raster_cts import OrientedRasterCTS
            self.ca = OrientedRasterCTS(self.grid, ns_dict, xn_list, nsg,
                                        prop_data, prop_reset_value)
        elif cts_type == 'hex':
            from landlab.ca.hex_cts import HexCTS
            self.ca = HexCTS(self.grid, ns_dict, xn_list, nsg, prop_data,
                             prop_reset_value)
        else:
            from landlab.ca.oriented_hex_cts import OrientedHexCTS
            self.ca = OrientedHexCTS(self.grid, ns_dict, xn_list, nsg,
                                     prop_data, prop_reset_value)

        # Initialize graphics
        self._show_plots = show_plots
        if show_plots == True:
            self.initialize_plotting(**kwds)


    def _set_closed_boundaries_for_hex_grid(self, closed_boundaries):
        """Setup one or more closed boundaries for a hex grid.
        
        Parameters
        ----------
        closed_boundaries : 4-element tuple of bool\
            Whether right, top, left, and bottom edges have closed nodes
#.........这里部分代码省略.........
开发者ID:gregtucker,项目名称:grain_hills,代码行数:103,代码来源:cts_model.py


注:本文中的landlab.HexModelGrid.add_zeros方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。