mirror of
https://github.com/rasterio/rasterio.git
synced 2025-12-08 17:36:12 +00:00
28 lines
855 B
Python
28 lines
855 B
Python
import logging
|
|
import sys
|
|
|
|
import numpy
|
|
|
|
import rasterio
|
|
import rasterio.features as ftrz
|
|
|
|
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
|
|
|
|
def test_sieve():
|
|
"""Test sieving a 10x10 feature from an ndarray."""
|
|
image = numpy.zeros((20, 20), dtype=rasterio.ubyte)
|
|
image[5:15,5:15] = 127
|
|
# There should be some True pixels.
|
|
assert image.any()
|
|
# An attempt to sieve out features smaller than 100 should not change the
|
|
# image.
|
|
with rasterio.drivers():
|
|
sieved_image = ftrz.sieve(image, 100)
|
|
assert (
|
|
list(map(list, numpy.where(sieved_image==127))) ==
|
|
list(map(list, numpy.where(image==127))))
|
|
# Setting the size to 100 should leave us an empty, False image.
|
|
with rasterio.drivers():
|
|
sieved_image = ftrz.sieve(image, 101)
|
|
assert not sieved_image.any()
|