mirror of
https://github.com/rasterio/rasterio.git
synced 2025-12-08 17:36:12 +00:00
Also reverted to ordinary ValueError since you won't handle invalid resampling values in a special way.
70 lines
2.2 KiB
Python
70 lines
2.2 KiB
Python
"""Tests of overview counting and creation."""
|
|
|
|
import logging
|
|
import sys
|
|
|
|
from click.testing import CliRunner
|
|
import pytest
|
|
|
|
import rasterio
|
|
from rasterio.enums import Resampling
|
|
|
|
|
|
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
|
|
|
|
|
|
def test_count_overviews_zero(data):
|
|
inputfile = str(data.join('RGB.byte.tif'))
|
|
with rasterio.open(inputfile) as src:
|
|
assert src.overviews(1) == []
|
|
assert src.overviews(2) == []
|
|
assert src.overviews(3) == []
|
|
|
|
|
|
def test_build_overviews_one(data):
|
|
inputfile = str(data.join('RGB.byte.tif'))
|
|
with rasterio.open(inputfile, 'r+') as src:
|
|
overview_factors = [2]
|
|
src.build_overviews(overview_factors, resampling=Resampling.nearest)
|
|
assert src.overviews(1) == [2]
|
|
assert src.overviews(2) == [2]
|
|
assert src.overviews(3) == [2]
|
|
|
|
|
|
def test_build_overviews_two(data):
|
|
inputfile = str(data.join('RGB.byte.tif'))
|
|
with rasterio.open(inputfile, 'r+') as src:
|
|
overview_factors = [2, 4]
|
|
src.build_overviews(overview_factors, resampling=Resampling.nearest)
|
|
assert src.overviews(1) == [2, 4]
|
|
assert src.overviews(2) == [2, 4]
|
|
assert src.overviews(3) == [2, 4]
|
|
|
|
|
|
def test_build_overviews_average(data):
|
|
inputfile = str(data.join('RGB.byte.tif'))
|
|
with rasterio.open(inputfile, 'r+') as src:
|
|
overview_factors = [2, 4]
|
|
src.build_overviews(overview_factors, resampling=Resampling.average)
|
|
assert src.overviews(1) == [2, 4]
|
|
assert src.overviews(2) == [2, 4]
|
|
assert src.overviews(3) == [2, 4]
|
|
|
|
|
|
def test_build_overviews_gauss(data):
|
|
inputfile = str(data.join('RGB.byte.tif'))
|
|
with rasterio.open(inputfile, 'r+') as src:
|
|
overview_factors = [2, 4]
|
|
src.build_overviews(overview_factors, resampling=Resampling.gauss)
|
|
assert src.overviews(1) == [2, 4]
|
|
assert src.overviews(2) == [2, 4]
|
|
assert src.overviews(3) == [2, 4]
|
|
|
|
|
|
def test_test_unsupported_algo(data):
|
|
inputfile = str(data.join('RGB.byte.tif'))
|
|
with pytest.raises(ValueError):
|
|
with rasterio.open(inputfile, 'r+') as src:
|
|
overview_factors = [2, 4]
|
|
src.build_overviews(overview_factors, resampling=Resampling.q1)
|