mirror of
https://github.com/rasterio/rasterio.git
synced 2026-01-25 14:10:17 +00:00
* Properly set color interpretation after writing a colormap Resolves #3133 * Appease flake8
27 lines
837 B
Python
27 lines
837 B
Python
"""Colormap tests."""
|
|
|
|
import rasterio
|
|
from rasterio.enums import ColorInterp
|
|
|
|
|
|
def test_write_colormap(tmp_path):
|
|
with rasterio.open("tests/data/shade.tif") as src:
|
|
shade = src.read(1)
|
|
profile = src.profile
|
|
|
|
profile["driver"] = "PNG"
|
|
|
|
with rasterio.open(tmp_path / "test.tif", "w", **profile) as dst:
|
|
dst.write(shade, indexes=1)
|
|
dst.write_colormap(1, {0: (255, 0, 0, 255), 255: (0, 0, 0, 0)})
|
|
assert dst.colorinterp == (ColorInterp.palette,)
|
|
cmap = dst.colormap(1)
|
|
assert cmap[0] == (255, 0, 0, 255)
|
|
assert cmap[255] == (0, 0, 0, 0)
|
|
|
|
with rasterio.open(tmp_path / "test.tif") as src:
|
|
assert src.colorinterp == (ColorInterp.palette,)
|
|
cmap = src.colormap(1)
|
|
assert cmap[0] == (255, 0, 0, 255)
|
|
assert cmap[255] == (0, 0, 0, 0)
|