Skip to content

Commit

Permalink
Merge pull request #300 from glostis/rasterio-1-4-3-compression-value
Browse files Browse the repository at this point in the history
Fix reading raster compression value with rasterio 1.4.3
  • Loading branch information
vincentsarago authored Dec 16, 2024
2 parents ad2e854 + 1ed7e0c commit ee1a1c7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion rio_cogeo/cogeo.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ def cog_info(
with rasterio.Env(**config):
with rasterio.open(src_path) as src_dst:
driver = src_dst.driver
compression = src_dst.compression.value if src_dst.compression else None
compression = getattr(src_dst.compression, "value", src_dst.compression)
colorspace = src_dst.photometric.value if src_dst.photometric else None
overviews = src_dst.overviews(1)

Expand Down
12 changes: 8 additions & 4 deletions tests/test_cogeo.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _validate_translated_rgb_jpeg(src):
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"
assert src.compression == "YCbCr JPEG" or src.compression.value == "JPEG"
assert src.photometric.value == "YCbCr"
assert src.interleaving.value == "PIXEL"
assert src.overviews(1) == [2, 4, 8]
Expand Down Expand Up @@ -101,7 +101,9 @@ def test_cog_translate_NodataLossyWarning(runner):
)
with rasterio.open("cogeo.tif") as src:
assert not src.nodata
assert src.compression.value == "JPEG"
assert (
src.compression == "YCbCr JPEG" or src.compression.value == "JPEG"
)
assert has_mask_band(src)


Expand Down Expand Up @@ -186,7 +188,9 @@ def test_cog_translate_validAlpha(runner):
)
with rasterio.open("cogeo.tif") as src:
assert src.count == 3
assert src.compression.value == "JPEG"
assert (
src.compression == "YCbCr JPEG" or src.compression.value == "JPEG"
)
assert has_mask_band(src)

with pytest.warns(UserWarning):
Expand Down Expand Up @@ -291,7 +295,7 @@ def test_cog_translate_validCustom(runner):
assert src.width == 512
assert src.meta["dtype"] == "uint8"
assert all([(256, 256) == (h, w) for (h, w) in src.block_shapes])
assert src.compression.value == "JPEG"
assert src.compression == "YCbCr JPEG" or src.compression.value == "JPEG"
assert src.profile["blockxsize"] == 256
assert src.profile["blockysize"] == 256
assert src.photometric.value == "YCbCr"
Expand Down

0 comments on commit ee1a1c7

Please sign in to comment.