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


Python landlab.HexModelGrid类代码示例

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


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

示例1: test_can_run_with_hex

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,代码行数:35,代码来源:test_space.py

示例2: test_non_raster

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,代码行数:33,代码来源:test_normal_fault.py

示例3: test_functions_with_Hex

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,代码行数:9,代码来源:test_chi_finder.py

示例4: test_flow__distance_irregular_grid_d4

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)
开发者ID:landlab,项目名称:landlab,代码行数:56,代码来源:test_flow__distance.py

示例5: test_transitions_as_ids

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,代码行数:10,代码来源:test_celllab_cts.py

示例6: test_save_and_load_hex

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,代码行数:10,代码来源:test_read_write_native.py

示例7: test_hex_cts

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,代码行数:11,代码来源:test_celllab_cts.py

示例8: test_oriented_hex_cts

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,代码行数:11,代码来源:test_celllab_cts.py

示例9: test_handle_grid_mismatch

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,代码行数:13,代码来源:test_celllab_cts.py

示例10: test_grid_type_testing

def test_grid_type_testing():
    """Test that only the right grids can be implemented."""
    dx=(2./(3.**0.5))**0.5
    hmg = HexModelGrid(9,5, dx)
    z = hmg.add_field('topographic__elevation', hmg.node_x + np.round(hmg.node_y), at = 'node')

    # D8 is ONLY RASTER
    with pytest.raises(NotImplementedError):
        FlowDirectorD8(hmg)

    # DINF IS ONLY RASTER RASTER
    with pytest.raises(NotImplementedError):
        FlowDirectorDINF(hmg)
开发者ID:glaubius,项目名称:landlab,代码行数:13,代码来源:test_flow_director.py

示例11: test_neighbor_shaping_hex

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,代码行数:11,代码来源:test_lake_fill.py

示例12: create_grid_and_node_state_field

    def create_grid_and_node_state_field(self, num_rows, num_cols, 
                                         grid_orientation, grid_shape,
                                         cts_type):
        """Create the grid and the field containing node states."""

        if cts_type == 'raster' or cts_type == 'oriented_raster':
            from landlab import RasterModelGrid
            self.grid = RasterModelGrid(shape=(num_rows, num_cols),
                                        spacing=1.0)
        else:
            from landlab import HexModelGrid
            self.grid = HexModelGrid(num_rows, num_cols, 1.0, 
                                     orientation=grid_orientation, 
                                     shape=grid_shape)

        self.grid.add_zeros('node', 'node_state', dtype=int)
开发者ID:Carralex,项目名称:landlab,代码行数:16,代码来源:cts_model.py

示例13: HexLatticeTectonicizer

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,代码行数:31,代码来源:hex_lattice_tectonicizer.py

示例14: __init__

    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,代码行数:26,代码来源:hex_lattice_tectonicizer.py

示例15: __init__

 def __init__(self, grid=None, node_state=None, propid=None, prop_data=None, prop_reset_value=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:
         #print 'setting node state'
         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
     
     # propid should be either a reference to a CA model's "property id" 
     # array, or None
     self.propid = propid
     self.prop_data = prop_data
     self.prop_reset_value = prop_reset_value
开发者ID:brigidlynch,项目名称:landlab,代码行数:33,代码来源:hex_lattice_tectonicizer.py


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