mapbox / rio-rgbify

Encoded arbitrary bit depth rasters in pseudo base-256
MIT License
102 stars 38 forks source link

ValueError for pixel values greater than than 256 ** 3 #16

Open planemad opened 6 years ago

planemad commented 6 years ago

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.

dnomadb commented 6 years ago

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:

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.

tomass commented 6 years ago

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_torgb, just before first statement of data = data.astype(np.float64) add this line: data[data < 0] = 0 This changes all negative values to 0.