From 55574f7ead2923fe826672eed2f108dc42606c5f Mon Sep 17 00:00:00 2001 From: Matt Savoie Date: Wed, 22 May 2024 15:45:49 -0600 Subject: [PATCH] DAS-2146: First stab at pulling correct asset from Item This probably works, but it is a first try. --- harmony_browse_image_generator/adapter.py | 26 ++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/harmony_browse_image_generator/adapter.py b/harmony_browse_image_generator/adapter.py index 77d86f7..74f4291 100644 --- a/harmony_browse_image_generator/adapter.py +++ b/harmony_browse_image_generator/adapter.py @@ -65,18 +65,34 @@ def validate_message(self): 'Harmony ScaleExtents must be in order [xmin,ymin,xmax,ymax].' ) + def asset_from_item(self, item: Item) -> Asset: + """Returns the correct asset from a stac Item. + + Find an asset with 'visual' in any of the item's values' roles. + If not found return the asset that has 'data' in its item's values' roles. + """ + try: + return next( + item_asset + for item_asset in item.assets.values() + if 'visual' in (item_asset.roles or []) + ) + except StopIteration: + return next( + item_asset + for item_asset in item.assets.values() + if 'data' in (item_asset.roles or []) + ) + def process_item(self, item: Item, source: HarmonySource) -> Item: """Processes a single input STAC item.""" + try: working_directory = mkdtemp() results = item.clone() results.assets = {} - asset = next( - item_asset - for item_asset in item.assets.values() - if 'data' in (item_asset.roles or []) - ) + asset = self.asset_from_item(item) color_palette = get_color_palette_from_item(item)