Skip to content

Commit

Permalink
fix: band resolution for multi-band assets #113
Browse files Browse the repository at this point in the history
Band name is now:

- Asset name when only one band per asset
- Alias if set and unique
- f"{asset}.{idx}" when multi-band and no aliases defined
  • Loading branch information
Kirill888 committed May 13, 2023
1 parent ea985be commit e2e5313
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion odc/stac/_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ def band_aliases(self, unique: bool = False) -> Dict[BandKey, List[str]]:

def _norm_key(self, k: BandKey) -> str:
asset, idx = k
if idx == 1:

# if single band asset it's just asset name
if idx == 1 and (asset, 2) not in self.bands:
return asset

# if any alias references this key as first choice return that
Expand Down
4 changes: 2 additions & 2 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def test_collection(collection_ab: RasterCollectionMetadata):
def test_collection_allbands():
xx = mk_parsed_item([b_("a.1"), b_("a.2"), b_("a.3")])
md = xx.collection
assert md.all_bands == ["a", "a.2", "a.3"]
assert md.all_bands == ["a.1", "a.2", "a.3"]

md.aliases["AA"] = [("a", 2)]
md.aliases["AAA"] = [("a", 3)]
Expand All @@ -142,7 +142,7 @@ def test_collection_allbands():

# expect aliases to be used for all_band when multi-band
# assets have unique aliases
assert md.all_bands == ["a", "AA", "AAA"]
assert md.all_bands == ["a.1", "AA", "AAA"]
assert md.canonical_name("a.2") == "AA"
assert md.canonical_name("AA") == "AA"
assert md.canonical_name("a.3") == "AAA"
Expand Down

0 comments on commit e2e5313

Please sign in to comment.