How to use the landlab.HexModelGrid function in landlab

To help you get started, we’ve selected a few landlab examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github landlab / landlab / tests / grid / test_hex_grid / testing_flux_divergence_hex_grid.py View on Github external
Test grid looks like this:

        (7)-17-.(8)-18-.(9)
        . .     . .     . .
      11  12  13  14  15  16
      /     \ /     \ /     \
    (3)--8-.(4)--9-.(5)-10-.(6)
      .     . .     . .     .
       2   3   4   5   6   7
        \ /     \ /     \ /
        (0)--0-.(1)--1-.(2)

    Node numbers in parentheses; others are link numbers; period indicates
    link head.
    """
    hmg = HexModelGrid(3, 3, reorient_links=True)

    f = hmg.add_zeros("link", "test_flux")
    f[:] = np.arange(hmg.number_of_links)

    make_links_at_node_array(hmg)

    assert_array_equal(hmg.gt_num_links_at_node, [3, 4, 3, 3, 6, 6, 3, 3, 4, 3])

    assert_array_equal(
        hmg.gt_links_at_node,
        [
            [0, 0, 1, 2, 3, 5, 7, 11, 13, 15],
            [2, 1, 6, 8, 4, 6, 10, 12, 14, 16],
            [3, 4, 7, 11, 8, 9, 16, 17, 17, 18],
            [-1, 5, -1, -1, 9, 10, -1, -1, 18, -1],
            [-1, -1, -1, -1, 12, 14, -1, -1, -1, -1],
github TerrainBento / terrainbento / tests / test_base_level_single_node_baselevel_handler.py View on Github external
def test_outlet_lowering_object_with_scaling():
    """Test using an outlet lowering object with scaling."""

    mg = HexModelGrid((5, 5))
    z = mg.add_zeros("node", "topographic__elevation")
    node_id = 27
    file = os.path.join(_TEST_DATA_DIR, "outlet_history.txt")
    bh = SingleNodeBaselevelHandler(
        mg,
        outlet_id=node_id,
        lowering_file_path=file,
        model_end_elevation=-318.0,
    )

    for _ in range(241):
        bh.run_one_step(10)

    assert bh.z[node_id] == -95.0
    assert z[1] == 0.0
github landlab / landlab / tests / ca / test_celllab_cts.py View on Github external
def test_handle_grid_mismatch():
    """Test error handling when user passes wrong grid type."""
    mg = HexModelGrid((3, 2), spacing=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_state_grid", at="node")
    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)
github landlab / landlab / tests / components / space / test_space.py View on Github external
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("topographic__elevation", at="node")
    _ = mg.add_zeros("soil__depth", at="node")
    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,
github landlab / landlab / tests / ca / cts_model.py View on Github external
def create_grid_and_node_state_field(
        self, num_rows, num_cols, grid_orientation, node_layout, 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), xy_spacing=1.0)
        else:
            from landlab import HexModelGrid

            self.grid = HexModelGrid(
                num_rows,
                num_cols,
                xy_spacing=1.0,
                orientation=grid_orientation,
                node_layout=node_layout,
            )

        self.grid.add_zeros("node", "node_state", dtype=int)
github TerrainBento / terrainbento / tests / test_base_level_precip_changer.py View on Github external
def test_not_passing_daily_rainfall__intermittency_factor():
    mg = HexModelGrid((5, 5))
    with pytest.raises(ValueError):
        PrecipChanger(
            mg,
            daily_rainfall__intermittency_factor_time_rate_of_change=0.001,
            rainfall__mean_rate=3.0,
            rainfall__mean_rate_time_rate_of_change=0.2,
            rainfall__shape_factor=0.65,
            infiltration_capacity=2.0,
        )
github landlab / landlab / landlab / core / utils.py View on Github external
grid_dict : dict
        Dictionary with method name strings as keys and lists of cats as
        values.
    FAILS : dict of dicts
        contains any problematic LLCAT entries. Keys: 'MISSING' - list of names
        of any public method or property without an LLCAT declared.
    """
    import inspect
    import re
    from landlab import ModelGrid, RasterModelGrid, HexModelGrid, \
        RadialModelGrid, VoronoiDelaunayGrid
    from copy import copy

    grid_str_to_grid = {'ModelGrid': ModelGrid,
                        'RasterModelGrid': RasterModelGrid,
                        'HexModelGrid': HexModelGrid,
                        'RadialModelGrid': RadialModelGrid,
                        'VoronoiDelaunayGrid': VoronoiDelaunayGrid}
    grid_dict = {}
    cat_dict = {}
    FAILS = {'MISSING': []}
    grid = grid_str_to_grid[grid_type]
    funcs = {}
    for name, func in inspect.getmembers(grid):
        funcs[name] = func
    for method_name in funcs.keys():
        if method_name[0] == '_':
            continue
        else:
            method_doc = funcs[method_name].__doc__
            try:
                cat_str = re.search('LLCATS:.+', method_doc)
github landlab / landlab / landlab / ca / examples / sir / sir.py View on Github external
nc = 41
    plot_interval = 0.25
    run_duration = 5.0
    report_interval = 5.0  # report interval, in real-time seconds
    infection_rate = 8.0
    outfilename = 'sirmodel'+str(int(infection_rate))+'ir'

    # 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

    time_slice = 0

    # Create a grid
    hmg = HexModelGrid(nr, nc, 1.0)

    # Set up the states and pair transitions.
    # Transition data here represent the disease status of a population.
    ns_dict = { 0 : 'susceptible', 1 : 'infectious', 2: 'recovered' }
    xn_list = setup_transition_list(infection_rate)

    # Create data and initialize values
    node_state_grid = hmg.add_zeros('node', 'node_state_grid')
    wid = nc-1.0
    ht = (nr-1.0)*0.866
    is_middle_rows = logical_and(hmg.node_y>=0.4*ht, hmg.node_y<=0.5*ht)
    is_middle_cols = logical_and(hmg.node_x>=0.4*wid, hmg.node_x<=0.6*wid)
    middle_area = where(logical_and(is_middle_rows, is_middle_cols))[0]
    node_state_grid[middle_area] = 1
    node_state_grid[0] = 2  # to force full color range, set lower left to 'recovered'
github landlab / landlab / landlab / grid / examples / hex_grid_types.py View on Github external
Example showing the four types of hex grid.

Created on Sun Nov 16 09:25:04 2014

@author: gtucker
"""

from landlab import HexModelGrid
from numpy import arange
from pylab import figure, show, title

# Case 1: Make and display a hex-shaped grid with horizontal rows of nodes

# Create the grid
hg1 = HexModelGrid(5, 3, 1.0, orientation='horizontal', shape='hex')

# Make some data
d = hg1.add_zeros('node', 'mydata')
d[:] = arange(hg1.number_of_nodes)

# Display the grid
figure(1)
hg1.hexplot(d)
title('hexagon shape, horizontal orientation')
show()


# Case 2: Make and display a hex-shaped grid with vertical columns of nodes

# Create the grid
hg2 = HexModelGrid(3, 5, 1.0, orientation='vertical', shape='hex')
github landlab / landlab / landlab / ca / examples / grains.py View on Github external
# 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_xmiddle-1.)
    node_state_grid[where(is_middle_cols)[0]] = 1