예제 #1
0
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_river(tmp_path_factory):
    """Define the test river network."""
    np.random.seed(1)
    return river(
        'Brahmclip',
        os.path.normpath('tests/integration/data/Brahma/brahma_mask_clip.tif'),
        os.path.join(tmp_path_factory.mktemp('brahma')),
        exit_sides='ns')
예제 #3
0
def test_river():
    """Define the test river network."""
    np.random.seed(1)
    return river(
        'Brahmclip',
        os.path.join(
            basepath,
            os.path.normpath('tests/data/Brahma/brahma_mask_clip.tif')),
        os.path.join(basepath, os.path.normpath('tests/results/brahma/')),
        exit_sides='ns')
예제 #4
0
def known_river(tmp_path_factory):
    """Define the known river network."""
    np.random.seed(1)
    known_river = river(
        'Brahmclip',
        os.path.normpath('tests/integration/data/Brahma/brahma_mask_clip.tif'),
        os.path.join(tmp_path_factory.mktemp('brahma')),
        exit_sides='ns')
    known_river.load_network(path=os.path.normpath(
        'tests/integration/data/Brahma/Brahmclip_network.pkl'))
    return known_river
예제 #5
0
def known_river():
    """Define the known river network."""
    np.random.seed(1)
    known_river = river(
        'Brahmclip',
        os.path.join(
            basepath,
            os.path.normpath('tests/data/Brahma/brahma_mask_clip.tif')),
        os.path.join(basepath, os.path.normpath('tests/results/brahma/')),
        exit_sides='ns')
    known_river.load_network(path=os.path.join(
        basepath, os.path.normpath('tests/data/Brahma/Brahmclip_network.pkl')))
    return known_river
예제 #6
0
def test_river_sw():
    """Test river with exit sides 'sw'."""
    test_sw = river(
        'Brahmclip',
        os.path.join(
            basepath,
            os.path.normpath('tests/data/Brahma/brahma_mask_clip.tif')),
        os.path.join(basepath, os.path.normpath('tests/results/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'
예제 #7
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'
예제 #8
0
def test_river_noexit():
    """Raise Warning when river created without exit sides."""
    with pytest.raises(Warning):
        river('synth_river',
              'tests/data/SyntheticCycle/skeleton.tif',
              'tests/results/synthetic_cycles/')