Ejemplo n.º 1
0
def test_flowdir_noflats_optimized(fillednoflatsdata, flowdirdata):
    speedups.enable()
    assert speedups.enabled
    flowdir = flow.terrain_flowdirection(fillednoflatsdata)
    assert np.all(flowdir >= 0)
    assert np.all(flowdir <= 8)
    assert np.all(flowdir == flowdirdata)
Ejemplo n.º 2
0
def test_optimized_fill(dtmdata, filleddata):
    speedups.enable()
    assert 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)
Ejemplo n.º 3
0
def test_optimized_fill_no_flats(dtmdata, fillednoflatsdata):
    speedups.enable()
    assert speedups.enabled
    short, diag = fill.minimum_safe_short_and_diag(dtmdata)
    filled = fill.fill_terrain_no_flats(dtmdata, short, diag)
    assert np.sum(filled > dtmdata) > 0
    assert np.all(filled <= np.max(dtmdata) +
                  (dtmdata.shape[0] + dtmdata.shape[1]) * diag)
    assert np.all(filled == fillednoflatsdata)
Ejemplo n.º 4
0
def test_accumulated_flow_optimized(flowdirdata):
    from malstroem.algorithms import speedups
    assert speedups.available
    speedups.enable()
    assert 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
Ejemplo n.º 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
Ejemplo n.º 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"
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 10
0
def test_watersheds_optimized32(flowdirdata, bspotdata):
    speedups.enable()
    assert speedups.enabled
    watersheds = np.copy(bspotdata)
    assert watersheds.dtype == np.int32
    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)
Ejemplo n.º 11
0
def test_label_stats_optimized(filleddata, bspotdata):
    speedups.enable()
    assert 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)
Ejemplo n.º 12
0
def test_label_data_optimized(bspotdata, depthsdata):
    speedups.enable()
    assert 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"
Ejemplo n.º 13
0
def test_label_min_index_optimized(fillednoflatsdata, bspotdata):
    speedups.enable()
    assert speedups.enabled
    min_ix = label.label_min_index(fillednoflatsdata, bspotdata)
    assert len(min_ix) == np.max(bspotdata) + 1