Skip to content

Commit

Permalink
Merge pull request #278 from sgillies/patch-1
Browse files Browse the repository at this point in the history
Replace usage of is_tiled with tests of block shapes
  • Loading branch information
vincentsarago authored Jan 25, 2024
2 parents ff60e82 + befc58a commit c321ab4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
9 changes: 6 additions & 3 deletions rio_cogeo/cogeo.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ def cog_validate( # noqa: C901

overviews = src.overviews(1)
if src.width > 512 and src.height > 512:
if not src.is_tiled:
if src.block_shapes and src.block_shapes[0][1] == src.width:
errors.append(
"The file is greater than 512xH or 512xW, but is not tiled"
)
Expand Down Expand Up @@ -592,7 +592,10 @@ def cog_validate( # noqa: C901
for ix, _dec in enumerate(overviews):
with rasterio.open(src_path, OVERVIEW_LEVEL=ix) as ovr_dst:
if ovr_dst.width > 512 and ovr_dst.height > 512:
if not ovr_dst.is_tiled:
if (
ovr_dst.block_shapes
and ovr_dst.block_shapes[0][1] == ovr_dst.width
):
errors.append("Overview of index {} is not tiled".format(ix))

if warnings and not quiet:
Expand Down Expand Up @@ -660,7 +663,7 @@ def cog_info(
Bands=src_dst.count,
Width=src_dst.width,
Height=src_dst.height,
Tiled=src_dst.is_tiled,
Tiled=(src_dst.block_shapes[0][1] != src_dst.width),
Dtype=src_dst.dtypes[0],
Interleave=src_dst.interleaving.value
if src_dst.interleaving
Expand Down
10 changes: 5 additions & 5 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_cogeo_valid(runner):
assert src.height == 512
assert src.width == 512
assert src.meta["dtype"] == "uint8"
assert src.is_tiled
assert all([(512, 512) == (h, w) for (h, w) in src.block_shapes])
assert src.compression.value == "DEFLATE"
assert not src.photometric
assert src.interleaving.value == "PIXEL"
Expand Down Expand Up @@ -205,7 +205,7 @@ def test_cogeo_validOvrOption(runner):
assert not result.exception
assert result.exit_code == 0
with rasterio.open("output.tif") as src:
assert src.is_tiled
assert all([(512, 512) == (h, w) for (h, w) in src.block_shapes])
assert src.overviews(1) == [2, 4]


Expand All @@ -228,7 +228,7 @@ def test_cogeo_overviewTilesize(monkeypatch, runner):
assert not result.exception
assert result.exit_code == 0
with rasterio.open("output.tif") as src:
assert src.is_tiled
assert all([(128, 128) == (h, w) for (h, w) in src.block_shapes])
assert src.overviews(1)

with rasterio.open("output.tif", OVERVIEW_LEVEL=1) as src:
Expand All @@ -242,7 +242,7 @@ def test_cogeo_overviewTilesize(monkeypatch, runner):
assert not result.exception
assert result.exit_code == 0
with rasterio.open("output.tif") as src:
assert src.is_tiled
assert all([(128, 128) == (h, w) for (h, w) in src.block_shapes])
assert src.overviews(1)

with rasterio.open("output.tif", OVERVIEW_LEVEL=1) as src:
Expand Down Expand Up @@ -332,7 +332,7 @@ def test_cogeo_validgdalBlockOption(runner):
assert not result.exception
assert result.exit_code == 0
with rasterio.open("output.tif") as src:
assert src.is_tiled
assert all([(128, 128) == (h, w) for (h, w) in src.block_shapes])
assert src.overviews(1) == [2, 4]


Expand Down
12 changes: 6 additions & 6 deletions tests/test_cogeo.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def _validate_translated_rgb_jpeg(src):
assert src.height == 512
assert src.width == 512
assert src.meta["dtype"] == "uint8"
assert src.is_tiled
assert all([(64, 64) == (h, w) for (h, w) in src.block_shapes])
assert src.profile["blockxsize"] == 64
assert src.profile["blockysize"] == 64
assert src.compression.value == "JPEG"
Expand Down Expand Up @@ -127,7 +127,7 @@ def test_cog_translate_validRaw(runner):
with rasterio.open("cogeo.tif") as src:
assert src.height == 512
assert src.width == 512
assert src.is_tiled
assert all([(64, 64) == (h, w) for (h, w) in src.block_shapes])
assert not src.compression
assert src.interleaving.value == "PIXEL"

Expand Down Expand Up @@ -161,7 +161,7 @@ def test_cog_translate_validAlpha(runner):
assert src.height == 512
assert src.width == 512
assert src.meta["dtype"] == "uint8"
assert src.is_tiled
assert all([(64, 64) == (h, w) for (h, w) in src.block_shapes])
assert src.compression.value == "WEBP"
assert has_alpha_band(src)

Expand Down Expand Up @@ -259,7 +259,7 @@ def test_cog_translate_validCustom(runner):
assert src.height == 512
assert src.width == 512
assert src.meta["dtype"] == "uint8"
assert src.is_tiled
assert all([(256, 256) == (h, w) for (h, w) in src.block_shapes])
assert src.compression.value == "JPEG"
assert src.profile["blockxsize"] == 256
assert src.profile["blockysize"] == 256
Expand Down Expand Up @@ -317,7 +317,7 @@ def test_cog_translate_valid_blocksize(runner):
with rasterio.open("cogeo.tif") as src:
assert src.height == 171
assert src.width == 171
assert src.is_tiled
all([(128, 128) == (h, w) for (h, w) in src.block_shapes])
assert src.profile["blockxsize"] == 128
assert src.profile["blockysize"] == 128
assert src.overviews(1) == [2]
Expand All @@ -327,7 +327,7 @@ def test_cog_translate_valid_blocksize(runner):
with rasterio.open("cogeo.tif") as src:
assert src.height == 51
assert src.width == 51
assert src.is_tiled
assert all([(512, 512) == (h, w) for (h, w) in src.block_shapes])
assert src.profile.get("blockxsize") == 512
assert src.profile.get("blockysize") == 512
assert not src.overviews(1)
Expand Down

0 comments on commit c321ab4

Please sign in to comment.