コード例 #1
0
def test_python_fill(dtmdata, filleddata):
    speedups.disable()
    assert not speedups.enabled
    filled = fill.fill_terrain(dtmdata)
    assert np.all(filled >= np.min(dtmdata))
    assert np.max(filled) == np.max(dtmdata)
    assert np.all(filled == filleddata)
コード例 #2
0
def test_flowdir_noflats(fillednoflatsdata, flowdirdata):
    speedups.disable()
    assert not speedups.enabled
    flowdir = flow.terrain_flowdirection(fillednoflatsdata)
    assert np.all(flowdir >= 0)
    assert np.all(flowdir <= 8)
    assert np.all(flowdir == flowdirdata)
コード例 #3
0
def test_accumulated_flow(flowdirdata):
    from malstroem.algorithms import speedups
    if speedups.enabled:
        speedups.disable()
    assert not speedups.enabled
    accum = flow.accumulated_flow(flowdirdata)
    assert np.min(accum) >= 1  # All cells MUST be >= 1
    assert np.max(accum) == 11158
    assert np.sum(accum) == 3578615
コード例 #4
0
def test_python_fill_no_flats(dtmdata, fillednoflatsdata):
    speedups.disable()
    assert not speedups.enabled
    short, diag = fill.minimum_safe_short_and_diag(dtmdata)
    filled = fill.fill_terrain_no_flats(dtmdata, short, diag)
    assert np.all(filled >= np.min(dtmdata))
    assert np.all(filled <= np.max(dtmdata) +
                  (dtmdata.shape[0] + dtmdata.shape[1]) * diag)
    assert np.all(filled == fillednoflatsdata)
コード例 #5
0
def test_compare_label_stats(filleddata, bspotdata):
    speedups.disable()
    assert not speedups.enabled
    stats = label.label_stats(filleddata, bspotdata)
    speedups.enable()
    assert speedups.enabled
    statsopt = label.label_stats(filleddata, bspotdata)

    for s, so in zip(stats, statsopt):
        assert s == so
コード例 #6
0
def test_speedups_toggl(method):
    speedups.disable()
    assert not is_speedups_method(getattr(
        label, method)), f"Speedup for {method} not disabled"
    speedups.enable()
    assert is_speedups_method(getattr(
        label, method)), f"Speedup for {method} not enabled"
    speedups.disable()
    assert not is_speedups_method(getattr(
        label, method)), f"Speedup for {method} not disabled"
コード例 #7
0
def test_compare_fill_no_flats_python_and_optimized(dtmdata):
    speedups.enable()
    assert speedups.enabled
    short, diag = fill.minimum_safe_short_and_diag(dtmdata)
    filled_optimized = fill.fill_terrain_no_flats(dtmdata, short, diag)
    speedups.disable()
    assert not speedups.enabled
    filled_python = fill.fill_terrain_no_flats(dtmdata, short, diag)

    assert np.all(filled_optimized == filled_python)
コード例 #8
0
def test_compare_fill_python_and_optimized(dtmdata):
    speedups.enable()
    assert speedups.enabled

    filled_optimized = fill.fill_terrain(dtmdata)

    speedups.disable()
    assert not speedups.enabled
    filled_python = fill.fill_terrain(dtmdata)
    assert np.all(filled_optimized == filled_python)
コード例 #9
0
def test_compare_label_min_index(fillednoflatsdata, bspotdata):
    speedups.disable()
    assert not speedups.enabled
    min_ix = label.label_min_index(fillednoflatsdata, bspotdata)
    speedups.enable()
    assert speedups.enabled
    min_ix_opt = label.label_min_index(fillednoflatsdata, bspotdata)
    assert len(min_ix) == len(min_ix_opt)
    for m, mopt in zip(min_ix, min_ix_opt):
        for v, vopt in zip(m, mopt):
            assert np.isclose(v, vopt)
コード例 #10
0
def test_watersheds(flowdirdata, bspotdata):
    speedups.disable()
    assert not speedups.enabled
    watersheds = np.copy(bspotdata)
    flow.watersheds_from_labels(flowdirdata, watersheds, unassigned=0)

    labelled_indexes = bspotdata > 0
    assert np.all(watersheds[labelled_indexes] == bspotdata[labelled_indexes])
    assert np.max(watersheds) == np.max(bspotdata)
    assert np.sum(watersheds) == 2337891

    # Check that all watersheds are a connected component
    for lbl in range(1, np.max(watersheds) + 1):
        labeled, nlabels = label.connected_components(watersheds == lbl)
        assert nlabels == 1, "Watershed {} is not a connected component".format(
            lbl)
コード例 #11
0
def test_label_stats(filleddata, bspotdata):
    speedups.disable()
    assert not speedups.enabled
    stats = label.label_stats(filleddata, bspotdata)
    assert len(stats) == np.max(bspotdata) + 1
    assert np.all(stats[:]['min'] <= stats[:]['max'])
    assert np.sum(stats[:]['count']) == bspotdata.shape[0] * bspotdata.shape[1]
    assert np.min(stats[:]['min']) == np.min(filleddata)
    assert np.max(stats[:]['max']) == np.max(filleddata)

    # Check label with most cells
    lbl = np.argmax(stats[:]['count'])
    lblix = bspotdata == lbl
    assert stats[lbl]['min'] == np.min(filleddata[lblix])
    assert stats[lbl]['max'] == np.max(filleddata[lblix])
    np.testing.assert_almost_equal(
        stats[lbl]['sum'], np.sum(filleddata.astype(np.float64)[lblix]))
    assert stats[lbl]['count'] == np.sum(lblix)
コード例 #12
0
def test_label_data(bspotdata, depthsdata):
    speedups.disable()
    assert not speedups.enabled
    data_per_label = label.label_data(depthsdata,
                                      bspotdata,
                                      nlabels=None,
                                      background=0)
    assert len(data_per_label) > 0
    assert len(data_per_label) == np.max(bspotdata) + 1
    assert len(data_per_label[0]) == 0, "Background data list should be empty"
    for e, values_list in enumerate(data_per_label[1:]):
        assert len(values_list) > 0, f"label {e+1} has zero data values"

    # Sum collected values
    sums = [sum(x) for x in data_per_label]
    global_sum = sum(sums)

    # Make sum in numpy using rasters only
    np_sum = np.sum(depthsdata[bspotdata != 0])
    assert pytest.approx(
        np_sum) == global_sum, "Returned values do not sum correctly"
コード例 #13
0
def test_label_min_index(fillednoflatsdata, bspotdata):
    speedups.disable()
    assert not speedups.enabled
    min_ix = label.label_min_index(fillednoflatsdata, bspotdata)
    assert len(min_ix) == np.max(bspotdata) + 1