Skip to content

Commit

Permalink
Merge pull request #80 from stac-utils/fix/rde/sentinel2
Browse files Browse the repository at this point in the history
Sentinel2: Use band id as the asset keys for image band assets.
  • Loading branch information
lossyrob authored Mar 24, 2021
2 parents bfdb7cb + 4be4188 commit e29546e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 4 additions & 3 deletions stactools_sentinel2/stactools/sentinel2/stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ def create_item(
for image_path in product_metadata.image_paths
])

for asset in image_assets.items():
item.add_asset(*asset)
for key, asset in image_assets.items():
assert key not in item.assets
item.add_asset(key, asset)

# Thumbnail

Expand Down Expand Up @@ -205,7 +206,7 @@ def set_asset_properties(asset):
roles=['data'])
item.ext.eo.set_bands([SENTINEL_BANDS[band_id]], asset)
set_asset_properties(asset)
return (asset_href[-7:].replace('_', '-'), asset)
return (band_id, asset)

# Handle auxiliary images

Expand Down
9 changes: 9 additions & 0 deletions tests/sentinel2/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from stactools.core.projection import reproject_geom
from stactools.sentinel2.commands import create_sentinel2_command
from stactools.sentinel2.constants import SENTINEL_BANDS
from tests.utils import (TestData, CliTestCase)


Expand Down Expand Up @@ -56,7 +57,15 @@ def check_proj_bbox(item):

item.validate()

bands_seen = set()

for asset in item.assets.values():
self.assertTrue(is_absolute_href(asset.href))
bands = item.ext.eo.get_bands(asset)
if bands is not None:
bands_seen |= set(b.name for b in bands)

self.assertEqual(bands_seen,
set(SENTINEL_BANDS.keys()))

check_proj_bbox(item)

0 comments on commit e29546e

Please sign in to comment.