opendatacube / odc-geo

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

Reproject replaces 0 with -1 if nodata is not set #172

Open simonreise opened 3 months ago

simonreise commented 3 months ago

I have a custom Landsat cloud mask based on QA band with values 0 and 1 and a Landsat panchromatic band. When I try to match cloud mask to a resolution of a panchromatic band with odc.reproject, 0's in a mask are replaced with -1's.

mask_pan = mask.odc.reproject(pan.odc.geobox).persist()
mask.rio.nodata == None                  # True (nodata is not set)
mask_pan.rio.nodata == None              # True (nodata is not set)
mask.data[0][2000][2000].compute()       # 0 (0 - data, 1 - cloud)
mask_pan.data[0][4000][4000].compute()   # -1 (panchromatic band is 2x larger than the others)
np.unique(mask)                          # array([0, 1])
np.unique(mask_pan)                      # array([-1,  1])

But, for example, if we set a nodata in mask, or pass dst_nodata=-1 arg, then 0's are not replaced.

Also, it happens only if data is integer, and everything works correctly if data is float.

P.S. Here is also a notebook with minimum examples that shows the cases when this bug occurs and when it does not. https://colab.research.google.com/drive/1MPoYkNOsBAZ6CBOSitYxtR1mhwn1QMU5?usp=sharing

SpacemanPaul commented 3 months ago

Hi Simon.

1) What odc-geo version are you using?

import odc.geo as geo
geo.__version__

2) mask_pan.odc.nodata == mask_pan.rio.nodata?

simonreise commented 3 months ago
  1. odc-geo version: 0.4.8
  2. mask_pan.odc.nodata == mask_pan.rio.nodata is True