rio-rgbify icon indicating copy to clipboard operation
rio-rgbify copied to clipboard

ValueError for pixel values greater than than 256 ** 3

Open planemad opened this issue 6 years ago • 2 comments

While processing a tif with very large no data value, i get this error:

ValueError: Data of 3.4028234663852886e+38 larger than 256 ** 3

A little unexpected since there is no documentation of this limitation.

planemad avatar Feb 27 '18 09:02 planemad

It's implicit within the value range of possible output. The maximum value that can be represented by 3 position base 256 is:

256 ** 3 = 16777216

3.4028234663852886e+38 is the max/min value of float32, and probably is a nodata value.

There is no way to encode this very large absolute value within the smaller above range. In addition, there isn't any concept of transparent (yet) in this kind of encoding, and no clear path forward.

In order to handle this, you should:

  • Decide on a "fill" pixel value for these nodata areas -- probably 0
  • Set these pixels to the desired value

That said -- thanks for the heads up on documentation. Some docstrings have been written in the code, I should generate some basic api docs on those.

dnomadb avatar Feb 27 '18 15:02 dnomadb

Workaround: you can automatically change nodata values to some other value, for example 0 or base value. To do that, in encoders.py function data_to_rgb, just before first statement of data = data.astype(np.float64) add this line: data[data < 0] = 0 This changes all negative values to 0.

tomass avatar Sep 27 '18 09:09 tomass