stackstac icon indicating copy to clipboard operation
stackstac copied to clipboard

"errors_as_nodata" not working correctly

Open fkroeber opened this issue 1 year ago • 1 comments

In the following example, the errors_as_nodata parameter of stackstac.stack() causes a shape-related error down the way. The NodataReader returns an object with 2 dimensions missing the band dimension ("Unexpected shape (485, 1024), expected exactly 1 band.").

import planetary_computer as pc
import stackstac 
from pystac_client import Client
from rasterio.errors import RasterioIOError
from shapely.geometry import box

# load some data with broken links
t_start = "2022-05-15"
t_end = "2022-06-01"
xmin, ymin, xmax, ymax = 142.13,-34.2,142.18,-34.15

catalog = Client.open(
    "https://planetarycomputer.microsoft.com/api/stac/v1", 
    modifier=pc.sign_inplace
    )
query = catalog.search(
    collections="landsat-c2-l2",
    datetime=[t_start, t_end],
    limit=100,
    intersects=box(xmin, ymin, xmax, ymax)
)
item_coll = query.item_collection()
item_coll

# try to stack them 
cube = stackstac.stack(
    item_coll,
    assets=["red"],
    epsg=3857,
    resolution=(30,30),
    errors_as_nodata=(RasterioIOError(".*"),),
    xy_coords="center",
    snap_bounds=False,
)
data = cube.compute()

fkroeber avatar Mar 06 '24 22:03 fkroeber

I'm experiencing the exact same error using:

  • rasterio=='1.3.9'
  • xarray=='2023.12.0'
  • planetary_computer=='1.0.0'
  • stackstac=='0.5.0'
  • dask =='2024.2.0'

EDIT: So we made our code work by downgrading to stackstac 0.4.4.

PGuti avatar May 07 '24 08:05 PGuti

Thanks for reporting @fkroeber. I believe this should be fixed in https://github.com/gjoseph92/stackstac/pull/256.

gjoseph92 avatar Aug 10 '24 03:08 gjoseph92