cogeotiff / rio-tiler

User friendly Rasterio plugin to read raster datasets.
https://cogeotiff.github.io/rio-tiler/
BSD 3-Clause "New" or "Revised" License
511 stars 106 forks source link

nodata value being ignored for NaN #690

Closed cerolinx closed 6 months ago

cerolinx commented 6 months ago

The #672 do not work with numpy NaN. numpy.float32('nan') == numpy.float32('nan') and numpy.float64('nan') == numpy.float64('nan') are evaluated False.

Proposal (Line 240 in rio-tiler/rio_tiler/reader.py):

            # if data has Nodata then we simply make sure the mask == the nodata
            if nodata is not None:
                if numpy.isnan(nodata):
                    data.mask = numpy.isnan(data.data)
                else:
                    data.mask = data.data == nodata

The tile form my float32 dataset with NaN as nodata before:

tile_b

And after:

tile

Thanks!

vincentsarago commented 6 months ago

thanks for the report @cerolinx 🙏

would you be able to submit a PR (with tests)?

Thanks

vincentsarago commented 6 months ago

closed in #691