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

save_cog_with_dask: Handle single-band SYX #145

Closed mplough-kobold closed 5 months ago

mplough-kobold commented 5 months ago

Previously, save_cog_with_dask could not handle single-band SYX data. The test added in this PR...

    # SYX, one band
    img = xr_zeros(gbox, dtype, chunks=(1, n, n), time=["2000"])
    assert img.ndim == 3
    assert img.odc.ydim == 1
    fname = str(tmp_path / "cog-syx-one-band.tif")
    fut = save_cog_with_dask(img, fname, compression="deflate", level=2)
    rr = fut.compute()
    assert str(rr) == fname

...failed as follows:

tests/test_cog.py:440:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
odc/geo/cog/_tifffile.py:678: in save_cog_with_dask
    meta, hdr0 = _make_empty_cog(
odc/geo/cog/_tifffile.py:225: in _make_empty_cog
    tw.write(

...

E           ValueError: <PLANARCONFIG.SEPARATE: 2> does not match <StoredShape(frames=1, separate_samples=1, depth=1, length=1024, width=1024, contig_samples=1, extrasamples=0)>

/python/lib/python3.11/site-packages/tifffile/tifffile.py:2559: ValueError

This PR fixes the issue. I loaded the TIFF file produced by the new test into QGIS and noted that it loaded correctly.