Thanks for your module--I'm having a go at using in a project at the moment.
I have a geotiff file of float32 data. I've written a Python script to convert this to 4 channels of integers, and then use gdal2tiles to convert it to tiles. The problem is that the data ends up all corrupted: instead of being read as values between 75 and 950 it's being read as -2.318841646091599e+38 and similar. I'm sure it's the Python script that's the problem. Can you give me some guidance on where I might be going wrong? And with respect to your package, it would be great if you could improve your documentation to explain to new users how to do that conversion process (eg with some sample code). I'm sure I'm not the only one who would find this process difficult.
If it helps to know, I'm using macOS.
import numpy as np
import rasterio
# Convert tiff with 1 channel of 32-bit floats to a file with 4 channels of
# 8-bit integers
with rasterio.open('example_input_file.tif') as src:
floats = src.read()
floats[floats==src.nodata]=0 # replace 'nodata' value with zero, as all
# data values will be greater than zero
print("Max",floats.max())
print("Min",np.min(floats[np.nonzero(floats)]))
treated_as_ints = np.zeros((4, floats.shape[1], floats.shape[2]))
for channel in floats:
for i, row in enumerate(channel):
for j, cell in enumerate(row):
a,b,c,d = np.frombuffer(cell, dtype=np.uint8)
treated_as_ints[0][i][j] = a
treated_as_ints[1][i][j] = b
treated_as_ints[2][i][j] = c
treated_as_ints[3][i][j] = d
# Write to a new 4-channel 8-bit file.
profile = src.profile
profile.update(dtype=rasterio.uint8, count=4, compress='lzw', nodata=0)
with rasterio.open('example_output_file.tif', 'w', **profile) as dst:
dst.write(treated_as_ints.astype(rasterio.uint8))
gdal2tiles.py --xyz -w 'leaflet' -z '5' -s 'EPSG:27200' 'example_output_file.tif' tiles