Skip to content

Commit

Permalink
get accessories with set difference, and set empty in strip
Browse files Browse the repository at this point in the history
  • Loading branch information
Ariana Barzinpour committed Jan 28, 2025
1 parent 679e34e commit 74d2292
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
10 changes: 5 additions & 5 deletions odc/stac/_mdtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,6 @@ def parse_item(
band2grid = template.band2grid
has_proj = False if template.has_proj is False else has_proj_ext(item)
_assets = item.assets
_acc_names = list(_assets.keys())

_grids: Dict[str, GeoBox] = {}
bands: Dict[BandKey, RasterSource] = {}
Expand All @@ -677,14 +676,13 @@ def _get_grid(grid_name: str, asset: pystac.asset.Asset) -> GeoBox:
_grids[grid_name] = grid
return grid

band_names = []
for bk, meta in template.meta.bands.items():
asset_name, band_idx = bk
asset = _assets.get(asset_name)
if asset is None:
continue
# the assets that aren't bands should be accessories
if asset_name in _acc_names:
_acc_names.remove(asset_name)
band_names.append(asset_name)

grid_name = band2grid.get(asset_name, "default")
geobox: Optional[GeoBox] = _get_grid(grid_name, asset) if has_proj else None
Expand Down Expand Up @@ -715,7 +713,9 @@ def _get_grid(grid_name: str, asset: pystac.asset.Asset) -> GeoBox:
driver_data=driver_data,
)

accessories = {name: {"path": _assets[name].href} for name in _acc_names}
# the assets that aren't bands are accessories
acc_names = set(_assets.keys()).difference(set(band_names))
accessories = {name: {"path": _assets[name].href} for name in acc_names}

md = item.common_metadata
return ParsedItem(
Expand Down
2 changes: 1 addition & 1 deletion odc/stac/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ def strip(self) -> "ParsedItem":
"""
Copy of self but with stripped bands.
"""
return replace(self, bands={k: band.strip() for k, band in self.bands.items()})
return replace(self, bands={k: band.strip() for k, band in self.bands.items()}, accessories={})

def assets(self) -> Dict[str, List[RasterSource]]:
"""
Expand Down
1 change: 1 addition & 0 deletions tests/test_mdtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ def test_accessories_preserved(ga_landsat_stac: pystac.item.Item):
assert xx.accessories.get("thumbnail:nbart")
assert xx.accessories.get("checksum:sha1")
assert xx.accessories.get("metadata:processor")
assert xx.strip().accessories == {}


@pytest.fixture
Expand Down

0 comments on commit 74d2292

Please sign in to comment.