Exemple #1
0
import pylab

from landlab import ModelParameterDictionary, RasterModelGrid
from landlab.components.nonlinear_diffusion.Perron_nl_diffuse import PerronNLDiffuse

inputs = ModelParameterDictionary("./drive_perron_params.txt")
nrows = inputs.read_int("nrows")
ncols = inputs.read_int("ncols")
dx = inputs.read_float("dx")
dt = inputs.read_float("dt")
time_to_run = inputs.read_float("run_time")
# nt needs defining
uplift = inputs.read_float("uplift_rate")
init_elev = inputs.read_float("init_elev")

mg = RasterModelGrid(nrows, ncols, dx)
# mg.set_inactive_boundaries(False, False, False, False)
# mg.set_inactive_boundaries(True,True,True,True)
mg.set_looped_boundaries(True, True)

# create the fields in the grid
mg.add_zeros("topographic__elevation", at="node")
z = mg.zeros(at="node") + init_elev
mg["node"]["topographic__elevation"] = z + numpy.random.rand(len(z)) / 1000.

# Now add a step to diffuse out:
# mg.at_node['topographic__elevation'][mg.active_nodes[:(mg.active_nodes.shape[0]//2.)]]
# += 0.05 #half block uplift

# pylab.figure(1)
# pylab.close()
Exemple #2
0
def test_out_of_range():
    rmg = RasterModelGrid((4, 4))
    with pytest.raises(IndexError):
        rmg.area_of_cell[5]
Exemple #3
0
def test_all_cells_with_spacing():
    rmg = RasterModelGrid(4, 4, 10.)
    assert_array_equal(rmg.area_of_cell, 100 * np.ones(4))
Exemple #4
0
# Initializing the coefficients, domain-size and model parameters
K_sp = 0.000025
D = 0.005
U = 0.001
m_sp = 1
n_sp = 1
dx = 1.0
Nr = 101
Nc = 101

# Calculating "Xi" value
Xi = (K_sp * ((Nc - 1) * dx)**(m_sp + n_sp)) / (D**n_sp * U**(1 - n_sp))
print("Xi value for this simulation run is ", Xi)

# Initializing the grid
mg = RasterModelGrid((Nr, Nc), dx)

# Initializing the elevation values
_ = mg.add_zeros('node', 'topographic__elevation')
z = np.zeros((Nr, Nc))
mg.at_node['topographic__elevation'] = z.reshape(Nr * Nc)

# Imposing fixed elevation boundary conditions
for edge in (mg.nodes_at_left_edge, mg.nodes_at_right_edge):
    mg.status_at_node[edge] = FIXED_VALUE_BOUNDARY
for edge in (mg.nodes_at_bottom_edge, mg.nodes_at_top_edge):
    mg.status_at_node[edge] = FIXED_VALUE_BOUNDARY

# Selecting D_infinity as the flow direction method
fc = FlowAccumulator(mg, flow_director='FlowDirectorDINF')
fc.run_one_step()
Exemple #5
0
    ds = df_params['ds']  #mean storm depth [m]
    T_h = 20 * df_params['Th']  #total hydrological time [s]
except KeyError:
    df_params_1d = pd.read_csv('df_params_1d_%d.csv' % ID,
                               index_col=0)[task_id]
    pet = df_params_1d['pet']
    Srange = df_params_1d['Srange']
    tr = df_params_1d['tr']  #mean storm duration [s]
    tb = df_params_1d['tb']  #mean interstorm duration [s]
    ds = df_params_1d['ds']  #mean storm depth [m]
    T_h = df_params_1d['Nt'] * (tr + tb)  #total hydrological time [s]

sat_cond = 0.025  # distance from surface (units of hg) for saturation

#initialize grid
mg = RasterModelGrid(grid.shape, xy_spacing=grid.dx)
mg.set_status_at_node_on_edges(right=mg.BC_NODE_IS_CLOSED, top=mg.BC_NODE_IS_CLOSED, \
                              left=mg.BC_NODE_IS_FIXED_VALUE, bottom=mg.BC_NODE_IS_CLOSED)
z = mg.add_zeros('node', 'topographic__elevation')
z[:] = elev
zb = mg.add_zeros('node', 'aquifer_base__elevation')
zb[:] = base
zwt = mg.add_zeros('node', 'water_table__elevation')
zwt[:] = wt

f = open('../post_proc/%s/dt_qs_s_%d.csv' % (base_output_path, ID), 'w')


def write_SQ(grid, r, dt, file=f):
    cores = grid.core_nodes
    h = grid.at_node["aquifer__thickness"]
Exemple #6
0
def test_grid_coords_to_node_id_with_array():
    rmg = RasterModelGrid((4, 5))
    assert_array_equal(rmg.grid_coords_to_node_id((3, 2), (4, 1)),
                       np.array([19, 11]))
Exemple #7
0
def test_grid_dimensions_non_unit_spacing():
    """Test extent of grid with non-unit spacing."""
    rmg = RasterModelGrid((4, 5), xy_spacing=2.)
    assert rmg.extent[0] == 6.
    assert rmg.extent[1] == 8.
Exemple #8
0
def test_node_is_core():
    rmg = RasterModelGrid((4, 5))
    for cell_id in [0, 1, 2, 3, 4, 5, 9, 10, 14, 15, 16, 17, 18, 19]:
        assert not rmg.node_is_core(cell_id)
    for cell_id in [6, 7, 8, 11, 12, 13]:
        assert rmg.node_is_core(cell_id)
Exemple #9
0
def test_get_interior_cells():
    rmg = RasterModelGrid((4, 5))
    assert_array_equal(rmg.node_at_core_cell, np.array([6, 7, 8, 11, 12, 13]))
Exemple #10
0
def test_node_axis_coordinates():
    rmg = RasterModelGrid((4, 5))
    assert rmg.node_axis_coordinates(axis=0).base is rmg.node_y.base
    assert rmg.node_axis_coordinates(axis=1).base is rmg.node_x.base
    assert rmg.node_axis_coordinates(axis=-1).base is rmg.node_x.base
    assert rmg.node_axis_coordinates(axis=-2).base is rmg.node_y.base
Exemple #11
0
def test_diagonal_list_boundary():
    rmg = RasterModelGrid((4, 5))
    assert_array_equal(rmg.diagonal_adjacent_nodes_at_node[0],
                       np.array([6, X, X, X]))
Exemple #12
0
def test_node_y_is_immutable():
    rmg = RasterModelGrid((4, 5))
    with pytest.raises(ValueError):
        rmg.node_y[0] = 0
from landlab import ModelParameterDictionary, RasterModelGrid
from landlab.components import FlowAccumulator, StreamPowerEroder
from landlab.components.stream_power import FastscapeEroder as Fsc
from landlab.plot import channel_profile as prf, imshow as llplot

inputs = ModelParameterDictionary("./drive_sp_params.txt")
nrows = inputs.read_int("nrows")
ncols = inputs.read_int("ncols")
dx = inputs.read_float("dx")
dt = inputs.read_float("dt")
time_to_run = inputs.read_float("run_time")
# nt needs defining
uplift = inputs.read_float("uplift_rate")
init_elev = inputs.read_float("init_elev")

mg = RasterModelGrid(nrows, ncols, xy_spacing=dx)

# create the fields in the grid
mg.add_zeros("topographic__elevation", at="node")
z = mg.zeros(at="node") + init_elev
mg["node"]["topographic__elevation"] = z + numpy.random.rand(len(z)) / 1000.

# make some K values in a field to test
mg.at_node["K_values"] = 1.e-6 + numpy.random.rand(nrows * ncols) * 1.e-8

mg.set_closed_boundaries_at_grid_edges(False, True, True, True)

print("Running ...")

# instantiate the components:
fr = FlowAccumulator(mg, flow_director="D8")
Exemple #14
0
#define run params
time_to_run = 500000  #years
timestep = 2  #years
plot_every = 1000  #years
nplots = time_to_run / plot_every

#setup grid
dx = 5.0
channel_width = 10  #m constant
nr = 200
nc = 400
save_topo_every = 1000  #save topo every ____ years
save_topo_flag = True  #True to save netcdf every save_topo_every years.
save_profiles_every = 10000  #save out channel profile arrays every _____ years
save_profiles_flag = True  #True to save info every dt, written out every save_profiles_every years
mg = RasterModelGrid((nr, nc), dx)

#define fluvial model parameters
bl_drop = 0.0001  #m/yr, baselevel lowering rate
z0 = 0.1  #m; bed roughness length scale
bedrock__erodibility = 0.000001
bedrock__critical_stress = 0.  #critical shear stress to erode bedrock [Pa]
block__erodibility = 0.00000005
block__critical_stress = 0  #critical shear stress to erode blocks [Pa]
drag_cube = 0.8  #drag coefficient on a cube [-]
constant_volumetric_Q = 30.  #m3/s
constant_q = constant_volumetric_Q / channel_width

#define hillslope parameters
linear_diffusivity = 0.2
soil_transport_decay_depth = 0.1
Exemple #15
0
def test_grid_dimensions():
    """Test extent of grid with unit spacing."""
    rmg = RasterModelGrid((4, 5))
    assert rmg.extent[0] == rmg.number_of_node_rows - 1
    assert rmg.extent[1] == rmg.number_of_node_columns - 1
Exemple #16
0
def test__active_links_at_node_scalar_interior():
    rmg = RasterModelGrid((4, 5))
    assert_array_equal(rmg._active_links_at_node([6]),
                       np.array([[5, 9, 14, 10]]).T)
Exemple #17
0
def test_grid_coords_to_node_id_with_scalar():
    rmg = RasterModelGrid((4, 5))
    assert rmg.grid_coords_to_node_id(3, 4) == 19
Exemple #18
0
def test__active_links_at_node_scalar_boundary():
    rmg = RasterModelGrid((4, 5))
    assert_array_equal(rmg._active_links_at_node([1]),
                       np.array([[-1, -1, 5, -1]]).T)
Exemple #19
0
def test_grid_coords_to_node_id_outside_of_grid():
    rmg = RasterModelGrid((4, 5))
    with pytest.raises(ValueError):
        rmg.grid_coords_to_node_id(5, 0)
Exemple #20
0
def test_active_node_with_array_arg():
    rmg = RasterModelGrid((4, 5))
    assert_array_equal(rmg._active_links_at_node([6, 7]),
                       np.array([[5, 9, 14, 10], [6, 10, 15, 11]]).T)
Exemple #21
0
def test_neighbor_list_with_array_arg():
    rmg = RasterModelGrid((4, 5))
    assert_array_equal(
        rmg.active_adjacent_nodes_at_node[[6, -1]],
        np.array([[7, 11, 5, 1], [X, X, X, X]]),
    )
Exemple #22
0
def test__active_links_at_node_with_no_args():
    rmg = RasterModelGrid((4, 5))
    assert_array_equal(
        rmg._active_links_at_node(),
        np.array([
            [
                -1,
                -1,
                -1,
                -1,
                -1,
                -1,
                5,
                6,
                7,
                -1,
                -1,
                14,
                15,
                16,
                -1,
                -1,
                23,
                24,
                25,
                -1,
            ],
            [
                -1,
                -1,
                -1,
                -1,
                -1,
                -1,
                9,
                10,
                11,
                12,
                -1,
                18,
                19,
                20,
                21,
                -1,
                -1,
                -1,
                -1,
                -1,
            ],
            [
                -1,
                5,
                6,
                7,
                -1,
                -1,
                14,
                15,
                16,
                -1,
                -1,
                23,
                24,
                25,
                -1,
                -1,
                -1,
                -1,
                -1,
                -1,
            ],
            [
                -1,
                -1,
                -1,
                -1,
                -1,
                9,
                10,
                11,
                12,
                -1,
                18,
                19,
                20,
                21,
                -1,
                -1,
                -1,
                -1,
                -1,
                -1,
            ],
        ]),
    )
ks = df_params['ksat'][ID]
pet = df_params['pet'][ID]
Srange = df_params['Srange'][ID]
b = df_params['b'][ID]
ds = df_params['ds'][ID]
tr = df_params['tr'][ID]
tb = df_params['tb'][ID]
Lh = df_params['Lh'][ID]
D = df_params['D'][ID]
U = df_params['U'][ID]
sc = df_params['sc'][ID]
Lh = df_params['Lh'][ID]

# initialize grid
grid = RasterModelGrid((Ny, Nx), xy_spacing=Lh/Nx)
grid.set_status_at_node_on_edges(right=grid.BC_NODE_IS_CLOSED, top=grid.BC_NODE_IS_CLOSED, \
                              left=grid.BC_NODE_IS_FIXED_VALUE, bottom=grid.BC_NODE_IS_CLOSED)
elev = grid.add_zeros('node', 'topographic__elevation')
x = grid.x_of_node
z =  calc_z(x, sc, U, D) - calc_z(x[-1], sc, U, D)
z = np.fliplr(z.reshape(grid.shape))
elev[:] = z.flatten()
base = grid.add_zeros('node', 'aquifer_base__elevation')
base[:] = elev - b
wt = grid.add_zeros('node', 'water_table__elevation')
wt[:] = elev

# initialize landlab and DupuitLEM components
gdp = GroundwaterDupuitPercolator(grid,
                                  porosity=n,
Exemple #24
0
def test_links_at_node_with_scalar_interior():
    rmg = RasterModelGrid((4, 5))
    assert_array_equal(rmg.links_at_node[6], np.array([10, 14, 9, 5]))
Exemple #25
0
def test_unit_grid_last_cell():
    rmg = RasterModelGrid((4, 4))
    assert_array_equal(rmg.area_of_cell[-1], 1.)
Exemple #26
0
def test_links_at_node_with_scalar_boundary():
    rmg = RasterModelGrid((4, 5))
    assert_array_equal(rmg.links_at_node[1], np.array([1, 5, 0, -1]))
Exemple #27
0
def test_is_immutable():
    rmg = RasterModelGrid((4, 4))
    with pytest.raises(ValueError):
        rmg.area_of_cell[0] = 0.
Exemple #28
0
def test_links_at_node_with_array_arg():
    rmg = RasterModelGrid((4, 5))
    assert_array_equal(rmg.links_at_node[6:8],
                       np.array([[10, 14, 9, 5], [11, 15, 10, 6]]))
Exemple #29
0
def test_unit_grid_all_cells():
    rmg = RasterModelGrid((4, 4))
    assert_array_equal(rmg.area_of_cell, np.ones(4))
Exemple #30
0
def setup_unit_grid():
    globals().update({
        '_RMG': RasterModelGrid(4, 5)
    })