opendatacube / odc-geo

GeoBox and geometry utilities extracted from datacube-core
https://odc-geo.readthedocs.io/en/latest/
Apache License 2.0
80 stars 12 forks source link

Fix NaN nodata values in band statistics #143

Closed mplough-kobold closed 5 months ago

mplough-kobold commented 5 months ago

When the save_cog_with_dask function computed statistics on a float32 band that included NaN values and had a nodata value of NaN, the minimum and maximum values were incorrectly computed as NaN.

When the save_cog_with_dask function computed statistics on a float32 band that included NaN values and had a finite nodata value, the NaN values were included in the statistics computation. Although the correct behavior here is debatable, the best thing to do is to match GDAL and GDAL excludes the NaN values.

This PR updates NaN value handling in statistics computations and adds test coverage to verify how things are handled.

Note that dask.array's nanmin, nanmax, etc. methods are equivalent to min, max, etc. when used with integer data.

codecov[bot] commented 5 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 95.24%. Comparing base (6af5d0c) to head (2199d68). Report is 10 commits behind head on develop.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop #143 +/- ## =========================================== - Coverage 95.26% 95.24% -0.02% =========================================== Files 31 31 Lines 5323 5347 +24 =========================================== + Hits 5071 5093 +22 - Misses 252 254 +2 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.