Skip to content

Commit

Permalink
Test option to ignore overviews (OVERVIEW_LEVEL=-1) (#2050)
Browse files Browse the repository at this point in the history
* Test for upcoming GDAL feature (from 3.3) allowing existing overviews to
not be exposed
- see OSGeo/gdal#3181
- see https://rasterio.groups.io/g/main/message/649

The test:
- requires gdal 3.3
- tests whether a dataset can be opened with OVERVIEW_LEVEL=-1
- ensures that opening a dataset with OVERVIEW_LEVEL=-1 ignores the file
overview
- ensures that a decimated read on a dataset opened with
OVERVIEW_LEVEL=1 does not read the file overview

* Make test for ignoring overviews when performing decimated read more
simple and robust
  • Loading branch information
loicdtx committed Dec 2, 2020
1 parent ea8220b commit 28ea232
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
4 changes: 4 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,3 +622,7 @@ def __init__(self, geojson):
requires_gdal3 = pytest.mark.skipif(
not gdal_version.at_least('3.0'),
reason="Requires GDAL 3.0.x")

requires_gdal33 = pytest.mark.skipif(
not gdal_version.at_least('3.3'),
reason="Requires GDAL 3.3.x")
35 changes: 34 additions & 1 deletion tests/test_overviews.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Tests of overview counting and creation."""
import math

import numpy as np
import pytest

from .conftest import requires_gdal2
from .conftest import requires_gdal2, requires_gdal33

import rasterio
from rasterio.enums import Resampling
Expand Down Expand Up @@ -104,3 +106,34 @@ def test_build_overviews_new_file(tmpdir, path_rgb_byte_tif):
with rasterio.open(dst_file, overview_level=1) as src:
data = src.read()
assert data.any()


@requires_gdal33
def test_ignore_overviews(data):
"""open dataset with OVERVIEW_LEVEL=-1, overviews should be ignored"""
inputfile = str(data.join('RGB.byte.tif'))
with rasterio.open(inputfile, 'r+') as src:
src.build_overviews([2], resampling=Resampling.nearest)

with rasterio.open(inputfile, OVERVIEW_LEVEL=-1) as src:
assert src.overviews(1) == []
assert src.overviews(2) == []
assert src.overviews(3) == []


@requires_gdal33
def test_decimated_no_use_overview(red_green):
"""Force ignore existing overviews when performing decimated read"""
# Corrupt overview of red file
green_ovr = red_green.join("green.tif.ovr")
green_ovr.rename(red_green.join("red.tif.ovr"))
assert not green_ovr.exists()
# Read the corrupted red overview
with rasterio.open(str(red_green.join("red.tif.ovr"))) as ovr:
ovr_data = ovr.read()
ovr_shape = ovr_data.shape
assert (ovr_data[1] == 204).all()
# Perform decimated read and ensure no use of file overview (different from corrupted)
with rasterio.open(str(red_green.join("red.tif")), OVERVIEW_LEVEL=-1) as src:
decimated_data = src.read(out_shape=ovr_shape)
assert not np.array_equal(ovr_data, decimated_data)

0 comments on commit 28ea232

Please sign in to comment.