opendatacube / odc-geo

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

'save_cog_with_dask' fails with numpy > 2 #189

Open remi-braun opened 4 days ago

remi-braun commented 4 days ago

Hello,

With numpy <2, save_cog_with_dask fails because illegal casting.

This issue is based on this discussion: https://discourse.pangeo.io/t/save-cog-with-dask-cannot-convert-fill-value-999999-to-dtype-uint8/4713/9

As @maxrjones said there:

This is most likely coming from NumPy’s defaults for masked arrays - numpy.ma.default_fill_value — NumPy v2.1 Manual.

Minimal working example:

import numpy as np
import rioxarray as rxr
from odc.geo import cog, xr  # noqa
xds = rxr.open_rasterio(r"not_cog.tif", chunks=True)
nodata = 0
cog.save_cog_with_dask(
    xds.copy(data=xds.fillna(nodata).astype(np.uint8)).rio.set_nodata(
        nodata
    ),
    r"cog.tif",
).compute()

Data : not_cog.zip

I'm on Windows, maybe this doesn't help...

remi-braun commented 3 days ago

Maybe linked to https://github.com/numpy/numpy/issues/25677 and more specifically this comment