gjoseph92 / stackstac

Turn a STAC catalog into a dask-based xarray
https://stackstac.readthedocs.io
MIT License
232 stars 49 forks source link

"errors_as_nodata" not working correctly #243

Open fkroeber opened 5 months ago

fkroeber commented 5 months ago

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()
PGuti commented 2 months ago

I'm experiencing the exact same error using:

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