Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add warning when no materialized overview are found #386

Merged
merged 3 commits into from
Apr 17, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion rio_tiler/io/cogeo.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from .. import reader
from ..constants import WEB_MERCATOR_TMS, WGS84_CRS, BBox, Indexes, NoData
from ..errors import ExpressionMixingWarning, TileOutsideBounds
from ..errors import ExpressionMixingWarning, NoOverviewWarning, TileOutsideBounds
from ..expression import apply_expression, parse_expression
from ..models import ImageData, ImageStatistics, Info
from ..utils import create_cutline, has_alpha_band, has_mask_band
Expand Down Expand Up @@ -109,6 +109,14 @@ def __attrs_post_init__(self):
if self.colormap is None:
self._get_colormap()

if min(
self.dataset.width, self.dataset.height
) > 512 and not self.dataset.overviews(1):
warnings.warn(
"The dataset has no materialized Overviews. rio-tiler performances might be impacted",
vincentsarago marked this conversation as resolved.
Show resolved Hide resolved
NoOverviewWarning,
)

def close(self):
"""Close rasterio dataset."""
if self.filepath:
Expand Down
9 changes: 9 additions & 0 deletions tests/test_io_cogeo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from rio_tiler.errors import (
AlphaBandWarning,
ExpressionMixingWarning,
NoOverviewWarning,
TileOutsideBounds,
)
from rio_tiler.io import COGReader, GCPCOGReader
Expand All @@ -29,6 +30,7 @@
COG_GCPS = os.path.join(PREFIX, "cog_gcps.tif")
COG_DLINE = os.path.join(PREFIX, "cog_dateline.tif")
COG_EARTH = os.path.join(PREFIX, "cog_fullearth.tif")
GEOTIFF = os.path.join(PREFIX, "nocog.tif")

KEY_ALPHA = "hro_sources/colorado/201404_13SED190110_201404_0x1500m_CL_1_alpha.tif"
COG_ALPHA = os.path.join(PREFIX, "my-bucket", KEY_ALPHA)
Expand Down Expand Up @@ -672,3 +674,10 @@ def test_read():

img = cog.read(indexes=(1, 1,))
assert img.data.shape == (2, 2667, 2658)


def test_no_overviews():
"""Should warns when no overviews are found."""
with pytest.warns(NoOverviewWarning):
with COGReader(GEOTIFF):
pass