No colormapping support for float dtype #659
-
I'm working with some rasters that have At present, using a colormap with non-integer dtype rasters errors with rio-tiler: from rio_tiler.io import Reader
from rio_tiler.colormap import cmap
reader = Reader("test_raster_float64.tif")
reader.tile(0, 0, 0).render(
img_format="png",
colormap=cmap.get("viridis"),
)
Code to create the tiff: import rasterio
import numpy as np
from rasterio.transform import from_origin
# Create an array of float64 values
data = np.random.rand(100, 100).astype('float64')
# Define the transformation and metadata
transform = from_origin(0, 0, 1, 1) # Assuming a basic transformation
metadata = {
'driver': 'GTiff',
'height': data.shape[0],
'width': data.shape[1],
'count': 1,
'dtype': 'float64',
'crs': '+proj=latlong',
'transform': transform
}
# Create a test raster file
with rasterio.open('test_raster_float64.tif', 'w', **metadata) as dst:
dst.write(data, 1) I'm wondering if there is an easy way to rescale my image before rendering to avoid this error and the warning that will happen when not using a colormap? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
@banesullivan-kobold Colormaps work with https://cogeotiff.github.io/rio-tiler/intro/#rescale-non-byte-data-andor-apply-colormap |
Beta Was this translation helpful? Give feedback.
@banesullivan-kobold Colormaps work with
uint8
data (0->255) meaning that you'll have to first rescale the data from amin-max
https://cogeotiff.github.io/rio-tiler/intro/#rescale-non-byte-data-andor-apply-colormap
see https://cogeotiff.github.io/rio-tiler/colormap/