コード例 #1
0
ファイル: test_river_int.py プロジェクト: jonschwenk/RivGraph
def test_river_dirs(tmp_path):
    """Test river with exit sides 'ne' and 'sw'."""
    img_path = os.path.normpath(
        'tests/integration/data/Brahma/brahma_mask_clip.tif')
    out_path = os.path.join(tmp_path, 'cropped.tif')
    geo_utils.crop_geotif(img_path, npad=10, outpath=out_path)
    test_ne = river('Brahmclip', out_path,
                    os.path.join(tmp_path, 'brahma'),
                    exit_sides='ne')
    test_ne.compute_network()
    test_ne.compute_mesh()
    test_ne.prune_network()

    # make assertions
    assert len(test_ne.nodes['inlets']) == 1
    assert len(test_ne.nodes['outlets']) == 1
    assert test_ne.exit_sides == 'ne'

    # test sw
    test_sw = river('Brahmclip', out_path,
                    os.path.join(tmp_path, 'brahma'),
                    exit_sides='sw')
    test_sw.compute_network()
    test_sw.compute_mesh()
    test_sw.prune_network()

    # make assertions
    assert len(test_sw.nodes['inlets']) == 1
    assert len(test_sw.nodes['outlets']) == 1
    assert test_sw.exit_sides == 'sw'
コード例 #2
0
def test_crop_geotiff_out():
    """Test crop_geotif() with no outpath."""
    g_path = os.path.join(basepath, os.path.normpath('tests/data/Colville/Colville_islands_filled.tif'))
    # run cropping function
    o_path = geo_utils.crop_geotif(g_path)
    # assert file name and existance
    assert o_path == g_path.split('.')[-2] + '_cropped.tif'
    assert os.path.isfile(o_path) == True
コード例 #3
0
def test_croppad_geotiff():
    """Test crop_geotif() with padding."""
    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/croppedpad.tif'))
    # run cropping function
    o_path = geo_utils.crop_geotif(g_path, npad=6, outpath=outpath)
    # assert file name and existance
    assert o_path == outpath
    assert os.path.isfile(o_path) == True
コード例 #4
0
def test_river_ne():
    """Test river with exit sides 'ne'."""
    img_path = os.path.join(
        basepath, os.path.normpath('tests/data/Brahma/brahma_mask_clip.tif'))
    out_path = os.path.join(
        basepath, os.path.normpath('tests/results/brahma/cropped.tif'))
    geo_utils.crop_geotif(img_path, npad=10, outpath=out_path)
    test_ne = river('Brahmclip',
                    out_path,
                    os.path.join(basepath,
                                 os.path.normpath('tests/results/brahma/')),
                    exit_sides='ne')
    test_ne.compute_network()
    test_ne.compute_mesh()
    test_ne.prune_network()

    # make assertions
    assert len(test_ne.nodes['inlets']) == 1
    assert len(test_ne.nodes['outlets']) == 1
    assert test_ne.exit_sides == 'ne'
コード例 #5
0
def test_crop_geotiff(tmp_path):
    """Test crop_geotif()."""
    g_path = os.path.normpath(
        'tests/integration/data/Colville/Colville_islands_filled.tif')
    outpath = os.path.join(tmp_path, 'cropped.tif')
    # run cropping function
    o_path = geo_utils.crop_geotif(g_path, outpath=outpath)
    # assert file name and existance
    assert o_path == outpath
    assert os.path.isfile(o_path) == True

    # check output of cropped file
    crop_file = gdal.Open(o_path)
    o_file = crop_file.ReadAsArray()
    # check that first/last rows and columns not all 0s
    assert np.sum(o_file[0, :]) > 0
    assert np.sum(o_file[-1, :]) > 0
    assert np.sum(o_file[:, 0]) > 0
    assert np.sum(o_file[:, -1]) > 0