mapbox / rio-rgbify

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

Fix nodata values at source edges #38

Open systemed opened 2 years ago

systemed commented 2 years ago

This is in case anyone else runs into the same issue, really.

I was having issues with artefacts at the edges of source images, caused by nodata values. Adding a call to numpy's nan_to_num in data_to_rgb (encoders.py) fixes it:

data /= interval
data = np.nan_to_num(data, True, 100000.0)
data = np.around(data / 2**round_digits) * 2**round_digits

(100000.0 is from the -b and -i values of my invocation and shouldn't be hardcoded, obviously.)