示例#1
0
def test_rock_block_xarray():
    """Test that the xarray method works as expected."""
    sample_depths = np.arange(0, 10, 1)

    mg = RasterModelGrid((3, 3), 1)
    mg.add_zeros("node", "topographic__elevation")
    layer_ids = np.tile([0, 1, 2, 3], 5)
    layer_elevations = 3. * np.arange(-10, 10)
    layer_elevations[-1] = layer_elevations[-2] + 100
    attrs = {"K_sp": {0: 0.0003, 1: 0.0001, 2: 0.0002, 3: 0.0004}}

    lith = LithoLayers(mg,
                       layer_elevations,
                       layer_ids,
                       function=lambda x, y: x + y,
                       attrs=attrs)
    ds = lith.rock_cube_to_xarray(sample_depths)
    expected_array = np.array([
        [[3., 2., 2.], [2., 2., 2.], [2., 2., 1.]],
        [[3., 3., 2.], [3., 2., 2.], [2., 2., 2.]],
        [[3., 3., 3.], [3., 3., 2.], [3., 2., 2.]],
        [[0., 3., 3.], [3., 3., 3.], [3., 3., 2.]],
        [[0., 0., 3.], [0., 3., 3.], [3., 3., 3.]],
        [[0., 0., 0.], [0., 0., 3.], [0., 3., 3.]],
        [[1., 0., 0.], [0., 0., 0.], [0., 0., 3.]],
        [[1., 1., 0.], [1., 0., 0.], [0., 0., 0.]],
        [[1., 1., 1.], [1., 1., 0.], [1., 0., 0.]],
        [[2., 1., 1.], [1., 1., 1.], [1., 1., 0.]],
    ])

    assert_array_equal(ds.rock_type__id.values, expected_array)
示例#2
0
def test_rock_block_xarray():
    """Test that the xarray method works as expected."""
    sample_depths = np.arange(0, 10, 1)

    mg = RasterModelGrid((3, 3))
    mg.add_zeros("node", "topographic__elevation")
    layer_ids = np.tile([0, 1, 2, 3], 5)
    layer_elevations = 3.0 * np.arange(-10, 10)
    layer_elevations[-1] = layer_elevations[-2] + 100
    attrs = {"K_sp": {0: 0.0003, 1: 0.0001, 2: 0.0002, 3: 0.0004}}

    lith = LithoLayers(
        mg, layer_elevations, layer_ids, function=lambda x, y: x + y, attrs=attrs
    )
    ds = lith.rock_cube_to_xarray(sample_depths)
    expected_array = np.array(
        [
            [[3.0, 2.0, 2.0], [2.0, 2.0, 2.0], [2.0, 2.0, 1.0]],
            [[3.0, 3.0, 2.0], [3.0, 2.0, 2.0], [2.0, 2.0, 2.0]],
            [[3.0, 3.0, 3.0], [3.0, 3.0, 2.0], [3.0, 2.0, 2.0]],
            [[0.0, 3.0, 3.0], [3.0, 3.0, 3.0], [3.0, 3.0, 2.0]],
            [[0.0, 0.0, 3.0], [0.0, 3.0, 3.0], [3.0, 3.0, 3.0]],
            [[0.0, 0.0, 0.0], [0.0, 0.0, 3.0], [0.0, 3.0, 3.0]],
            [[1.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 3.0]],
            [[1.0, 1.0, 0.0], [1.0, 0.0, 0.0], [0.0, 0.0, 0.0]],
            [[1.0, 1.0, 1.0], [1.0, 1.0, 0.0], [1.0, 0.0, 0.0]],
            [[2.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 0.0]],
        ]
    )

    assert_array_equal(ds.rock_type__id.values, expected_array)
示例#3
0
def test_rock_block_xarray():
    """Test that the xarray method works as expected."""
    func = lambda x, y : x + y
    sample_depths = np.arange(0, 10, 1)

    mg = RasterModelGrid((3, 3), 1)
    z = mg.add_zeros('node', 'topographic__elevation')
    layer_ids = np.tile([0,1,2,3], 5)
    layer_elevations = 3. * np.arange(-10, 10)
    layer_elevations[-1] = layer_elevations[-2] + 100
    attrs = {'K_sp': {0: 0.0003,
                      1: 0.0001,
                      2: 0.0002,
                      3: 0.0004}}

    lith = LithoLayers(mg, layer_elevations, layer_ids, function=func, attrs=attrs)
    ds = lith.rock_cube_to_xarray(sample_depths)
    expected_array = np.array([[[ 3.,  2.,  2.],
                                [ 2.,  2.,  2.],
                                [ 2.,  2.,  1.]],
                               [[ 3.,  3.,  2.],
                                [ 3.,  2.,  2.],
                                [ 2.,  2.,  2.]],
                               [[ 3.,  3.,  3.],
                                [ 3.,  3.,  2.],
                                [ 3.,  2.,  2.]],
                               [[ 0.,  3.,  3.],
                                [ 3.,  3.,  3.],
                                [ 3.,  3.,  2.]],
                               [[ 0.,  0.,  3.],
                                [ 0.,  3.,  3.],
                                [ 3.,  3.,  3.]],
                               [[ 0.,  0.,  0.],
                                [ 0.,  0.,  3.],
                                [ 0.,  3.,  3.]],
                               [[ 1.,  0.,  0.],
                                [ 0.,  0.,  0.],
                                [ 0.,  0.,  3.]],
                               [[ 1.,  1.,  0.],
                                [ 1.,  0.,  0.],
                                [ 0.,  0.,  0.]],
                               [[ 1.,  1.,  1.],
                                [ 1.,  1.,  0.],
                                [ 1.,  0.,  0.]],
                               [[ 2.,  1.,  1.],
                                [ 1.,  1.,  1.],
                                [ 1.,  1.,  0.]]])

    assert_array_equal(ds.rock_type__id.values , expected_array)
def test_function_returns_wrong_number_of_values():
    mg = RasterModelGrid(3, 3)
    z0s = [-4, -3, -2, -1, 0, 1, 2, 4, 6]
    ids = [1, 2, 1, 2, 1, 2, 1, 2, 1]
    attrs = {"K_sp": {1: 0.001, 2: 0.0001}}
    with pytest.raises(ValueError):
        LithoLayers(mg, z0s, ids, attrs, function=lambda x, y: np.array([1.0]))
def test_function_returns_scalar():
    mg = RasterModelGrid(3, 3)
    z0s = [-4, -3, -2, -1, 0, 1, 2, 4, 6]
    ids = [1, 2, 1, 2, 1, 2, 1, 2, 1]
    attrs = {"K_sp": {1: 0.001, 2: 0.0001}}
    with pytest.raises(ValueError):
        LithoLayers(mg, z0s, ids, attrs, function=lambda x, y: 1.0)
def test_z0s_bad_order():
    """Test that providing z0s in a bad order raises an error."""
    mg = RasterModelGrid(3, 3)
    z0s = [-4, -3, -2, -1, 0, 1, 2, 6, 4]
    ids = [1, 2, 1, 2, 1, 2, 1, 2, 1]
    attrs = {"K_sp": {1: 0.001, 2: 0.0001}}
    with pytest.raises(ValueError):
        LithoLayers(mg, z0s, ids, attrs)
def test_z0s_ids_different_shape():
    """Test that providing z0s and ids of different shapes raises an error."""
    mg = RasterModelGrid(3, 3)
    z0s = [-4, -3, -2, -1, 0, 1, 2, 3, 4]
    ids = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]
    attrs = {"K_sp": {1: 0.001, 2: 0.0001}}
    with pytest.raises(ValueError):
        LithoLayers(mg, z0s, ids, attrs)
示例#8
0
def test_bad_function():
    """Test that providing a function of three variables."""
    mg = RasterModelGrid((3, 3))
    z0s = [-4, -3, -2, -1, 0, 1, 2, 4, 6]
    ids = [1, 2, 1, 2, 1, 2, 1, 2, 1]
    attrs = {"K_sp": {1: 0.001, 2: 0.0001}}
    with pytest.raises(ValueError):
        LithoLayers(mg, z0s, ids, attrs, function=lambda x, y, z: 0 * x + 0 * y + z)
示例#9
0
def test_function_returns_wrong_number_of_values():
    mg = RasterModelGrid(3, 3)
    z = mg.add_zeros('node', 'topographic__elevation')
    z0s = [-4, -3, -2, -1, 0, 1, 2, 4, 6]
    ids = [1, 2, 1, 2, 1, 2, 1, 2, 1]
    attrs = {'K_sp': {1: 0.001, 2: 0.0001}}
    func = lambda x, y: np.array([1.0])
    with pytest.raises(ValueError):
        LithoLayers(mg, z0s, ids, attrs, function=func)
示例#10
0
def test_z0s_bad_order():
    """Test that providing z0s in a bad order raises an error."""
    mg = RasterModelGrid(3, 3)
    z = mg.add_zeros('node', 'topographic__elevation')
    z0s = [-4, -3, -2, -1, 0, 1, 2, 6, 4]
    ids = [1, 2, 1, 2, 1, 2, 1, 2, 1]
    attrs = {'K_sp': {1: 0.001, 2: 0.0001}}
    with pytest.raises(ValueError):
        LithoLayers(mg, z0s, ids, attrs)
示例#11
0
def test_z0s_ids_different_shape():
    """Test that providing z0s and ids of different shapes raises an error."""
    mg = RasterModelGrid(3, 3)
    z = mg.add_zeros('node', 'topographic__elevation')
    z0s = [-4, -3, -2, -1, 0, 1, 2, 3, 4]
    ids = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]
    attrs = {'K_sp': {1: 0.001, 2: 0.0001}}
    with pytest.raises(ValueError):
        LithoLayers(mg, z0s, ids, attrs)
示例#12
0
def test_bad_function():
    """Test that providing a function of three variables."""
    mg = RasterModelGrid(3, 3)
    z = mg.add_zeros('node', 'topographic__elevation')
    z0s = [-4, -3, -2, -1, 0, 1, 2, 4, 6]
    ids = [1, 2, 1, 2, 1, 2, 1, 2, 1]
    attrs = {'K_sp': {1: 0.001, 2: 0.0001}}
    func = lambda x, y, z: 0 * x + 0 * y + z
    with pytest.raises(ValueError):
        LithoLayers(mg, z0s, ids, attrs, function=func)