Skip to content

Commit abfa723

Browse files
authored
Merge pull request #243 from emmanuelmathot/feature/eo-bands-assets-only
Get eo bands defined in assets only
2 parents e695f2c + 3a282e5 commit abfa723

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

pystac/extensions/eo.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def get_bands(self, asset=None):
5555
"""Gets an Item or an Asset bands.
5656
5757
If an Asset is supplied and the bands property exists on the Asset,
58-
returns the Asset's value. Otherwise returns the Item's value
58+
returns the Asset's value. Otherwise returns the Item's value or
59+
all the asset's eo bands
5960
6061
Returns:
6162
List[Band]
@@ -65,6 +66,13 @@ def get_bands(self, asset=None):
6566
else:
6667
bands = self.item.properties.get('eo:bands')
6768

69+
# get assets with eo:bands even if not in item
70+
if asset is None and bands is None:
71+
bands = []
72+
for (key, value) in self.item.get_assets().items():
73+
if 'eo:bands' in value.properties:
74+
bands.extend(value.properties.get('eo:bands'))
75+
6876
if bands is not None:
6977
bands = [Band(b) for b in bands]
7078

tests/extensions/test_eo.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ def test_asset_bands(self):
6161
asset_bands = eo_item.ext.eo.get_bands(index_asset)
6262
self.assertIs(None, asset_bands)
6363

64+
# No asset specified
65+
asset_bands = eo_item.ext.eo.get_bands()
66+
self.assertIsNot(None, asset_bands)
67+
6468
# Set
6569
b2_asset = eo_item.assets['B2']
6670
self.assertEqual(eo_item.ext.eo.get_bands(b2_asset)[0].name, "B2")

0 commit comments

Comments
 (0)