Пример #1
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)
Пример #2
0
def process_pourpoints(bluespots, depths, watersheds, dem, accum, out, format,
                       layername, dsco, lco):
    """Determine pour points.

    \b
    Determines a pour point for each bluespot using one of two methods:
        * Random candidate. Requires DEM only
        * Maximum accumulated flow candidate. Requires accumulated flow
    The output of the two methods only differ when there are more than one pour point candidate (ie multiple threshold
    cells with identical Z) for a given bluespot.

    For documentation of OGR features (format, dsco and lco) see http://www.gdal.org/ogr_formats.html
    """
    bspot_reader = io.RasterReader(bluespots)
    depths_reader = io.RasterReader(depths)
    wsheds_reader = io.RasterReader(watersheds)

    data = accum if accum else dem
    if not data:
        raise Exception('Either accum or dem must be specified')
    data_reader = io.RasterReader(data)

    format = str(format)
    layername = str(layername)

    pourpnt_writer = io.VectorWriter(format, out, layername, [], ogr.wkbPoint,
                                     depths_reader.crs, dsco, lco)

    # Recalculate stats on filtered bluespots
    labeled_data = bspot_reader.read()
    depths_data = depths_reader.read()
    bluespot_stats = label.label_stats(depths_data, labeled_data)
    del depths_data

    if accum:
        pp_pix = label.label_max_index(data_reader.read(), labeled_data)
    elif dem:
        dem_data = data_reader.read()
        short, diag = fill.minimum_safe_short_and_diag(dem_data)
        filled_no_flats = fill.fill_terrain_no_flats(dem_data, short, diag)
        pp_pix = label.label_min_index(filled_no_flats, labeled_data)
        del dem_data

    watershed_stats = label.label_count(wsheds_reader.read())
    pour_points = assemble_pourpoints(depths_reader.transform, pp_pix,
                                      bluespot_stats, watershed_stats)

    feature_collection = dict(type="FeatureCollection", features=pour_points)
    pourpnt_writer.write_geojson_features(feature_collection)
Пример #3
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