gdal_translate -scale
from osgeo import gdal
ds = gdal.Translate("/vsimem/scl.tif", "autotest/gcore/data/float32.tif", options = "-scale")
ds.GetRasterBand(1).ComputeRasterMinMax()
#(0.0, 255.99899291992188)
replace "autotest/..." above with this for general online use without the source tree
ds = gdal.Translate("/vsimem/scl.tif", "/vsicurl/https://github.com/OSGeo/gdal/raw/master/autotest/gcore/data/float24.tif", options = "-scale")
generate specific data:
from osgeo import gdal
import struct
ln = 16
ds = gdal.GetDriverByName("GTiff").Create("/vsimem/scaled.tif", 1, ln, 1, gdal.GDT_Float32)
ds.GetRasterBand(1).WriteRaster(0, 0, 1, ln, b"".join(struct.pack("f", v) for v in range(ln)))
ds = None
ds = gdal.Translate("/vsimem/scaled1.tif", "/vsimem/scaled.tif", options = "-scale")
ds.GetRasterBand(1).ComputeRasterMinMax()
# (0.0, 255.99899291992188)