Пример #1
0
def test_downsample_bad_factor():
    """Test downsampling geotiff with invalid ds_factor."""
    g_path = os.path.join(basepath, os.path.normpath('tests/data/Colville/Colville_islands_filled.tif'))
    outpath = os.path.join(basepath, os.path.normpath('tests/results/known/downsampled.tif'))
    # run downsampling function and throw error
    with pytest.raises(ValueError):
        geo_utils.downsample_binary_geotiff(g_path, 2.0, outpath)
Пример #2
0
def test_downsample_input_thresh(tmp_path):
    """Test downsampling geotiff with defined thresh."""
    g_path = os.path.normpath(
        'tests/integration/data/Colville/Colville_islands_filled.tif')
    outpath = os.path.join(tmp_path, 'downsampled.tif')
    # run downsampling function
    outfile = geo_utils.downsample_binary_geotiff(g_path,
                                                  0.5,
                                                  outpath,
                                                  thresh=0.1)
    # assert output
    assert outfile == outpath

    # check downsampled output
    # original
    og_file = gdal.Open(g_path)
    og_img = og_file.ReadAsArray()
    # downsampled
    ds_file = gdal.Open(outpath)
    o_file = ds_file.ReadAsArray()
    # check that downsampled size is smaller
    assert np.shape(og_img)[0] > np.shape(o_file)[0]
    assert np.shape(og_img)[1] > np.shape(o_file)[1]
    # check pixel resolution - should be double the original
    assert (ds_file.GetGeoTransform()[1]) == (og_file.GetGeoTransform()[1] * 2)
    assert (ds_file.GetGeoTransform()[5]) == (og_file.GetGeoTransform()[5] * 2)
Пример #3
0
def test_downsample_w_pad():
    """Test downsampling geotiff with some padding due to division."""
    g_path = os.path.join(basepath, os.path.normpath('tests/data/Colville/Colville_islands_filled.tif'))
    outpath = os.path.join(basepath, os.path.normpath('tests/results/known/downsampled.tif'))
    # run downsampling function
    ofile = geo_utils.downsample_binary_geotiff(g_path, 0.76, outpath)
    # assert output
    assert ofile == outpath
Пример #4
0
def test_downsample_default_thresh():
    """Test downsampling geotiff with default thresh."""
    g_path = os.path.join(basepath, os.path.normpath('tests/data/Colville/Colville_islands_filled.tif'))
    outpath = os.path.join(basepath, os.path.normpath('tests/results/known/downsampled.tif'))
    # run downsampling function
    ofile = geo_utils.downsample_binary_geotiff(g_path, 0.5, outpath)
    # assert output
    assert ofile == outpath