コード例 #1
0
ファイル: test_lithology.py プロジェクト: landlab/landlab
def test_deposit_with_no_rock_id():
    """Test that adding a deposit to Lithology with no id raises an error."""
    mg = RasterModelGrid((3, 3))
    mg.add_zeros("node", "topographic__elevation")
    thicknesses = [1, 2, 4, 1, 5]
    ids = [1, 2, 1, 2, 1]
    attrs = {"K_sp": {1: 0.001, 2: 0.0001}}
    lith = Lithology(mg, thicknesses, ids, attrs)
    with pytest.raises(ValueError):
        lith.add_layer(100)
コード例 #2
0
ファイル: test_lithology.py プロジェクト: landlab/landlab
def test_updating_rock_type_that_doesnt_exist():
    """Test adding an new rock type with an extra attribute."""
    mg = RasterModelGrid((3, 3))
    mg.add_zeros("node", "topographic__elevation")
    thicknesses = [1, 2, 4, 1, 5]
    ids = [1, 2, 1, 2, 1]
    attrs = {"K_sp": {1: 0.001, 2: 0.0001}}
    lith = Lithology(mg, thicknesses, ids, attrs)
    with pytest.raises(ValueError):
        lith.update_rock_properties("K_sp", 3, 4)
コード例 #3
0
ファイル: test_lithology.py プロジェクト: cmshobe/landlab
def test_updating_attribute_that_doesnt_exist():
    """Test updating an attribute that doesn't exist."""
    mg = RasterModelGrid(3, 3)
    mg.add_zeros("node", "topographic__elevation")
    thicknesses = [1, 2, 4, 1, 5]
    ids = [1, 2, 1, 2, 1]
    attrs = {"K_sp": {1: 0.001, 2: 0.0001}}
    lith = Lithology(mg, thicknesses, ids, attrs)
    with pytest.raises(ValueError):
        lith.update_rock_properties("spam", 1, 4)
コード例 #4
0
ファイル: test_lithology.py プロジェクト: landlab/landlab
def test_erode_to_zero_thickness():
    """Test that eroding Lithology to zero thickness raises an error."""
    mg = RasterModelGrid((3, 3))
    mg.add_zeros("node", "topographic__elevation")
    thicknesses = [1, 2, 4, 1, 5]
    ids = [1, 2, 1, 2, 1]
    attrs = {"K_sp": {1: 0.001, 2: 0.0001}}
    lith = Lithology(mg, thicknesses, ids, attrs)
    with pytest.raises(ValueError):
        lith.add_layer(-100)
コード例 #5
0
ファイル: test_lithology.py プロジェクト: landlab/landlab
def test_run_one_step_deposit_no_id_raises_error():
    """Test that giving the run one step method a deposit with no id raises an error."""
    mg = RasterModelGrid((3, 3))
    z = mg.add_zeros("node", "topographic__elevation")
    thicknesses = [1, 2, 4, 1, 5]
    ids = [1, 2, 1, 2, 1]
    attrs = {"K_sp": {1: 0.001, 2: 0.0001}}
    lith = Lithology(mg, thicknesses, ids, attrs)
    z += 1
    with pytest.raises(ValueError):
        lith.run_one_step()
コード例 #6
0
ファイル: test_lithology.py プロジェクト: landlab/landlab
def test_run_one_step_erodes_all_raises_error():
    """Test that eroding all material with the run one step method raises an error."""
    mg = RasterModelGrid((3, 3))
    z = mg.add_zeros("node", "topographic__elevation")
    thicknesses = [1, 2, 4, 1, 5]
    ids = [1, 2, 1, 2, 1]
    attrs = {"K_sp": {1: 0.001, 2: 0.0001}}
    lith = Lithology(mg, thicknesses, ids, attrs)
    z -= 30
    with pytest.raises(ValueError):
        lith.run_one_step()
コード例 #7
0
ファイル: test_lithology.py プロジェクト: landlab/landlab
def test_adding_new_id_missing_attribute():
    """Test adding an new rock type with an extra attribute."""
    mg = RasterModelGrid((3, 3))
    mg.add_zeros("node", "topographic__elevation")
    thicknesses = [1, 2, 4, 1, 5]
    ids = [1, 2, 1, 2, 1]
    attrs = {"K_sp": {1: 0.001, 2: 0.0001}}
    lith = Lithology(mg, thicknesses, ids, attrs)
    new_attr = {"D": {4: 0.001, 5: 0.0001}}
    with pytest.raises(ValueError):
        lith.add_rock_type(new_attr)
コード例 #8
0
ファイル: test_lithology.py プロジェクト: landlab/landlab
def test_adding_new_id_existing_rock_type():
    """Test adding an rock type that already exists."""
    mg = RasterModelGrid((3, 3))
    mg.add_zeros("node", "topographic__elevation")
    thicknesses = [1, 2, 4, 1, 5]
    ids = [1, 2, 1, 2, 1]
    attrs = {"K_sp": {1: 0.001, 2: 0.0001}}
    lith = Lithology(mg, thicknesses, ids, attrs)

    new_attr = {"K_sp": {1: 0.001, 5: 0.0001}}

    with pytest.raises(ValueError):
        lith.add_rock_type(new_attr)
コード例 #9
0
ファイル: test_lithology.py プロジェクト: cmshobe/landlab
def test_adding_existing_attribute():
    """Test adding an existing attribute."""
    mg = RasterModelGrid(3, 3)
    mg.add_zeros("node", "topographic__elevation")
    thicknesses = [1, 2, 4, 1, 5]
    ids = [1, 2, 1, 2, 1]
    attrs = {"K_sp": {1: 0.001, 2: 0.0001}}
    lith = Lithology(mg, thicknesses, ids, attrs)

    new_attr = {"K_sp": {1: 0.001, 2: 0.0001}}

    with pytest.raises(ValueError):
        lith.add_property(new_attr)
コード例 #10
0
ファイル: test_lithology.py プロジェクト: landlab/landlab
def test_adding_new_attribute_extra_rock_id():
    """Test adding an new attribute with an extra rock id."""
    mg = RasterModelGrid((3, 3))
    mg.add_zeros("node", "topographic__elevation")
    thicknesses = [1, 2, 4, 1, 5]
    ids = [1, 2, 1, 2, 1]
    attrs = {"K_sp": {1: 0.001, 2: 0.0001}}
    lith = Lithology(mg, thicknesses, ids, attrs)

    new_attr = {"D": {1: 0.001, 2: 0.0001, 3: 5.3}}

    with pytest.raises(ValueError):
        lith.add_property(new_attr)
コード例 #11
0
def test_adding_new_attribute_missing_rock_id():
    """Test adding an new attribute missing an existing rock id."""
    mg = RasterModelGrid(3, 3)
    z = mg.add_zeros('node', 'topographic__elevation')
    thicknesses = [1, 2, 4, 1, 5]
    ids = [1, 2, 1, 2, 1]
    attrs = {'K_sp': {1: 0.001, 2: 0.0001}}
    lith = Lithology(mg, thicknesses, ids, attrs)

    new_attr = {'D': {2: 0.0001}}

    with pytest.raises(ValueError):
        lith.add_property(new_attr)
コード例 #12
0
def test_adding_new_id_extra_attribute():
    """Test adding an new rock type with an extra attribute."""
    mg = RasterModelGrid(3, 3)
    z = mg.add_zeros('node', 'topographic__elevation')
    thicknesses = [1, 2, 4, 1, 5]
    ids = [1, 2, 1, 2, 1]
    attrs = {'K_sp': {1: 0.001, 2: 0.0001}}
    lith = Lithology(mg, thicknesses, ids, attrs)

    new_attr = {'K_sp': {4: 0.001, 5: 0.0001},
                'D':    {4: 0.001, 5: 0.0001}}

    with pytest.raises(ValueError):
        lith.add_rock_type(new_attr)
コード例 #13
0
ファイル: test_lithology.py プロジェクト: cmshobe/landlab
def test_deposit_with_bad_rock_id():
    """Test that adding a deposit to Lithology with no id raises an error."""
    mg = RasterModelGrid(3, 3)
    mg.add_zeros("node", "topographic__elevation")
    thicknesses = [1, 2, 4, 1, 5]
    ids = [1, 2, 1, 2, 1]
    attrs = {"K_sp": {1: 0.001, 2: 0.0001}}
    lith = Lithology(mg, thicknesses, ids, attrs)
    with pytest.raises(ValueError):
        lith.add_layer(100, rock_id=3)

    ones = np.ones(mg.number_of_nodes)
    new_ids = [0, 1, 3, 4, 0, 1, 0, 1, 5]
    with pytest.raises(ValueError):
        lith.add_layer(ones, rock_id=new_ids)
コード例 #14
0
ファイル: test_lithology.py プロジェクト: zrduan/landlab
def test_thickness_ndim3():
    """Test too many ndim for thickness."""
    # next as both as ndim = 3 arrays
    attrs = {'K_sp': {1: 0.001, 2: 0.0001}}
    mg = RasterModelGrid(3, 3)
    ones = np.ones((mg.number_of_nodes, 2))
    z = mg.add_zeros('node', 'topographic__elevation')
    thicknesses = [1 * ones, 2 * ones, 4 * ones, 1 * ones, 5 * ones]
    ids = [1, 2, 1, 2]
    with pytest.raises(ValueError):
        Lithology(mg, thicknesses, ids, attrs)
コード例 #15
0
def test_id_ndim3():
    """Test too many ndim for ids."""
    # next as both as ndim = 3 arrays
    attrs = {"K_sp": {1: 0.001, 2: 0.0001}}
    mg = RasterModelGrid(3, 3)
    ones = np.ones(mg.number_of_nodes)

    extra_ones = np.ones((mg.number_of_nodes, 2))
    mg.add_zeros("node", "topographic__elevation")
    thicknesses = [1 * ones, 2 * ones, 4 * ones, 1 * ones, 5 * ones]
    ids = [1 * extra_ones, 2 * extra_ones, 1 * extra_ones, 2 * extra_ones]
    with pytest.raises(ValueError):
        Lithology(mg, thicknesses, ids, attrs)
コード例 #16
0
def test_deposit_with_bad_rock_id():
    """Test that adding a deposit to Lithology with no id raises an error."""
    mg = RasterModelGrid(3, 3)
    mg.add_zeros("node", "topographic__elevation")
    thicknesses = [1, 2, 4, 1, 5]
    ids = [1, 2, 1, 2, 1]
    attrs = {"K_sp": {1: 0.001, 2: 0.0001}}
    lith = Lithology(mg, thicknesses, ids, attrs)
    with pytest.raises(ValueError):
        lith.add_layer(100, rock_id=3)

    ones = np.ones(mg.number_of_nodes)
    new_ids = [0, 1, 3, 4, 0, 1, 0, 1, 5]
    with pytest.raises(ValueError):
        lith.add_layer(ones, rock_id=new_ids)
コード例 #17
0
                                          np.random.rand(nrows * ncols))

## Adapted script so that there is a band of weaker rock along the shear zone
# Possible improvements -
# Make the initialization a bit less arbritrary
# Not sure that the lithology elements get tracked with the nodes, this does not matter in the strike slip case but may matter in other cases

z = rmg['node']['topographic__elevation']

# The variable lithology is done the only way I know how (most likely not the best way)
attrs = {'K_sp': {1: 0.05, 2: 0.09}, 'D': {1: 0.02, 2: 0.02}}
# Dummy thickness
thickness = [1, 1]

# instantiate the Lithology component
lith = Lithology(rmg, thickness, [1, 2], attrs)

# put in the damage zone a third of the way in the model
spatially_variable_rock_id = rmg.ones('node')

# Comment/Uncomment below to introduce a damage zone kdc!
spatially_variable_rock_id[(rmg.y_of_node > 2 * ymax / 5)
                           & (rmg.y_of_node < 3 * ymax / 5)] = 2

# grow the topography up (this is clearly dumb)
z += 1.
dz_ad = 0.
lith.run_one_step(dz_advection=dz_ad, rock_id=spatially_variable_rock_id)
imshow_grid(rmg, 'rock_type__id', cmap='viridis', vmin=0, vmax=3)

#  since we will not update z after this, the erodability parameters of the rock should not change