Skip to content

Commit

Permalink
Merge branch 'main' into js/kerchunk-stacking
Browse files Browse the repository at this point in the history
  • Loading branch information
jsignell committed Apr 5, 2024
2 parents b1688a7 + 7b77ecc commit 40f381b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def test_to_xarray_with_pystac_client_search_passes_kwargs_through(simple_search
def test_to_xarray_with_different_stacking_library(simple_search, stacking_library):
ds = to_xarray(simple_search, stacking_library=stacking_library)
assert isinstance(ds, xr.Dataset)
assert "band" not in ds.dims


def test_to_xarray_with_drop_variables_raises(simple_search):
Expand Down
12 changes: 11 additions & 1 deletion xpystac/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,17 @@ def _(
return odc_stac.load(items, **{"chunks": {"x": 1024, "y": 1024}, **kwargs})
elif stacking_library == "stackstac":
stackstac = _import_optional_dependency("stackstac")
return stackstac.stack(obj, **kwargs).to_dataset(dim="band", promote_attrs=True)
da = stackstac.stack(obj, **kwargs)
bands = {}
for band in da.band.values:
b = da.sel(band=band)
scalar_coords = {k: v.item() for k, v in b.coords.items() if v.shape == ()}
b = b.assign_attrs(
**{k: v for k, v in scalar_coords.items() if v is not None}
)
b = b.drop_vars(scalar_coords)
bands[band] = b
return xarray.Dataset(bands, attrs=da.attrs)
else:
media_type = kwargs.get("media_type")
role = kwargs.get("role")
Expand Down

0 comments on commit 40f381b

Please sign in to comment.