예제 #1
0
def test_crop_nothing_to_crop():
    arr = np.array(
        [[0, 4, 0, 3], [0, 4, 4, 3], [0, 1, 1, 3], [0, 1, 1, 3], [0, 0, 0, 0]],
        dtype=np.int64)

    raster = create_test_arr(arr)
    result = crop(raster, raster, zones_ids=(0, ))
    assert result.shape == arr.shape
    compare = arr == result.data
    assert compare.all()
예제 #2
0
def test_crop():
    arr = np.array(
        [[0, 4, 0, 3], [0, 4, 4, 3], [0, 1, 1, 3], [0, 1, 1, 3], [0, 0, 0, 0]],
        dtype=np.int64)

    raster = create_test_arr(arr)
    result = crop(raster, raster, zones_ids=(1, 3))
    assert result.shape == (4, 3)

    trimmed_arr = np.array([[4, 0, 3], [4, 4, 3], [1, 1, 3], [1, 1, 3]],
                           dtype=np.int64)

    compare = trimmed_arr == result.data
    assert compare.all()
예제 #3
0
def test_crop():
    arr = np.array(
        [[0, 4, 0, 3], [0, 4, 4, 3], [0, 1, 1, 3], [0, 1, 1, 3], [0, 0, 0, 0]],
        dtype=np.int64)

    raster = create_test_arr(arr)

    # add crs for tests
    raster = _add_EPSG4326_crs_to_da(raster)

    result = crop(raster, raster, zones_ids=(1, 3))
    assert result.shape == (4, 3)

    # crs tests
    assert result.attrs == raster.attrs
    for coord in raster.coords:
        assert np.all(result[coord] == raster[coord])

    trimmed_arr = np.array([[4, 0, 3], [4, 4, 3], [1, 1, 3], [1, 1, 3]],
                           dtype=np.int64)

    compare = trimmed_arr == result.data
    assert compare.all()