Skip to content

Commit 74d2292

Browse files
author
Ariana Barzinpour
committed
get accessories with set difference, and set empty in strip
1 parent 679e34e commit 74d2292

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

odc/stac/_mdtools.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,6 @@ def parse_item(
660660
band2grid = template.band2grid
661661
has_proj = False if template.has_proj is False else has_proj_ext(item)
662662
_assets = item.assets
663-
_acc_names = list(_assets.keys())
664663

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

679+
band_names = []
680680
for bk, meta in template.meta.bands.items():
681681
asset_name, band_idx = bk
682682
asset = _assets.get(asset_name)
683683
if asset is None:
684684
continue
685-
# the assets that aren't bands should be accessories
686-
if asset_name in _acc_names:
687-
_acc_names.remove(asset_name)
685+
band_names.append(asset_name)
688686

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

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

720720
md = item.common_metadata
721721
return ParsedItem(

odc/stac/model.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ def strip(self) -> "ParsedItem":
400400
"""
401401
Copy of self but with stripped bands.
402402
"""
403-
return replace(self, bands={k: band.strip() for k, band in self.bands.items()})
403+
return replace(self, bands={k: band.strip() for k, band in self.bands.items()}, accessories={})
404404

405405
def assets(self) -> Dict[str, List[RasterSource]]:
406406
"""

tests/test_mdtools.py

+1
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ def test_accessories_preserved(ga_landsat_stac: pystac.item.Item):
400400
assert xx.accessories.get("thumbnail:nbart")
401401
assert xx.accessories.get("checksum:sha1")
402402
assert xx.accessories.get("metadata:processor")
403+
assert xx.strip().accessories == {}
403404

404405

405406
@pytest.fixture

0 commit comments

Comments
 (0)